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;

语言 ID 获取(字符串索引为 0)

USB 控制端点收到的数据

0x80 0x6 0x0 0x3 0x0 0x0 0xff 0x0
  • bmRequestType:0x80
    • 数据传输方向为 1,device-to-host
    • 标准请求
    • 请求的接收者为设备。
  • bRequest:0x06
    • GET_DESCRIPTOR 获取描述符请求。
  • wValue:0x0300(LSB)
    • 低位:0x00 索引号,当前字符串索引为 0,表示获取语言 ID。
    • 高位:0x03 字符串描述符
  • wIndex:0x0000(LSB)
    • 低位:0x00
    • 高位:0x00
  • wLength:0xff
    • 低位:0xff 请求返回的字节数为 0xff,设备实际返回的字节数可以比该域指定的字节数少。
    • 高位:0x00

语言 ID 返回

0x4 0x3 0x9 0x4 
  • bLength:0x04
    • 描述符的长度。语言 ID 描述符的长度为 0x04。
  • bDescriptorType:0x03
    • 描述符的类型。字符串描述符的类型编码为 0x03。
  • 语言 ID:0x0409
  • 0x0409为美式英语的 ID。

厂商字符串获取(字符串索引为 1)

设备描述符,将 iManufacturer,的索引设置为 1。所以主机请求索引为 1 的字符串时,需要返回厂商字符串

USB 控制端点收到的数据

0x80 0x6 0x1 0x3 0x9 0x4 0xff 0x0
  • bmRequestType:0x80
    • 数据传输方向为 1,device-to-host
    • 标准请求
    • 请求的接收者为设备
  • bRequest:0x06
    • GET_DESCRIPTOR 获取描述符请求
  • wValue:0x0301(LSB)
    • 低位:0x01 索引号,当前字符串索引为 1,表示获取厂商字符串。
    • 高位:0x03 字符串描述符
  • wIndex:0x0409(LSB)
    • 低位:0x09 主机使用获取到的语言 ID 0x0409。
    • 高位:0x04
  • wLength:0xff
    • 低位:0xff 请求返回的字节数为 0xff,设备实际返回的字节数可以比该域指定的字节数少。
    • 高位:0x00

厂商字符串返回

0x10 0x3 0x74 0x0 0x79 0x0 0x75 0x0 0x73 0x0 0x74 0x0 0x6c 0x0 0x69 0x0
  • bLength:0x10
    • 描述符的长度。本次使用的厂商字符串描述符的长度为 0x10。
  • bDescriptorType:0x03
    • 描述符的类型。字符串描述符的类型编码为 0x03。
  • 厂商字符串:
  • 0x74 0x0 0x79 0x0 0x75 0x0 0x73 0x0 0x74 0x0 0x6c 0x0 0x69 0x0 UNICODE 编码的字符串,即为 tyustli

产品字符串获取(字符串索引为 2)

设备描述符,将 iProduct,的索引设置为 2。

USB 控制端点收到的数据

0x80 0x6 0x2 0x3 0x9 0x4 0xff 0x0
  • bmRequestType:0x80
    • 数据传输方向为 1,device-to-host
    • 标准请求
    • 请求的接收者为设备
  • bRequest:0x06
    • GET_DESCRIPTOR 获取描述符请求
  • wValue:0x0302(LSB)
    • 低位:0x02 索引号,当前字符串索引为 2,表示获取产品字符串。
    • 高位:0x03 字符串描述符
  • wIndex:0x0409(LSB)
    • 低位:0x09 主机使用获取到的语言 ID 0x0409。
    • 高位:0x04
  • wLength:0xff
    • 低位:0xff 请求返回的字节数为 0xff,设备实际返回的字节数可以比该域指定的字节数少。
    • 高位:0x00

产品字符串返回

0x1e 0x3 0x74 0x0 0x79 0x0 0x75 0x0 0x73 0x0 0x74 0x0 0x6c 0x0 0x69 0x0 0x20 0x0 0x44 0x0 0x65 0x0 0x76 0x0 0x69 0x0 0x63 0x0 0x65 0x0 
  • bLength:0x1e
    • 描述符的长度。本次使用的产品字符串描述符的长度为 0x1e。
  • bDescriptorType:0x03
    • 描述符的类型。字符串描述符的类型编码为 0x03。
  • 厂商字符串:
  • 0x74 0x0 0x79 0x0 0x75 0x0 0x73 0x0 0x74 0x0 0x6c 0x0 0x69 0x0 0x20 0x0 0x44 0x0 0x65 0x0 0x76 0x0 0x69 0x0 0x63 0x0 0x65 0x0 UNICODE 编码的字符串,即为 tyustli Device

产品序列号字符串获取(字符串索引为 3)

设备描述符,将 iSerialNumber,的索引设置为 3。

USB 控制端点收到的数据

0x80 0x6 0x3 0x3 0x9 0x4 0xff 0x0
  • bmRequestType:0x80
    • 数据传输方向为 1,device-to-host
    • 标准请求
    • 请求的接收者为设备
  • bRequest:0x06
    • GET_DESCRIPTOR 获取描述符请求
  • wValue:0x0303(LSB)
    • 低位:0x03 索引号,当前字符串索引为 3,表示获取产品序列号字符串。
    • 高位:0x03 字符串描述符
  • wIndex:0x0409(LSB)
    • 低位:0x09 主机使用获取到的语言 ID 0x0409。
    • 高位:0x04
  • wLength:0xff
    • 低位:0xff 请求返回的字节数为 0xff,设备实际返回的字节数可以比该域指定的字节数少。
    • 高位:0x00

产品序列号字符串返回

0xe 0x3 0x31 0x0 0x32 0x0 0x33 0x0 0x34 0x0 0x35 0x0 0x36 0x0 
  • bLength:0x0e
    • 描述符的长度。本次使用的产品字符串描述符的长度为 0x0e。
  • bDescriptorType:0x03
    • 描述符的类型。字符串描述符的类型编码为 0x03。
  • 产品序列号字符串:
  • 0x31 0x0 0x32 0x0 0x33 0x0 0x34 0x0 0x35 0x0 0x36 0x0 UNICODE 编码的字符串,即为 123456

附 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 0x5 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 0x74 0x0 0x79 0x0 0x75 0x0 0x73 0x0 0x74 0x0 0x6c 0x0 0x69 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 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 0x1 0x3 0x9 0x4 0xff 0x0 
send xfer complete event
dcd xfer
input ep int 
d->h :0x10 0x3 0x74 0x0 0x79 0x0 0x75 0x0 0x73 0x0 0x74 0x0 0x6c 0x0 0x69 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 0x74 0x0 0x79 0x0 0x75 0x0 0x73 0x0 0x74 0x0 0x6c 0x0 0x69 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 0x74 0x0 0x79 0x0 0x75 0x0 0x73 0x0 0x74 0x0 0x6c 0x0 0x69 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 0x2 0x3 0x9 0x4 0xff 0x0 
send xfer complete event
dcd xfer
input ep int 
d->h :0x1e 0x3 0x74 0x0 0x79 0x0 0x75 0x0 0x73 0x0 0x74 0x0 0x6c 0x0 0x69 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
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

猜你喜欢

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