8000 add hid keyboard LED indicator stub · tannewt/circuitpython@4bece22 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4bece22

Browse files
committed
add hid keyboard LED indicator stub
1 parent 05139e2 commit 4bece22

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

ports/nrf/common-hal/usb_hid/Device.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,29 @@ void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t*
7070
}
7171

7272
// Callbacks invoked when receive Get_Report request through control endpoint
73-
uint16_t tud_hid_generic_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
74-
{
73+
uint16_t tud_hid_generic_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) {
7574
// only support Input Report
7675
if ( report_type != HID_REPORT_TYPE_INPUT ) return 0;
7776

77+
// index is ID-1
78+
uint8_t idx = ( report_id ? (report_id-1) : 0 );
79+
7880
// fill buffer with current report
79-
memcpy(buffer, usb_hid_devices[report_id].report_buffer, reqlen);
81+
memcpy(buffer, usb_hid_devices[idx].report_buffer, reqlen);
8082
return reqlen;
8183
}
8284

8385
// Callbacks invoked when receive Set_Report request through control endpoint
84-
void tud_hid_generic_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
85-
{
86+
void tud_hid_generic_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) {
87+
// index is ID-1
88+
uint8_t idx = ( report_id ? (report_id-1) : 0 );
89+
8690
if ( report_type == HID_REPORT_TYPE_OUTPUT ) {
87-
// TODO Support Keyboard LED e.g Capslock
91+
// Check if it is Keyboard device
92+
if ( (usb_hid_devices[idx].usage_page == HID_USAGE_PAGE_DESKTOP) && (usb_hid_devices[idx].usage == HID_USAGE_DESKTOP_KEYBOARD) ) {
93+
// This is LED indicator (CapsLock, NumLock)
94+
// TODO Light up some LED here
95+
}
8896
}
8997
}
9098

0 commit comments

Comments
 (0)
0