Skip to content

Commit

Permalink
Simplify extrakeys sending at the host driver level
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark committed Aug 31, 2022
1 parent 0237ff0 commit 1d33ada
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 90 deletions.
10 changes: 3 additions & 7 deletions tests/test_common/test_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions tests/test_common/test_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 2 additions & 15 deletions tmk_core/protocol/arm_atsam/main_arm_atsam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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];
Expand Down
5 changes: 2 additions & 3 deletions tmk_core/protocol/chibios/chibios.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 1 addition & 13 deletions tmk_core/protocol/chibios/usb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tmk_core/protocol/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ 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) {
if (report == last_consumer_report) return;
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) {
Expand Down
5 changes: 2 additions & 3 deletions tmk_core/protocol/host_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
void send_digitizer(report_digitizer_t *report);
35 changes: 7 additions & 28 deletions tmk_core/protocol/lufa/lufa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 2 additions & 15 deletions tmk_core/protocol/vusb/vusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 1d33ada

Please sign in to comment.