USB 鼠标详解阅读顺序
1、枚举
2、设备描述符
3、设置地址
4、配置描述符
5、接口描述符
6、HID 描述符
7、端点描述符
8、字符串描述符
10、HID 报告的返回
端点描述符定义
端点描述符数据结构
typedef struct __attribute__ ((packed))
{
uint8_t bLength ; // Size of this descriptor in bytes
uint8_t bDescriptorType ; // ENDPOINT Descriptor Type
uint8_t bEndpointAddress ; // The address of the endpoint
struct __attribute__ ((packed)) {
uint8_t xfer : 2; // Control, ISO, Bulk, Interrupt
uint8_t sync : 2; // None, Asynchronous, Adaptive, Synchronous
uint8_t usage : 2; // Data, Feedback, Implicit feedback
uint8_t : 2;
} bmAttributes;
uint16_t wMaxPacketSize ; // Bit 10..0 : max packet size, bit 12..11 additional transaction per highspeed micro-frame
uint8_t bInterval ; // Polling interval, in frames or microframes depending on the operating speed
}usb_desc_endpoint_t;
省略了音频相关的数据结构
- bLength:该描述符的长度。标准的 USB 端点描述符的长度为 7 字节
- bDescriptorType:描述符的类型,端点描述符的类型编码为 0x05
- bEndpointAddress:该端点地址。最高位 D7 为该端点的传输方向,1 为输入,0 为输出。D3-D0 为端点号。D6-D4保留,为 0
- bmAttributes:该端点的属性
- wMaxPacketSize:2 字节,该端点所支持的最大包长度,注意低字节在前
- bInterval:表示该端点的查询时间。对于中断端点,表示查询的帧间隔数。
USB 鼠标的数据传输如下
- 0x07 bLength 字段。端点描述符长度为 7 字节
- 0x05 bDescriptorType 字段。端点描述符编号为 0x05
- 0x81 bEndpointAddress 字段。端点的地址,7 位表示数据方向,输入端点 D7 为 1。所以输入端点 1 的地址为 0x81
- 0x03 bmAttributes 字段。D1~D0 为端点传输类型选择,该端点为中断端点。中断端点的编号为 3。其它位保留为 0
- 0x05 wMaxPacketSize 字段。该端点的最大包长,低位为 0x05。端点 1 的最大包长为 5 字节, LSB 低字节在前
- 0x00 该端点的最大包长,高位为 0x00
- 0x0A bInterval字段。端点查询的时间,我们设置为 10 个帧时间,即10ms
至此,USB 的配置描述符已经全部返回。包括:配置描述符,接口描述符,HID 描述符和端点描述符