Skip to content

Commit eca1d0a

Browse files
committed
Add a standard five button mouse report descriptor
1 parent 7712e4b commit eca1d0a

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

debug/usb/README.md

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ hid report descriptors在usb描述符中的关系
3434

3535
总共有3个按键
3636

37-
REPORT_COUNT (3) # 每个按键时单独上报,需要上报3次按键信息
37+
REPORT_COUNT (3) # 每个按键值是单独上报的,需要上报3次按键信息
3838
REPORT_SIZE (1) # 每次上报的大小为1bit
3939

4040
上报数据描述
4141

42-
INPUT (Data, Var, Abs)
42+
INPUT (Data, Var, Abs) # 2
4343

4444
所以按键的所有描述合起来就是如下
4545

@@ -56,7 +56,13 @@ hid report descriptors在usb描述符中的关系
5656

5757
REPORT_COUNT (1) # 只需要上报一次
5858
REPORT_SIZE (5) # 一次性上报5bit数据
59-
INPUT (Cnst,Var,Abs)
59+
INPUT (Cnst,Var,Abs) # 3
60+
61+
或者也可以
62+
63+
REPORT_COUNT (5) # 上报5次
64+
REPORT_SIZE (1) # 每次上报1bit数据
65+
INPUT (Cnst,Var,Abs) # 3
6066

6167
x轴的数据上报(y轴同理)
6268

@@ -79,7 +85,7 @@ x轴的数据上报(y轴同理)
7985
REPORT_COUNT (2) # 需要上报2次
8086
INPUT (Data,Var,Rel)
8187

82-
按键合xy轴合起来如下
88+
按键和xy轴合起来如下
8389

8490
USAGE_PAGE (Button)
8591
USAGE_MINIMUM (Button 1)
@@ -335,6 +341,10 @@ spice捕获坐标后传递给qemu的input子系统来作为鼠标数据提供给
335341
SpiceInput(spice-input.c)->InputCore(input.c)->USB HID Device(hid.c)
336342

337343
SpiceInput中通过button_mask来传入鼠标按键掩码值
344+
345+
- 传入对应按键的掩码表示该按键按下(Press)
346+
- 传入0表示该按键抬起(Release)
347+
338348
下面代将button4配置为side, button5配置为extra
339349
```c
340350
static void spice_update_buttons(QemuSpicePointer *pointer,
@@ -446,6 +456,47 @@ static const USBDescIface desc_iface_tablet = {
446456
sizeof(qemu_tablet_hid_report_descriptor) / sizeof(uint8_t), 0, /* u16 len */
447457
},
448458
...
459+
460+
/* 比较合理的做法是根据设备能支持的按键数来配置, 如下是标准五键鼠标 */
461+
static const uint8_t qemu_tablet_hid_report_descriptor[] = {
462+
0x05, 0x01, /* Usage Page (Generic Desktop) */
463+
0x09, 0x02, /* Usage (Mouse) */
464+
0xa1, 0x01, /* Collection (Application) */
465+
0x09, 0x01, /* Usage (Pointer) */
466+
0xa1, 0x00, /* Collection (Physical) */
467+
0x05, 0x09, /* Usage Page (Button) */
468+
0x19, 0x01, /* Usage Minimum (1) */
469+
0x29, 0x05, /* Usage Maximum (5) */
470+
0x15, 0x00, /* Logical Minimum (0) */
471+
0x25, 0x01, /* Logical Maximum (1) */
472+
0x95, 0x05, /* Report Count (5) */
473+
0x75, 0x01, /* Report Size (1) */
474+
0X81, 0x02, /* Input (Data, Variable, Absolute) */
475+
0x95, 0x01, /* Report Count (1) */
476+
0x75, 0x03, /* Report Size (3) */
477+
0x81, 0x03, /* Input (Constant) */
478+
0x05, 0x01, /* Usage Page (Generic Desktop) */
479+
0x09, 0x30, /* Usage (X) */
480+
0x09, 0x31, /* Usage (Y) */
481+
0x15, 0x00, /* Logical Minimum (0) */
482+
0x26, 0xff, 0x7f, /* Logical Maximum (0x7fff) */
483+
0x35, 0x00, /* Physical Minimum (0) */
484+
0x46, 0xff, 0x7f, /* Physical Maximum (0x7fff) */
485+
0x75, 0x10, /* Report Size (16) */
486+
0x95, 0x02, /* Report Count (2) */
487+
0x81, 0x02, /* Input (Data, Variable, Absolute) */
488+
0x05, 0x01, /* Usage Page (Generic Desktop) */
489+
0x09, 0x38, /* Usage (Wheel) */
490+
0x15, 0x81, /* Logical Minimum (-0x7f) */
491+
0x25, 0x7f, /* Logical Maximum (0x7f) */
492+
0x35, 0x00, /* Physical Minimum (same as logical) */
493+
0x45, 0x00, /* Physical Maximum (same as logical) */
494+
0x75, 0x08, /* Report Size (8) */
495+
0x95, 0x01, /* Report Count (1) */
496+
0x81, 0x06, /* Input (Data, Variable, Relative) */
497+
0xc0, /* End Collection */
498+
0xc0, /* End Collection */
499+
};
449500
```
450501

451502
### 调试输入数据

0 commit comments

Comments
 (0)