USB鼠标实现——配置描述符集合(三)

配置描述符集合

仓库地址

仓库地址

USB 鼠标阅读顺序

获取配置描述符请求

在这里插入图片描述

标准设备请求

typedef struct __attribute__ ((packed)){
    
    
    union {
    
    
        struct __attribute__ ((packed)) {
    
    
          uint8_t recipient :  5; ///< Recipient type usb_request_recipient_t.
          uint8_t type      :  2; ///< Request type usb_request_type_t.
          uint8_t direction :  1; ///< Direction type. usb_dir_t
        } bmRequestType_bit;

        uint8_t bmRequestType;
    };

    uint8_t  bRequest;
    uint16_t wValue;
    uint16_t wIndex;
    uint16_t wLength;
} usb_control_request_t;

USB 控制端点收到的数据

0x80 0x6 0x0 0x2 0x0 0x0 0xff 0x0
  • bmRequestType:0x80
    • 数据传输方向为 1,device-to-host
    • 标准请求
    • 请求的接收者为设备
  • bRequest:0x06
    • GET_DESCRIPTOR 获取描述符请求
  • wValue:0x0002(LSB)
    • 低位:0x02 配置描述符
    • 高位:0x00 索引号
  • wIndex:0x0000(LSB)
    • 低位:0x00
    • 高位:0x00
  • wLength:0xff
    • 低位:0xff 请求返回的字节数为 0xff,设备实际返回的字节数可以比该域指定的字节数少
    • 高位:0x00

配置描述符集合返回

USB描述符之间的关系可以知道,由于当前只有一个接口和一个端点,所以配置描述符的集合为

{
    
    
    配置描述符,
    接口描述符,
    类特殊描述符 (HID 描述符),
    端点描述符,
}

配置描述符集合数据

0x9 0x2 0x22 0x0 0x1 0x1 0x0 0xa0 0x32 0x9 0x4 0x0 0x0 0x1 0x3 0x1 0x2 0x0 0x9 0x21 0x11 0x1 0x0 0x1 0x22 0x4d 0x0 0x7 0x5 0x81 0x3 0x8 0x0 0xa

配置描述符集合分析

  • 配置描述符 (0x9 0x2 0x22 0x0 0x1 0x1 0x0 0xa0 0x32)
    • bLength:0x09
      • 描述符的长度。配置描述符的长度为 0x09。
    • bDescriptorType:0x02
      • 描述符的类型。配置描述符的类型编码为 0x02。
    • wTotalLength:0x0022
      • 整个配置描述符集合的总长度,包括配置描述符,接口描述符,类特殊描述符 (HID 描述符) 和端点描述符,注意低字节在前。
    • bNumInterfaces:0x01
      • 该配置所支持的接口数量。通常功能单一的设备只具有一个接口,而复合设备则具有多个接口 。
    • bConfigurationValue:0x01
      • 该配置的值。通常一个 USB 设备可以支持多个配置。
    • iConfiguration:0x00
      • 描述该配置的字符串的索引值,如果该值为 0 ,表示没有字符串。
    • bmAttributes:0xa0
      • 用来描述设备的一些特性。
      • bit7 reserved(set to one)
      • bit5 remote wakeup
    • bMaxPower:0x32
      • 表示设备需要从总线获取的最大电流量,单位为 2 mA。
  • 接口描述符 (0x9 0x4 0x0 0x0 0x1 0x3 0x1 0x2 0x0)
    • bLength:0x09
      • 描述符的长度。标准的 USB 接口描述符的长度为 9 字节
    • bDescriptorType:0x04
      • 描述符的类型。接口描述符的类型编码为 0x04
    • bInterfaceNumber:0x00
      • 接口的编号。当一个配置具有多个接口时,每个接口的编号都不同。第一个接口,编号为 0
    • bAlternateSetting:0x00
      • 接口的备用编号,为 0
    • bNumEndpoints:0x01
      • 非 0 端点的数目。由于 USB 鼠标只需要一个中断输入端点,因此该值为 1
    • bInterfaceClass:0x03
      • 该接口所使用的类。USB 鼠标是 HID 类, HID 类的编码为 0x03
    • bInterfaceSubClass:0x01
      • 该接口所使用的子类。在 HID1.1 协议中只规定了一种子类:支持 BIOS 引导启动的子类。USB 键盘、鼠标属于该子类,子类代码为 0x01
    • bInterfaceProtocol:0x02
      • 如果子类为支持引导启动的子类,则协议可选择鼠标和键盘。键盘代码为 0x01,鼠标代码为 0x02。
    • iInterface:0x00
      • 接口的字符串的索引值为 0
  • 类特殊描述符 (HID 描述符:0x9 0x21 0x11 0x1 0x0 0x1 0x22 0x4d 0x0)
    • bLength:0x09
      • 本 HID 描述符下只有一个下级描述符。所以长度为 9 字节
    • bDescriptorType:0x21
      • HID 描述符的编号为 0x21
    • bcdHID:0x0111
      • 本协议使用的 HID 协议。低字节在先
    • bCountryCode:0x00
      • 设备适用的国家代码,大多数硬件都没有本地化,因此该值为 0
    • bNumDescriptors:0x01
      • 下级描述符的数目。我们只有一个报告描述符
    • bReportType:0x22
      • 下级描述符的类型,为报告描述符,编号为 0x22
    • wReportLength:0x004d
      • 级描述符的长度。下级描述符为报告描述符
  • 端点描述符 (0x7 0x5 0x81 0x3 0x8 0x0 0xa)
    • bLength:0x07
      • 描述符的长度。标准的 USB 端点描述符的长度为 7 字节
    • bDescriptorType:0x05
      • 描述符的类型,端点描述符的类型编码为 0x05
    • bEndpointAddress:0x81
      • 端点的地址, 7 位表示数据方向,输入端点 D7 为 1。所以输入端点 1 的地址为 0x81
    • bmAttributes:0x03
      • D1~D0 为端点传输类型选择, 该端点为中断端点。中断端点的编号为 3。其它位保留为 0
    • wMaxPacketSize:0x0008
      • 该端点的最大包长,低位为 0x08。端点 1 的最大包长为 8 字节, LSB 低字节在前
    • bInterval:0x0a
      • 端点查询的时间,我们设置为 10 个帧时间,即 10ms

附 STM32 枚举日志

HID 鼠标枚举过程分析

suspend int
bus reset int
enum done int
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x0 0x1 0x0 0x0 0x40 0x0
dcd xfer
input ep int
d->h :0x12 0x1 0x0 0x2 0x0 0x0 0x0 0x40 0xfe 0xca 0x8 0x40 0x0 0x1 0x1 0x2 0x3 0x1
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
bus reset int
output ep int
send xfer complete event
enum done int
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x0 0x5 0x4 0x0 0x0 0x0 0x0 0x0
dcd xfer
input ep int
edpt int send xfer complete event
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x0 0x1 0x0 0x0 0x12 0x0
dcd xfer
input ep int
d->h :0x12 0x1 0x0 0x2 0x0 0x0 0x0 0x40 0xfe 0xca 0x8 0x40 0x0 0x1 0x1 0x2 0x3 0x1
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
output ep int
send xfer complete event
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x0 0x2 0x0 0x0 0xff 0x0
dcd xfer
input ep int
d->h :0x9 0x2 0x22 0x0 0x1 0x1 0x0 0xa0 0x32 0x9 0x4 0x0 0x0 0x1 0x3 0x1 0x2 0x0 0x9 0x21 0x11 0x1 0x0 0x1 0x22 0x4d 0x0 0x7 0x5 0x81 0x3 0x8 0x0 0xa
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x3 0x3 0x9 0x4 0xff 0x0
send xfer complete event
dcd xfer
input ep int
d->h :0xe 0x3 0x31 0x0 0x32 0x0 0x33 0x0 0x34 0x0 0x35 0x0 0x36 0x0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x0 0x3 0x0 0x0 0xff 0x0
send xfer complete event
dcd xfer
input ep int
d->h :0x4 0x3 0x9 0x4
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x2 0x3 0x9 0x4 0xff 0x0
send xfer complete event
dcd xfer
input ep int
d->h :0x1e 0x3 0x54 0x0 0x69 0x0 0x6e 0x0 0x79 0x0 0x55 0x0 0x53 0x0 0x42 0x0 0x20 0x0 0x44 0x0 0x65 0x0 0x76 0x0 0x69 0x0 0x63 0x0 0x65 0x0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x0 0x6 0x0 0x0 0xa 0x0
send xfer complete event
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x0 0x1 0x0 0x0 0x12 0x0
dcd xfer
input ep int
d->h :0x12 0x1 0x0 0x2 0x0 0x0 0x0 0x40 0xfe 0xca 0x8 0x40 0x0 0x1 0x1 0x2 0x3 0x1
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x0 0x2 0x0 0x0 0x9 0x0
send xfer complete event
dcd xfer
input ep int
d->h :0x9 0x2 0x22 0x0 0x1 0x1 0x0 0xa0 0x32
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x0 0x2 0x0 0x0 0x22 0x0
send xfer complete event
dcd xfer
input ep int
d->h :0x9 0x2 0x22 0x0 0x1 0x1 0x0 0xa0 0x32 0x9 0x4 0x0 0x0 0x1 0x3 0x1 0x2 0x0 0x9 0x21 0x11 0x1 0x0 0x1 0x22 0x4d 0x0 0x7 0x5 0x81 0x3 0x8 0x0 0xa
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x0 0x9 0x1 0x0 0x0 0x0 0x0 0x0
send xfer complete event
edpt open
dcd xfer
input ep int
edpt int send xfer complete event
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x21 0xa 0x0 0x0 0x0 0x0 0x0 0x0
dcd xfer
input ep int
edpt int send xfer complete event
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x81 0x6 0x0 0x22 0x0 0x0 0x8d 0x0
dcd xfer
input ep int
d->h :0x5 0x1 0x9 0x2 0xa1 0x1 0x9 0x1 0xa1 0x0 0x5 0x9 0x19 0x1 0x29 0x5 0x15 0x0 0x25 0x1 0x95 0x5 0x75 0x1 0x81 0x2 0x95 0x1 0x75 0x3 0x81 0x1 0x5 0x1 0x9 0x30 0x9 0x31 0x15 0x81 0x25 0x7f 0x95 0x2 0x75 0x8 0x81 0x6 0x9 0x38 0x15 0x81 0x25 0x7f 0x95 0x1 0x75 0x8 0x81 0x6 0x5 0xc 0xa 0x38
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
input ep int
d->h :0x2 0x15 0x81 0x25 0x7f 0x95 0x1 0x75 0x8 0x81 0x6 0xc0 0xc0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
output ep int
send xfer complete event
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x0 0x3 0x0 0x0 0xff 0x0
dcd xfer
input ep int
d->h :0x4 0x3 0x9 0x4
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x1 0x3 0x9 0x4 0xff 0x0
send xfer complete event
dcd xfer
input ep int
d->h :0x10 0x3 0x54 0x0 0x69 0x0 0x6e 0x0 0x79 0x0 0x55 0x0 0x53 0x0 0x42 0x0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x0 0x3 0x0 0x0 0xff 0x0
send xfer complete event
dcd xfer
input ep int
d->h :0x4 0x3 0x9 0x4
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x2 0x3 0x9 0x4 0xff 0x0
send xfer complete event
dcd xfer
input ep int
d->h :0x1e 0x3 0x54 0x0 0x69 0x0 0x6e 0x0 0x79 0x0 0x55 0x0 0x53 0x0 0x42 0x0 0x20 0x0 0x44 0x0 0x65 0x0 0x76 0x0 0x69 0x0 0x63 0x0 0x65 0x0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x1 0x3 0x9 0x4 0xff 0x0
send xfer complete event
dcd xfer
input ep int
d->h :0x10 0x3 0x54 0x0 0x69 0x0 0x6e 0x0 0x79 0x0 0x55 0x0 0x53 0x0 0x42 0x0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
setup packed recvd
setup packed done
output ep int
h->d: 0x80 0x6 0x2 0x3 0x9 0x4 0xff 0x0
send xfer complete event
dcd xfer
input ep int
d->h :0x1e 0x3 0x54 0x0 0x69 0x0 0x6e 0x0 0x79 0x0 0x55 0x0 0x53 0x0 0x42 0x0 0x20 0x0 0x44 0x0 0x65 0x0 0x76 0x0 0x69 0x0 0x63 0x0 0x65 0x0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
rxflvl int
output ep int
send xfer complete event
dcd xfer
0x0 0x5 0x5 0x0 0x0
input ep int
d->h :0x0 0x5 0x5 0x0 0x0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
0x0 0x5 0x5 0x0 0x0
input ep int
d->h :0x0 0x5 0x5 0x0 0x0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
0x0 0x5 0x5 0x0 0x0
input ep int
d->h :0x0 0x5 0x5 0x0 0x0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
0x0 0x5 0x5 0x0 0x0
input ep int
d->h :0x0 0x5 0x5 0x0 0x0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
0x0 0x5 0x5 0x0 0x0
input ep int
d->h :0x0 0x5 0x5 0x0 0x0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
0x0 0x5 0x5 0x0 0x0
input ep int
d->h :0x0 0x5 0x5 0x0 0x0
turn off txfe
input ep int
edpt int send xfer complete event
dcd xfer
0x0 0x5 0x5 0x0 0x0
input ep int
d->h :0x0 0x5 0x5 0x0 0x0
turn off txfe
input ep int
edpt int send xfer complete event

```![在这里插入图片描述](https://img-blog.csdnimg.cn/f2d7898a6c85444fb3daf2dc3c485cf8.png#pic_center)

猜你喜欢

转载自blog.csdn.net/tyustli/article/details/129773965