diff options
author | Ryan <fauxpark@gmail.com> | 2022-10-07 13:35:01 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-06 19:35:01 -0700 |
commit | 6dbbeea46a0ac7527235982cb6406802df846805 (patch) | |
tree | 55b2a71430ad3726ab098a53b581a69efdd1602d /tmk_core/protocol | |
parent | cbe1c22d468d64d7a3274061ce9c2073ecb208a4 (diff) |
Refactor `send_extra` (#18615)
Diffstat (limited to 'tmk_core/protocol')
-rw-r--r-- | tmk_core/protocol/arm_atsam/main_arm_atsam.c | 9 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/udi_device_conf.h | 14 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c | 29 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h | 1 | ||||
-rw-r--r-- | tmk_core/protocol/chibios/chibios.c | 2 | ||||
-rw-r--r-- | tmk_core/protocol/chibios/usb_main.c | 7 | ||||
-rw-r--r-- | tmk_core/protocol/host.c | 40 | ||||
-rw-r--r-- | tmk_core/protocol/host.h | 8 | ||||
-rw-r--r-- | tmk_core/protocol/host_driver.h | 2 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 8 | ||||
-rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 14 |
11 files changed, 50 insertions, 84 deletions
diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index 0537e3937d..1ccfbfb54a 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c @@ -37,7 +37,7 @@ void main_subtasks(void); uint8_t keyboard_leds(void); void send_keyboard(report_keyboard_t *report); void send_mouse(report_mouse_t *report); -void send_extra(uint8_t report_id, uint16_t data); +void send_extra(report_extra_t *report); #ifdef DEFERRED_EXEC_ENABLE void deferred_exec_task(void); @@ -113,7 +113,7 @@ void send_mouse(report_mouse_t *report) { #endif // MOUSEKEY_ENABLE } -void send_extra(uint8_t report_id, uint16_t data) { +void send_extra(report_extra_t *report) { #ifdef EXTRAKEY_ENABLE uint32_t irqflags; @@ -121,9 +121,8 @@ void send_extra(uint8_t report_id, uint16_t data) { __disable_irq(); __DMB(); - udi_hid_exk_report.desc.report_id = report_id; - udi_hid_exk_report.desc.report_data = data; - udi_hid_exk_b_report_valid = 1; + memcpy(udi_hid_exk_report, report, UDI_HID_EXK_REPORT_SIZE); + udi_hid_exk_b_report_valid = 1; udi_hid_exk_send_report(); __DMB(); diff --git a/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h b/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h index eeed196275..a3c6f1c397 100644 --- a/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h +++ b/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h @@ -352,21 +352,9 @@ typedef struct { // clang-format on -// set report buffer (from host) -extern uint8_t udi_hid_exk_report_set; - // report buffer # define UDI_HID_EXK_REPORT_SIZE 3 - -typedef union { - struct { - uint8_t report_id; - uint16_t report_data; - } desc; - uint8_t raw[UDI_HID_EXK_REPORT_SIZE]; -} udi_hid_exk_report_t; - -extern udi_hid_exk_report_t udi_hid_exk_report; +extern uint8_t udi_hid_exk_report[UDI_HID_EXK_REPORT_SIZE]; COMPILER_PACK_RESET() diff --git a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c index be4f2bb0c9..5d681a8b71 100644 --- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c +++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c @@ -371,13 +371,13 @@ static uint8_t udi_hid_exk_rate; COMPILER_WORD_ALIGNED static uint8_t udi_hid_exk_protocol; -COMPILER_WORD_ALIGNED -uint8_t udi_hid_exk_report_set; +// COMPILER_WORD_ALIGNED +// uint8_t udi_hid_exk_report_set; bool udi_hid_exk_b_report_valid; COMPILER_WORD_ALIGNED -udi_hid_exk_report_t udi_hid_exk_report; +uint8_t udi_hid_exk_report[UDI_HID_EXK_REPORT_SIZE]; static bool udi_hid_exk_b_report_trans_ongoing; @@ -415,39 +415,24 @@ UDC_DESC_STORAGE udi_hid_exk_report_desc_t udi_hid_exk_report_desc = {{ //clang-format on }}; -static bool udi_hid_exk_setreport(void); - static void udi_hid_exk_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep); -static void udi_hid_exk_setreport_valid(void); - bool udi_hid_exk_enable(void) { // Initialize internal values udi_hid_exk_rate = 0; udi_hid_exk_protocol = 0; udi_hid_exk_b_report_trans_ongoing = false; - memset(udi_hid_exk_report.raw, 0, UDI_HID_EXK_REPORT_SIZE); + memset(udi_hid_exk_report, 0, UDI_HID_EXK_REPORT_SIZE); udi_hid_exk_b_report_valid = false; return UDI_HID_EXK_ENABLE_EXT(); } void udi_hid_exk_disable(void) { UDI_HID_EXK_DISABLE_EXT(); } -bool udi_hid_exk_setup(void) { return udi_hid_setup(&udi_hid_exk_rate, &udi_hid_exk_protocol, (uint8_t *)&udi_hid_exk_report_desc, udi_hid_exk_setreport); } +bool udi_hid_exk_setup(void) { return udi_hid_setup(&udi_hid_exk_rate, &udi_hid_exk_protocol, (uint8_t *)&udi_hid_exk_report_desc, NULL); } uint8_t udi_hid_exk_getsetting(void) { return 0; } -static bool udi_hid_exk_setreport(void) { - if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (1 == udd_g_ctrlreq.req.wLength)) { - // Report OUT type on report ID 0 from USB Host - udd_g_ctrlreq.payload = &udi_hid_exk_report_set; - udd_g_ctrlreq.callback = udi_hid_exk_setreport_valid; - udd_g_ctrlreq.payload_size = 1; - return true; - } - return false; -} - bool udi_hid_exk_send_report(void) { if (!main_b_exk_enable) { return false; @@ -457,7 +442,7 @@ bool udi_hid_exk_send_report(void) { return false; } - memcpy(udi_hid_exk_report_trans, udi_hid_exk_report.raw, UDI_HID_EXK_REPORT_SIZE); + memcpy(udi_hid_exk_report_trans, udi_hid_exk_report, UDI_HID_EXK_REPORT_SIZE); udi_hid_exk_b_report_valid = false; udi_hid_exk_b_report_trans_ongoing = udd_ep_run(UDI_HID_EXK_EP_IN | USB_EP_DIR_IN, false, udi_hid_exk_report_trans, UDI_HID_EXK_REPORT_SIZE, udi_hid_exk_report_sent); @@ -474,8 +459,6 @@ static void udi_hid_exk_report_sent(udd_ep_status_t status, iram_size_t nb_sent, } } -static void udi_hid_exk_setreport_valid(void) {} - #endif // EXTRAKEY_ENABLE //******************************************************************************************** diff --git a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h index a330014498..e17538fa70 100644 --- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h +++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h @@ -79,7 +79,6 @@ bool udi_hid_nkro_send_report(void); #ifdef EXTRAKEY_ENABLE extern UDC_DESC_STORAGE udi_api_t udi_api_hid_exk; extern bool udi_hid_exk_b_report_valid; -extern uint8_t udi_hid_exk_report_set; bool udi_hid_exk_send_report(void); #endif // EXTRAKEY_ENABLE diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c index 82ade4259b..10a976608a 100644 --- a/tmk_core/protocol/chibios/chibios.c +++ b/tmk_core/protocol/chibios/chibios.c @@ -58,7 +58,7 @@ uint8_t keyboard_leds(void); void send_keyboard(report_keyboard_t *report); void send_mouse(report_mouse_t *report); -void send_extra(uint8_t report_id, uint16_t data); +void send_extra(report_extra_t *report); /* host struct */ host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra}; diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 3fd34a604e..5eda5dd09f 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -943,7 +943,7 @@ void shared_in_cb(USBDriver *usbp, usbep_t ep) { * --------------------------------------------------------- */ -void send_extra(uint8_t report_id, uint16_t data) { +void send_extra(report_extra_t *report) { #ifdef EXTRAKEY_ENABLE osalSysLock(); if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) { @@ -962,10 +962,7 @@ void send_extra(uint8_t report_id, uint16_t data) { } } - static report_extra_t report; - report = (report_extra_t){.report_id = report_id, .usage = data}; - - usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report_extra_t)); + usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)report, sizeof(report_extra_t)); osalSysUnlock(); #endif } diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c index e6c12d8a36..b441d2d5d9 100644 --- a/tmk_core/protocol/host.c +++ b/tmk_core/protocol/host.c @@ -41,8 +41,8 @@ extern keymap_config_t keymap_config; #endif static host_driver_t *driver; -static uint16_t last_system_report = 0; -static uint16_t last_consumer_report = 0; +static uint16_t last_system_usage = 0; +static uint16_t last_consumer_usage = 0; void host_set_driver(host_driver_t *d) { driver = d; @@ -126,27 +126,37 @@ void host_mouse_send(report_mouse_t *report) { (*driver->send_mouse)(report); } -void host_system_send(uint16_t report) { - if (report == last_system_report) return; - last_system_report = report; +void host_system_send(uint16_t usage) { + if (usage == last_system_usage) return; + last_system_usage = usage; if (!driver) return; - (*driver->send_extra)(REPORT_ID_SYSTEM, report); + + report_extra_t report = { + .report_id = REPORT_ID_SYSTEM, + .usage = usage, + }; + (*driver->send_extra)(&report); } -void host_consumer_send(uint16_t report) { - if (report == last_consumer_report) return; - last_consumer_report = report; +void host_consumer_send(uint16_t usage) { + if (usage == last_consumer_usage) return; + last_consumer_usage = usage; #ifdef BLUETOOTH_ENABLE if (where_to_send() == OUTPUT_BLUETOOTH) { - bluetooth_send_consumer(report); + bluetooth_send_consumer(usage); return; } #endif if (!driver) return; - (*driver->send_extra)(REPORT_ID_CONSUMER, report); + + report_extra_t report = { + .report_id = REPORT_ID_CONSUMER, + .usage = usage, + }; + (*driver->send_extra)(&report); } #ifdef JOYSTICK_ENABLE @@ -232,10 +242,10 @@ void host_programmable_button_send(uint32_t data) { __attribute__((weak)) void send_programmable_button(report_programmable_button_t *report) {} -uint16_t host_last_system_report(void) { - return last_system_report; +uint16_t host_last_system_usage(void) { + return last_system_usage; } -uint16_t host_last_consumer_report(void) { - return last_consumer_report; +uint16_t host_last_consumer_usage(void) { + return last_consumer_usage; } diff --git a/tmk_core/protocol/host.h b/tmk_core/protocol/host.h index 08bd498d38..dfa86cd7b5 100644 --- a/tmk_core/protocol/host.h +++ b/tmk_core/protocol/host.h @@ -45,12 +45,12 @@ uint8_t host_keyboard_leds(void); led_t host_keyboard_led_state(void); void host_keyboard_send(report_keyboard_t *report); void host_mouse_send(report_mouse_t *report); -void host_system_send(uint16_t data); -void host_consumer_send(uint16_t data); +void host_system_send(uint16_t usage); +void host_consumer_send(uint16_t usage); void host_programmable_button_send(uint32_t data); -uint16_t host_last_system_report(void); -uint16_t host_last_consumer_report(void); +uint16_t host_last_system_usage(void); +uint16_t host_last_consumer_usage(void); #ifdef __cplusplus } diff --git a/tmk_core/protocol/host_driver.h b/tmk_core/protocol/host_driver.h index bb4dcdd877..7dc6c3d810 100644 --- a/tmk_core/protocol/host_driver.h +++ b/tmk_core/protocol/host_driver.h @@ -27,7 +27,7 @@ typedef struct { uint8_t (*keyboard_leds)(void); void (*send_keyboard)(report_keyboard_t *); void (*send_mouse)(report_mouse_t *); - void (*send_extra)(uint8_t, uint16_t); + void (*send_extra)(report_extra_t *); } host_driver_t; void send_joystick(report_joystick_t *report); diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 869ed71d76..fa3ced8fd6 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -84,7 +84,7 @@ static report_keyboard_t keyboard_report_sent; static uint8_t keyboard_leds(void); static void send_keyboard(report_keyboard_t *report); static void send_mouse(report_mouse_t *report); -static void send_extra(uint8_t report_id, uint16_t data); +static void send_extra(report_extra_t *report); host_driver_t lufa_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra}; #ifdef VIRTSER_ENABLE @@ -663,11 +663,9 @@ static void send_report(void *report, size_t size) { * * FIXME: Needs doc */ -static void send_extra(uint8_t report_id, uint16_t data) { +static void send_extra(report_extra_t *report) { #ifdef EXTRAKEY_ENABLE - static report_extra_t r; - r = (report_extra_t){.report_id = report_id, .usage = data}; - send_report(&r, sizeof(r)); + send_report(report, sizeof(report_extra_t)); #endif } diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 8456d2c5ab..84b01b203e 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -224,7 +224,7 @@ void console_task(void) { static uint8_t keyboard_leds(void); static void send_keyboard(report_keyboard_t *report); static void send_mouse(report_mouse_t *report); -static void send_extra(uint8_t report_id, uint16_t data); +static void send_extra(report_extra_t *report); static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_extra}; @@ -267,18 +267,10 @@ static void send_mouse(report_mouse_t *report) { #endif } -static void send_extra(uint8_t report_id, uint16_t data) { +static void send_extra(report_extra_t *report) { #ifdef EXTRAKEY_ENABLE - static uint8_t last_id = 0; - static uint16_t last_data = 0; - if ((report_id == last_id) && (data == last_data)) return; - last_id = report_id; - last_data = data; - - static report_extra_t report; - report = (report_extra_t){.report_id = report_id, .usage = data}; if (usbInterruptIsReadyShared()) { - usbSetInterruptShared((void *)&report, sizeof(report_extra_t)); + usbSetInterruptShared((void *)report, sizeof(report_extra_t)); } #endif } |