USB 设备第一次连接到主机时, 要接收主机枚举( Enumera tion) 和配置(Configuration) , 目的是让主机知道设备功能、是哪一类的USB 设备、占用多少资源、使用了哪些传输方式以及传输的数据量等等。只有主机完全确认了这些信息后, 设备才能真正开始工作。这些信息是通过存储在设备中的USB 描述符来体现的。因此, 这种USB 描述符也可以看作是USB 设备的身份证明。
USB设备使用描述符报告其属性。
描述符是具有定义格式的数据结构。每个描述符都以[描述符的字节数字段]开头,
该字段包含描述符中的总字节数,后跟一个标识[描述符类型编号字段]的字节宽度字段。
偏移量 | 字段名称 | 长度(Byte) | 字段值 | 意义 |
---|---|---|---|---|
0 | bLength | 1 | 0x12 | 描述符的字节数 |
1 | bDescriptorType | 1 | 0x01 | 描述符类型编号 |
…… |
标准描述符类型 | bDescriptorType |
---|---|
设备描述符(Device Descriptor) | 0x01 |
配置描述符(Configuration Descriptor) | 0x02 |
字符串描述符(String Descriptor,可选) | 0x03 |
接口描述符(Interface Descriptor) | 0x04 |
端点描述符(Endpoint Descriptor) | 0x05 |
设备限定描述符(DEVICE_QUALIFIER) | 0x06 |
其他速率配置描述符(OTHER_SPEED_CONFIGURATION) | 0x07 |
接口功率描述符(INTERFACE_POWER) | 0x08 |
设备类描述符 | bDescriptorType 字段 |
---|---|
Audiointerface Descriptor | 0x24 |
Audioendpoint Descriptor | 0x25 |
设备描述符 → 配置描述符(N个)
配置描述符 → 接口描述符(N个)
接口描述符 → 端点描述符(N个)
每个描述符都是由一系列字段( Field , 为了与组成包的域相区别, 这里叫做字段) 所组成的,每个字段开头小写字母表示了该字段使用的数据格式。
首位小写字母 | 意义 | Example |
---|---|---|
b | Byte | bLength |
w | 16 bits Word/ 2 bytes | wTotalLength |
bm | Bit Map | bmAttributes |
bcd | BCD码 | bcdUSB |
i | Index | iSerialNumber |
id | Identifier | idVendor |
偏移量 | 字段名称 | 长度(Byte) | 字段值 | 意义 |
---|---|---|---|---|
0 | bLength | 1 | 0x12 | 描述符的字节数 |
1 | bDescriptorType | 1 | 0x01 | 描述符类型编号 |
2 | bcdUSB | 2 | 如1.1=0x0110,2.0=0x0200 | USB版本号 |
4 | bDeviceClass | 1 | 类 | USB分配设备类代码(0x01-0xFE)FF为厂商自定义 |
5 | bDeviceSubClass | 1 | 子类 | USB分配子类代码 |
6 | bDeviceProtocol | 2 | 协议 | USB分配设备协议代码 |
7 | bMaxPacketSize0 | 1 | 控制传输端点0包大小 | 端点0最大数据包长度,必须为8、16、32或64 |
8 | idVendor | 2 | ID编号 | 厂商编号 |
10 | idProduct | 2 | ID编号 | 产品编号 |
12 | bcdDevice | 2 | BCD码 | 设备出厂编号 |
14 | iManufacturer | 1 | 索引 | 厂商字符串索引 |
15 | iProduct | 1 | 索引 | 产品字符串索引 |
16 | iSerialNumber | 1 | 索引 | 设备序列号字符串索引 |
17 | bNumConfigurations | 1 | 配置描述符数量 | 可用配置数量 |
USB defines class code information that is used to identify a device’s functionality and to nominally load a device driver based on that functionality. The information is contained in three bytes with the names Base Class, SubClass, and Protocol. (Note that ‘Base Class’ is used in this description to identify the first byte of the Class Code triple. That terminology is not used in the USB Specification). There are two places on a device where class code information can be placed.One place is in the Device Descriptor, and the other is in Interface Descriptors. Some defined class codes are allowed to be used only in a Device Descriptor, others can be used in both Device and Interface Descriptors, and some can only be used in Interface Descriptors. The table below shows the currently defined set of Base Class values, what the generic usage is, and where that Base Class can be used (either Device or Interface Descriptors or both).
Base Class | Descriptor Usage | Description |
---|---|---|
00h | Device | Use class information in the Interface Descriptors |
01h | Interface | Audio |
02h | Both | Communications and CDC Control |
03h | Interface | HID (Human Interface Device) |
05h | Interface | Physical |
06h | Interface | Image |
07h | Interface | Printer |
08h | Interface | Mass Storage |
09h | Device | Hub |
0Ah | Interface | CDC-Data |
0Bh | Interface | Smart Card |
0Dh | Interface | Content Security |
0Eh | Interface | Video |
0Fh | Interface | Personal Healthcare |
10h | Interface | Audio/Video Devices |
11h | Device | Billboard Device Class |
12h | Interface | USB Type-C Bridge Class |
DCh | Both | Diagnostic Device |
E0h | Interface | Wireless Controller |
EFh | Both | Miscellaneous |
FEh | Interface | Application Specific |
FFh | Both | Vendor Specific |
在读取设备描述符后,主机可以读取该设备的配置、接口以及端点描述符。每一个设备都至少有一个配置描述符,用来描述该设备的特性与能力。通常一个设置配置就已经足够,不过多用途或模式的设备可以支持多个设置配置,在同一时间只能有一个作用。 每一个设置配置都需要一个描述符,此描述符包含设备中的电源使用以及支持的接口数目。每一个配置描述符都有附属的描述符,包含一个或多个接口描述符,以及选择性的端点描述符。
配置描述符:
D7保留值,固定为1 D6表示供电方式(1:自供电,0:总线供电) D5远程唤醒设置(1:支持远程唤醒,0:不支持远程唤醒) D4~D0 保留值,固定为0
偏移量 | 字段名称 | 长度(字节) | 字段值 | 意义 |
---|---|---|---|---|
0 | bLength | 1 | 0x09 | 描述符的字节数 |
1 | bDescriptorType | 1 | 0x02 | 描述符类型编号 |
2 | wTotalLength | 2 | 数字 | 表示该配置所返回的所有描述符( 包括配置、接口和端点描述符) 的大小总和。 |
3 | bNumInterfaces | 1 | 接口描述符个数 | 此配置所支持的接口数量 |
4 | bConfigurationValue | 1 | 数字 | Set_Configuration /Get_Configuration命令需要的参数值 |
5 | iConfiguration | 1 | 索引 | 描述该配置的字符串的索引值 |
6 | bmAttributes | 1 | 位组合 | 供电模式选择 |
7 | MaxPower | 1 | 字段值*2(mA) | 设备从总线提取的最大电流(⇐500mA) |
Example:
接口表示设备的特性或功能所使用的端点、配置的接口描述符,包含该接口所支持的端点信息。 每一个设置配置必须支持一个接口,对大部分设备来说,一个接口就已经足够,不过一个设置配置,可以同时有多个作用中的接口。每一个接口有它自己的接口描述符,此接口所支持的所有端点又各有一个附属描述符。 如果一个设备拥有同时多个作用中接口的设置配置,它就是一个复合设备,主机会为每一个接口,加载一个驱动程序。
一个设置配置可以支持多个互不相关的接口,改变接口比改变设置配置容易。主机使用set_interface来要求一个接口,并且以get_interface要求来读取目前接口的号码。每一个接口都有它自己的接口描述符与附属描述符。
接口描述符:
偏移量 | 字段名称 | 长度(字节) | 字段值 | 意义 |
---|---|---|---|---|
0 | bLength | 1 | 0x09 | 描述符的字节数 |
1 | bDescriptorType | 1 | 0x04 | 描述符类型编号 |
2 | bInterfaceNumber | 1 | 数字 | 接口编号 |
3 | bAlternateSetting | 1 | 数字 | 备用的接口描述符标号 |
4 | bNumEndpoints | 1 | 使用的端点数 | 该接口使用的端点数(不包括端点0),如果数值为0,说明只用了端点0 |
5 | bInterfaceClass | 1 | 类 | 接口类型(参考设备描述符) |
6 | bInterfaceSubClass | 1 | 子类 | 接口子类类型(参考设备描述符) |
7 | bInterfaceProtocol | 1 | 协议 | 接口遵循的协议 |
8 | iInterface | 1 | 索引 | 描述该接口的字符串索引值 |
如果一个配置拥有N个接口, 那么这些接口都是互不相干的, 每一个接口都有惟一的编号, USB 就是通过此字段来识别不同的接口。默认值为0。
USB设备配置与USB配置描述符是一一对应的, 即一个配置只能有一个配置描述符。虽然由bInterfaceNumber字段可知, 每一个接口都有一个惟一确定的接口编号, 但是一个接口却可以由不只一个接口描述符来描述它。USB 允许多个接口描述符来描述同一个接口, 且这些描述符都可通过命令切换。此字段就是每一个这类描述符惟一的编号。USB可通过调用这个字段来切换描述同一个接口的不同描述符。控制传输中的Get_Inter face 命令可以用来得到目前正在使用的描述一个确定接口的接口描述符的编号, 即此字段。而Set_Inte rface 命令则以此字段值为参数, 用来使相应的接口描述符描述某个确定的接口
USB音频类定义在接口层,而USB音频类又分为不同的子类(SubClass)以便于进一步的细节枚举和设置。所有的USB音频功能都被包括在USB音频类的子类中。目前,USB定义了3种不同的音频子类:
Audio Subclass Code | bDescriptorType 字段 |
---|---|
SUBCLASS_UNDEFINED | 0x00 |
AUDIOCONTROL | 0x01 |
AUDIOSTREAMING | 0x02 |
MIDISTREMING | 0x03 |
用于接口的每个端点都有自己的描述符。 此描述符包含信息需要主机确定每个端点的带宽要求。
端点描述符:
偏移量 | 字段名称 | 长度(字节) | 字段值 | 意义 |
---|---|---|---|---|
0 | bLength | 1 | 0x07 | 端点描述符的字节数大小 |
1 | bDescriptorType | 1 | 0x05 | 端点描述符类型编号 |
2 | bEndpointAddress | 1 | 端点 | 端点地址及输入输出属性 |
3 | bmAttributes | 1 | 位图 | 端点的传输类型属性 |
4 | wMaxPacketSize | 2 | 数字 | 端点收、发的最大包的大小 |
6 | bInterval | 1 | 数字 | 主机查询端点的时间间隔 |
偏移量 | 字段名称 | 长度(字节) | 字段值 | 意义 |
---|---|---|---|---|
0 | bLength | 1 | N+2 | 描述符的字节数 |
1 | bDescriptorType | 1 | 0x03 | 描述符类型编号 |
2 | bString | N | UNICODE | UNICODE编码字符串 |
struct usb_ac_interface_descriptor {
U8 bLength; /* Size of this descriptor in bytes */ U8 bDescriptorType; /* INTERFACE descriptor type */ U8 bInterfaceNumber; /* Number of the interface (0 based) */ U8 bAlternateSetting; U8 bNumEndpoints; /* Number of endpoints in this interface */ U8 bInterfaceClass; /* AUDIO Interface class code */ U8 bInterfaceSubclass; /* AUDIO_STREAMING Interface subclass code */ U8 bInterfaceProtocol; /* IP_VERSION_02_00 Interface protocol code */ U8 iInterface; /* String descriptor of this Interface */
};
bLength = 0x09; struct size,固定0x09; bDescriptorType = 0x04; 表明此数据是Interface描述符; bInterfaceClass = 0x01; 说明这是一个Audio device; bInterfaceSubclass = 0x01; 说明这是一个audio control interface; 0x02 是audio streaming interface; 0x03 是midi streaming interface; bInterfaceNumber : 同配置的Interface index,以0开始; bAlternateSetting: 可替换的Interface index; bNumEndpoints: 除0端点外,此Interface所使用的端点数量,如果有可替换的端点,则为1,否则是0; bInterfaceProtocol: 未使用,必须设为0; iInterface: 如果有字符串描述符,则描述此Interface的字符串描述符索引。
struct usb_ac_cs_interface_descriptor {
U8 bLength; /*Size of this descriptor, in bytes: 8+n*/ U8 bDescriptorType; /*CS_INTERFACE descriptor type*/ U8 bDescriptorSubtype; /*HEADER descriptor subtype.*/ U16 bcdADC; /*Audio Device Class Specification Release Number in Binary-Coded Decimal.*/ U16 wTotalLength; /*Total number of bytes returned for the class-specific AudioControl interface descriptor. Includes the combined length of this descriptor header and all Unit and Terminal descriptors.*/ U8 bInCollection; /*The number of AudioStreaming and MIDIStreaming interfaces in the Audio Interface Collection to which this AudioControl interface belongs: n*/ U8 *baInterfaceNr; /*Interface number of the first AudioStreaming or MIDIStreaming interface in the Collection.*/
};
bLength = 8+n; bDescriptor = 0x24; 说明这是一个class-specific audio device interface, 注意,不一定是Audio Control interface, 也可能是Audio Streaming interface; 如果是 Audio Streaming interface,则bLength=0x07; bDescriptorSubtype = 0x01; 说明这是head descriptor; bcdADC: BCD编码的class specification Release编号,即版本号,如果是0x100,就是1.00版,0x200,就是2.00版; wTotalLength: 包含Header和所有Unit, Terminal的总和的length; bInCollection:此Audio Control Interface所拥有的Audio Streaming和Audio MidiStreaming的interface集合数量;即bLength = 8+n 中的n baInterfaceNr: Audio Streaming 和MidiStreaming在集合中的索引值;
struct usb_input_terminal_descriptor {
U8 bLength; /*Size of this descriptor, in bytes: 12*/ U8 bDescriptorType; /*CS_INTERFACE descriptor type.*/ U8 bDescriptorSubtype; /*INPUT_TERMINAL descriptor subtype.*/ U8 bTermialID; /*Constant uniquely identifying the Terminal within the audio function. This value is used in all requests to address this Terminal.*/ U16 wTerminalType; /*Constant characterizing the type of Terminal. See USB Audio Terminal Types.*/ U8 bAssocTerminal; /*ID of the Output Terminal to which this Input Terminal is associated.*/ U8 bNrChannels; /*Number of logical output channels in the Terminal’s output audio channel cluster.*/ U16 wChannelConfig; /*Describes the spatial location of the logical channels.*/ U8 iChannelNames; /*Index of a string descriptor, describing the name of the first logical channel.*/ U8 iTerminal; /*Index of a string descriptor, describing the Input Terminal.*/
}
bLength = 12; bDescriptorType = 0x24; 说明这是 class-specific interface; bDescriptorSubtype = 0x02;说明这是 input terminal descriptor; bTerminalID: Terminal ID, 值唯一; wTerminalType: USB streaming (0x101), ……; bAssocTerminal: 与之相关联的output terminal ID,如果为0,则表示此值未使用; bNrChannels: 逻辑输出声道数; wChannelConfig: Describes the spatial location of the logical channels; iChannelNames: logical channel string index; iTerminal: string index;
struct usb_output_terminal_descriptor{
U8 bLength; /*Size of this descriptor, in bytes: 9*/ U8 bDescriptorType; /*CS_INTERFACE descriptor type.*/ U8 bDescriptorSubtype; /*OUTPUT_TERMINAL descriptor subtype.*/ U8 bTerminalID; /*Constant uniquely identifying the Terminal within the audio function. This value is used in all requests to address this Terminal.*/ U16 wTerminalType; /*Constant characterizing the type of Terminal. See USB Audio Terminal Types.*/ U8 bAssocTerminal; /*Constant, identifying the Input Terminal to which this Output Terminal is associated.*/ U8 bSourceID; /*ID of the Unit or Terminal to which this Terminal is connected.*/ U8 iTerminal; /*Index of a string descriptor, describing the Output Terminal.*/
}; bLength = 0x09; bDescriptorType = 0x24; 说明这是CS_INTERFACE; bDescriptorSubtype = 0x03; 说明这是 output terminal; bTerminalID: terminal ID,值唯一; wTerminalType: Terminal类型,Speaker(0x301), Headphones(0x302), Head Mounted Display Audio(0x303), Desktop speaker(0x304), Room speaker(0x305), Communication speaker(0x306), Low frequency effects speaker(0x307), USB streaming(0x101); bAssocTerminal: 相关的input terminal ID,0代表此值未使用; bSourceID: 与此Terminal相连接的Unit, Terminal 的 ID,需要在Input Terminal, Feature Unit…中查找; iTerminal: string index
偏移量 | 字段名称 | 长度(字节) | 字段值 | 意义 |
---|---|---|---|---|
0 | bLength | 1 | 0x07 | 端点描述符的字节数大小 |
1 | bDescriptorType | 1 | 0x05 | 端点描述符类型编号 |
2 | bEndpointAddress | 1 | 端点 | 端点地址及输入输出属性 |
3 | bmAttributes | 1 | 位图 | 端点的传输类型属性 |
4 | wMaxPacketSize | 2 | 数字 | 端点收、发的最大包的大小 |
6 | bInterval | 1 | 数字 | 主机查询端点的时间间隔 |
struct usb_feature_unit_descriptor {
U8 bLength; /*Size of this descriptor, in bytes: 7+(ch+1)*n*/ U8 bDescriptorType; /*CS_INTERFACE descriptor type.*/ U8 bDescriptorSubtype; /*FEATURE_UNIT descriptor subtype.*/ U8 bUnitID; /*Constant uniquely identifying the Unit within the audio function. This value is used in all requests to address this Unit.*/ U8 bSourceID; /*ID of the Unit or Terminal to which this Feature Unit is connected.*/ U8 bControlSize; /*Size in bytes of an element of the bmaControls() array: n*/ U8 *bmaControls; /* bmaControls+ 0 means A bit set to 1 indicates that the mentioned Control is supported for master channel 0: D0: Mute D1: Volume D2: Bass D3: Mid D4: Treble D5: Graphic Equalizer D6: Automatic Gain D7: Delay D8: Bass Boost D9: Loudness D10..(n*8-1): Reserved (bmaControls + n) means A bit set to 1 indicates that the mentioned Control is supported for logical channel ch.*/ U8 iFeature; /*Index of a string descriptor, describing this Feature Unit.*/
}; bLength = 7+(ch+1)*n; bDescriptorType = 0x24; 说明是 class-specific interface; bUnitID: Unit ID, 值唯一; bSourceID: 与之相连的Unit, Terminal ID; bControlSize: bLength中的n值,即一个bmaControls的size; bmaControls[0]: master channel 0 的 control, D0: Mute D1: Volume D2: Bass D3: Mid D4: Treble D5: Graphic Equalizer D6: Automatic Gain D7: Delay D8: Bass Boost D9: Loudness D10..(n*8-1): Reserved; bmaControls[1]: logical channel 1 的control ; …… bmaControls[ch]: logical channel ch的control; iFeature: string index;
struct usb_as_cs_interface_descriptor {
U8 bLength; /*Size of this descriptor in bytes: 7 */ U8 bDescriptorType; /*CS_INTERFACE descriptor type.*/ U8 bDescriptorSubtype; /*GENERAL_SUB_TYPE descriptor subtype.*/ U8 bTerminalLink; /*The Terminal ID of the Terminal to which the endpoint of this interface is connected.*/ U8 bDelay; /*Delay (d) introduced by the data path (see Section 3.4, “Inter Channel Synchronization”). Expressed in number of frames.*/ U16 wFormatTag; /*The Audio Data Format that has to be used to communicate with this interface.*/
}; bLength = 0x07; bDescriptorType = 0x24; 说明是CS_INTERFACE; bDescriptorSubtype = 0x01; 说明是 AS_GENERAL; bTerminalLink: 此interface所连接的endpoint的terminalID,可以通过这个值找到Terminal; bDelay: wFormatTag: 数据格式 FORMAT_TYPE_UNDEFINED 0X00 FORMAT_TYPE_I 0X01 FORMAT_TYPE_II 0X02 FORMAT_TYPE_III 0X03 Format type I支持pcm, pcm8, IEE_FLOAT, ALAW, MULAW; Format type II支持 mpeg, AC-3 Format type III 支持 IEC1937_AC-3, IEC1937_MPEG-1_Layer1, IEC1937_MPEG-1_Layer2/3 / IEC1937_MPEG-2_NOEXT, IEC1937_MPEG-2_EXT, IEC1937_MPEG-2_Layer1_LS, IEC1937_MPEG-2_Layer2/3_LS
struct usb_as_interface_descriptor {
U8 bLength; /* Size of this descriptor in bytes */ U8 bDescriptorType; /* INTERFACE descriptor type */ U8 bInterfaceNumber; /* Number of interface. A zero-based value
identifying the index in the array of concurrent interfaces supported by this configuration. */
U8 bAlternateSetting; /*Value used to select an alternate setting
for the interface identified in the prior field.*/
U8 bNumEndpoints; /* Number of endpoints in this interface */ U8 bInterfaceClass; /* AUDIO Interface class code */ U8 bInterfaceSubclass; /* AUDIO_STREAMING Interface subclass code */ U8 bInterfaceProtocol; /* Not used. Must be set to 0. */ U8 iInterface; /* Index of a string descriptor that describes
this interface. */ }; bLength = 0x09; bDescriptorType = 0x04; 说明这是一个Interface descriptor; bInterfaceNumber: 此配置所支持的Interface index; bAlternateSetting: 可变更的Interface; bNumEndpoints: 除了endpoint0, 此interface使用的endpoint; bInterfaceClass = 0x01; 说明是 Audio interface class; bInterfaceSubClass = 0x02; 说明是 audio streaming intertface class; bInterfaceProtocol: 未使用,强制设为0; iInterface: 如果有string descriptor, 则此值是 string 的 index;
struct usb_format_type_1 {
U8 bLength; /*Size of this descriptor, in bytes: 8+(ns*3)*/ U8 bDescriptorType; /*CS_INTERFACE descriptor type*/ U8 bDescriptorSubtype; /*FORMAT_TYPE descriptor subtype.*/ U8 bFormatType; /*FORMAT_TYPE_I. Constant identifying the Format Type the AudioStreaming interface is using.*/ U8 bNrChannels; /*Indicates the number of physical channels in the audio data stream.*/ U8 bSubframeSize; /*The number of bytes occupied by one audio subframe. Can be 1, 2, 3 or 4.*/ U8 bBitResolution; /*The number of effectively used bits from the available bits in an audio subframe.*/ U8 bSamFreqType; /*Indicates how the sampling frequency can be programmed: 0: Continuous sampling frequency 1..255: The number of discrete sampling frequencies supported by the isochronous data endpoint of the AudioStreaming interface (ns)*/ U8 tLowerSamFreq[3]; /*Lower bound in Hz of the sampling frequency range for this isochronous data endpoint.*/ U8 tUpperSamFreq[3]; /*Upper bound in Hz of the sampling frequency range for this isochronous data endpoint.*/
};
bLength = 8+(ns*3); 当为continous frequecy 时, ns = 2; bDescriptorType = 0x24; class-specific interface; bDescriptorSubtype = 0x02; 同input terminal→bDescriptorSubtype, 此时要通过bLength来区别,input terminal→bLength = 12; bFormatType = 0x01; FORMAT_TYPE_I; bNrChannels: audio streaming 物理声道数; bSubframeSize: 对于一个subframe, 需要多少bytes; bBitResolution: bit resolution,即多少位的pcm数据; bSamFreqType: 0 表示 continuous sampling frequecy; 1…ns(max=255)表示离散的sampling freqency; tLowSamFreq/tUpperSamFreq: Sampling Frequency的高低位;
struct usb_standard_as_isochronous_endpoint_descriptor {
U8 bLength; /*Size of this descriptor, in bytes : 9*/ U8 bDescriptorType; /*ENDPOINT descriptor type*/ U8 bEndpointAddress; /*The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: D7: Direction. 0 = OUT endpoint 1 = IN endpoint D6..4: Reserved, reset to zero D3..0: The endpoint number, determined by the designer.*/ U8 bmAttributes; /*D3..2: Synchronization type 01 = Asynchronous 10 = Adaptive 11 = Synchronous D1..0: Transfer type 01 = Isochronous All other bits are reserved.*/ U16 wMaxPacketSize; /*Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. This is determined by the audio bandwidth constraints of the endpoint.*/ U8 bInterval; /*Interval for polling endpoint for data transfers expressed in milliseconds. Must be set to 1.*/ U8 bRefresh; /*Reset to 0.*/ U8 bSynchAddress; /*The address of the endpoint used to communicate synchronization information if required by this endpoint. Reset to zero if no synchronization pipe is used.*/
};
bLength = 0x09; bDescriptorType = 0x05; endpoint descriptor; bEndpointAddress: 含义如下 D7: Direction. 0 = OUT endpoint 1 = IN endpoint D6..4: Reserved, reset to zero D3..0: The endpoint number, determined by the designer. bmAttributes: 含义如下 D3..2: 同步类型 01 = Asynchronous 10 = Adaptive 11 = Synchronous D1..0: 传输类型 01 = Isochronous wMaxPacketSize: max packet size, 由带宽决定; bInterval: 数据传输所需时间,单位milliseconds; bRefresh = 0; 未使用; bSynchAddress: 如果用此endpoint进行同步信息交互,则使用此地址,=0则不使用同步信息。
对于Standard Audio Streaming Isochronous Synch Endpoint Descriptor, 结构与此相同,但含义略有不同,不同点如下: bmAttributes: D3..2: Synchronization type 00 = None D1..0: Transfer type 01 = Isochronous bInterval = 1; 未使用,必须为1; bRefresh: 同步管道提供新的同步feedback数据时的速率,必须是2的幂次方,范围是1(2ms)~9(512ms); bSynchAddress = 0; 未使用;
struct usb_standard_interface_descriptor {
U8 bLength; /*Size of this descriptor in bytes*/ U8 bDescriptorType; /*INTERFACE Descriptor Type*/ U8 bInterfaceNumber; /*Number of this interface. Zero-based value identifying the index in the array of concurrent interfaces supported by this configuration.*/ U8 bAlternateSetting; /*Value used to select this alternate setting for the interface identified in the prior field*/ U8 bNumEndpoints; /*Number of endpoints used by this interface (excluding endpoint zero). If this value is zero, this interface only uses the Default Control Pipe.*/ U8 bInterfaceClass; /*Class code (assigned by the USB-IF). A value of zero is reserved for future standardization. If this field is set to FFH, the interface class is vendor-specific. All other values are reserved for assignment by the USB-IF.*/ U8 bInterfaceSubClass; /* **Hid = 0x03** */ /*Subclass code (assigned by the USB-IF). These codes are qualified by the value of the bInterfaceClass field. If the bInterfaceClass field is reset to zero, this field must also be reset to zero. If the bInterfaceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.*/ U8 bInterfaceProtocol; /*Protocol code (assigned by the USB). These codes are qualified by the value of the bInterfaceClass and the bInterfaceSubClass fields. If an interface supports class-specific requests, this code identifies the protocols that the device uses as defined by the specification of the device class. If this field is reset to zero, the device does not use a class-specific protocol on this interface. If this field is set to FFH, the device uses a vendor-specific protocol for this interface.*/ U8 iInterface; /*Index of string descriptor describing this interface*/
};
在Standard Interface Descriptor后面,会跟着 Hid Descriptor, 如下:
struct hid_descriptor{
U8 bLength; /*Numeric expression that is the total size of the
HID descriptor.*/
U8 bDescriptoryType; /*Constant name specifying type of HID
descriptor. USB_DESCRIPTOR_TYPE_INTERFACE = 0x04*/
U16 bcdHID; /*Numeric expression identifying the HID Class
Specification release.*/
U8 bCountryCode; /*Numeric expression identifying country code of
the localized hardware.*/
U8 bNumDescriptor; /*Numeric expression specifying the number of
class descriptors (always at least one i.e. Report descriptor.)*/
U8 bDescriptorType; /*Constant name identifying type of class
descriptor. See Section 7.1.2: Set_Descriptor Request for a table of class descriptor constants.*/
U16 wDescriptorLength; /*Numeric expression that is the total size of the
Report descriptor.*/ U8 [bDescriptorType]; /*Constant name specifying type of optional descriptor.*/
U16 [wDescriptorLength]; /*Numeric expression that is the total size of the
optional descriptor.*/ };
在Standard Interface Descriptor之后可以有Report Descriptor和Physical Descriptor。如图
Physicial Descriptor可选,一般没有,此时bNumDescriptor=1, 并且没有[bDescriptorType]和[wDescriptorLength]。
Report Descriptor没有固定的结构,它的最小单位是Item。从长度分类,Item分为两类,长item和短item。从功能分,Item分为3类Main item, Gobal item和Local item。大部分item都是短item,短Item的第一个字节含有item信息,如下图:
bTag占4bit, bType占2bit,bSize占2bit。由于bSize只有2bit,所以短item的长度只能为0(00),1(01),2(10),4(11),注意:size没有3。 根据第一个字节的信息,Main Item又分为Input, output, feature, collection, end collection; Gobal item又分为Usage Page, logical Minimum, logical Maximum, physical Minimum, physical maximum, Unit Exponent, Unit, Report Size, Report ID, Report Count, Push, Pop; Local Item又分为Usage, Usage Minimum, usage maximum, designator index, designator minimum, designator maximum, string index, string minimum, string maximum, delimiter; 下表为bTag值:
main item bType = 00; global item bType = 01; local item bType = 10; 当main item识别出来时,即后面的数据是一个新的item, 所有的local item数据将被清除,gobal item数据不变。一个report可以包含许多main item。
TYPE I主要针对于音频数据流是按照物理时序以采样为单位的数据格式,每一个采样点由一个数据表示,而最终的音频信号是将这些连续发送的采样数据进行DA转换后得到的波形。在此类型中,使用某些压缩算法并不改变其格式类型,只要该压缩算法不影响数据以样本为单位的基本格式,例如G.711语音编码算法。在TYPE I格式下如果需要传送多个声道的数据,不同声道的数据是交叉传送的。因此,要从TYPE I中恢复多声道数据,只需要将每个簇(Cluster)中依次提取出各个声道的采样值并分别恢复即可,因此,TYPE I在传送过程中,保存了每个声道的独立性,恢复非常方便。典型的TYPE I信号就是标准的PCM码。
Offset | Field | Size | SizeValue | Comment |
---|---|---|---|---|
0 | bLength | 1 | Number | 0x0B |
1 | bDescriptorType | 1 | Constant | |
2 | bDescriptorSubtype | 1 | Constant | |
3 | bFormatType | 1 | Constant | Type-I(0x01) |
4 | bNrChannels | 1 | Number | Number of Channel |
5 | bSubframeSize | 1 | Number | Subframe Size |
6 | bBitResolution | 1 | Number | |
7 | bSamFreqType | 1 | Number | |
8 | tSamFreq | 3 | Number | Sample Rate |
bLength=8+(ns*3) 公式中,8为固定字段长度,ns代表该接口的端点支持的不同采样率数量。每种采样率需用3个字节表示。即单一采样率时,描述符总长度为11(8+3),两种采样率时描述符总长度为14(8+3x2). bDescriptorType 表示该描述符种类为音频类特有的接口 bDescriptorSubtype 表示该描述符为数据格式描述符 bFormatType 指定该接口具体数据格式 bNrChannels 表示该接口支持的物理声道数 bSubframeSize 音频子帧大小 bBitResolution 指定采样量化比特数 bSamFreqType 指定该接口支持频率类型,可选为连续和固定两种 最后一个字段由bSamFreqType决定,目前,采用单一采样率,只需要填入以24位二进制数表示的具体采样率值即可,可选范围为0到16777215Hz。
//Type 1 Format type descriptor:FORMAT_TYPE(0x02),FORMAT_TYPE_I(0x01), //physical channels 0x02,two byte per audio subframe(0x02),16bit, //32K(0x007d00) 0x0b, //Length 0x24, //DescriptorType:audio interface descriptor 0x02, //DescriptorSubType:Format_type 0x01, //FormatType:Format type 1 0x02, //NumberOfChanne:2 0x02, //SubframeSize:2byte 0x10, //BitsResolution:16bit 0x01, //SampleFreqType:One sampling frequency. 0x00, 0x7d, 0x00, //32K(0x007d00)
http://makaidong.com/heiyue/279451_1108963.html USB音频类描述符及其说明
wChannelConfig D0: Left Front (L) D1: Right Front (R) D2: Center Front (C) D3: Low Frequency Enhancement (LFE) D4: Left Surround (LS) D5: Right Surround (RS) D6: Left of Center (LC) D7: Right of Center (RC) D8: Surround (S) D9: Side Left (SL) D10: Side Right (SR) D11: Top (T) D15..12: Reserved