Could you help teach me, how to add a microphone input to this usb audio code.
MCB1700 Sample Code Bundle for LPC17xx Peripherals using Keil's MDK-ARM V2.00 (Jan 10, 2011) ics.nxp.com/.../mcb1700.code.bundle.lpc17xx.keil.zip
Could we start with the usbuser.c file and the changes that must be made,
thankyou.
The USB Audio spec shows a descriptor example for Microphone. www.usb.org/.../audio10.pdf Appendix B. Example 1: USB Microphone (Informative)
Modify the descriptors (usbdesc.c) of the example, first.
For Audio Control Interface, - Append "B.3.3.3 Input Terminal Descriptor" and "B.3.3.4 Output Terminal Descriptor" from the microphone example after the original Audio Output Terminal. - Tune the bTerminalID and bSourceID values of these descriptors, so that they don't conflict with the original speaker's. (bTerminalID = 4, 5 bSourceID = 4) - Increase wTotalLength of Class-specific AC Interface Descriptor by these terminal descriptors.
For the extra Audio Streaming Interface of microphone, - Append the descriptors from "B.3.4.1.1.1 Standard AS Interface Descriptor" to "B.3.4.2.1.5 Class-specific Isochronous Audio Data Endpoint Descriptor" on the spec, after the last descriptor of the original. - Change bInterfaceNumber of two Interface descriptors into 2 - Match bTerminalLink of "Class-specific AS General Interface Descriptor" with the bTerminalID (5) of above Output Terminal Descriptor
Lastly, tune the Config descriptor - wTotalLength: Add the size of extra descriptors - bNumInterfaces: from 2 to 3
At this stage of modification, the microphone interface should be recognized by your PC. When you finish this modification successfully, we move to the next step ;-)
Tsuneo
/* Audio Input Terminal (Speaker)*/ AUDIO_INPUT_TERMINAL_DESC_SIZE, /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_CONTROL_INPUT_TERMINAL, /* bDescriptorSubtype */ 0x01, /* bTerminalID */ WBVAL(AUDIO_TERMINAL_USB_STREAMING), /* wTerminalType */ 0x00, /* bAssocTerminal */ 0x01, /* bNrChannels */ WBVAL(AUDIO_CHANNEL_M), /* wChannelConfig */ 0x00, /* iChannelNames */ 0x00, /* iTerminal */ /* Audio Feature Unit */ AUDIO_FEATURE_UNIT_DESC_SZ(1,1), /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_CONTROL_FEATURE_UNIT, /* bDescriptorSubtype */ 0x02, /* bUnitID */ 0x01, /* bSourceID */ 0x01, /* bControlSize */ AUDIO_CONTROL_MUTE | AUDIO_CONTROL_VOLUME, /* bmaControls(0) */ 0x00, /* bmaControls(1) */ 0x00, /* iTerminal */ /* Audio Output Terminal (Speaker)*/ AUDIO_OUTPUT_TERMINAL_DESC_SIZE, /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_CONTROL_OUTPUT_TERMINAL, /* bDescriptorSubtype */ 0x03, /* bTerminalID */ WBVAL(AUDIO_TERMINAL_SPEAKER), /* wTerminalType */ 0x00, /* bAssocTerminal */ 0x02, /* bSourceID */ 0x00, /* iTerminal */ /* Audio Audio Input Terminal (Microphone) */ AUDIO_INPUT_TERMINAL_DESC_SIZE, /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_CONTROL_INPUT_TERMINAL, /* bDescriptorSubtype */ 0x04, /* bTerminalID */ WBVAL(AUDIO_TERMINAL_MICROPHONE), /* wTerminalType */ 0x00, /* bAssocTerminal */ 0x01, /* bNrChannels */ WBVAL(AUDIO_CHANNEL_M), /* wChannelConfig */ 0x00, /* iChannelNames */ 0x00, /* iTerminal */ /* Audio Output Terminal (Microphone) */ AUDIO_OUTPUT_TERMINAL_DESC_SIZE, /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_CONTROL_OUTPUT_TERMINAL, /* bDescriptorSubtype */ 0x05, /* bTerminalID */ WBVAL(AUDIO_TERMINAL_USB_STREAMING), /* wTerminalType */ 0x00, /* bAssocTerminal */ 0x04, /* bSourceID */ 0x00, /* iTerminal */ /* Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith */ USB_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ 0x01, /* bInterfaceNumber */ 0x00, /* bAlternateSetting */ 0x00, /* bNumEndpoints */ USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ 0x00, /* iInterface */
/* Interface 1, Alternate Setting 1, Audio Streaming - Operational */ USB_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ 0x01, /* bInterfaceNumber */ 0x01, /* bAlternateSetting */ 0x01, /* bNumEndpoints */ USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ 0x00, /* iInterface */ /* Audio Streaming Interface */ AUDIO_STREAMING_INTERFACE_DESC_SIZE, /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_STREAMING_GENERAL, /* bDescriptorSubtype */ 0x01, /* bTerminalLink */ 0x00, /* bDelay */ WBVAL(AUDIO_FORMAT_PCM), /* wFormatTag */ /* Audio Type I Format */ AUDIO_FORMAT_TYPE_I_DESC_SZ(1), /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_STREAMING_FORMAT_TYPE, /* bDescriptorSubtype */ AUDIO_FORMAT_TYPE_I, /* bFormatType */ 0x01, /* bNrChannels */ 0x02, /* bSubFrameSize */ 16, /* bBitResolution */ 0x01, /* bSamFreqType */ B3VAL(32000), /* tSamFreq */ /* Endpoint - Standard Descriptor */ AUDIO_STANDARD_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_OUT(3), /* bEndpointAddress */ USB_ENDPOINT_TYPE_ISOCHRONOUS, /* bmAttributes */ WBVAL(66), /* wMaxPacketSize */ 0x01, /* bInterval */ 0x00, /* bRefresh */ 0x00, /* bSynchAddress */ /* Endpoint - Audio Streaming */ AUDIO_STREAMING_ENDPOINT_DESC_SIZE, /* bLength */ AUDIO_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_ENDPOINT_GENERAL, /* bDescriptor */ 0x00, /* bmAttributes */ 0x00, /* bLockDelayUnits */ WBVAL(0x0000), /* wLockDelay */ /* Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith USB_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ 0x02, /* bInterfaceNumber */ 0x00, /* bAlternateSetting */ 0x00, /* bNumEndpoints */ USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ 0x00, /* iInterface */ /* Interface 1, Alternate Setting 1, Audio Streaming - Operational USB_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ 0x02, /* bInterfaceNumber */ 0x01, /* bAlternateSetting */ 0x01, /* bNumEndpoints */ USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ 0x00, /* iInterface */ /* Audio Streaming Interface */ AUDIO_STREAMING_INTERFACE_DESC_SIZE, /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_SUBCLASS_AUDIOCONTROL, /* bDescriptorSubtype */ 0x05, /* bTerminalLink */ (output terminal microphone) 0x01, /* bDelay */ WBVAL(AUDIO_FORMAT_PCM), /* wFormatTag */ /* Audio Type I Format */ AUDIO_FORMAT_TYPE_I_DESC_SZ(1), /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_SUBCLASS_AUDIOSTREAMING , /* bDescriptorSubtype */ AUDIO_FORMAT_TYPE_I, /* bFormatType */ 0x01, /* bNrChannels */ 0x02, /* bSubFrameSize */ 16, /* bBitResolution */ 0x01, /* bSamFreqType */ B3VAL(32000), /* tSamFreq */ /* Endpoint - Standard Descriptor */ AUDIO_STANDARD_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_IN(3), /* bEndpointAddress */ USB_ENDPOINT_TYPE_ISOCHRONOUS, /* bmAttributes */ WBVAL(66), /* wMaxPacketSize */ 0x01, /* bInterval */ 0x00, /* bRefresh */ 0x00, /* bSynchAddress */ /* Endpoint - Audio Streaming */ AUDIO_STREAMING_ENDPOINT_DESC_SIZE, /* bLength */ AUDIO_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_ENDPOINT_GENERAL, /* bDescriptor */ 0x00, /* bmAttributes */ 0x00, /* bLockDelayUnits */ WBVAL(0x0000), /* wLockDelay */ /* Terminator */ 0 /* bLength */ }; /* USB String Descriptor (optional) */ const uint8_t USB_StringDescriptor[] = { /* Index 0x00: LANGID Codes */ 0x04, /* bLength */ USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(0x0409), /* US English */ /* wLANGID */ /* Index 0x01: Manufacturer */ (13*2 + 2), /* bLength (13 Char + Type + lenght) */ USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ 'N',0, 'X',0, 'P',0, ' ',0, 'S',0, 'e',0, 'm',0, 'i',0, 'c',0, 'o',0, 'n',0, 'd',0, ' ',0, /* Index 0x02: Product */ (20*2 + 2), /* bLength ( 20 Char + Type + lenght) */ USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ 'N',0, 'X',0, 'P',0, ' ',0, 'L',0, 'P',0, 'C',0, '1',0, '7',0, 'x',0, 'x',0, ' ',0, 'S',0, 'p',0, 'e',0, 'a',0, 'k',0, 'e',0, 'r',0, ' ',0, /* Index 0x03: Serial Number */ (12*2 + 2), /* bLength (12 Char + Type + lenght) */ USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ 'D',0, 'E',0, 'M',0, 'O',0, '0',0, '0',0, '0',0, '0',0, '0',0, '0',0, '0',0, '0',0, };
View all questions in Keil forum