Skip to content

Commit 38f4281

Browse files
committed
fix gc; update KEYBOARD report descriptor
The default KEYBOARD report descriptor had a signed/unsigned error, and also could have allowed more keycodes. So I changed it, using the very vanilla descriptor from a very plain extremely common commercial keyboard, modifying it only have 5 LED's instead of 3, and added a report ID.
1 parent f37e1d7 commit 38f4281

File tree

2 files changed

+44
-41
lines changed

2 files changed

+44
-41
lines changed

shared-module/usb_hid/Device.c

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,39 @@
3636
#include "tusb.h"
3737

3838
static const uint8_t keyboard_report_descriptor[] = {
39-
0x05, 0x01, // 0,1 Usage Page (Generic Desktop Ctrls)
40-
0x09, 0x06, // 2,3 Usage (Keyboard)
41-
0xA1, 0x01, // 4,5 Collection (Application)
42-
0x85, 0x01, // 6,7 Report ID (1)
43-
0x05, 0x07, // Usage Page (Kbrd/Keypad)
44-
0x19, 0xE0, // Usage Minimum (0xE0)
45-
0x29, 0xE7, // Usage Maximum (0xE7)
46-
0x15, 0x00, // Logical Minimum (0)
47-
0x25, 0x01, // Logical Maximum (1)
48-
0x75, 0x01, // Report Size (1)
49-
0x95, 0x08, // Report Count (8)
50-
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
51-
0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
52-
0x19, 0x00, // Usage Minimum (0x00)
53-
0x29, 0xDD, // Usage Maximum (0xDD)
54-
0x15, 0x00, // Logical Minimum (0)
55-
0x25, 0xDD, // Logical Maximum (-35)
56-
0x75, 0x08, // Report Size (8)
57-
0x95, 0x06, // Report Count (6)
58-
0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
59-
0x05, 0x08, // Usage Page (LEDs)
60-
0x19, 0x01, // Usage Minimum (Num Lock)
61-
0x29, 0x05, // Usage Maximum (Kana)
62-
0x15, 0x00, // Logical Minimum (0)
63-
0x25, 0x01, // Logical Maximum (1)
64-
0x75, 0x01, // Report Size (1)
65-
0x95, 0x05, // Report Count (5)
66-
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
67-
0x95, 0x03, // Report Count (3)
68-
0x91, 0x01, // Output (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
69-
0xC0, // End Collection
39+
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
40+
0x09, 0x06, // Usage (Keyboard)
41+
0xA1, 0x01, // Collection (Application)
42+
0x85, 0x01, // Report ID (1)
43+
0x05, 0x07, // Usage Page (Kbrd/Keypad)
44+
0x19, 0xE0, // Usage Minimum (0xE0)
45+
0x29, 0xE7, // Usage Maximum (0xE7)
46+
0x15, 0x00, // Logical Minimum (0)
47+
0x25, 0x01, // Logical Maximum (1)
48+
0x75, 0x01, // Report Size (1)
49+
0x95, 0x08, // Report Count (8)
50+
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
51+
0x95, 0x01, // Report Count (1)
52+
0x75, 0x08, // Report Size (8)
53+
0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
54+
0x95, 0x03, // Report Count (3)
55+
0x75, 0x01, // Report Size (1)
56+
0x05, 0x08, // Usage Page (LEDs)
57+
0x19, 0x01, // Usage Minimum (Num Lock)
58+
0x29, 0x05, // Usage Maximum (Kana)
59+
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
60+
0x95, 0x01, // Report Count (1)
61+
0x75, 0x05, // Report Size (5)
62+
0x91, 0x01, // Output (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
63+
0x95, 0x06, // Report Count (6)
64+
0x75, 0x08, // Report Size (8)
65+
0x15, 0x00, // Logical Minimum (0)
66+
0x26, 0xFF, 0x00, // Logical Maximum (255)
67+
0x05, 0x07, // Usage Page (Kbrd/Keypad)
68+
0x19, 0x00, // Usage Minimum (0x00)
69+
0x2A, 0xFF, 0x00, // Usage Maximum (0xFF)
70+
0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
71+
0xC0, // End Collection
7072
};
7173

7274
const usb_hid_device_obj_t usb_hid_device_keyboard_obj = {
@@ -84,11 +86,11 @@ const usb_hid_device_obj_t usb_hid_device_keyboard_obj = {
8486
};
8587

8688
static const uint8_t mouse_report_descriptor[] = {
87-
0x05, 0x01, // 0,1 Usage Page (Generic Desktop Ctrls)
88-
0x09, 0x02, // 2,3 Usage (Mouse)
89-
0xA1, 0x01, // 4,5 Collection (Application)
90-
0x09, 0x01, // 6,7 Usage (Pointer)
91-
0xA1, 0x00, // 8,9 Collection (Physical)
89+
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
90+
0x09, 0x02, // Usage (Mouse)
91+
0xA1, 0x01, // Collection (Application)
92+
0x09, 0x01, // Usage (Pointer)
93+
0xA1, 0x00, // Collection (Physical)
9294
0x85, 0x02, // 10, 11 Report ID (2)
9395
0x05, 0x09, // Usage Page (Button)
9496
0x19, 0x01, // Usage Minimum (0x01)
@@ -134,10 +136,10 @@ const usb_hid_device_obj_t usb_hid_device_mouse_obj = {
134136
};
135137

136138
static const uint8_t consumer_control_report_descriptor[] = {
137-
0x05, 0x0C, // 0,1 Usage Page (Consumer)
138-
0x09, 0x01, // 2,3 Usage (Consumer Control)
139-
0xA1, 0x01, // 4,5 Collection (Application)
140-
0x85, 0x03, // 6,7 Report ID (3)
139+
0x05, 0x0C, // Usage Page (Consumer)
140+
0x09, 0x01, // Usage (Consumer Control)
141+
0xA1, 0x01, // Collection (Application)
142+
0x85, 0x03, // Report ID (3)
141143
0x75, 0x10, // Report Size (16)
142144
0x95, 0x01, // Report Count (1)
143145
0x15, 0x01, // Logical Minimum (1)

shared-module/usb_hid/__init__.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@ void usb_hid_gc_collect(void) {
250250
// and not copied into RAM.
251251
gc_collect_ptr((void *)hid_devices[device_idx].report_descriptor);
252252

253-
// Collect all the OUT report buffers for this device.
253+
// Collect all the report buffers for this device.
254254
for (size_t id_idx = 0; id_idx < hid_devices[device_idx].num_report_ids; id_idx++) {
255+
gc_collect_ptr(hid_devices[id_idx].in_report_buffers[id_idx]);
255256
gc_collect_ptr(hid_devices[id_idx].out_report_buffers[id_idx]);
256257
}
257258
}

0 commit comments

Comments
 (0)