USB系列之-UAC麦克风实例分享

原创 嵌入式Lee 2024-04-05 07:26

.前言

UAC的规格书可以从usb.org网站下载,目前有1.0,2.0,3.0三个版本,本文以1.0为例分享一个UAC扬声器的实例, 重点在于描述符拓扑。

规格书《UAC1.0/USB_AV_Specification_Rev_1.0》定义了UAC设备类完整的信息,但是比较复杂,UAC1.0\BasicAudioDevice-10\BasicAudioDevice-10.pdf》定义了其一个最小子集,一般我们实现其子集就够了。所以我们可以参考BasicAudioDevice-10.pdf的最简拓扑结构实现设备,然后具体的描述符,请求等细节可以参考USB_AV_Specification_Rev_1.0

.拓扑

BasicAudioDevice-10.pdf定义了需要支持的3个设备

Headphone:耳机设备,实际上声音播放的都算,所以PC上叫扬声器或者耳机。

Microphone:麦克风设备。

Headset:以上两者的集合,既有麦克风又有扬声器。

我们接下来就分三篇分享下这个三个设备实例,包括描述符拓扑,枚举过程等。

前文已经分享了扬声器,本文以麦克风为例。

我们这里以最简单的单声道为例。

如下是其拓扑结构,即最简单的有一个输入终端, 一个特征单元,一个输出终端。

数据流是: -> 输入终端 -> 特征单元 -> 输出终端 -> USB IN端点。

可以看到和扬声器的数据流是反向的,USB IN端点绑定到输出终端,这一点要特别注意。

其中特征单元用于静音,音量控制等。

.描述符拓扑

相关描述符参考BasicAudioDevice-10.pdf的第六章

我这里分享一个基于IAD的描述符拓扑实例

一共2个接口,接口2是控制接口,

接口3alt00带宽接口,设置接口选择该alt时关闭流,alt1是数据流接口,设置接口选择该alt时启动流,该接口下有一个IN端点用于发送数据。

控制接口中包括输入终端4,特征单元5和输出终端6。流接口3alt 1绑定到输出终端,

而输出终端对应的是IN端点0x82

四. 描述符实例

设备描述符和配置描述符如下,字符串描述符就略去了,描述符后有详细的注释和注意说明,不再赘述。

static const uint8_t dev_desc[] = {    0x12,        /* bLength 本描述符长度,固定为0x12 */    0x01,        /* bDescriptorType 描述符类型DEVICE=1, 见Table 9-5. Descriptor Types */    0x00,0x02,   /* bcdUSB USB规格书发布编号,BCD,小端 */    /* bDeviceClass-bDeviceSubClass-DeviceProtocol决定具体设备类型 见https://www.usb.org/defined-class-codes     * 这里EF-02-01表示IAD设备     */    0xEF,        /* bDeviceClass 设备类类型  */    0x02,        /* bDeviceSubClass 设备子类 */    0x01,        /* bDeviceProtocol 设备协议 */    0x40,        /* bMaxPacketSize0 控制端点最大包大小 */    0x4A,0x4C,   /* idVendor 厂商ID VID,小端*/    0x55,0x4C,   /* idProduct 产品ID PID,小端*/    0x00,0x01,   /* bcdDevice 设备发布号,BCD,小端*/    0x01,        /* iManufacturer 制造商字符串描述符索引 */      0x02,        /* iProduct 产品字符串描述符索引 */    0x03,        /* iSerialNumber 设备序列号字符串描述符索引 0则不使用 */    0x01,        /* bNumConfigurations 配置个数 */};
static const uint8_t cfg_desc[] = {    /* 配置描述符见Table 9-10. Standard Configuration Descriptor */    0x09,  /* bLength 本描述符长度,固定为9 */    0x02,  /* bDescriptorType 描述符类型CONFIGURATION =0x02, 见Table 9-5. Descriptor Types P251 */    0x75,  /* wTotalLength 本配置符所有内容长度,小端 */    0x00,    0x02,  /* bNumInterfaces 本配置的接口数 一个控制一个流 */    0x01,  /* bConfigurationValue 设置配置请求,选择该配置的对应的设置值 */    0x04,  /* iConfiguration 本配置对应的字符串描述符,配置为0则没有     */    0x80,  /* bmAttributes 配置特征 D7固定为1 D6:Self-powered D5:Remote Wakeup*/    0xC8,  /* bMaxPower 最大消耗电流,单位2mA */
    /********************************************************     *           以下是MIC+SPK部分     *******************************************************/    /**     * IAD描述符  参考InterfaceAssociationDescriptor_ecn P4    */    0x08,         /* bLength 本描述符长度,固定为8 */    0x0B,         /* bDescriptorType 描述符类型 INTERFACE_ASSOCIATION=0x0B 参考InterfaceAssociationDescriptor_ecn P3 */    MIC_AC_ITF,   /* bFirstInterface 本IAD下第一个接口 */    0x02,         /* bInterfaceCount 本IAD下接口数,默认一个控制接口一个SPK流接口一个MIC流接口 */    0x01,         /* bFunctionClass UAC是接口中说明类功能 这里应该是接口类 见https://www.usb.org/defined-class-codes (Audio=1) 见audio10.pdf P99 Table A-1: Audio Interface Class Code AUDIO=1 */    0x02,         /* bFunctionSubClass  UAC是接口中说明类功能 这里应该是接口类子类 见audio10.pdf P99 Table A-2: Audio Interface Subclass Codes AUDIOSTREAMING=0x02 */    0x00,         /* bFunctionProtocol UAC是接口中说明类功能 这里应该是接口协议号 见audio10.pdf P99 Table A-3: Audio Interface Protocol Codes PR_PROTOCOL_UNDEFINED=0x00  */    0x07,         /* iFunction 对应字符串索引                                */
        /********************************************************         *           控制接口部分         *******************************************************/        /* 接口描述符 UAC是接口描述符说明功能          * 见usb_20 P268 Table 9-12. Standard Interface Descriptor         */        0x09,         /* bLength                */        0x04,         /* bDescriptorType   见usb_20 P251 Table 9-5. Descriptor Types  INTERFACE=4   */        MIC_AC_ITF,   /* bInterfaceNumber       */        0x00,         /* bAlternateSetting      */        0x00,         /* bNumEndpoints 本接口下无端点*/        0x01,         /* bInterfaceClass    (Audio)  见audio10.pdf P99 Table A-1: Audio Interface Class Code AUDIO=1  */        0x01,         /* bInterfaceSubClass (Audio Control) 见audio10.pdf P99 Table A-2: Audio Interface Subclass Codes AUDIOCONTROL=0x01 */        0x00,         /* bInterfaceProtocol   见audio10.pdf P99 Table A-3: Audio Interface Protocol Codes PR_PROTOCOL_UNDEFINED=0x00  */        0x07,         /* iInterface 对应字符串索引           */
        /* BasicAudioDevice-10.pdf P57 Table 7-4: Headset Class-Specific AC Interface Header Descriptor */        0x09,         /* bLength */        0x24,         /* bDescriptorType 见audio10.pdf P99 Table A-4: Audio Class-specific Descriptor Types CS_INTERFACE=0x24  */        0x01,         /* bDescriptorSubtype 见audio10.pdf P100 Table A-5: Audio Class-Specific AC Interface Descriptor Subtypes HEADER=0x01 */        0x00,0x01,    /* bcdADC Audio 1.0 */        0x27,0x00,    /* wTotalLength 本接口下后续所有描述符的长度 包括本描述符 */        0x01,         /* bInCollection 1个流接口 */        MIC_AS_ITF,   /* baInterfaceNr(1) MIC流接口号 */                    /* BasicAudioDevice-10.pdf P59 7.3.3.1.6 Headset Microphone Input Terminal ID4 Descriptor         * BasicAudioDevice-10.pdf P40 6.3.3.1.3 Microphone Input Terminal ID4 Descriptor         * BasicAudioDevice-10.pdf P22 Table 5-3: Mono Input Terminal Descriptor        */        0x0C,       /* bLength */        0x24,       /* bDescriptorType 见audio10.pdf P99 Table A-4: Audio Class-specific Descriptor Types CS_INTERFACE=0x24 */        0x02,       /* bDescriptorSubtype 见audio10.pdf P100 Table A-5: Audio Class-Specific AC Interface Descriptor Subtypes INPUT_TERMINAL=0x02 */        MIC_INPUT_TID,/* bTerminalID TID=4*/        0x01,0x02,    /* wTerminalType TT Terminal is Microphone. */        0x00,         /* bAssocTerminal */        0x01,         /* bNrChannels 1个通道 */        0x04,0x00,    /* wChannelConfig Center Front channel. @todo 0x0000改为0004*/        0x00,         /* iChannelNames 固定为0 */        0x00,         /* iTerminal 对应字符串描述符索引 */
        /*         * BasicAudioDevice-10.pdf P60 7.3.3.1.10 Headset Feature Unit ID5 Descriptor        */        0x09,      /* bLength */        0x24,      /* bDescriptorType 见audio10.pdf P99 Table A-4: Audio Class-specific Descriptor Types CS_INTERFACE=0x24 */        0x06,      /* bDescriptorSubtype 见audio10.pdf P100 Table A-5: Audio Class-Specific AC Interface Descriptor Subtypes FEATURE_UNIT=0x06 */        MIC_FEATURE_TID,      /* bUnitID   */        MIC_INPUT_TID,        /* bSourceID */        0x01,                 /* bControlSize 这里配置不对会枚举失败 */        /**            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        */        0x01,                 /* bmaControls(0) Mute Control on Master Channel.*/        /*A bit set to 1 indicates that the mentioned          Control is supported for logical channel 1 */        0x02,                 /* bmaControls(1) Volume Control on Center Front channel */        0x00,                 /* iFeature 对应字符串描述符索引 */
        /*         * BasicAudioDevice-10.pdf P67 7.3.3.1.17 Headset Output Terminal ID6 Descriptor        */        0x09,    /* bLength */        0x24,    /* bDescriptorType 见audio10.pdf P99 Table A-4: Audio Class-specific Descriptor Types CS_INTERFACE=0x24 */        0x03,    /* bDescriptorSubtype 见audio10.pdf P100 Table A-5: Audio Class-Specific AC Interface Descriptor Subtypes OUTPUT_TERMINAL=0x03 */        MIC_OUTPUT_TID,       /* bTerminalID */        0x01,0x01,            /* wTerminalType USB Streaming Terminal Type*/        0x02,                 /* bAssocTerminal */        MIC_FEATURE_TID,      /* bSourceID */        0x00,                 /* iTerminal */
        /********************************************************         *           MIC流部分         *******************************************************/        /* 接口描述符        * usb_20.pdf P268 Table 9-12. Standard Interface Descriptor         * BasicAudioDevice-10.pdf P30  Table 5-13: Headphone Standard AS Interface Descriptor (Alt. Set. 0)        */        0x09,    /* bLength */        0x04,    /* bDescriptorType INTERFACE */        MIC_AS_ITF,    /* bInterfaceNumber */        0x00,    /* bAlternateSetting */        0x00,    /* bNumEndpoints */        0x01,    /* bInterfaceClass 见audio10.pdf P99 Table A-1: Audio Interface Class Code AUDIO=1  */        0x02,    /* bInterfaceSubClass 见audio10.pdf P99 Table A-2: Audio Interface Subclass Codes AUDIOSTREAMING=0x02 */        0x00,    /* bInterfaceProtocol 见audio10.pdf P99 Table A-3: Audio Interface Protocol Codes PR_PROTOCOL_UNDEFINED = 0x00 */        0x00,    /* iInterface         */
        /* 接口描述符        * usb_20.pdf P268 Table 9-12. Standard Interface Descriptor         BasicAudioDevice-10.pdf P31  Table 5-14: Headphone Standard AS Interface Descriptor (Alt. Set .1)        */        0x09,   /* bLength */        0x04,   /* bDescriptorType INTERFACE */        MIC_AS_ITF,   /* bInterfaceNumber */        0x01,   /* bAlternateSetting */        0x01,   /* bNumEndpoints 一个端点 */        0x01,   /* bInterfaceClass 见audio10.pdf P99 Table A-1: Audio Interface Class Code AUDIO=1 */        0x02,   /* bInterfaceSubClass 见audio10.pdf P99 Table A-2: Audio Interface Subclass Codes AUDIOSTREAMING=0x02 */        0x00,   /* bInterfaceProtocol 见audio10.pdf P99 Table A-3: Audio Interface Protocol Codes PR_PROTOCOL_UNDEFINED = 0x00 */        0x00,   /* iInterface         */
        /*         * BasicAudioDevice-10.pdf P31  Table 5-15: Headphone Class-specific AS General Interface Descriptor        */        0x07,   /* bLength */        0x24,   /* bDescriptorType 见audio10.pdf P99 Table A-4: Audio Class-specific Descriptor Types CS_INTERFACE=0x24  */        0x01,   /* bDescriptorSubtype 见audio10.pdf P100 Table A-6: Audio Class-Specific AS Interface Descriptor Subtypes AS_GENERAL=0x01 */        MIC_OUTPUT_TID,   /* bTerminalLink */        0x01,            /* bDelay Total interface delay, expressed in frames. Not used and shall be set to 0x00 */        0x01,0x00,       /* wFormatTag PCM Format */
        /*         * BasicAudioDevice-10.pdf P32 Table 5-16: Mono Headphone Type I Format Type Descriptor         */        0x0B,  /* bLength */        0x24,  /* bDescriptorType 见audio10.pdf P99 Table A-4: Audio Class-specific Descriptor Types CS_INTERFACE=0x24  */        0x02,  /* bDescriptorSubtype 见audio10.pdf P100 Table A-6: Audio Class-Specific AS Interface Descriptor Subtypes FORMAT_TYPE=0x02 */        0x01,  /* bFormatType 见frmts10.pdf P20 Table A-4: Format Type Codes FORMAT_TYPE_I=0x01 */        0x01,  /* bNrChannels One channel. */        0x02,  /* bSubFrameSize Two bytes per audio subframe. */        0x10,  /* bBitResolution 16 bits per sample */        0x01,  /* bSamFreqType One frequency supported. */        0x80,0x3E,0x00, /* tSamFreq 0x003E80=16000 */
        /* 端点描述符         * usb_20.pdf P269 Table 9-13. Standard Endpoint Descriptor        * BasicAudioDevice-10.pdf P33 Table 5-18: Mono Headphone Standard AS Audio Data Endpoint Descriptor        */        0x09,  /* bLength */        0x05,  /* bDescriptorType 见usb_20.pdf P251 Table 9-5. Descriptor Types ENDPOINT=5 */        MIC_IN_EP, /* bEndpointAddress */        0x0D,  /* bmAttributes b[1:0] 01 = Isochronous, b[3:2] 11 = Synchronous */        0x20,  0x00,  /* wMaxPacketSize */        0x01,  /* bInterval 1ms一包 */        0x00,  /* bRefresh  */        0x00,  /* bSynchAddress */
        /*         * BasicAudioDevice-10.pdf P33 Table 5-20: Headphone Class-specific Isoc. Audio Data Endpoint Descriptor        */        0x07,  /* bLength                                */        0x25,  /* bDescriptorType 见audio10.pdf P99 Table A-4: Audio Class-specific Descriptor Types CS_ENDPOINT=0x25 */        0x01,  /* bDescriptorSubtype 见audio10.pdf P101 Table A-8: Audio Class-Specific Endpoint Descriptor Subtypes EP_GENERAL=0x01. */        0x00,  /* bmAttributes No sampling frequency control, no pitch control, no packet padding.*/        0x00,  /* bLockDelayUnits */        0x00,  0x00, /* wLockDelay */};

如下是UsbTreeView抓到的描述符



---------------------- Device Descriptor ----------------------bLength : 0x12 (18 bytes)bDescriptorType : 0x01 (Device Descriptor)bcdUSB : 0x200 (USB Version 2.0)bDeviceClass : 0xEF (Miscellaneous)bDeviceSubClass : 0x02bDeviceProtocol : 0x01 (IAD - Interface Association Descriptor)bMaxPacketSize0 : 0x40 (64 bytes)idVendor : 0x4C4A (Unknown Vendor)idProduct : 0x4C55bcdDevice : 0x0100iManufacturer : 0x01 (String Descriptor 1) Language 0x0409 : "xxx.Technology"iProduct : 0x02 (String Descriptor 2) Language 0x0409 : "USB.Audio"iSerialNumber : 0x03 (String Descriptor 3) Language 0x0409 : "0.1"bNumConfigurations : 0x01 (1 Configuration)Data (HexDump) : 12 01 00 02 EF 02 01 40 4A 4C 55 4C 00 01 01 02 .......@JLUL.... 03 01 ..
------------------ Configuration Descriptor -------------------bLength : 0x09 (9 bytes)bDescriptorType : 0x02 (Configuration Descriptor)wTotalLength : 0x0075 (117 bytes)bNumInterfaces : 0x02 (2 Interfaces)bConfigurationValue : 0x01 (Configuration 1)iConfiguration : 0x04 (String Descriptor 4) Language 0x0409 : "UAC"bmAttributes : 0x80 D7: Reserved, set 1 : 0x01 D6: Self Powered : 0x00 (no) D5: Remote Wakeup : 0x00 (no) D4..0: Reserved, set 0 : 0x00MaxPower : 0xC8 (400 mA)Data (HexDump) : 09 02 75 00 02 01 04 80 C8 08 0B 02 02 01 02 00 ..u............. 07 09 04 02 00 00 01 01 00 07 09 24 01 00 01 27 ...........$... 00 01 03 0C 24 02 04 01 02 00 01 04 00 00 00 09 ....$........... 24 06 05 04 01 01 02 00 09 24 03 06 01 01 02 05 $........$...... 00 09 04 03 00 00 01 02 00 00 09 04 03 01 01 01 ................ 02 00 00 07 24 01 06 01 01 00 0B 24 02 01 01 02 ....$......$.... 10 01 80 3E 00 09 05 82 0D 20 00 01 00 00 07 25 ...>..... .....% 01 00 00 00 00 .....
------------------- IAD Descriptor --------------------bLength : 0x08 (8 bytes)bDescriptorType : 0x0B (Interface Association Descriptor)bFirstInterface : 0x02 (Interface 2)bInterfaceCount : 0x02 (2 Interfaces)*!*ERROR The total number of interfaces (2) must be greater than or equal to the highest linked interface number (base 2 + count 2 = 4)bFunctionClass : 0x01 (Audio)bFunctionSubClass : 0x02 (Audio Streaming)bFunctionProtocol : 0x00iFunction : 0x07 (String Descriptor 7) Language 0x0409 : "UAC"Data (HexDump) : 08 0B 02 02 01 02 00 07 ........
---------------- Interface Descriptor -----------------bLength : 0x09 (9 bytes)bDescriptorType : 0x04 (Interface Descriptor)bInterfaceNumber : 0x02 (Interface 2)bAlternateSetting : 0x00bNumEndpoints : 0x00 (Default Control Pipe only)bInterfaceClass : 0x01 (Audio)bInterfaceSubClass : 0x01 (Audio Control)bInterfaceProtocol : 0x00iInterface : 0x07 (String Descriptor 7) Language 0x0409 : "UAC"Data (HexDump) : 09 04 02 00 00 01 01 00 07 .........
------ Audio Control Interface Header Descriptor ------bLength : 0x09 (9 bytes)bDescriptorType : 0x24 (Audio Interface Descriptor)bDescriptorSubtype : 0x01 (Header)bcdADC : 0x0100wTotalLength : 0x0027 (39 bytes)bInCollection : 0x01baInterfaceNr[1] : 0x03Data (HexDump) : 09 24 01 00 01 27 00 01 03 .$... ...
------- Audio Control Input Terminal Descriptor -------bLength : 0x0C (12 bytes)bDescriptorType : 0x24 (Audio Interface Descriptor)bDescriptorSubtype : 0x02 (Input Terminal)bTerminalID : 0x04wTerminalType : 0x0201 (Microphone)bAssocTerminal : 0x00bNrChannels : 0x01 (1 channel)wChannelConfig : 0x0004 (C)iChannelNames : 0x00 (No String Descriptor)iTerminal : 0x00 (No String Descriptor)Data (HexDump) : 0C 24 02 04 01 02 00 01 04 00 00 00 .$..........
-------- Audio Control Feature Unit Descriptor --------bLength : 0x09 (9 bytes)bDescriptorType : 0x24 (Audio Interface Descriptor)bDescriptorSubtype : 0x06 (Feature Unit)bUnitID : 0x05 (5)bSourceID : 0x04 (4)bControlSize : 0x01 (1 byte per control)bmaControls[0] : 0x01 D0: Mute : 1 D1: Volume : 0 D2: Bass : 0 D3: Mid : 0 D4: Treble : 0 D5: Graphic Equalizer : 0 D6: Automatic Gain : 0 D7: Delay : 0bmaControls[1] : 0x02 D0: Mute : 0 D1: Volume : 1 D2: Bass : 0 D3: Mid : 0 D4: Treble : 0 D5: Graphic Equalizer : 0 D6: Automatic Gain : 0 D7: Delay : 0iFeature : 0x00 (No String Descriptor)Data (HexDump) : 09 24 06 05 04 01 01 02 00 .$.......
------- Audio Control Output Terminal Descriptor ------bLength : 0x09 (9 bytes)bDescriptorType : 0x24 (Audio Interface Descriptor)bDescriptorSubtype : 0x03 (Output Terminal)bTerminalID : 0x06wTerminalType : 0x0101 (USB Streaming)bAssocTerminal : 0x02 (2)bSourceID : 0x05 (5)iTerminal : 0x00 (No String Descriptor)Data (HexDump) : 09 24 03 06 01 01 02 05 00 .$.......
---------------- Interface Descriptor -----------------bLength : 0x09 (9 bytes)bDescriptorType : 0x04 (Interface Descriptor)bInterfaceNumber : 0x03 (Interface 3)bAlternateSetting : 0x00bNumEndpoints : 0x00 (Default Control Pipe only)bInterfaceClass : 0x01 (Audio)bInterfaceSubClass : 0x02 (Audio Streaming)bInterfaceProtocol : 0x00iInterface : 0x00 (No String Descriptor)Data (HexDump) : 09 04 03 00 00 01 02 00 00 .........
---------------- Interface Descriptor -----------------bLength : 0x09 (9 bytes)bDescriptorType : 0x04 (Interface Descriptor)bInterfaceNumber : 0x03 (Interface 3)bAlternateSetting : 0x01bNumEndpoints : 0x01 (1 Endpoint)bInterfaceClass : 0x01 (Audio)bInterfaceSubClass : 0x02 (Audio Streaming)bInterfaceProtocol : 0x00iInterface : 0x00 (No String Descriptor)Data (HexDump) : 09 04 03 01 01 01 02 00 00 .........
-------- Audio Streaming Interface Descriptor ---------bLength : 0x07 (7 bytes)bDescriptorType : 0x24 (Audio Interface Descriptor)bDescriptorSubtype : 0x01 (AS_GENERAL)bTerminalLink : 0x06 (Terminal ID 6)bDelay : 0x01 (1 frame)wFormatTag : 0x0001 (PCM)Data (HexDump) : 07 24 01 06 01 01 00 .$.....
------- Audio Streaming Format Type Descriptor --------bLength : 0x0B (11 bytes)bDescriptorType : 0x24 (Audio Interface Descriptor)bDescriptorSubtype : 0x02 (Format Type)bFormatType : 0x01 (FORMAT_TYPE_I)bNrChannels : 0x01 (1 channel)bSubframeSize : 0x02 (2 bytes per subframe)bBitResolution : 0x10 (16 bits per sample)bSamFreqType : 0x01 (supports 1 sample frequence)tSamFreq[1] : 0x03E80 (16000 Hz)Data (HexDump) : 0B 24 02 01 01 02 10 01 80 3E 00 .$.......>.
----------------- Endpoint Descriptor -----------------bLength : 0x09 (9 bytes)bDescriptorType : 0x05 (Endpoint Descriptor)bEndpointAddress : 0x82 (Direction=IN EndpointID=2)bmAttributes : 0x0D (TransferType=Isochronous SyncType=Synchronous EndpointType=Data)wMaxPacketSize : 0x0020 Bits 15..13 : 0x00 (reserved, must be zero) Bits 12..11 : 0x00 (0 additional transactions per microframe -> allows 1..1024 bytes per packet) Bits 10..0 : 0x20 (32 bytes per packet)bInterval : 0x01 (1 ms)bRefresh : 0x00bSynchAddress : 0x00Data (HexDump) : 09 05 82 0D 20 00 01 00 00 .... ....
----------- Audio Data Endpoint Descriptor ------------bLength : 0x07 (7 bytes)bDescriptorType : 0x25 (Audio Endpoint Descriptor)bDescriptorSubtype : 0x01 (General)bmAttributes : 0x00 D0 : Sampling Freq : 0x00 (not supported) D1 : Pitch : 0x00 (not supported) D6..2: Reserved : 0x00 D7 : MaxPacketsOnly : 0x00 (no)bLockDelayUnits : 0x00 (Undefined)wLockDelay : 0x0000Data (HexDump) : 07 25 01 00 00 00 00 .%.....
--------- Device Qualifier Descriptor (for Full-Speed) --------bLength : 0x0A (10 bytes)bDescriptorType : 0x06 (Device_qualifier Descriptor)bcdUSB : 0x200 (USB Version 2.00)bDeviceClass : 0xEF (Miscellaneous)bDeviceSubClass : 0x02bDeviceProtocol : 0x01 (IAD - Interface Association Descriptor)bMaxPacketSize0 : 0x40 (64 Bytes)bNumConfigurations : 0x01 (1 other-speed configuration)bReserved : 0x00Data (HexDump) : 0A 06 00 02 EF 02 01 40 01 00 .......@..
------------------ Configuration Descriptor -------------------bLength : 0x09 (9 bytes)bDescriptorType : 0x02 (Configuration Descriptor)wTotalLength : 0x0075 (117 bytes)bNumInterfaces : 0x02 (2 Interfaces)bConfigurationValue : 0x01 (Configuration 1)iConfiguration : 0x04 (String Descriptor 4) Language 0x0409 : "UAC"bmAttributes : 0x80 D7: Reserved, set 1 : 0x01 D6: Self Powered : 0x00 (no) D5: Remote Wakeup : 0x00 (no) D4..0: Reserved, set 0 : 0x00MaxPower : 0xC8 (400 mA)Data (HexDump) : 09 02 75 00 02 01 04 80 C8 08 0B 02 02 01 02 00 ..u............. 07 09 04 02 00 00 01 01 00 07 09 24 01 00 01 27 ...........$... 00 01 03 0C 24 02 04 01 02 00 01 04 00 00 00 09 ....$........... 24 06 05 04 01 01 02 00 09 24 03 06 01 01 02 05 $........$...... 00 09 04 03 00 00 01 02 00 00 09 04 03 01 01 01 ................ 02 00 00 07 24 01 06 01 01 00 0B 24 02 01 01 02 ....$......$.... 10 01 80 3E 00 09 05 82 0D 20 00 01 00 00 07 25 ...>..... .....% 01 00 00 00 00 .....
------------------- IAD Descriptor --------------------bLength : 0x08 (8 bytes)bDescriptorType : 0x0B (Interface Association Descriptor)bFirstInterface : 0x02 (Interface 2)bInterfaceCount : 0x02 (2 Interfaces)*!*ERROR The total number of interfaces (2) must be greater than or equal to the highest linked interface number (base 2 + count 2 = 4)bFunctionClass : 0x01 (Audio)bFunctionSubClass : 0x02 (Audio Streaming)bFunctionProtocol : 0x00iFunction : 0x07 (String Descriptor 7) Language 0x0409 : "UAC"Data (HexDump) : 08 0B 02 02 01 02 00 07 ........
---------------- Interface Descriptor -----------------bLength : 0x09 (9 bytes)bDescriptorType : 0x04 (Interface Descriptor)bInterfaceNumber : 0x02 (Interface 2)bAlternateSetting : 0x00bNumEndpoints : 0x00 (Default Control Pipe only)bInterfaceClass : 0x01 (Audio)bInterfaceSubClass : 0x01 (Audio Control)bInterfaceProtocol : 0x00iInterface : 0x07 (String Descriptor 7) Language 0x0409 : "UAC"Data (HexDump) : 09 04 02 00 00 01 01 00 07 .........
------ Audio Control Interface Header Descriptor ------bLength : 0x09 (9 bytes)bDescriptorType : 0x24 (Audio Interface Descriptor)bDescriptorSubtype : 0x01 (Header)bcdADC : 0x0100wTotalLength : 0x0027 (39 bytes)bInCollection : 0x01baInterfaceNr[1] : 0x03Data (HexDump) : 09 24 01 00 01 27 00 01 03 .$... ...
------- Audio Control Input Terminal Descriptor -------bLength : 0x0C (12 bytes)bDescriptorType : 0x24 (Audio Interface Descriptor)bDescriptorSubtype : 0x02 (Input Terminal)bTerminalID : 0x04wTerminalType : 0x0201 (Microphone)bAssocTerminal : 0x00bNrChannels : 0x01 (1 channel)wChannelConfig : 0x0004 (C)iChannelNames : 0x00 (No String Descriptor)iTerminal : 0x00 (No String Descriptor)Data (HexDump) : 0C 24 02 04 01 02 00 01 04 00 00 00 .$..........
-------- Audio Control Feature Unit Descriptor --------bLength : 0x09 (9 bytes)bDescriptorType : 0x24 (Audio Interface Descriptor)bDescriptorSubtype : 0x06 (Feature Unit)bUnitID : 0x05 (5)bSourceID : 0x04 (4)bControlSize : 0x01 (1 byte per control)bmaControls[0] : 0x01 D0: Mute : 1 D1: Volume : 0 D2: Bass : 0 D3: Mid : 0 D4: Treble : 0 D5: Graphic Equalizer : 0 D6: Automatic Gain : 0 D7: Delay : 0bmaControls[1] : 0x02 D0: Mute : 0 D1: Volume : 1 D2: Bass : 0 D3: Mid : 0 D4: Treble : 0 D5: Graphic Equalizer : 0 D6: Automatic Gain : 0 D7: Delay : 0iFeature : 0x00 (No String Descriptor)Data (HexDump) : 09 24 06 05 04 01 01 02 00 .$.......
------- Audio Control Output Terminal Descriptor ------bLength : 0x09 (9 bytes)bDescriptorType : 0x24 (Audio Interface Descriptor)bDescriptorSubtype : 0x03 (Output Terminal)bTerminalID : 0x06wTerminalType : 0x0101 (USB Streaming)bAssocTerminal : 0x02 (2)bSourceID : 0x05 (5)iTerminal : 0x00 (No String Descriptor)Data (HexDump) : 09 24 03 06 01 01 02 05 00 .$.......
---------------- Interface Descriptor -----------------bLength : 0x09 (9 bytes)bDescriptorType : 0x04 (Interface Descriptor)bInterfaceNumber : 0x03 (Interface 3)bAlternateSetting : 0x00bNumEndpoints : 0x00 (Default Control Pipe only)bInterfaceClass : 0x01 (Audio)bInterfaceSubClass : 0x02 (Audio Streaming)bInterfaceProtocol : 0x00iInterface : 0x00 (No String Descriptor)Data (HexDump) : 09 04 03 00 00 01 02 00 00 .........
---------------- Interface Descriptor -----------------bLength : 0x09 (9 bytes)bDescriptorType : 0x04 (Interface Descriptor)bInterfaceNumber : 0x03 (Interface 3)bAlternateSetting : 0x01bNumEndpoints : 0x01 (1 Endpoint)bInterfaceClass : 0x01 (Audio)bInterfaceSubClass : 0x02 (Audio Streaming)bInterfaceProtocol : 0x00iInterface : 0x00 (No String Descriptor)Data (HexDump) : 09 04 03 01 01 01 02 00 00 .........
-------- Audio Streaming Interface Descriptor ---------bLength : 0x07 (7 bytes)bDescriptorType : 0x24 (Audio Interface Descriptor)bDescriptorSubtype : 0x01 (AS_GENERAL)bTerminalLink : 0x06 (Terminal ID 6)bDelay : 0x01 (1 frame)wFormatTag : 0x0001 (PCM)Data (HexDump) : 07 24 01 06 01 01 00 .$.....
------- Audio Streaming Format Type Descriptor --------bLength : 0x0B (11 bytes)bDescriptorType : 0x24 (Audio Interface Descriptor)bDescriptorSubtype : 0x02 (Format Type)bFormatType : 0x01 (FORMAT_TYPE_I)bNrChannels : 0x01 (1 channel)bSubframeSize : 0x02 (2 bytes per subframe)bBitResolution : 0x10 (16 bits per sample)bSamFreqType : 0x01 (supports 1 sample frequence)tSamFreq[1] : 0x03E80 (16000 Hz)Data (HexDump) : 0B 24 02 01 01 02 10 01 80 3E 00 .$.......>.
----------------- Endpoint Descriptor -----------------bLength : 0x09 (9 bytes)bDescriptorType : 0x05 (Endpoint Descriptor)bEndpointAddress : 0x82 (Direction=IN EndpointID=2)bmAttributes : 0x0D (TransferType=Isochronous SyncType=Synchronous EndpointType=Data)wMaxPacketSize : 0x0020 (32 bytes)bInterval : 0x01 (1 ms)bRefresh : 0x00bSynchAddress : 0x00Data (HexDump) : 09 05 82 0D 20 00 01 00 00 .... ....
----------- Audio Data Endpoint Descriptor ------------bLength : 0x07 (7 bytes)bDescriptorType : 0x25 (Audio Endpoint Descriptor)bDescriptorSubtype : 0x01 (General)bmAttributes : 0x00 D0 : Sampling Freq : 0x00 (not supported) D1 : Pitch : 0x00 (not supported) D6..2: Reserved : 0x00 D7 : MaxPacketsOnly : 0x00 (no)bLockDelayUnits : 0x00 (Undefined)wLockDelay : 0x0000Data (HexDump) : 07 25 01 00 00 00 00 .%.....
-------------------- String Descriptors ------------------- ------ String Descriptor 0 ------bLength : 0x04 (4 bytes)bDescriptorType : 0x03 (String Descriptor)Language ID[0] : 0x0409 (English - United States)Data (HexDump) : 04 03 09 04 .... ------ String Descriptor 1 ------bLength : 0x1E (30 bytes)bDescriptorType : 0x03 (String Descriptor)Language 0x0409 : "xxx.Technology"Data (HexDump) : 1E 03 78 00 78 00 78 00 2E 00 54 00 65 00 63 00 ..x.x.x...T.e.c. 68 00 6E 00 6F 00 6C 00 6F 00 67 00 79 00 h.n.o.l.o.g.y. ------ String Descriptor 2 ------bLength : 0x14 (20 bytes)bDescriptorType : 0x03 (String Descriptor)Language 0x0409 : "USB.Audio"Data (HexDump) : 14 03 55 00 53 00 42 00 2E 00 41 00 75 00 64 00 ..U.S.B...A.u.d. 69 00 6F 00 i.o. ------ String Descriptor 3 ------bLength : 0x08 (8 bytes)bDescriptorType : 0x03 (String Descriptor)Language 0x0409 : "0.1"Data (HexDump) : 08 03 30 00 2E 00 31 00 ..0...1. ------ String Descriptor 4 ------bLength : 0x08 (8 bytes)bDescriptorType : 0x03 (String Descriptor)Language 0x0409 : "UAC"Data (HexDump) : 08 03 55 00 41 00 43 00 ..U.A.C. ------ String Descriptor 5 ------bLength : 0x08 (8 bytes)bDescriptorType : 0x03 (String Descriptor)Language 0x0409 : "UAC"Data (HexDump) : 08 03 55 00 41 00 43 00 ..U.A.C. ------ String Descriptor 6 ------bLength : 0x08 (8 bytes)bDescriptorType : 0x03 (String Descriptor)Language 0x0409 : "UAC"Data (HexDump) : 08 03 55 00 41 00 43 00 ..U.A.C. ------ String Descriptor 7 ------bLength : 0x08 (8 bytes)bDescriptorType : 0x03 (String Descriptor)Language 0x0409 : "UAC"Data (HexDump) : 08 03 55 00 41 00 43 00 ..U.A.C. ------ String Descriptor 8 ------bLength : 0x08 (8 bytes)bDescriptorType : 0x03 (String Descriptor)Language 0x0409 : "UAC"Data (HexDump) : 08 03 55 00 41 00 43 00 ..U.A.C.

四. 枚举过程

见九.抓包文件分享,不再赘述

五. 开关控制

切换选择麦克风

可以看到如下请求

通过选择流接口的alt 0带宽接口来关闭流,

选择流接口的非0带宽接口,这里只有一个alt1来打开流。

即设置接口标准请求。

我们这里流接口号是3

01 0b 01 00 03 00 00 00

01 0b 00 00 03 00 00 00

.静音与音量控制

系统声音点击静音,可以看到如下请求

静音

发送请求

21 01 00 01 02 05 01 00

数据为

01

取消静音

发送请求

21 01 00 01 02 05 01 00

数据为

00

Audio10.pdf

P66 5.2.1.1 Set Request

P75 5.2.2.4.3.1 Mute Control

所以解释如下


21

01

00 01

02 05

01 00

数据

接口类请求

SET_CUR

高字节表示Control Selector

(CS)

P102

Table A-11: Feature Unit Control Selectors

0x01表示静音控制

 

低字节(前面的02表示接口2)

高字节(后面的05)表示unit ID5即特征单元.

表示后面数据只有一个字节

1个字节,1表示静音,0表示不静音


类似的系统声音修改音量,可以看到如下请求

21 01 01 02 02 05 02 00 数据为28 f3

解释如下

21

01

01 02

02 05

02 00

数据

SET接口类请求

SET_CUR

高字节表示Control Selector

(CS)

P102

Table A-11: Feature Unit Control Selectors

0x02表示音量控制

 

低字节(前面的02表示接口2)

高字节(后面的05)表示unit ID5即特征单元.

表示后面数据2个字节

2个字节音量

音量和静音的控制使能要在特征单元描述符中指定

而音量的最小值,最大值,步进值枚举时通过GET请求获取

我这里是0xfc50,0xe3a0,0xff0f,0x0030

请求如下

解释如下


81

01

01 02

02 02

02 00

数据

GET接口类请求

81 GET_CUR

82 GET_DEF

83 GET_MAX

84 GET_RES

高字节表示Control Selector

(CS)

P102

Table A-11: Feature Unit Control Selectors

0x02表示音量控制

 

低字节(前面的02表示接口2)

高字节(后面的05)表示unit ID5即特征单元.

表示后面数据2个字节

2个字节音量

.数据传输

16k采样率,16位,单通道,正好是1ms传输32字节。

和描述符对应

 /*         * BasicAudioDevice-10.pdf P32 Table 5-16: Mono Headphone Type I Format Type Descriptor         */        0x0B,  /* bLength */        0x24,  /* bDescriptorType 见audio10.pdf P99 Table A-4: Audio Class-specific Descriptor Types CS_INTERFACE=0x24  */        0x02,  /* bDescriptorSubtype 见audio10.pdf P100 Table A-6: Audio Class-Specific AS Interface Descriptor Subtypes FORMAT_TYPE=0x02 */        0x01,  /* bFormatType 见frmts10.pdf P20 Table A-4: Format Type Codes FORMAT_TYPE_I=0x01 */        0x01,  /* bNrChannels One channel. */        0x02,  /* bSubFrameSize Two bytes per audio subframe. */        0x10,  /* bBitResolution 16 bits per sample */        0x01,  /* bSamFreqType One frequency supported. */        0x80,0x3E,0x00, /* tSamFreq 0x003E80=16000 */

.抓包文件分享

UAC_MIC.upv

可以使用USB Packet Viewer这个软件回放,方便查看枚举和数据传输过程。

链接:https://pan.baidu.com/s/1JUumn4s0FwDgASHDPRPQow?pwd=y8sb

提取码:y8sb

十. 总结

以上分享了一个完整的UAC的麦克风实例,描述符可以直接使用。USB描述符的正确是能顺利枚举的首要条件,枚举完成了,基本就成功了一半了。有时候描述符一丁点不对就会导致枚举失败,所以有时候这些问题会困扰很久,有一个正确的描述符作为参考显得很有价值。故特分享此案例。


评论 (0)
  • 文/郭楚妤编辑/cc孙聪颖‍相较于一众措辞谨慎、毫无掌舵者个人风格的上市公司财报,利亚德的财报显得尤为另类。利亚德光电集团成立于1995年,是一家以LED显示、液晶显示产品设计、生产、销售及服务为主业的高新技术企业。自2016年年报起,无论业绩优劣,董事长李军每年都会在财报末尾附上一首七言打油诗,抒发其对公司当年业绩的感悟。从“三年翻番顺大势”“智能显示我第一”“披荆斩棘幸从容”等词句中,不难窥见李军的雄心壮志。2012年,利亚德(300296.SZ)在深交所创业板上市。成立以来,该公司在细分领
    华尔街科技眼 2025-05-07 19:25 438浏览
  • Matter协议是一个由Amazon Alexa、Apple HomeKit、Google Home和Samsung SmartThings等全球科技巨头与CSA联盟共同制定的开放性标准,它就像一份“共生契约”,能让原本相互独立的家居生态在应用层上握手共存,同时它并非另起炉灶,而是以IP(互联网协议)为基础框架,将不同通信协议下的家居设备统一到同一套“语义规则”之下。作为应用层上的互通标准,Matter协议正在重新定义智能家居行业的运行逻辑,它不仅能向下屏蔽家居设备制造商的生态和系统,让设备、平
    华普微HOPERF 2025-05-08 11:40 385浏览
  • 随着智能驾驶时代到来,汽车正转变为移动计算平台。车载AI技术对存储器提出新挑战:既要高性能,又需低功耗和车规级可靠性。贞光科技代理的紫光国芯车规级LPDDR4存储器,以其卓越性能成为国产芯片产业链中的关键一环,为智能汽车提供坚实的"记忆力"支持。作为官方授权代理商,贞光科技通过专业技术团队和完善供应链,让这款国产存储器更好地服务国内汽车厂商。本文将探讨车载AI算力需求现状及贞光科技如何通过紫光国芯LPDDR4产品满足市场需求。 车载AI算力需求激增的背景与挑战智能驾驶推动算力需求爆发式
    贞光科技 2025-05-07 16:54 220浏览
  • 二位半 5线数码管的驱动方法这个2位半的7段数码管只用5个管脚驱动。如果用常规的7段+共阳/阴则需要用10个管脚。如果把每个段看成独立的灯。5个管脚来点亮,任选其中一个作为COM端时,另外4条线可以单独各控制一个灯。所以实际上最多能驱动5*4 = 20个段。但是这里会有一个小问题。如果想点亮B1,可以让第3条线(P3)置高,P4 置低,其它阳极连P3的灯对应阴极P2 P1都应置高,此时会发现C1也会点亮。实际操作时,可以把COM端线P3设置为PP输出,其它线为OD输出。就可以单独控制了。实际的驱
    southcreek 2025-05-07 15:06 549浏览
  • 后摄像头是长这个样子,如下图。5孔(D-,D+,5V,12V,GND),说的是连接线的个数,如下图。4LED,+12V驱动4颗LED灯珠,给摄像头补光用的,如下图。打开后盖,发现里面有透明白胶(防水)和白色硬胶(固定),用合适的工具,清理其中的胶状物。BOT层,AN3860,Panasonic Semiconductor (松下电器)制造的,Cylinder Motor Driver IC for Video Camera,如下图。TOP层,感光芯片和广角聚焦镜头组合,如下图。感光芯片,看着是玻
    liweicheng 2025-05-07 23:55 449浏览
  • UNISOC Miracle Gaming奇迹手游引擎亮点:• 高帧稳帧:支持《王者荣耀》等主流手游90帧高画质模式,连续丢帧率最高降低85%;• 丝滑操控:游戏冷启动速度提升50%,《和平精英》开镜开枪操作延迟降低80%;• 极速网络:专属游戏网络引擎,使《王者荣耀》平均延迟降低80%;• 智感语音:与腾讯GVoice联合,弱网环境仍能保持清晰通话;• 超高画质:游戏画质增强、超级HDR画质、游戏超分技术,优化游戏视效。全球手游市场规模日益壮大,游戏玩家对极致体验的追求愈发苛刻。紫光展锐全新U
    紫光展锐 2025-05-07 17:07 335浏览
  • 硅二极管温度传感器是一种基于硅半导体材料特性的测温装置,其核心原理是利用硅二极管的电学参数(如正向压降或电阻)随温度变化的特性实现温度检测。以下是其工作原理、技术特点及典型应用:一、工作原理1、‌PN结温度特性‌硅二极管由PN结构成,当温度变化时,其正向电压 VF与温度呈线性负相关关系。例如,温度每升高1℃,VF约下降2 mV。2、‌电压—温度关系‌通过jing确测量正向电压的微小变化,可推算出环境温度值。部分型号(如SI410)在宽温域内(如1.4 K至475 K)仍能保持高线性度。
    锦正茂科技 2025-05-09 13:52 248浏览
  • 温度传感器的工作原理依据其类型可分为以下几种主要形式:一、热电阻温度传感器利用金属或半导体材料的电阻值随温度变化的特性实现测温:l ‌金属热电阻‌(如铂电阻 Pt100、Pt1000):高温下电阻值呈线性增长,稳定性高,适用于工业精密测温。l ‌热敏电阻‌(NTC/PTC):NTC 热敏电阻阻值随温度升高而下降,PTC 则相反;灵敏度高但线性范围较窄,常用于电子设备温控。二、热电偶传感器基于‌塞贝克效应‌(Seebeck effect):两种不同
    锦正茂科技 2025-05-09 13:31 235浏览
  • 这款无线入耳式蓝牙耳机是长这个样子的,如下图。侧面特写,如下图。充电接口来个特写,用的是卡座卡在PCB板子上的,上下夹紧PCB的正负极,如下图。撬开耳机喇叭盖子,如下图。精致的喇叭(HY),如下图。喇叭是由电学产生声学的,具体结构如下图。电池包(AFS 451012  21 12),用黄色耐高温胶带进行包裹(安规需求),加强隔离绝缘的,如下图。451012是电池包的型号,聚合物锂电池+3.7V 35mAh,详细如下图。电路板是怎么拿出来的呢,剪断喇叭和电池包的连接线,底部抽出PCB板子
    liweicheng 2025-05-06 22:58 632浏览
  • 飞凌嵌入式作为龙芯合作伙伴,隆重推出FET-2K0300i-S全国产自主可控工业级核心板!FET-2K0300i-S核心板基于龙芯2K0300i工业级处理器开发设计,集成1个64位LA264处理器,主频1GHz,提供高效的计算能力;支持硬件ECC;2K0300i还具备丰富的连接接口USB、SDIO、UART、SPI、CAN-FD、Ethernet、ADC等一应俱全,龙芯2K0300i支持四路CAN-FD接口,具备良好的可靠性、实时性和灵活性,可满足用户多路CAN需求。除性价比超高的国产处理器外,
    飞凌嵌入式 2025-05-07 11:54 95浏览
我要评论
0
0
点击右上角,分享到朋友圈 我知道啦
请使用浏览器分享功能 我知道啦