Browse Source

Add USB audio descriptors (adapted from MickMad)

teensy4-core
PaulStoffregen 8 years ago
parent
commit
47658da91f
2 changed files with 227 additions and 1 deletions
  1. +197
    -1
      teensy3/usb_desc.c
  2. +30
    -0
      teensy3/usb_desc.h

+ 197
- 1
teensy3/usb_desc.c View File

@@ -407,7 +407,14 @@ static uint8_t flightsim_report_desc[] = {
#define KEYMEDIA_INTERFACE_DESC_SIZE 0
#endif

#define CONFIG_DESC_SIZE KEYMEDIA_INTERFACE_DESC_POS+KEYMEDIA_INTERFACE_DESC_SIZE
#define AUDIO_INTERFACE_DESC_POS KEYMEDIA_INTERFACE_DESC_POS+KEYMEDIA_INTERFACE_DESC_SIZE
#ifdef AUDIO_INTERFACE
#define AUDIO_INTERFACE_DESC_SIZE 9+10+12+9+12+9 + 9+9+7+11+9+7 + 9+9+7+11+9+7
#else
#define AUDIO_INTERFACE_DESC_SIZE 0
#endif

#define CONFIG_DESC_SIZE AUDIO_INTERFACE_DESC_POS+AUDIO_INTERFACE_DESC_SIZE



@@ -847,6 +854,195 @@ static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
KEYMEDIA_SIZE, 0, // wMaxPacketSize
KEYMEDIA_INTERVAL, // bInterval
#endif // KEYMEDIA_INTERFACE

#ifdef AUDIO_INTERFACE
// Standard AudioControl (AC) Interface Descriptor
// USB DCD for Audio Devices 1.0, Table 4-1, page 36
9, // bLength
4, // bDescriptorType, 4 = INTERFACE
AUDIO_INTERFACE, // bInterfaceNumber
0, // bAlternateSetting
0, // bNumEndpoints
1, // bInterfaceClass, 1 = AUDIO
1, // bInterfaceSubclass, 1 = AUDIO_CONTROL
0, // bInterfaceProtocol
0, // iInterface
// Class-specific AC Interface Header Descriptor
// USB DCD for Audio Devices 1.0, Table 4-2, page 37-38
10, // bLength
0x24, // bDescriptorType, 0x24 = CS_INTERFACE
0x01, // bDescriptorSubtype, 1 = HEADER
0x00, 0x01, // bcdADC (version 1.0)
LSB(52), MSB(52), // wTotalLength
2, // bInCollection
AUDIO_INTERFACE+1, // baInterfaceNr(1) - Transmit to PC
AUDIO_INTERFACE+2, // baInterfaceNr(2) - Receive from PC
// Input Terminal Descriptor
// USB DCD for Audio Devices 1.0, Table 4-3, page 39
12, // bLength
0x24, // bDescriptorType, 0x24 = CS_INTERFACE
0x02, // bDescriptorSubType, 2 = INPUT_TERMINAL
1, // bTerminalID
//0x01, 0x02, // wTerminalType, 0x0201 = MICROPHONE
//0x03, 0x06, // wTerminalType, 0x0603 = Line Connector
0x02, 0x06, // wTerminalType, 0x0602 = Digital Audio
0, // bAssocTerminal, 0 = unidirectional
2, // bNrChannels
0x00, 0x03, // wChannelConfig, 0x0003 = Left & Right Front
0, // iChannelNames
0, // iTerminal
// Output Terminal Descriptor
// USB DCD for Audio Devices 1.0, Table 4-4, page 40
9, // bLength
0x24, // bDescriptorType, 0x24 = CS_INTERFACE
3, // bDescriptorSubtype, 3 = OUTPUT_TERMINAL
2, // bTerminalID
0x01, 0x01, // wTerminalType, 0x0101 = USB_STREAMING
0, // bAssocTerminal, 0 = unidirectional
1, // bCSourceID, connected to input terminal, ID=1
0, // iTerminal
// Input Terminal Descriptor
// USB DCD for Audio Devices 1.0, Table 4-3, page 39
12, // bLength
0x24, // bDescriptorType, 0x24 = CS_INTERFACE
2, // bDescriptorSubType, 2 = INPUT_TERMINAL
3, // bTerminalID
0x01, 0x01, // wTerminalType, 0x0101 = USB_STREAMING
0, // bAssocTerminal, 0 = unidirectional
2, // bNrChannels
0x00, 0x03, // wChannelConfig, 0x0003 = Left & Right Front
0, // iChannelNames
0, // iTerminal
// Output Terminal Descriptor
// USB DCD for Audio Devices 1.0, Table 4-4, page 40
9, // bLength
0x24, // bDescriptorType, 0x24 = CS_INTERFACE
3, // bDescriptorSubtype, 3 = OUTPUT_TERMINAL
4, // bTerminalID
//0x02, 0x03, // wTerminalType, 0x0302 = Headphones
0x02, 0x06, // wTerminalType, 0x0602 = Digital Audio
0, // bAssocTerminal, 0 = unidirectional
3, // bCSourceID, connected to input terminal, ID=3
0, // iTerminal
// Standard AS Interface Descriptor
// USB DCD for Audio Devices 1.0, Section 4.5.1, Table 4-18, page 59
// Alternate 0: default setting, disabled zero bandwidth
9, // bLenght
4, // bDescriptorType = INTERFACE
AUDIO_INTERFACE+1, // bInterfaceNumber
0, // bAlternateSetting
0, // bNumEndpoints
1, // bInterfaceClass, 1 = AUDIO
2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
0, // bInterfaceProtocol
0, // iInterface
// Alternate 1: streaming data
9, // bLenght
4, // bDescriptorType = INTERFACE
AUDIO_INTERFACE+1, // bInterfaceNumber
1, // bAlternateSetting
1, // bNumEndpoints
1, // bInterfaceClass, 1 = AUDIO
2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
0, // bInterfaceProtocol
0, // iInterface
// Class-Specific AS Interface Descriptor
// USB DCD for Audio Devices 1.0, Section 4.5.2, Table 4-19, page 60
7, // bLength
0x24, // bDescriptorType = CS_INTERFACE
1, // bDescriptorSubtype, 1 = AS_GENERAL
2, // bTerminalLink: Terminal ID = 2
3, // bDelay (approx 3ms delay, audio lib updates)
0x01, 0x00, // wFormatTag, 0x0001 = PCM
// Type I Format Descriptor
// USB DCD for Audio Data Formats 1.0, Section 2.2.5, Table 2-1, page 10
11, // bLength
0x24, // bDescriptorType = CS_INTERFACE
2, // bDescriptorSubtype = FORMAT_TYPE
1, // bFormatType = FORMAT_TYPE_I
2, // bNrChannels = 2
2, // bSubFrameSize = 2 byte
16, // bBitResolution = 16 bits
1, // bSamFreqType = 1 frequency
LSB(44100), MSB(44100), 0, // tSamFreq
// Standard AS Isochronous Audio Data Endpoint Descriptor
// SB DCD for Audio Devices 1.0, Section 4.6.1.1, Table 4-20, page 61-62
9, // bLength
5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
AUDIO_TX_ENDPOINT | 0x80, // bEndpointAddress
0x05, // bmAttributes = isochronous, asynchronous
LSB(AUDIO_TX_SIZE), MSB(AUDIO_TX_SIZE), // wMaxPacketSize
1, // bInterval, 1 = every frame
0, // bRefresh
0, // bSynchAddress
// Class-Specific AS Isochronous Audio Data Endpoint Descriptor
// USB DCD for Audio Devices 1.0, Section 4.6.1.2, Table 4-21, page 62-63
7, // bLength
0x25, // bDescriptorType, 0x25 = CS_ENDPOINT
1, // bDescriptorSubtype, 1 = EP_GENERAL
0x01, // bmAttributes = Sampling Frequency
1, // bLockDelayUnits, 1 = ms
0x30, 0x00, // wLockDelay
// Standard AS Interface Descriptor
// USB DCD for Audio Devices 1.0, Section 4.5.1, Table 4-18, page 59
// Alternate 0: default setting, disabled zero bandwidth
9, // bLenght
4, // bDescriptorType = INTERFACE
AUDIO_INTERFACE+2, // bInterfaceNumber
0, // bAlternateSetting
0, // bNumEndpoints
1, // bInterfaceClass, 1 = AUDIO
2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
0, // bInterfaceProtocol
0, // iInterface
// Alternate 1: streaming data
9, // bLenght
4, // bDescriptorType = INTERFACE
AUDIO_INTERFACE+2, // bInterfaceNumber
1, // bAlternateSetting
1, // bNumEndpoints
1, // bInterfaceClass, 1 = AUDIO
2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
0, // bInterfaceProtocol
0, // iInterface
// Class-Specific AS Interface Descriptor
// USB DCD for Audio Devices 1.0, Section 4.5.2, Table 4-19, page 60
7, // bLength
0x24, // bDescriptorType = CS_INTERFACE
1, // bDescriptorSubtype, 1 = AS_GENERAL
3, // bTerminalLink: Terminal ID = 3
3, // bDelay (approx 3ms delay, audio lib updates)
0x01, 0x00, // wFormatTag, 0x0001 = PCM
// Type I Format Descriptor
// USB DCD for Audio Data Formats 1.0, Section 2.2.5, Table 2-1, page 10
11, // bLength
0x24, // bDescriptorType = CS_INTERFACE
2, // bDescriptorSubtype = FORMAT_TYPE
1, // bFormatType = FORMAT_TYPE_I
2, // bNrChannels = 2
2, // bSubFrameSize = 2 byte
16, // bBitResolution = 16 bits
1, // bSamFreqType = 1 frequency
LSB(44100), MSB(44100), 0, // tSamFreq
// Standard AS Isochronous Audio Data Endpoint Descriptor
// SB DCD for Audio Devices 1.0, Section 4.6.1.1, Table 4-20, page 61-62
9, // bLength
5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
AUDIO_RX_ENDPOINT, // bEndpointAddress
0x05, // bmAttributes = isochronous, asynchronous
LSB(AUDIO_RX_SIZE), MSB(AUDIO_RX_SIZE), // wMaxPacketSize
1, // bInterval, 1 = every frame
0, // bRefresh
0, // bSynchAddress
// Class-Specific AS Isochronous Audio Data Endpoint Descriptor
// USB DCD for Audio Devices 1.0, Section 4.6.1.2, Table 4-21, page 62-63
7, // bLength
0x25, // bDescriptorType, 0x25 = CS_ENDPOINT
1, // bDescriptorSubtype, 1 = EP_GENERAL
0x01, // bmAttributes = Sampling Frequency
1, // bLockDelayUnits, 1 = ms
0x30, 0x00, // wLockDelay
#endif
};



+ 30
- 0
teensy3/usb_desc.h View File

@@ -43,6 +43,8 @@
#define ENDPOINT_TRANSIMIT_ONLY 0x15
#define ENDPOINT_RECEIVE_ONLY 0x19
#define ENDPOINT_TRANSMIT_AND_RECEIVE 0x1D
#define ENDPOINT_RECEIVE_ISOCHRONOUS 0x18
#define ENDPOINT_TRANSMIT_ISOCHRONOUS 0x14

/*
Each group of #define lines below corresponds to one of the
@@ -340,6 +342,34 @@ let me know? http://forum.pjrc.com/forums/4-Suggestions-amp-Bug-Reports
#define ENDPOINT3_CONFIG ENDPOINT_TRANSMIT_AND_RECEIVE
#define ENDPOINT4_CONFIG ENDPOINT_RECEIVE_ONLY

#elif defined(USB_AUDIO)
#define VENDOR_ID 0x16C0
#define PRODUCT_ID 0x0485 // TODO: assign unique
#define MANUFACTURER_NAME {'T','e','e','n','s','y','d','u','i','n','o'}
#define MANUFACTURER_NAME_LEN 11
#define PRODUCT_NAME {'T','e','e','n','s','y',' ','A','u','d','i','o'}
#define PRODUCT_NAME_LEN 12
#define EP0_SIZE 64
#define NUM_ENDPOINTS 4
#define NUM_USB_BUFFERS 16
#define NUM_INTERFACE 4
#define SEREMU_INTERFACE 3 // Serial emulation
#define SEREMU_TX_ENDPOINT 1
#define SEREMU_TX_SIZE 64
#define SEREMU_TX_INTERVAL 1
#define SEREMU_RX_ENDPOINT 2
#define SEREMU_RX_SIZE 32
#define SEREMU_RX_INTERVAL 2
#define AUDIO_INTERFACE 0 // Audio (uses 3 consecutive interfaces)
#define AUDIO_TX_ENDPOINT 3
#define AUDIO_TX_SIZE 180
#define AUDIO_RX_ENDPOINT 4
#define AUDIO_RX_SIZE 180
#define ENDPOINT1_CONFIG ENDPOINT_TRANSIMIT_ONLY
#define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_ONLY
#define ENDPOINT3_CONFIG ENDPOINT_TRANSMIT_ISOCHRONOUS
#define ENDPOINT4_CONFIG ENDPOINT_RECEIVE_ISOCHRONOUS

#endif

#ifdef USB_DESC_LIST_DEFINE

Loading…
Cancel
Save