首页 文章

启用USB Audio Class 2.0音频输入流

提问于
浏览
1

我一直在尝试在我的微控制器设备上设置USB音频输入流 . 我知道每个USB音频流都有两个备用设置;备用设置0是没有流可用的地方;备用设置1是有可用流的时间 .

我已经设置了USB音频输出,所以我知道流描述符工作正常 . 显然,当主机告知音频何时通过时,微控制器调用USB中断来激活输出(告诉微控制器启用备用设置1 ......) . 但是,现在我很困惑如何启用USB音频输入端 . 我很困惑,因为显然主机没有告诉微控制器输入正在通过......而是设备告诉主机它正在发送数据 .

如果有人能够让我了解我将如何正确地启用输入流,这将是非常好的 . 我想知道我是否应该只是硬启用 endpoints 并以这种方式发送数据?如果需要,我可以提供更多代码,但我想这更像是一种思维类型/算法方法 .

这是我的流的备用设置的描述符:

.iface_alt0.bLength                  = sizeof(usb_iface_desc_t)
.iface_alt0.bDescriptorType          = USB_DT_INTERFACE
.iface_alt0.bInterfaceNumber         = UDI_AUDIO_IFACE_DATA_IN_NUMBER
.iface_alt0.bAlternateSetting        = 0
.iface_alt0.bNumEndpoints            = 0
.iface_alt0.bInterfaceClass          = AUDIO_IFACE_CLASS
.iface_alt0.bInterfaceSubClass       = AUDIO_IFACE_SUBCLASS_STREAMING
.iface_alt0.bInterfaceProtocol       = AUDIO_IFACE_IP_VERSION_02_00
.iface_alt0.iInterface               = 0
.iface_alt1.bLength                  = sizeof(usb_iface_desc_t)
.iface_alt1.bDescriptorType          = USB_DT_INTERFACE
.iface_alt1.bInterfaceNumber         = UDI_AUDIO_IFACE_DATA_IN_NUMBER
.iface_alt1.bAlternateSetting        = 1
.iface_alt1.bNumEndpoints            = UDI_AUDIO_IN_NB_ENDPOINTS
.iface_alt1.bInterfaceClass          = AUDIO_IFACE_CLASS
.iface_alt1.bInterfaceSubClass       = AUDIO_IFACE_SUBCLASS_STREAMING
.iface_alt1.bInterfaceProtocol       = AUDIO_IFACE_IP_VERSION_02_00
.iface_alt1.iInterface               = 0

谢谢!

EDIT - 刚看过这个来源:

"When this configuration is enabled, the first two interface descriptors with bAlternativeSettings equal to zero is used. However during operation the host can send a SetInterface request directed to that of Interface one with a alternative setting of one to enable the other interface descriptor." - USB in a Nutshell

Revised Question: How do I send a SetInterface Request to enable the USB device accept an input stream?

new update - 有没有办法可以通过描述符设置备用设置?我正在读这个关于流描述符 - > "The bmControls field contains a set of bit pairs, indicating which Controls are present and what their capabilities are." "D1..0 Active Alternate Setting Control","D3..2 Valid Alternate Setting Control" .

resolved sort of -
所以看起来我只需要在我的主机设备上打开一个音频应用程序来启用备用设置......我不知道是这种情况 .

1 回答

  • 1

    int libusb_set_interface_alt_setting (libusb_device_handle * dev, int interface_number, int alternate_setting)

    http://libusb.org/static/api-1.0/group__dev.html#ga3047fea29830a56524388fd423068b53

    通常,描述符中的字段类似于指向存储器位置的指针 . 如果映射有问题,则设备将无法工作 . 由于主机在其驱动程序中具有某个映射,因此设备必须遵守此映射

    http://www.usb.org/developers/docs/devclass_docs/audio10.pdf(第117页)中,据说有一个顶级标准AudioControl描述符和更低级别的特定于类的音频控制描述符 .

    除了AudioStreaming描述符,您还必须正确设置其他描述符 . 在http://www.usb.org/developers/docs/devclass_docs/audio10.pdf中的示例中,必须设置标准音频流接口描述符,类特定音频流描述符,类型I格式描述符,标准 endpoints 描述符,类特定等时音频数据 endpoints 描述符

    我不知道你的设备实现了什么类,也许你应该设置所有这些描述符然后它可能会工作我在AudioStreaming描述符中找不到bmControl字段 .

    通常,备用设置用于在 endpoints 或AudioStreaming接口之间切换,请参阅特定于类的接口描述符(第117页)

    来自第58-64页的http://www.usb.org/developers/docs/devclass_docs/audio10.pdf中的所有音频流相关描述符

    在linux USB音频驱动程序中有一个bmControl字段:

    /* 22  * bmControl field decoders
     23  *
     24  * From the USB Audio spec v2.0:
     25  *
     26  *   bmaControls() is a (ch+1)-element array of 4-byte bitmaps,
     27  *   each containing a set of bit pairs. **If a Control is present,
     28  *   it must be Host readable.** If a certain Control is not
     29  *   present then the bit pair must be set to 0b00.
     30  *   If a Control is present but read-only, the bit pair must be
     31  *   set to 0b01. If a Control is also Host programmable, the bit
     32  *   pair must be set to 0b11. The value 0b10 is not allowed.
     33  *
     34  */
    

    http://lxr.free-electrons.com/source/include/linux/usb/audio-v2.h

    (第36页http://www.usb.org/developers/docs/devclass_docs/audio10.pdf

相关问题