From c71d01f254e32df4703cd242d49076afe57f29f0 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Wed, 22 Jan 2020 01:17:33 +1100 Subject: Fix lock LEDs for ChibiOS when using shared endpoints (#7877) * Fix lock LEDs for ChibiOS when using shared endpoints * Tweak comments * Doesn't need to be uint16 anymore --- tmk_core/protocol/chibios/usb_main.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'tmk_core/protocol') diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index c2a62d173f..1e0c3637af 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -65,7 +65,7 @@ extern keymap_config_t keymap_config; uint8_t keyboard_idle __attribute__((aligned(2))) = 0; uint8_t keyboard_protocol __attribute__((aligned(2))) = 1; -uint16_t keyboard_led_stats __attribute__((aligned(2))) = 0; +uint8_t keyboard_led_stats = 0; volatile uint16_t keyboard_idle_count = 0; static virtual_timer_t keyboard_idle_timer; static void keyboard_idle_timer_cb(void *arg); @@ -411,14 +411,17 @@ static uint16_t get_hword(uint8_t *p) { * Other Device Required Optional Optional Optional Optional Optional */ -#if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP) static uint8_t set_report_buf[2] __attribute__((aligned(2))); static void set_led_transfer_cb(USBDriver *usbp) { - if ((set_report_buf[0] == REPORT_ID_KEYBOARD) || (set_report_buf[0] == REPORT_ID_NKRO)) { - keyboard_led_stats = set_report_buf[1]; + if (usbp->setup[6] == 2) { /* LSB(wLength) */ + uint8_t report_id = set_report_buf[0]; + if ((report_id == REPORT_ID_KEYBOARD) || (report_id == REPORT_ID_NKRO)) { + keyboard_led_stats = set_report_buf[1]; + } + } else { + keyboard_led_stats = set_report_buf[0]; } } -#endif /* Callback for SETUP request on the endpoint 0 (control) */ static bool usb_request_hook_cb(USBDriver *usbp) { @@ -474,18 +477,12 @@ static bool usb_request_hook_cb(USBDriver *usbp) { case USB_RTYPE_DIR_HOST2DEV: switch (usbp->setup[1]) { /* bRequest */ case HID_SET_REPORT: - switch (usbp->setup[4]) { /* LSB(wIndex) (check MSB==0 and wLength==1?) */ + switch (usbp->setup[4]) { /* LSB(wIndex) (check MSB==0?) */ + case KEYBOARD_INTERFACE: #if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP) case SHARED_INTERFACE: - usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_led_transfer_cb); - return TRUE; - break; #endif - - case KEYBOARD_INTERFACE: - /* keyboard_led_stats = - * keyboard_led_stats needs be word (or dword), otherwise we get an exception on F0 */ - usbSetupTransfer(usbp, (uint8_t *)&keyboard_led_stats, 1, NULL); + usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_led_transfer_cb); return TRUE; break; } @@ -664,7 +661,7 @@ static void keyboard_idle_timer_cb(void *arg) { } /* LED status */ -uint8_t keyboard_leds(void) { return (uint8_t)(keyboard_led_stats & 0xFF); } +uint8_t keyboard_leds(void) { return keyboard_led_stats; } /* prepare and start sending a report IN * not callable from ISR or locked state */ -- cgit v1.2.3