![usb库文件usb_desc.c分析 usb库文件usb_desc.c分析](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
参考《圈圈教你玩USB》
usb协议中使用的是小端结构,所以实际数据在传输时是低字节在先的。
设备描述符的实现:
已知每个设备都必须有且仅有一个设备描述符,它的结构在USB协议中有详细的定义。
偏移量 | 域 | 大小/字节 | 说 明 |
0 | bLength | 1 | 该描述符的长度(18字节) |
1 | bDescription | 1 | 描述符类型(设备描述符为0x01) |
2 | bcdUSB | 2 | 本设备所使用的usb协议版本 |
4 | bDeviceClass | 1 | 类代码 |
5 | bDeviceSubClass | 1 | 子类代码 |
6 | bDeviceProtocol | 1 | 设备所使用的协议 |
7 | bMaxPackSize0 | 1 | 端点0最大包长 |
8 | idVender | 2 | 厂商id |
10 | idProduct | 2 | 产品ID |
12 | bcdDevice | 2 | 设备版本号 |
14 | iManufacturer | 1 | 描述厂商的字符串的索引 |
15 | iProduct | 1 | 描述产品的字符串的索引 |
16 | iSerialNumber | 1 | 产品序列号字符串的索引 |
17 | bNumcofigurations | 1 | 可能的配置数 |
const uint8_t MASS_DeviceDescriptor[MASS_SIZ_DEVICE_DESC] =
{
0x12, /* bLength */
0x01, /* bDescriptorType */
0x00, /* bcdUSB, version 2.00 */
0x02,
0x00, /* bDeviceClass : each interface define the device class */
0x00, /* bDeviceSubClass */
0x00, /* bDeviceProtocol */
0x40, /* bMaxPacketSize0 0x40 = 64 */
0x83, /* idVendor (0483) */
0x04,
0x20, /* idProduct */
0x57,
0x00, /* bcdDevice 2.00*/
0x02,
, /* index of string Manufacturer */
/**/
, /* index of string descriptor of product*/
/* */
, /* */
/* */
/* */
0x01 /*bNumConfigurations */
};