USB鼠标实现——设置配置和获取配置
Posted tyustli
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了USB鼠标实现——设置配置和获取配置相关的知识,希望对你有一定的参考价值。
文章目录
设置配置和获取配置
仓库地址
USB 鼠标阅读顺序
- 枚举过程
- USB鼠标实现——设备描述符(一)
- USB鼠标实现——设置地址(二)
- USB鼠标实现——配置描述符集合(三)
- USB鼠标实现——字符串描述符(四)
- USB鼠标实现——设备限定描述符(五)
- USB鼠标实现——设置配置和获取配置(六)
- USB鼠标实现——报告描述符(七)
- USB鼠标实现——HID 报告的返回(八)
set configuration
和 get configuration
主机在获取完 device qualifier
后,又单独获取了几次设备描述符和配置描述符等,描述符的返回这里不再赘述。
标准设备请求中有 set configuration
和 get configuration
。
只有在收到非 0 的配置值之后才可以使能非 0 端点,否则要禁用非 0 端点
设置配置
bRequest
域为 0x09
USB 控制端点收到的数据
0x0 0x9 0x1 0x0 0x0 0x0 0x0 0x0
- bmRequestType:0x00
- 数据传输方向为 0,host-to-device
- 标准请求
- 请求的接收者为设备
- bRequest:0x09
- SET_CONFIGURATION 设置配置请求。
- wValue:0x0001(LSB)
- 低位:0x01 配置值低位为 0x01。
- 高位:0x00 配置值高位为 0x00。
- wIndex:0x0000(LSB)
- 低位:0x00
- 高位:0x00
- wLength:0x00
- 低位:0x00
- 高位:0x00
无数据阶段
获取配置
bRequest
域为 0x08
USB 控制端点收到的数据
0x0 0x8 0x0 0x0 0x0 0x0 0x1 0x0
- bmRequestType:0x00
- 数据传输方向为 0,host-to-device
- 标准请求
- 请求的接收者为设备
- bRequest:0x08
- GET_CONFIGURATION 获取配置请求。
- wValue:0x0000(LSB)
- 低位:0x00
- 高位:0x00
- wIndex:0x0000(LSB)
- 低位:0x00
- 高位:0x00
- wLength:0x01
- 低位:0x01 数据长度为 1 个字节
- 高位:0x00
在数据阶段返回 1 字节的 set configuration
设置的值即可
注意事项
- 虽然枚举阶段可能没有用到
get configuration
,但是在过 USB 认证的时候CV test
会调用set/get configuration
。所以最好还是实现这一对请求,不然后续会返回来查找 bug 。 - 只有在收到非 0 的配置值之后才可以使能非 0 端点,否则要禁用非 0 端点。
附 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
get device qualifier
stall ep0
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
以上是关于USB鼠标实现——设置配置和获取配置的主要内容,如果未能解决你的问题,请参考以下文章