这一次使用 CH567 制作一个USB键盘,参考的对象是Dostyle 的MK60 机械键盘。
同样的,使用 USBlyzer 抓取描述符信息:
USB Composite Device
Connection Status | Device connected |
Current Configuration | 1 |
Speed | Full (12 Mbit/s) |
Device Address | 8 |
Number Of Open Pipes | 2 |
Device Descriptor Gaming KB
Offset | Field | Size | Value | Description |
0 | bLength | 1 | 12h | |
1 | bDescriptorType | 1 | 01h | Device |
2 | bcdUSB | 2 | 0110h | USB Spec 1.1 |
4 | bDeviceClass | 1 | 00h | Class info in Ifc Descriptors |
5 | bDeviceSubClass | 1 | 00h | |
6 | bDeviceProtocol | 1 | 00h | |
7 | bMaxPacketSize0 | 1 | 08h | 8 bytes |
8 | idVendor | 2 | 258Ah | |
10 | idProduct | 2 | 002Ah | |
12 | bcdDevice | 2 | 1201h | 12.01 |
14 | iManufacturer | 1 | 01h | "SINO WEALTH" |
15 | iProduct | 1 | 02h | "Gaming KB " |
16 | iSerialNumber | 1 | 00h | |
17 | bNumConfigurations | 1 | 01h |
Configuration Descriptor 1 Bus Powered, 500 mA
Offset | Field | Size | Value | Description |
0 | bLength | 1 | 09h | |
1 | bDescriptorType | 1 | 02h | Configuration |
2 | wTotalLength | 2 | 003Bh | |
4 | bNumInterfaces | 1 | 02h | |
5 | bConfigurationValue | 1 | 01h | |
6 | iConfiguration | 1 | 00h | |
7 | bmAttributes | 1 | A0h | Bus Powered, Remote Wakeup |
4..0: Reserved | ...00000 | |||
5: Remote Wakeup | ..1..... | Yes | ||
6: Self Powered | .0...... | No, Bus Powered | ||
7: Reserved (set to one) (bus-powered for 1.0) | 1....... | |||
8 | bMaxPower | 1 | FAh | 500 mA |
Interface Descriptor 0/0 HID, 1 Endpoint
Offset | Field | Size | Value | Description |
0 | bLength | 1 | 09h | |
1 | bDescriptorType | 1 | 04h | Interface |
2 | bInterfaceNumber | 1 | 00h | |
3 | bAlternateSetting | 1 | 00h | |
4 | bNumEndpoints | 1 | 01h | |
5 | bInterfaceClass | 1 | 03h | HID |
6 | bInterfaceSubClass | 1 | 01h | Boot Interface |
7 | bInterfaceProtocol | 1 | 01h | Keyboard |
8 | iInterface | 1 | 00h |
Offset | Field | Size | Value | Description |
0 | bLength | 1 | 09h | |
1 | bDescriptorType | 1 | 21h | HID |
2 | bcdHID | 2 | 0111h | 1.11 |
4 | bCountryCode | 1 | 00h | |
5 | bNumDescriptors | 1 | 01h | |
6 | bDescriptorType | 1 | 22h | Report |
7 | wDescriptorLength | 2 | 0043h | 67 bytes |
Endpoint Descriptor 81 1 In, Interrupt, 1 ms
Offset | Field | Size | Value | Description |
0 | bLength | 1 | 07h | |
1 | bDescriptorType | 1 | 05h | Endpoint |
2 | bEndpointAddress | 1 | 81h | 1 In |
3 | bmAttributes | 1 | 03h | Interrupt |
1..0: Transfer Type | ......11 | Interrupt | ||
7..2: Reserved | 000000.. | |||
4 | wMaxPacketSize | 2 | 0008h | 8 bytes |
6 | bInterval | 1 | 01h | 1 ms |
Interface Descriptor 1/0 HID, 1 Endpoint
Offset | Field | Size | Value | Description |
0 | bLength | 1 | 09h | |
1 | bDescriptorType | 1 | 04h | Interface |
2 | bInterfaceNumber | 1 | 01h | |
3 | bAlternateSetting | 1 | 00h | |
4 | bNumEndpoints | 1 | 01h | |
5 | bInterfaceClass | 1 | 03h | HID |
6 | bInterfaceSubClass | 1 | 00h | |
7 | bInterfaceProtocol | 1 | 00h | |
8 | iInterface | 1 | 00h |
Offset | Field | Size | Value | Description |
0 | bLength | 1 | 09h | |
1 | bDescriptorType | 1 | 21h | HID |
2 | bcdHID | 2 | 0111h | 1.11 |
4 | bCountryCode | 1 | 00h | |
5 | bNumDescriptors | 1 | 01h | |
6 | bDescriptorType | 1 | 22h | Report |
7 | wDescriptorLength | 2 | 00CCh | 204 bytes |
Endpoint Descriptor 82 2 In, Interrupt, 1 ms
Offset | Field | Size | Value | Description |
0 | bLength | 1 | 07h | |
1 | bDescriptorType | 1 | 05h | Endpoint |
2 | bEndpointAddress | 1 | 82h | 2 In |
3 | bmAttributes | 1 | 03h | Interrupt |
1..0: Transfer Type | ......11 | Interrupt | ||
7..2: Reserved | 000000.. | |||
4 | wMaxPacketSize | 2 | 0010h | 16 bytes |
6 | bInterval | 1 | 01h | 1 ms |
Interface 0 HID Report Descriptor Keyboard
Item Tag (Value) | Raw Data |
Usage Page (Generic Desktop) | 05 01 |
Usage (Keyboard) | 09 06 |
Collection (Application) | A1 01 |
Usage Page (Keyboard/Keypad) | 05 07 |
Usage Minimum (Keyboard Left Control) | 19 E0 |
Usage Maximum (Keyboard Right GUI) | 29 E7 |
Logical Minimum (0) | 15 00 |
Logical Maximum (1) | 25 01 |
Report Count (8) | 95 08 |
Report Size (1) | 75 01 |
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) | 81 02 |
Report Count (1) | 95 01 |
Report Size (8) | 75 08 |
Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) | 81 03 |
Report Count (6) | 95 06 |
Report Size (8) | 75 08 |
Logical Minimum (0) | 15 00 |
Logical Maximum (255) | 26 FF 00 |
Usage Page (Keyboard/Keypad) | 05 07 |
Usage Minimum (Undefined) | 19 00 |
Usage Maximum | 2A FF 00 |
Input (Data,Ary,Abs) | 81 00 |
Logical Maximum (1) | 25 01 |
Report Count (5) | 95 05 |
Report Size (1) | 75 01 |
Usage Page (LEDs) | 05 08 |
Usage Minimum (Num Lock) | 19 01 |
Usage Maximum (Kana) | 29 05 |
Output (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) | 91 02 |
Report Count (1) | 95 01 |
Report Size (3) | 75 03 |
Output (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) | 91 03 |
End Collection | C0 |
Interface 1 HID Report Descriptor System Control
Item Tag (Value) | Raw Data |
Usage Page (Generic Desktop) | 05 01 |
Usage (System Control) | 09 80 |
Collection (Application) | A1 01 |
Report ID (1) | 85 01 |
Usage Minimum (System Power Down) | 19 81 |
Usage Maximum (System Wake Up) | 29 83 |
Logical Minimum (0) | 15 00 |
Logical Maximum (1) | 25 01 |
Report Size (1) | 75 01 |
Report Count (3) | 95 03 |
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) | 81 02 |
Report Count (5) | 95 05 |
Input (Cnst,Ary,Abs) | 81 01 |
End Collection | C0 |
Usage Page (Consumer Devices) | 05 0C |
Usage (Consumer Control) | 09 01 |
Collection (Application) | A1 01 |
Report ID (2) | 85 02 |
Usage Minimum (Undefined) | 19 00 |
Usage Maximum (AC Format) | 2A 3C 02 |
Logical Minimum (0) | 15 00 |
Logical Maximum (572) | 26 3C 02 |
Report Count (1) | 95 01 |
Report Size (16) | 75 10 |
Input (Data,Ary,Abs) | 81 00 |
End Collection | C0 |
Usage Page (Vendor-Defined 1) | 06 00 FF |
Usage (Vendor-Defined 1) | 09 01 |
Collection (Application) | A1 01 |
Report ID (5) | 85 05 |
Logical Minimum (0) | 15 00 |
Logical Maximum (255) | 26 FF 00 |
Usage Minimum (Vendor-Defined 1) | 19 01 |
Usage Maximum (Vendor-Defined 2) | 29 02 |
Report Size (8) | 75 08 |
Report Count (5) | 95 05 |
Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) | B1 02 |
End Collection | C0 |
Usage Page (Generic Desktop) | 05 01 |
Usage (Keyboard) | 09 06 |
Collection (Application) | A1 01 |
Report ID (6) | 85 06 |
Logical Minimum (0) | 15 00 |
Logical Maximum (1) | 25 01 |
Report Size (1) | 75 01 |
Report Count (112) | 95 70 |
Usage Page (Keyboard/Keypad) | 05 07 |
Usage Minimum (Keyboard Left Control) | 19 E0 |
Usage Maximum (Keyboard Right GUI) | 29 E7 |
Usage Minimum (Undefined) | 19 00 |
Usage Maximum (Keypad =) | 29 67 |
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) | 81 02 |
Report Count (8) | 95 08 |
Input (Cnst,Ary,Abs) | 81 01 |
End Collection | C0 |
Usage Page (Vendor-Defined 1) | 06 00 FF |
Usage (Vendor-Defined 1) | 09 01 |
Collection (Application) | A1 01 |
Report ID (9) | 85 09 |
Logical Minimum (0) | 15 00 |
Logical Maximum (255) | 26 FF 00 |
Usage (Undefined) | 09 00 |
Report Size (8) | 75 08 |
Report Count (504) | 96 F8 01 |
Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) | B1 02 |
End Collection | C0 |
Usage Page (Vendor-Defined 1) | 06 00 FF |
Usage (Vendor-Defined 1) | 09 01 |
Collection (Application) | A1 01 |
Report ID (10) | 85 0A |
Logical Minimum (0) | 15 00 |
Logical Maximum (255) | 26 FF 00 |
Usage (Undefined) | 09 00 |
Report Size (8) | 75 08 |
Report Count (41) | 95 29 |
Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) | B1 02 |
End Collection | C0 |
Usage Page (Vendor-Defined 1) | 06 00 FF |
Usage (Vendor-Defined 1) | 09 01 |
Collection (Application) | A1 01 |
Report ID (11) | 85 0B |
Logical Minimum (0) | 15 00 |
Logical Maximum (255) | 26 FF 00 |
Usage (Undefined) | 09 00 |
Report Size (8) | 75 08 |
Report Count (126) | 95 7E |
Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) | B1 02 |
End Collection | C0 |
Usage Page (Vendor-Defined 1) | 06 00 FF |
Usage (Vendor-Defined 1) | 09 01 |
Collection (Application) | A1 01 |
Report ID (12) | 85 0C |
Logical Minimum (0) | 15 00 |
Logical Maximum (255) | 26 FF 00 |
Usage (Undefined) | 09 00 |
Report Size (8) | 75 08 |
Report Count (1920) | 96 80 07 |
Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) | B1 02 |
End Collection | C0 |
This report was generated by USBlyzer
需要特别注意的是:这个设备是 USB Full Speed(12Mbits/s)的,必须在文件头部设置为 Full Speed,如果继续使用 Low Speed,插入之后读取描述符后 Host就会停止继续发送数据(Windows 行为,我不知道原因)。
除此之外,和之前的鼠标代码相比还增加了一个HID 描述符,另外,在 Main 中定时发送打开Windows 菜单(Win按键)。