写在前面:
前两天拿到一个产品,也就是一speakerphone;以前自己也参加过音频类USB设备的研发,当然只是单独的speaker或microphone,也曾经想过怎么让同一USB设备即作speaker输出又作microphone输入,只不过没有具体去实现。当拿到这个speakerphone后就有一种去实现这样一个USB设备的冲动,于是就有了这篇文章.......
先给出完整的usb描述符供参考:
const unsigned char Demo_DeviceDescriptor[] =
{
//Device:USB1.10,Vid=0x0435,Pid=0x2430,bNumConfigurations = 0x01,
0x12, //Length
0x01, //DescriptorType
0x10,0x01, //bcdUSB
0x00, //DeviceClass
0x00, //DeviceSubClass
0x00, //DeviceProtocol
0x08, //bMaxPacketSize 8
0x35,0x04, //idVendor........
0x30,0x24, //idProduct........
0x01,0x00, //bcdDevice
1, //iManufacturer
2, //iProduct
3, //iSerialNumber
0x01 //bNumConfigurations
};
/* USB Configuration Descriptor */
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
const unsigned char Demo_ConfigDescriptor[] =
{
//Configuration:wTotalLength = 0x00be,NumInterfaces = 0x03,
0x09, //Length
0x02, //DescriptorType : ConfigDescriptor
0xbe,0x00, //TotalLength:0x00be
0x03, //NumInterfaces:3
0x01, //ConfigurationValue
0x00, //Configuration String
0x80, //Attributes:Bus Power
0xfa, //MaxPower = 0xfa*2ma
//standard interface AC descriptor(Interface 0, Alternate Setting 0):
//bNumEndpoints = 0x00,bInterFaceClass = 0x01(audio),bInterfaceSubClass = 0x01(audio ctl),
0x09, //Length
0x04, //DescriptorType:Inerface
0x00, //InterfaceNum:0
0x00, //AlternateSetting:0
0x00, //NumEndpoint:0
0x01, //InterfaceClass:audio
0x01, //InterfaceSubClass:audio ctl
0x00, //InterfaceProtocol
0x00, //Interface String
//class-specific AC interface descriptor,audio interface(0x24),audio control header(0x01),
//Total Length 0x0048,Number of streaming interface 2,interfaceNr 2,1
0x0a, //Length
0x24, //DescriptorType:audio interface descriptor
0x01, //DescriptorSubType:audio control header
0x00,0x01, //bcdADC:audio Device Class v1.00
0x48,0x00, //TotalLength:0x0048
0x02, //InCollection:2 AudioStreaming interface
0x02, //InterfaceNr(2) - AS #1 id AudioStreaming interface 2 belongs to this AudioControl interface
0x01, //InterfaceNr(1) - AS #2 id AudioStreaming interface 1 belongs to this AudioControl interface
//USB Microphone IT:audio interface descriptor,audio control input terminal(0x02),terminal id 0x01,
//Microphone(0x0201),Input Terminal(0x02),2 channel:Left Front,Right Front
0x0c, //Length
0x24, //DescriptorType:audio interface descriptor
0x02, //DescriptorSubType:Input Terminal
0x01, //TerminalID:0x01
0x01,0x02, //TerminalType:USB Microphone