配置描述符:前9个字节格式固定,后面紧跟的各种描述结构跟实际配置有关,每增加一种描述结构,该描述结构的第一字节说明了结构的长度,第二直接说明了结构的类型。在配置描述符中一般包含配置描述、接口描述、端点描述,如果需要同样可增加自定义的描述。使用标准USB设备类别时,配置描述符的结构也必须满足此类标准设备的数据结构。
const unsigned char cbDescriptor_Config[DESC_SIZE_CONFIG] =
{
// Descriptor of configuration
0x09, // lengths
DESCRIPTOR_CONFIG, // descriptor type
DESC_SIZE_CONFIG, // Total configuration descriptor lengths LSB
0x00, // Total configuration descriptor lengths MSB
0x01, // bNumInterfaces: Total number of interfaces
0x01, // bConfigurationValue: Configuration value
0x00, // iConfiguration: Index of string descriptor describing the configuration
0xA0, // bmAttributes: bus powered
// bit 4...0 : Reserved, set to 0
// bit 5 : Remote wakeup (1:yes)
// bit 6 : Self power (1:yes)
// bit 7 : Reserved, set to 1
0x32, // bMaxPower: this current is used for detecting Vbus = 100mA
// Descriptor of interface
0x09,
DESCRIPTOR_INTERFACE,
0x00, // bInterfaceNumber: Number of Interface
0x00, // bAlternateSetting: Alternate setting
0x02, // bNumEndpoints: Number of endpoints except EP0
0x00, // bInterfaceClass:
0x00, // bInterfaceSubClass:
0x00, // nInterfaceProtocol:
0x00, // iInterface: Index of string descriptor describing the interface
// Descriptor of endpoint1 OUT
0x07,
DESCRIPTOR_ENDPOINT,
0x01, // bEndpointAddress
// bit 3...0 : the endpoint number
// bit 6...4 : reserved
// bit 7 : 0(OUT), 1(IN)
0x03, // bmAttributes
// bit 1...0 : Transfer type
// 00(CONTROL), 01(ISOCHRONOUS), 10(BULK), 11(INTERRUPT)
// bit 3...2 : Synchronization type
// 00(No Synch), 01(Asynchronous), 10(Adaptive), 11(Synchronous)
// bit 5...4 : Endpoint Usage type
// 00(data), 01(Feedback), 10(Implicit feedback data endpoint), 11(Reserved)
// bit 7...6 : Reserved, must be zero
0x40, // packet size LSB
0x00, // packet size MSB
0x20, // polling interval time: 32ms
// Descriptor of endpoint2 IN
0x07,
DESCRIPTOR_ENDPOINT,
0x82, // bEndpointAddress
// bit 3...0 : the endpoint number
// bit 6...4 : reserved
// bit 7 : 0(OUT), 1(IN)
0x03, // bmAttributes
// bit 1...0 : Transfer type
// 00(CONTROL), 01(ISOCHRONOUS), 10(BULK), 11(INTERRUPT)
// bit 3...2 : Synchronization type
// 00(No Synch), 01(Asynchronous), 10(Adaptive), 11(Synchronous)
// bit 5...4 : Endpoint Usage type
// 00(data), 01(Feedback), 10(Implicit feedback data endpoint), 11(Reserved)
// bit 7...6 : Reserved, must be zero
0x40, // packet size LSB
0x00, // packet size MSB
0x20 // polling interval time: 32ms
};
字符串描述符:定义了与设备有关的一些信息,常见的为以下四种,如果有需要,同样可以定义自己的字符串描述符。
const unsigned char cbDescriptor_StringLangID[DESC_SIZE_STRING_LANGID] =
{
DESC_SIZE_STRING_LANGID, // bLength
DESCRIPTOR_STRING, // bDescriptorType = String Descriptor
0x09, // LangID LSB:
0x04 // LangID MSB: 0x0409(U.S. English)
};
const unsigned char cbDescriptor_StringVendor[DESC_SIZE_STRING_VENDOR] =
{
DESC_SIZE_STRING_VENDOR, // bLength
DESCRIPTOR_STRING, // bDescriptorType = String Descriptor
// String: "LaBiXiaoXiaoXin"
'L',0, 'a',0, 'B',0, 'i',0, 'X',0, 'i',0, 'a',0, 'o',0,
'X',0, 'i',0, 'a',0, 'o',0, 'X',0, 'i',0, 'n',0
};
const unsigned char cbDescriptor_StringProduct[DESC_SIZE_STRING_PRODUCT] =
{
DESC_SIZE_STRING_PRODUCT, // bLength
DESCRIPTOR_STRING, // bDescriptorType = String Descriptor
// String: "STM32 ezUSB-CORE V1.01"
'S',0, 'T',0, 'M',0, '3',0, '2',0, ' ',0, 'e',0, 'z',0, 'U',0, 'S',0, 'B',0,
'-',0, 'C',0, 'O',0, 'R',0, 'E',0, ' ',0, 'V',0, '1',0, '.',0, '0',0, '1',0
};
const unsigned char cbDescriptor_StringSerial[DESC_SIZE_STRING_SERIAL] =
{
DESC_SIZE_STRING_SERIAL, // bLength
DESCRIPTOR_STRING, // bDescriptorType = String Descriptor
// String: "ezUSB-CORE Demo 2008/11/18"
'e',0, 'z',0, 'U',0, 'S',0, 'B',0, '-',0, 'C',0, 'O',0, 'R',0, 'E',0, ' ',0,
'D',0, 'e',0, 'm',0, 'o',0, ' ',0, '2',0, '0',0, '0',0, '8',0, '/',0, '1',0, '1',0, '/',0, '1',0, '8',0
};
了解这些描述符的用法以及作用,最好的方法的是编写自定义的USB上位机驱动以及应用程序,这样你可以深刻了解USB设备与主机间的数据交换方式以及实现手段。
|