|
32 | 32 |
|
33 | 33 | #include "shared-bindings/usb_hid/Device.h" |
34 | 34 |
|
35 | | -#include "tools/autogen_usb_descriptor.h" |
| 35 | +#include "genhdr/autogen_usb_descriptor.h" |
36 | 36 |
|
37 | | -static uint8_t mouse_report_buffer[UDI_HID_MOUSE_REPORT_SIZE]; |
38 | | -static uint8_t kbd_report_buffer[UDI_HID_KBD_REPORT_SIZE]; |
| 37 | +// Buffers are report size + 1 to include the Report ID prefix byte |
| 38 | +static uint8_t keyboard_report_buffer[USB_HID_REPORT_LENGTH_KEYBOARD + 1]; |
| 39 | +static uint8_t mouse_report_buffer[USB_HID_REPORT_LENGTH_MOUSE + 1]; |
| 40 | +static uint8_t consumer_report_buffer[USB_HID_REPORT_LENGTH_CONSUMER + 1]; |
| 41 | +static uint8_t sys_control_report_buffer[USB_HID_REPORT_LENGTH_SYS_CONTROL + 1]; |
39 | 42 |
|
40 | | -usb_hid_device_obj_t usb_hid_devices[2] = { |
| 43 | +usb_hid_device_obj_t usb_hid_devices[USB_HID_NUM_DEVICES] = { |
41 | 44 | { |
42 | | - .kind = USB_HID_MOUSE, |
43 | | - .report_length = UDI_HID_MOUSE_REPORT_SIZE, |
| 45 | + .base = { .type = &usb_hid_device_type }, |
| 46 | + .report_buffer = keyboard_report_buffer, |
| 47 | + .endpoint = USB_HID_ENDPOINT_IN, |
| 48 | + .report_id = USB_HID_REPORT_ID_KEYBOARD, |
| 49 | + .report_length = USB_HID_REPORT_LENGTH_KEYBOARD, |
| 50 | + .usage_page = 0x01, |
| 51 | + .usage = 0x06, |
| 52 | + }, |
| 53 | + { |
| 54 | + .base = { .type = &usb_hid_device_type }, |
44 | 55 | .report_buffer = mouse_report_buffer, |
| 56 | + .endpoint = USB_HID_ENDPOINT_IN, |
| 57 | + .report_id = USB_HID_REPORT_ID_MOUSE, |
| 58 | + .report_length = USB_HID_REPORT_LENGTH_MOUSE, |
45 | 59 | .usage_page = 0x01, |
46 | 60 | .usage = 0x02, |
47 | 61 | }, |
48 | 62 | { |
49 | | - .kind = USB_HID_KEYBOARD, |
50 | | - .report_length = UDI_HID_KBD_REPORT_SIZE, |
51 | | - .report_buffer = kbd_report_buffer, |
| 63 | + .base = { .type = &usb_hid_device_type }, |
| 64 | + .report_buffer = consumer_report_buffer, |
| 65 | + .endpoint = USB_HID_ENDPOINT_IN, |
| 66 | + .report_id = USB_HID_REPORT_ID_CONSUMER, |
| 67 | + .report_length = USB_HID_REPORT_LENGTH_CONSUMER, |
| 68 | + .usage_page = 0x0C, |
| 69 | + .usage = 0x01, |
| 70 | + }, |
| 71 | + { |
| 72 | + .base = { .type = &usb_hid_device_type }, |
| 73 | + .report_buffer = sys_control_report_buffer, |
| 74 | + .endpoint = USB_HID_ENDPOINT_IN, |
| 75 | + .report_id = USB_HID_REPORT_ID_SYS_CONTROL, |
| 76 | + .report_length = USB_HID_REPORT_LENGTH_SYS_CONTROL, |
52 | 77 | .usage_page = 0x01, |
53 | | - .usage = 0x06, |
54 | | - } |
| 78 | + .usage = 0x80, |
| 79 | + }, |
55 | 80 | }; |
56 | 81 |
|
57 | | -// TODO(tannewt): Make this a mp_obj_tuple_t when it is dynamically allocated. |
58 | | -// until then we hard code it to two entries so LTO is happy. |
59 | | -mp_obj_tuple2_t common_hal_usb_hid_devices = { |
| 82 | + |
| 83 | +mp_obj_tuple_t common_hal_usb_hid_devices = { |
60 | 84 | .base = { |
61 | 85 | .type = &mp_type_tuple, |
62 | 86 | }, |
63 | | - .len = 2, |
| 87 | + .len = USB_HID_NUM_DEVICES, |
64 | 88 | .items = { |
65 | | - (mp_obj_t) &usb_hid_devices[USB_HID_DEVICE_MOUSE], |
66 | | - (mp_obj_t) &usb_hid_devices[USB_HID_DEVICE_KEYBOARD], |
| 89 | + (mp_obj_t) &usb_hid_devices[0], |
| 90 | + (mp_obj_t) &usb_hid_devices[1], |
| 91 | + (mp_obj_t) &usb_hid_devices[2], |
| 92 | + (mp_obj_t) &usb_hid_devices[3], |
67 | 93 | } |
68 | 94 | }; |
0 commit comments