====== USB的描述符 (基于USB Audio Class) ====== ---- [[https://blog.csdn.net/hushiganghu/article/details/54929066|USB2.0协议标准描述符]] \\ [[https://blog.csdn.net/terry_linux/article/details/5422312?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control|usb 音频类描述符及其说明(usb audio descriptor)]] \\ ===== - USB描述符概述 ===== USB 设备第一次连接到主机时, 要接收主机枚举( Enumera tion) 和配置(Configuration) , 目的是让主机知道设备功能、是哪一类的USB 设备、占用多少资源、使用了哪些传输方式以及传输的数据量等等。只有主机完全确认了这些信息后, 设备才能真正开始工作。这些信息是通过存储在设备中的USB 描述符来体现的。因此, 这种USB 描述符也可以看作是USB 设备的身份证明。 ==== - 描述符作用和结构 ==== USB设备使用描述符报告其属性。 \\ 描述符是具有定义格式的数据结构。每个描述符都以**[描述符的字节数字段]**开头, \\ 该字段包含描述符中的总字节数,后跟一个标识**[描述符类型编号字段]**的字节宽度字段。 ^偏移量 ^字段名称 ^长度(Byte) ^字段值 ^意义 ^ ^0 |bLength |1 |0x12 |描述符的字节数 | ^1 |bDescriptorType |1 |0x01 |描述符类型编号 | ^......||||| ==== - USB2.0 规范中定义的描述符类型 ==== ^ 标准描述符类型 ^ 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 | ===== - USB2.0协议标准描述符 ===== ==== - 设备描述符 ==== ---- * 每一个设备有且只有一个设备描述符 * 默认控制管道的数据包的长度( 端点0长度)是在设备描述符中定义, 而不像其他端点在端点描述符中定义 * 包含 14 个字段,共18 Byte ^ 偏移量 ^ 字段名称 ^ 长度(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 | 配置描述符数量 | 可用配置数量 | #define LOBYTE(x) ((uint8_t)(x & 0x00FF)) #define HIBYTE(x) ((uint8_t)((x & 0xFF00) >>8)) #define USBD_VID 0x0483 #define USBD_PID 0x5730 #define USB_DEVICE_DESCRIPTOR_TYPE 0x01 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02 #define USB_STRING_DESCRIPTOR_TYPE 0x03 #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04 #define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05 #define USB_SIZ_DEVICE_DESC 18 #define USB_SIZ_STRING_LANGID 4 #define USB_OTG_MAX_EP0_SIZE 64 #define USBD_IDX_LANGID_STR 0x00 #define USBD_IDX_MFC_STR 0x01 #define USBD_IDX_PRODUCT_STR 0x02 #define USBD_IDX_SERIAL_STR 0x03 #define USBD_IDX_CONFIG_STR 0x04 #define USBD_IDX_INTERFACE_STR 0x05 #define AUDIO_TOTAL_IF_NUM 0x02 #define USBD_CFG_MAX_NUM 1 #define USBD_ITF_MAX_NUM 1 uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] = { 0x12, /*bLength */ USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType = 0x01 */ 0x00, /*bcdUSB USB 2.0 */ 0x02, 0x00, /*bDeviceClass */ 0x00, /*bDeviceSubClass */ 0x00, /*bDeviceProtocol */ USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize = 64 */ LOBYTE(USBD_VID), /*idVendor */ HIBYTE(USBD_VID), /*idVendor */ LOBYTE(USBD_PID), /*idVendor */ HIBYTE(USBD_PID), /*idVendor */ 0x20, /*bcdDevice v1.20 */ 0x01, USBD_IDX_MFC_STR, /*Index of manufacturer string */ USBD_IDX_PRODUCT_STR, /*Index of product string */ USBD_IDX_SERIAL_STR, /*Index of serial number string */ USBD_CFG_MAX_NUM /*bNumConfigurations */ } === - 标准USB设备类 === 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 | [[https://www.usb.org/defined-class-codes#anchor_BaseClass09h|Defined Class Codes @ USB-IF]] ==== - 配置描述符(Configuration Descriptor) ==== ---- 在读取设备描述符后,主机可以读取该设备的配置、接口以及端点描述符。每一个设备都至少有一个配置描述符,用来描述该设备的特性与能力。通常一个设置配置就已经足够,不过多用途或模式的设备可以支持多个设置配置,在同一时间只能有一个作用。 每一个设置配置都需要一个描述符,此描述符包含设备中的电源使用以及支持的接口数目。每一个配置描述符都有附属的描述符,包含一个或多个接口描述符,以及选择性的端点描述符。 配置描述符: * 包含 8 个字段,共 9 Byte * 供电模式 bmAttributes字段 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: ==== - 接口描述符(Interface Descriptor) ==== ---- 接口表示设备的特性或功能所使用的端点、配置的接口描述符,包含该接口所支持的端点信息。 每一个设置配置必须支持一个接口,对大部分设备来说,一个接口就已经足够,不过一个设置配置,可以同时有多个作用中的接口。每一个接口有它自己的接口描述符,此接口所支持的所有端点又各有一个附属描述符。 如果一个设备拥有同时多个作用中接口的设置配置,它就是一个复合设备,主机会为每一个接口,加载一个驱动程序。 一个设置配置可以支持多个互不相关的接口,改变接口比改变设置配置容易。主机使用set_interface来要求一个接口,并且以get_interface要求来读取目前接口的号码。每一个接口都有它自己的接口描述符与附属描述符。 接口描述符: * 9 个字段,共 9 字节 * **只能作为配置描述符的一部分返回**,不能用GetDescriptor() 或 SetDescriptor() 直接访问。 ^ 偏移量 ^ 字段名称 ^ 长度(字节) ^ 字段值 ^ 意义 ^ ^ 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 | 索引 | 描述该接口的字符串索引值 | * bInterfaceNumber: 如果一个配置拥有N个接口, 那么这些接口都是互不相干的, 每一个接口都有惟一的编号, USB 就是通过此字段来识别不同的接口。默认值为0。 * bAlternateSetting: USB设备配置与USB配置描述符是一一对应的, 即一个配置只能有一个配置描述符。虽然由bInterfaceNumber字段可知, 每一个接口都有一个惟一确定的接口编号, 但是一个接口却可以由不只一个接口描述符来描述它。USB 允许多个接口描述符来描述同一个接口, 且这些描述符都可通过命令切换。此字段就是每一个这类描述符惟一的编号。USB可通过调用这个字段来切换描述同一个接口的不同描述符。控制传输中的Get_Inter face 命令可以用来得到目前正在使用的描述一个确定接口的接口描述符的编号, 即此字段。而Set_Inte rface 命令则以此字段值为参数, 用来使相应的接口描述符描述某个确定的接口 * bInterfaceClass [[https://www.usb.org/defined-class-codes|Defined Class Codes]] Last Update: January 7, 2022 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 3Ch Interface I3C Device Class DCh Both Diagnostic Device E0h Interface Wireless Controller EFh Both Miscellaneous FEh Interface Application Specific FFh Both Vendor Specific Base Class 00h (Device) This base class is defined to be used in Device Descriptors to indicate that class information should be determined from the Interface Descriptors in the device. There is one class code definition in this base class. All other values are reserved. This value is also used in Interface Descriptors to indicate a null class code triple. Base Class SubClass Protocol Meaning 00h 00h 00h Use class code info from Interface Descriptors Base Class 01h (Audio) This base class is defined for Audio capable devices that conform to the Audio Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes may only be used in Interface Descriptors. Base Class SubClass Protocol Meaning 01h xxh xxh Audio device Base Class 02h (Communications and CDC Control) This base class is defined for devices that conform to the Communications Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. Note that the Communication Device Class spec requires some class code values (triples) to be used in Device Descriptors and some to be used in Interface Descriptors. Base Class SubClass Protocol Meaning 02h xxh xxh Communication device class Base Class 03h (HID – Human Interface Device) This base class is defined for devices that conform to the HID Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes can only be used in Interface Descriptors. Base Class SubClass Protocol Meaning 03h xxh xxh HID device class Base Class 05h (Physical) This base class is defined for devices that conform to the Physical Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes can only be used in Interface Descriptors. Base Class SubClass Protocol Meaning 05h xxh xxh Physical device class Base Class 06h (Still Imaging) This base class is defined for devices that conform to the Imaging Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. Base Class SubClass Protocol Meaning 06h 01h 01h Still Imaging device Base Class 07h (Printer) This base class is defined for devices that conform to the Printer Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes can only be used in Interface Descriptors. Base Class SubClass Protocol Meaning 07h xxh xxh Printer device Base Class 08h (Mass Storage) This base class is defined for devices that conform to the Mass Storage Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes can only be used in Interface Descriptors. Base Class SubClass Protocol Meaning 08h xxh xxh Mass Storage device Base Class 09h (Hub) This base class is defined for devices that are USB hubs and conform to the definition in the USB specification. That specification defines the complete triples as shown below. All other values are reserved. These class codes can only be used in Device Descriptors. Base Class SubClass Protocol Meaning 09h 00h 00h Full speed Hub 01h Hi-speed hub with single TT 02h Hi-speed hub with multiple TTs Base Class 0Ah (CDC-Data) This base class is defined for devices that conform to the Communications Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values.Values outside of that defined spec are reserved. These class codes can only be used in Interface Descriptors. Base Class SubClass Protocol Meaning 0Ah xxh xxh CDC data device Base Class 0Bh (Smart Card) This base class is defined for devices that conform to the Smart Card Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values.Values outside of that defined spec are reserved. These class codes can only be used in Interface Descriptors. Base Class SubClass Protocol Meaning 0Bh xxh xxh Smart Card device Base Class 0Dh (Content Security) This base class is defined for devices that conform to the Content Security Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes can only be used in Interface Descriptors. Base Class SubClass Protocol Meaning 0Dh 00h 00h Content Security device Base Class 0Eh (Video) This base class is defined for devices that conform to the Video Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes can only be used in Interface Descriptors. Base Class SubClass Protocol Meaning 0Eh xxh xxh Video device Base Class 0Fh (Personal Healthcare) This base class is defined for devices that conform to the Personal Healthcare Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes should only be used in Interface Descriptors. Base Class SubClass Protocol Meaning 0Fh xxh xxh Personal Healthcare device Base Class 10h (Audio/Video Devices) The USB Audio/Video (AV) Device Class Definition describes the methods used to communicate with devices or functions embedded in composite devices that are used to manipulate audio, video, voice, and all image- and sound-related functionality. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes can only be used in Interface Descriptors. Base Class SubClass Protocol Meaning 10h 01h 02h 03h 00h Audio/Video Device – AVControl Interface 00h Audio/Video Device – AVData Video Streaming Interface 00h Audio/Video Device – AVData Audio Streaming Interface Base Class 11h (Billboard Device) This base class is defined for devices that conform to the Billboard Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes can only be used in Device Descriptors. Base Class SubClass Protocol Meaning 11h 00h 00h Billboard Device Base Class 12h (USB Type-C Bridge Device) This base class is defined for devices that conform to the USB Type-C Bridge Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes can only be used in Interface Descriptors. Base Class SubClass Protocol Meaning 12h 00h 00h USB Type-C Bridge Device Base Class 3Ch (I3C Device Class) This base class is defined for devices that conform to the USB I3C Device Class Specification found on this USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes can only be used in Interface Descriptions. Base Class SubClass Protocol Meaning 3Ch 00h 00h I3C Device Base Class DCh (Diagnostic Device) This base class is defined for devices that diagnostic devices. This class code can be used in Device or Interface Descriptors. Trace is a form of debugging where processor or system activity is made externally visible in real-time or stored and later retrieved for viewing by an applications developer, applications program, or, external equipment specializing observing system activity. Design for Debug or Test (Dfx). This refers to a logic block that provides debug or test support (E.g. via Test Access Port (TAP)). DvC: Debug Capability on the USB device (Device Capability) Base Class SubClass Protocol Meaning DCh 01h 01h USB2 Compliance Device. Definition for this device can be found at http://www.intel.com/technology/usb/spec.htm 02h 00h Debug Target vendor defined. Please see http://www.intel.com/content/www/us/en/io/universal-serial-bus/extensible-host-controler-interface-usb-xhci.html for more info. 01h GNU Remote Debug Command Set. Please see http://www.intel.com/content/www/us/en/io/universal-serial-bus/extensible-host-controler-interface-usb-xhci.html for more info. 03h 00h Undefined 01h Vendor defined Trace protocol on DbC. 04h 00h Undefined 01h Vendor defined Dfx protocol on DbC. 05h 00h Vendor defined Trace protocol over General Purpose (GP) endpoint on DvC. 01h GNU Protocol protocol over General Purpose (GP) endpoint on DvC. http://www.gnu.org/software/gdb/ 06h 00h Undefined 01h Vendor defined Dfx protocol on DvC. 07h 00h Undefined 01h Vendor defined Trace protocol on DvC. 08h 00h Undefined Base Class E0h (Wireless Controller) This base class is defined for devices that are Wireless controllers. Values not shown in the table below are reserved. These class codes are to be used in Interface Descriptors, with the exception of the Bluetooth class code which can also be used in a Device Descriptor. Base Class SubClass Protocol Meaning E0h 01h 01h Bluetooth Programming Interface. Get specific information from www.bluetooth.com. 02h UWB Radio Control Interface. Definition for this is found in the Wireless USB Specification in Chapter 8. 03h Remote NDIS. Information can be found at: http://www.microsoft.com/windowsmobile/mobileoperators/default.mspx 04h Bluetooth AMP Controller. Get specific information from www.bluetooth.com. 2h 01h Host Wire Adapter Control/Data interface. Definition can be found in the Wireless USB Specification in Chapter 8. 02h Device Wire Adapter Control/Data interface. Definition can be found in the Wireless USB Specification in Chapter 8. 03h Device Wire Adapter Isochronous interface. Definition can be found in the Wireless USB Specification in Chapter 8. Base Class EFh (Miscellaneous) This base class is defined for miscellaneous device definitions. Values not shown in the table below are reserved. The use of these class codes (Device or Interface descriptor) are specifically annotated in each entry below. Base Class SubClass Protocol Meaning EFh 01h 01h Active Sync device. This class code can be used in either Device or Interface Descriptors. Contact Microsoft for more information on this class. 02h Palm Sync. This class code can be used in either Device or Interface Descriptors. 02h 01h Interface Association Descriptor. The usage of this class code triple is defined in the Interface Association Descriptor ECN that is provided on www.usb.org . This class code may only be used in Device Descriptors. 02h Wire Adapter Multifunction Peripheral programming interface. Definition can be found in the Wireless USB Specification in Chapter 8. This class code may only be used in Device Descriptors 03h 01h Cable Based Association Framework. This is defined in the Association Model addendum to the Wireless USB specification. This class code may only be used in Interface Descriptors. 04h 01h RNDIS over Ethernet. Connecting a host to the Internet via Ethernet mobile device. The device appears to the host as an Ethernet gateway device. This class code may only be used in Interface Descriptors. 02h RNDIS over WiFi. Connecting a host to the Internet via WiFi enabled mobile device. The device represents itself to the host as an 802.11 compliant network device. This class code may only be used in Interface Descriptors. 03h RNDIS over WiMAX Connecting a host to the Internet via WiMAX enabled mobile device. The device is represented to the host as an 802.16 network device. This class code may only be used in Interface Descriptors. 04h RNDIS over WWAN Connecting a host to the Internet via a device using mobile broadband, i.e. WWAN (GSM/CDMA). This class code may only be used in Interface Descriptors. 05h RNDIS for Raw IPv4 Connecting a host to the Internet using raw IPv4 via non-Ethernet mobile device. Devices that provide raw IPv4, not in an Ethernet packet, may use this form to in lieu of other stock types. This class code may only be used in Interface Descriptors. 06h RNDIS for Raw IPv6 Connecting a host to the Internet using raw IPv6 via non-Ethernet mobile device. Devices that provide raw IPv6, not in an Ethernet packet, may use this form to in lieu of other stock types. This class code may only be used in Interface Descriptors. 07h RNDIS for GPRS Connecting a host to the Internet over GPRS mobile device using the device’s cellular radio 05h 00h USB3 Vision Control Interface Machine Vision Device conforming to the USB3 Vision specification. This standard covers cameras and other related devices that are typically used in machine vision, industrial, and embedded applications. Reference: http://visiononline.org/ This class code may only be used in Interface Descriptors. 01h USB3 Vision Event Interface 02h USB3 Vision Streaming Interface 06h 01h STEP. Stream Transport Efficient Protocol for content protection. 02h STEP RAW. Stream Transport Efficient Protocol for Raw content protection. 07h 01h Command Interface in IAD The DVB Common Interface (DVB-CI) specification describes a system whereby a removable CI Conditional Access Module (CICAM), given the appropriate usage rights, unscrambles protected pay-TV content and routes it over the same interface back to a TV receiver for display. An interface association for a DVB-CI function will contain a DVB-CI Command Interface for command, control, and status information, it may contain a DVB-CI Media Interface for audiovisual data streams, and it may also contain a CDC EEM interface to provide bridged networking to the CICAM. Reference: https://www.dvb.org/standards/dvb-ci-plus 01h Command Interface in Interface Descriptor 02h Media Interface in Interface Descriptor Base Class FEh (Application Specific) This base class is defined for devices that conform to several class specifications found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. Values outside of that defined spec are reserved. These class codes can only be used in Interface Descriptors. Base Class SubClass Protocol Meaning FEh 01h 01h Device Firmware Upgrade. Device class definition provided on www.usb.org . 02h 00h IRDA Bridge device. Device class definition provided on www.usb.org . 03h 00h USB Test and Measurement Device. Definition provided in the USB Test and Measurement Class spec found on www.usb.org . 01h USB Test and Measurement Device conforming to the USBTMC USB488 Subclass Specification found on www.usb.org. Base Class FFh (Vendor Specific) This base class is defined for vendors to use as they please. These class codes can be used in both Device and Interface Descriptors. Base Class SubClass Protocol Meaning FFh xxh xxh Vendor specific === - 子类和协议 === USB音频类定义在接口层,而USB音频类又分为不同的子类(SubClass)以便于进一步的细节枚举和设置。所有的USB音频功能都被包括在USB音频类的子类中。目前,USB定义了3种不同的音频子类: - 音频控制接口子类(AudioControl Interface Subclass) - 音频流接口子类(AudioStreaming Interface Subclass) - MIDI流接口子类(MIDIStreaming Interface Subclass) ^Audio Subclass Code ^bDescriptorType 字段 ^ ^SUBCLASS_UNDEFINED |0x00 | ^AUDIOCONTROL |0x01 | ^AUDIOSTREAMING |0x02 | ^MIDISTREMING |0x03 | ==== - 端点描述符(Endpoint Descriptor) ==== ---- 用于接口的每个端点都有自己的描述符。 此描述符包含信息需要主机确定每个端点的带宽要求。 * 端点描述符为始终由GetDescriptor(获取配置描述符),作为配置信息的一部分返回 * 端点描述符不能直接用GetDescriptor() 或 SetDescriptor() 直接访问 * 对于端点零,不存在端点描述符 端点描述符: * 6 个字段,共7 字节 * 只能作为配置描述符的一部分返回,不能用GetDescriptor()或SetDescriptor()直接访问 * 描述接口所使用的非0端点的属性, 包括输入/ 输出方向、端点号和端点容量即包的大小等 ^ 偏移量 ^ 字段名称 ^ 长度(字节) ^ 字段值 ^ 意义 ^ ^ 0 ^ bLength ^ 1 ^ 0x07 ^ 端点描述符的字节数大小 ^ ^ 1 ^ bDescriptorType ^ 1 ^ 0x05 ^ 端点描述符类型编号 ^ ^ 2 | bEndpointAddress | 1 | 端点 | 端点地址及输入输出属性 | ^ 3 | bmAttributes | 1 | 位图 | 端点的传输类型属性 | ^ 4 | wMaxPacketSize | 2 | 数字 | 端点收、发的最大包的大小 | ^ 6 | bInterval | 1 | 数字 | 主机查询端点的时间间隔 | bEndpointAddress: [3:0] 端点号 [6:4] 保留, 固定值为0 [7:7] 端点方向 1:输出(OUT)端点; 0:输入(IN)端点 bmAttributes: [1:0] 端点传输类型, 00:控制传输 01:同步传输 10:批量传输 11:中断传输 [5:2] isochronous附件设置为,其他传输方式设为:0000 Bits 3..2: Synchronization Type 00 = No Synchronization 01 = Asynchronous 10 = Adaptive 11 = Synchronous Bits 5..4: Usage Type 00 = Data endpoint 01 = Feedback endpoint 10 = Implicit feedback Data endpoint 11 = Reserved wMaxPacketSize:该端点最大包大小。 其中D10~D0 位共11 位为有效内容。在USB 协议1 .1 中D15 ~D11 位保留, 值为0 , 且最大包的大小范围为0~1 023。2.0协议D11.12用于高速和同步传输。 bInterval:主机轮询设备的周期。单位时间为1ms或125us 全速/高速同步端点,值为1-16,2^(bInterval-1) 全速/低速中断端点,值为1-255 高速中断端点,值为1-16,2^(bInterval-1) 高速批量和控制端点,值为0-255。 USB协议定义了同步传输的三种同步机制: 01 = Asynchronous 10 = Adaptive 11 = Synchronous Synchronous模式 Usb device 根据host发送的SOF帧来同步数据的发送。SOF帧是数据的起始帧,对于USB full speed 设备,USB host以 1.00 ms ±0.0005 ms 的间隔发送SOF帧, 对于high speed设备,间隔是125 µs ±0.0625 µs 。 Adaptive模式 自适应模式,即device端自动适应host端的数据发送率。如: 1. 虽然host数据发送不稳定,device端主动调整自身数据发送时钟,适应host的数据发送率 2. device通过resample的方式,插入或者丢弃buff内的samples来保证自身数据发送率的稳定性 Asynchronous模式 以上两种同步方式中原始audio数据总会有损失。而在asynchronous模式下,host会获取device端实际的数据发送率来实时调整自身数据发送率。 Device端能依据这一点来保证自身发送buff的稳定性,从而解决数据同步的问题,如,host端发送速率为48K,device反馈实际播放速率为46K, 那么主机就会调整自身发送速率为46K。 [[https://blog.csdn.net/xjq163/article/details/75531022]] ==== - 字符串描述符(String Descriptor) ==== ---- * 3个字段 ^ 偏移量 ^ 字段名称 ^ 长度(字节) ^ 字段值 ^ 意义 ^ ^ 0 | bLength | 1 | N+2 | 描述符的字节数 | ^ 1 ^ bDescriptorType ^ 1 ^ 0x03 ^ 描述符类型编号 ^ ^ 2 | bString | N | UNICODE | UNICODE编码字符串 | ==== - 设备限定描述符(DEVICE_QUALIFIER) ==== ==== - 其他速率配置描述符(OTHER_SPEED_CONFIGURATION) ==== ===== - USB音频类描述符(Usb Audio Device Descriptor) ===== ---- [[https://www.usb.org/document-library/audio-device-class-spec-basic-audio-devices-v10-and-adopters-agreement|Audio Device Class Spec for Basic Audio Devices v1.0 and Adopters Agreement]] ==== - Standard Audio Control Interface Descriptor ==== 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的字符串描述符索引。 ==== - Class-Specific Audio Control Interface Header Descriptor ==== 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在集合中的索引值; ==== - Input Terminal Descriptor ==== 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; ==== - Output Terminal Descriptor ==== 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 ==== - Feature Unit Descriptor ==== ^ 偏移量 ^ 字段名称 ^ 长度(字节) ^ 字段值 ^ 意义 ^ ^ 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; ==== - Class-Specific Audio Streaming Interface Descriptor ==== 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 ==== - Standard AS Interface Descriptor ==== 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; ==== - Type I Format Type Descriptor ==== 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的高低位; ==== - Standard Audio Streaming Isochronous Audio Data Endpoint Descriptor ==== 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; 未使用; ==== - Hid Device ==== 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。如图 {{:library:stm32:pasted:20210204-181301.png}} Physicial Descriptor可选,一般没有,此时bNumDescriptor=1, 并且没有[bDescriptorType]和[wDescriptorLength]。 Report Descriptor没有固定的结构,它的最小单位是Item。从长度分类,Item分为两类,长item和短item。从功能分,Item分为3类Main item, Gobal item和Local item。大部分item都是短item,短Item的第一个字节含有item信息,如下图: {{:library:stm32:pasted:20210204-181323.png}} 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描述符(FORMAT_TYPE descriptor) ==== 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 [[https://blog.csdn.net/Z_HUALIN/article/details/80732036|USB音频类描述符及其说明]] ===== Generic Input Terminal Descriptor ===== ---- 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