From 1d33ada87608987a19a3becb08e0829dad30cba7 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Wed, 31 Aug 2022 17:21:59 +1000 Subject: [PATCH] Simplify extrakeys sending at the host driver level --- tests/test_common/test_driver.cpp | 10 ++---- tests/test_common/test_driver.hpp | 6 ++-- tmk_core/protocol/arm_atsam/main_arm_atsam.c | 17 ++-------- tmk_core/protocol/chibios/chibios.c | 5 ++- tmk_core/protocol/chibios/usb_main.c | 14 +------- tmk_core/protocol/host.c | 4 +-- tmk_core/protocol/host_driver.h | 5 ++- tmk_core/protocol/lufa/lufa.c | 35 ++++---------------- tmk_core/protocol/vusb/vusb.c | 17 ++-------- 9 files changed, 23 insertions(+), 90 deletions(-) diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp index 86644ab6bda1..7ecd4931ed76 100644 --- a/tests/test_common/test_driver.cpp +++ b/tests/test_common/test_driver.cpp @@ -31,7 +31,7 @@ uint8_t hex_digit_to_keycode(uint8_t digit) { } } // namespace -TestDriver::TestDriver() : m_driver{&TestDriver::keyboard_leds, &TestDriver::send_keyboard, &TestDriver::send_mouse, &TestDriver::send_system, &TestDriver::send_consumer} { +TestDriver::TestDriver() : m_driver{&TestDriver::keyboard_leds, &TestDriver::send_keyboard, &TestDriver::send_mouse, &TestDriver::send_extra} { host_set_driver(&m_driver); m_this = this; } @@ -53,12 +53,8 @@ void TestDriver::send_mouse(report_mouse_t* report) { m_this->send_mouse_mock(*report); } -void TestDriver::send_system(uint16_t data) { - m_this->send_system_mock(data); -} - -void TestDriver::send_consumer(uint16_t data) { - m_this->send_consumer(data); +void TestDriver::send_extra(uint8_t report_id, uint16_t data) { + m_this->send_extra_mock(report_id, data); } namespace internal { diff --git a/tests/test_common/test_driver.hpp b/tests/test_common/test_driver.hpp index b58cfd1ebca4..983158760903 100644 --- a/tests/test_common/test_driver.hpp +++ b/tests/test_common/test_driver.hpp @@ -32,15 +32,13 @@ class TestDriver { MOCK_METHOD1(send_keyboard_mock, void(report_keyboard_t&)); MOCK_METHOD1(send_mouse_mock, void(report_mouse_t&)); - MOCK_METHOD1(send_system_mock, void(uint16_t)); - MOCK_METHOD1(send_consumer_mock, void(uint16_t)); + MOCK_METHOD1(send_extra_mock, void(uint8_t), void(uint16_t)); private: 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_system(uint16_t data); - static void send_consumer(uint16_t data); + static void send_extra(uint8_t report_id, uint16_t data); host_driver_t m_driver; uint8_t m_leds = 0; static TestDriver* m_this; diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index 8ee9e042e7ec..a2f20db66edb 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c @@ -37,14 +37,13 @@ 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_system(uint16_t data); -void send_consumer(uint16_t data); +void send_extra(uint8_t report_id, uint16_t data); #ifdef DEFERRED_EXEC_ENABLE void deferred_exec_task(void); #endif // DEFERRED_EXEC_ENABLE -host_driver_t arm_atsam_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer}; +host_driver_t arm_atsam_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra}; uint8_t led_states; @@ -132,18 +131,6 @@ void send_extra(uint8_t report_id, uint16_t data) { } #endif // EXTRAKEY_ENABLE -void send_system(uint16_t data) { -#ifdef EXTRAKEY_ENABLE - send_extra(REPORT_ID_SYSTEM, data); -#endif // EXTRAKEY_ENABLE -} - -void send_consumer(uint16_t data) { -#ifdef EXTRAKEY_ENABLE - send_extra(REPORT_ID_CONSUMER, data); -#endif // EXTRAKEY_ENABLE -} - #ifdef CONSOLE_ENABLE # define CONSOLE_PRINTBUF_SIZE 512 static char console_printbuf[CONSOLE_PRINTBUF_SIZE]; diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c index c9a480c32555..024160a92574 100644 --- a/tmk_core/protocol/chibios/chibios.c +++ b/tmk_core/protocol/chibios/chibios.c @@ -58,13 +58,12 @@ uint8_t keyboard_leds(void); void send_keyboard(report_keyboard_t *report); void send_mouse(report_mouse_t *report); -void send_system(uint16_t data); -void send_consumer(uint16_t data); +void send_extra(uint8_t report_id, uint16_t data); void send_programmable_button(uint32_t data); void send_digitizer(report_digitizer_t *report); /* host struct */ -host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer, send_programmable_button}; +host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra, send_programmable_button}; #ifdef VIRTSER_ENABLE void virtser_task(void); diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index eb9ef8255483..d218deb6f94c 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -947,7 +947,7 @@ void shared_in_cb(USBDriver *usbp, usbep_t ep) { */ #ifdef EXTRAKEY_ENABLE -static void send_extra(uint8_t report_id, uint16_t data) { +void send_extra(uint8_t report_id, uint16_t data) { osalSysLock(); if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) { osalSysUnlock(); @@ -973,18 +973,6 @@ static void send_extra(uint8_t report_id, uint16_t data) { } #endif -void send_system(uint16_t data) { -#ifdef EXTRAKEY_ENABLE - send_extra(REPORT_ID_SYSTEM, data); -#endif -} - -void send_consumer(uint16_t data) { -#ifdef EXTRAKEY_ENABLE - send_extra(REPORT_ID_CONSUMER, data); -#endif -} - void send_programmable_button(uint32_t data) { #ifdef PROGRAMMABLE_BUTTON_ENABLE osalSysLock(); diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c index 3d8604d5414a..2ebd176ea40e 100644 --- a/tmk_core/protocol/host.c +++ b/tmk_core/protocol/host.c @@ -107,7 +107,7 @@ void host_system_send(uint16_t report) { last_system_report = report; if (!driver) return; - (*driver->send_system)(report); + (*driver->send_extra)(REPORT_ID_SYSTEM, report); } void host_consumer_send(uint16_t report) { @@ -115,7 +115,7 @@ void host_consumer_send(uint16_t report) { last_consumer_report = report; if (!driver) return; - (*driver->send_consumer)(report); + (*driver->send_extra)(REPORT_ID_CONSUMER, report); } void host_digitizer_send(digitizer_t *digitizer) { diff --git a/tmk_core/protocol/host_driver.h b/tmk_core/protocol/host_driver.h index affd0dcb3489..680d9727d37a 100644 --- a/tmk_core/protocol/host_driver.h +++ b/tmk_core/protocol/host_driver.h @@ -27,9 +27,8 @@ typedef struct { uint8_t (*keyboard_leds)(void); void (*send_keyboard)(report_keyboard_t *); void (*send_mouse)(report_mouse_t *); - void (*send_system)(uint16_t); - void (*send_consumer)(uint16_t); + void (*send_extra)(uint8_t, uint16_t); void (*send_programmable_button)(uint32_t); } host_driver_t; -void send_digitizer(report_digitizer_t *report); \ No newline at end of file +void send_digitizer(report_digitizer_t *report); diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index b4b03357a36b..5c1a9b600ecd 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -101,10 +101,9 @@ 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_system(uint16_t data); -static void send_consumer(uint16_t data); +static void send_extra(uint8_t report_id, uint16_t data); static void send_programmable_button(uint32_t data); -host_driver_t lufa_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer, send_programmable_button}; +host_driver_t lufa_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra, send_programmable_button}; #ifdef VIRTSER_ENABLE // clang-format off @@ -748,30 +747,8 @@ static void send_report(void *report, size_t size) { */ #ifdef EXTRAKEY_ENABLE static void send_extra(uint8_t report_id, uint16_t data) { - static report_extra_t r; - r = (report_extra_t){.report_id = report_id, .usage = data}; - send_report(&r, sizeof(r)); -} -#endif - -/** \brief Send System - * - * FIXME: Needs doc - */ -static void send_system(uint16_t data) { -#ifdef EXTRAKEY_ENABLE - send_extra(REPORT_ID_SYSTEM, data); -#endif -} - -/** \brief Send Consumer - * - * FIXME: Needs doc - */ -static void send_consumer(uint16_t data) { -#ifdef EXTRAKEY_ENABLE # ifdef BLUETOOTH_ENABLE - if (where_to_send() == OUTPUT_BLUETOOTH) { + if (report_id == REPORT_ID_CONSUMER && where_to_send() == OUTPUT_BLUETOOTH) { # ifdef BLUETOOTH_BLUEFRUIT_LE bluefruit_le_send_consumer_key(data); # elif BLUETOOTH_RN42 @@ -781,9 +758,11 @@ static void send_consumer(uint16_t data) { } # endif - send_extra(REPORT_ID_CONSUMER, data); -#endif + static report_extra_t r; + r = (report_extra_t){.report_id = report_id, .usage = data}; + send_report(&r, sizeof(r)); } +#endif static void send_programmable_button(uint32_t data) { #ifdef PROGRAMMABLE_BUTTON_ENABLE diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 65f5027574ef..ed90b1151a53 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -224,11 +224,10 @@ 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_system(uint16_t data); -static void send_consumer(uint16_t data); +static void send_extra(uint8_t report_id, uint16_t data); static void send_programmable_button(uint32_t data); -static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer, send_programmable_button}; +static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_extra, send_programmable_button}; host_driver_t *vusb_driver(void) { return &driver; @@ -285,18 +284,6 @@ static void send_extra(uint8_t report_id, uint16_t data) { } #endif -static void send_system(uint16_t data) { -#ifdef EXTRAKEY_ENABLE - send_extra(REPORT_ID_SYSTEM, data); -#endif -} - -static void send_consumer(uint16_t data) { -#ifdef EXTRAKEY_ENABLE - send_extra(REPORT_ID_CONSUMER, data); -#endif -} - void send_digitizer(report_digitizer_t *report) { #ifdef DIGITIZER_ENABLE if (usbInterruptIsReadyShared()) {