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
I try my best to do but I am struggling with the highlighted in red
/* USB Standard Device Descriptor */ const uint8_t USB_DeviceDescriptor[] = { USB_DEVICE_DESC_SIZE, /* bLength */ USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(0x0200), /* 2.00 */ /* bcdUSB */ 0x00, /* bDeviceClass */ 0x00, /* bDeviceSubClass */ 0x00, /* bDeviceProtocol */ USB_MAX_PACKET0, /* bMaxPacketSize0 */ WBVAL(0x1FD3), /* idVendor */ WBVAL(0x4063), /* idProduct */ WBVAL(0x0100), /* 1.00 */ /* bcdDevice */ 0x01, /* iManufacturer */ 0x02, /* iProduct */ 0x03, /* iSerialNumber */ 0x01 /* bNumConfigurations: one possible configuration*/ }; /* USB Configuration Descriptor */ /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */ const uint8_t USB_ConfigDescriptor[] = { /* Configuration 1 */ USB_CONFIGUARTION_DESC_SIZE, /* bLength */ USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL( /* wTotalLength */ USB_CONFIGUARTION_DESC_SIZE + USB_INTERFACE_DESC_SIZE + AUDIO_CONTROL_INTERFACE_DESC_SZ(1) + AUDIO_INPUT_TERMINAL_DESC_SIZE + AUDIO_FEATURE_UNIT_DESC_SZ(1,1) + AUDIO_OUTPUT_TERMINAL_DESC_SIZE + AUDIO_INPUT_TERMINAL_DESC_SIZE + AUDIO_OUTPUT_TERMINAL_DESC_SIZE + USB_INTERFACE_DESC_SIZE + AUDIO_STREAMING_INTERFACE_DESC_SIZE + USB_INTERFACE_DESC_SIZE + AUDIO_STREAMING_INTERFACE_DESC_SIZE + AUDIO_STREAMING_GENERAL + AUDIO_FEATURE_UNIT_DESC_SZ(1,1) + USB_INTERFACE_DESC_SIZE + USB_INTERFACE_DESC_SIZE + AUDIO_STREAMING_INTERFACE_DESC_SIZE + AUDIO_FORMAT_TYPE_I_DESC_SZ(1) + AUDIO_STANDARD_ENDPOINT_DESC_SIZE + AUDIO_STREAMING_ENDPOINT_DESC_SIZE + AUDIO_STANDARD_ENDPOINT_DESC_SIZE ), 0x03, /* bNumInterfaces */ 0x01, /* bConfigurationValue */ 0x00, /* iConfiguration */ USB_CONFIG_BUS_POWERED, /* bmAttributes */ USB_CONFIG_POWER_MA(100), /* bMaxPower */ /* Interface 0, Alternate Setting 0, Audio Control */ USB_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ 0x00, /* bInterfaceNumber */ 0x00, /* bAlternateSetting */ 0x00, /* bNumEndpoints */ USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ AUDIO_SUBCLASS_AUDIOCONTROL, /* bInterfaceSubClass */ AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ 0x00, /* iInterface */ /* Audio Control Interface */ AUDIO_CONTROL_INTERFACE_DESC_SZ(1), /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_CONTROL_HEADER, /* bDescriptorSubtype */ WBVAL(0x0100), /* 1.00 */ /* bcdADC */ WBVAL( /* wTotalLength */ AUDIO_CONTROL_INTERFACE_DESC_SZ(1) + AUDIO_INPUT_TERMINAL_DESC_SIZE + AUDIO_FEATURE_UNIT_DESC_SZ(1,1) + AUDIO_OUTPUT_TERMINAL_DESC_SIZE ), 0x02, /* bInCollection */ 0x01, /* baInterfaceNr */ 0x02 /* baInterfaceNr */
/* 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, };
Are we ready to move on yet?
USB Composite Device Connection Status Device connected Current Configuration 0 Speed Full Device Address 2 Number Of Open Pipes 0 Device Descriptor NXP LPC17xx Speaker Offset Field Size Value Description 0 bLength 1 12h 1 bDescriptorType 1 01h Device 2 bcdUSB 2 0200h USB Spec 2.0 4 bDeviceClass 1 00h Class info in Ifc Descriptors 5 bDeviceSubClass 1 00h 6 bDeviceProtocol 1 00h 7 bMaxPacketSize0 1 40h 64 bytes 8 idVendor 2 1FD4h 10 idProduct 2 4064h 12 bcdDevice 2 0100h 1.00 14 iManufacturer 1 01h "NXP Semicond " 15 iProduct 1 02h "NXP LPC17xx Speaker " 16 iSerialNumber 1 03h "DEMO00000000" 17 bNumConfigurations 1 01h Configuration Descriptor 1 Bus Powered, 100 mA Offset Field Size Value Description 0 bLength 1 09h 1 bDescriptorType 1 02h Configuration 2 wTotalLength 2 00B7h 4 bNumInterfaces 1 03h 5 bConfigurationValue 1 01h 6 iConfiguration 1 00h 7 bmAttributes 1 80h Bus Powered 4..0: Reserved ...00000 5: Remote Wakeup ..0..... No 6: Self Powered .0...... No, Bus Powered 7: Reserved (set to one) (bus-powered for 1.0) 1....... 8 bMaxPower 1 32h 100 mA Interface Descriptor 0/0 Audio, 0 Endpoints Offset Field Size Value Description 0 bLength 1 09h 1 bDescriptorType 1 04h Interface 2 bInterfaceNumber 1 00h 3 bAlternateSetting 1 00h 4 bNumEndpoints 1 00h 5 bInterfaceClass 1 01h Audio 6 bInterfaceSubClass 1 01h Audio Control 7 bInterfaceProtocol 1 00h 8 iInterface 1 00h Audio Control Interface Header Descriptor Offset Field Size Value Description 0 bLength 1 09h 1 bDescriptorType 1 24h Audio Control Interface Header 2 7 01 00 01 27 00 01 01 Audio Control Input Terminal Descriptor Offset Field Size Value Description 0 bLength 1 0Ch 1 bDescriptorType 1 24h Audio Control Input Terminal 2 10 02 01 01 01 00 01 00 00 00 00 Audio Control Feature Unit Descriptor Offset Field Size Value Description 0 bLength 1 09h 1 bDescriptorType 1 24h Audio Control Feature Unit 2 7 06 02 01 01 03 00 00 Audio Control Output Terminal Descriptor Offset Field Size Value Description 0 bLength 1 09h 1 bDescriptorType 1 24h Audio Control Output Terminal 2 7 03 03 01 03 00 02 00 Audio Control Input Terminal Descriptor Offset Field Size Value Description 0 bLength 1 0Ch 1 bDescriptorType 1 24h Audio Control Input Terminal 2 10 02 04 01 02 00 01 00 00 00 00 Audio Control Output Terminal Descriptor Offset Field Size Value Description 0 bLength 1 09h 1 bDescriptorType 1 24h Audio Control Output Terminal 2 7 03 05 01 01 00 04 00 Interface Descriptor 1/0 Audio, 0 Endpoints Offset Field Size Value Description 0 bLength 1 09h 1 bDescriptorType 1 04h Interface 2 bInterfaceNumber 1 01h 3 bAlternateSetting 1 00h 4 bNumEndpoints 1 00h 5 bInterfaceClass 1 01h Audio 6 bInterfaceSubClass 1 02h Audio Streaming 7 bInterfaceProtocol 1 00h 8 iInterface 1 00h Interface Descriptor 1/1 Audio, 1 Endpoint Offset Field Size Value Description 0 bLength 1 09h 1 bDescriptorType 1 04h Interface 2 bInterfaceNumber 1 01h 3 bAlternateSetting 1 01h 4 bNumEndpoints 1 01h 5 bInterfaceClass 1 01h Audio 6 bInterfaceSubClass 1 02h Audio Streaming 7 bInterfaceProtocol 1 00h 8 iInterface 1 00h
Audio Streaming Interface Descriptor Offset Field Size Value Description 0 bLength 1 07h 1 bDescriptorType 1 24h Audio Streaming Interface 2 5 01 01 00 01 00 Audio Streaming Format Type Descriptor Offset Field Size Value Description 0 bLength 1 0Bh 1 bDescriptorType 1 24h Audio Streaming Format Type 2 9 02 01 01 02 10 01 00 7D 00 Endpoint Descriptor 03 3 Out, Isochronous, 1 ms Offset Field Size Value Description 0 bLength 1 09h 1 bDescriptorType 1 05h Endpoint 2 bEndpointAddress 1 03h 3 Out 3 bmAttributes 1 01h Isochronous, No Sync, Data 1..0: Transfer Type ......01 Isochronous 3..2: Sync Type ....00.. No Sync 5..4: Usage Type ..00.... Data 7..6: Reserved 00...... 4 wMaxPacketSize 2 0042h 66 bytes 6 bInterval 1 01h 1 ms 7 bRefresh 1 00h 8 bSynchAddress 1 00h Audio Streaming Isochronous Audio Data Endpoint Descriptor Offset Field Size Value Description 0 bLength 1 07h 1 bDescriptorType 1 25h Audio Streaming Isochronous Audio Data Endpoint 2 5 01 00 00 00 00 Interface Descriptor 2/0 Audio, 0 Endpoints Offset Field Size Value Description 0 bLength 1 09h 1 bDescriptorType 1 04h Interface 2 bInterfaceNumber 1 02h 3 bAlternateSetting 1 00h 4 bNumEndpoints 1 00h 5 bInterfaceClass 1 01h Audio 6 bInterfaceSubClass 1 02h Audio Streaming 7 bInterfaceProtocol 1 00h 8 iInterface 1 00h Interface Descriptor 2/1 Audio, 1 Endpoint Offset Field Size Value Description 0 bLength 1 09h 1 bDescriptorType 1 04h Interface 2 bInterfaceNumber 1 02h 3 bAlternateSetting 1 01h 4 bNumEndpoints 1 01h 5 bInterfaceClass 1 01h Audio 6 bInterfaceSubClass 1 02h Audio Streaming 7 bInterfaceProtocol 1 00h 8 iInterface 1 00h Audio Streaming Interface Descriptor Offset Field Size Value Description 0 bLength 1 07h 1 bDescriptorType 1 24h Audio Streaming Interface 2 5 01 05 01 01 00 Audio Streaming Format Type Descriptor Offset Field Size Value Description 0 bLength 1 0Bh 1 bDescriptorType 1 24h Audio Streaming Format Type 2 9 02 01 01 02 10 01 00 7D 00 Endpoint Descriptor 83 3 In, Isochronous, 1 ms Offset Field Size Value Description 0 bLength 1 09h 1 bDescriptorType 1 05h Endpoint 2 bEndpointAddress 1 83h 3 In 3 bmAttributes 1 01h Isochronous, No Sync, Data 1..0: Transfer Type ......01 Isochronous 3..2: Sync Type ....00.. No Sync 5..4: Usage Type ..00.... Data 7..6: Reserved 00...... 4 wMaxPacketSize 2 0042h 66 bytes 6 bInterval 1 01h 1 ms 7 bRefresh 1 00h 8 bSynchAddress 1 00h Audio Streaming Isochronous Audio Data Endpoint Descriptor Offset Field Size Value Description 0 bLength 1 07h 1 bDescriptorType 1 25h Audio Streaming Isochronous Audio Data Endpoint 2 5 01 00 00 00 00
Post C file here to big to fit on forum
http://pastebin.com/KiPJEGBD