Simplify extrakeys sending at the host driver level (#18230)

* Simplify extrakeys sending at the host driver level

* There are two arguments here

* Wrong syntax

* Adjust keyboards which use a custom host driver
This commit is contained in:
Ryan 2022-09-03 05:38:27 +10:00 committed by GitHub
parent 0ceaaaae8e
commit 09d668eb0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 70 additions and 149 deletions

View File

@ -24,15 +24,14 @@
/* -------------------- Static Function Prototypes -------------------------- */
static uint8_t ap2_ble_leds(void);
static void ap2_ble_mouse(report_mouse_t *report);
static void ap2_ble_system(uint16_t data);
static void ap2_ble_consumer(uint16_t data);
static void ap2_ble_extra(uint8_t report_id, uint16_t data);
static void ap2_ble_keyboard(report_keyboard_t *report);
static void ap2_ble_swtich_ble_driver(void);
/* -------------------- Static Local Variables ------------------------------ */
static host_driver_t ap2_ble_driver = {
ap2_ble_leds, ap2_ble_keyboard, ap2_ble_mouse, ap2_ble_system, ap2_ble_consumer,
ap2_ble_leds, ap2_ble_keyboard, ap2_ble_mouse, ap2_ble_extra
};
static uint8_t ble_mcu_wakeup[11] = {0x7b, 0x12, 0x53, 0x00, 0x03, 0x00, 0x01, 0x7d, 0x02, 0x01, 0x02};
@ -131,8 +130,6 @@ static uint8_t ap2_ble_leds(void) {
static void ap2_ble_mouse(report_mouse_t *report) {}
static void ap2_ble_system(uint16_t data) {}
static inline uint16_t CONSUMER2AP2(uint16_t usage) {
switch (usage) {
case AUDIO_VOL_DOWN:
@ -152,12 +149,14 @@ static inline uint16_t CONSUMER2AP2(uint16_t usage) {
}
}
static void ap2_ble_consumer(uint16_t data) {
static void ap2_ble_extra(uint8_t report_id, uint16_t data) {
if (report_id == REPORT_ID_CONSUMER) {
sdPut(&SD1, 0x0);
sdWrite(&SD1, ble_mcu_send_consumer_report, sizeof(ble_mcu_send_consumer_report));
sdPut(&SD1, CONSUMER2AP2(data));
static const uint8_t dummy[3] = {0};
sdWrite(&SD1, dummy, sizeof(dummy));
}
}
/*!

View File

@ -96,15 +96,14 @@ static void bluefruit_serial_send(uint8_t data)
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 bluefruit_driver = {
keyboard_leds,
send_keyboard,
send_mouse,
send_system,
send_consumer};
send_extra
};
host_driver_t null_driver = {};
@ -156,10 +155,6 @@ static void send_mouse(report_mouse_t *report)
#endif
}
static void send_system(uint16_t data)
{
}
/*
+-----------------+-------------------+-------+
| Consumer Key | Bit Map | Hex |
@ -182,8 +177,9 @@ static void send_system(uint16_t data)
#define CONSUMER2BLUEFRUIT(usage) \
(usage == AUDIO_MUTE ? 0x00e2 : (usage == AUDIO_VOL_UP ? 0x00e9 : (usage == AUDIO_VOL_DOWN ? 0x00ea : (usage == TRANSPORT_NEXT_TRACK ? 0x00b5 : (usage == TRANSPORT_PREV_TRACK ? 0x00b6 : (usage == TRANSPORT_STOP ? 0x00b7 : (usage == TRANSPORT_STOP_EJECT ? 0x00b8 : (usage == TRANSPORT_PLAY_PAUSE ? 0x00b1 : (usage == AL_CC_CONFIG ? 0x0183 : (usage == AL_EMAIL ? 0x018c : (usage == AL_CALCULATOR ? 0x0192 : (usage == AL_LOCAL_BROWSER ? 0x0196 : (usage == AC_SEARCH ? 0x021f : (usage == AC_HOME ? 0x0223 : (usage == AC_BACK ? 0x0224 : (usage == AC_FORWARD ? 0x0225 : (usage == AC_STOP ? 0x0226 : (usage == AC_REFRESH ? 0x0227 : (usage == AC_BOOKMARKS ? 0x022a : 0)))))))))))))))))))
static void send_consumer(uint16_t data)
static void send_extra(uint8_t report_id, uint16_t data)
{
if (report_id == REPORT_ID_CONSUMER) {
static uint16_t last_data = 0;
if (data == last_data)
return;
@ -206,6 +202,7 @@ static void send_consumer(uint16_t data)
#ifdef BLUEFRUIT_TRACE_SERIAL
bluefruit_trace_footer();
#endif
}
}
void usart_init(void)

View File

@ -12,15 +12,13 @@
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 rn42_driver = {
keyboard_leds,
send_keyboard,
send_mouse,
send_system,
send_consumer
send_extra
};
@ -198,12 +196,6 @@ static void send_mouse(report_mouse_t *report)
serial_send(report->v);
}
static void send_system(uint16_t data)
{
// Table 5-6 of RN-BT-DATA-UB
// 81,82,83 scan codes can be used?
}
static uint16_t usage2bits(uint16_t usage)
{
@ -228,14 +220,17 @@ static uint16_t usage2bits(uint16_t usage)
return 0;
}
static void send_consumer(uint16_t data)
static void send_extra(uint8_t report_id, uint16_t data)
{
if (report_id == REPORT_ID_CONSUMER) {
uint16_t bits = usage2bits(data);
serial_send(0xFD); // Raw report mode
serial_send(3); // length
serial_send(3); // descriptor type
serial_send(bits&0xFF);
serial_send((bits>>8)&0xFF);
}
}
@ -243,19 +238,16 @@ static void send_consumer(uint16_t data)
static uint8_t config_keyboard_leds(void);
static void config_send_keyboard(report_keyboard_t *report);
static void config_send_mouse(report_mouse_t *report);
static void config_send_system(uint16_t data);
static void config_send_consumer(uint16_t data);
static void config_send_extra(uint8_t report_id, uint16_t data);
host_driver_t rn42_config_driver = {
config_keyboard_leds,
config_send_keyboard,
config_send_mouse,
config_send_system,
config_send_consumer
config_send_extra
};
static uint8_t config_keyboard_leds(void) { return leds; }
static void config_send_keyboard(report_keyboard_t *report) {}
static void config_send_mouse(report_mouse_t *report) {}
static void config_send_system(uint16_t data) {}
static void config_send_consumer(uint16_t data) {}
static void config_send_extra(uint8_t report_id, uint16_t data) {}

View File

@ -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 {

View File

@ -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_METHOD2(send_extra_mock, void(uint8_t, 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;

View File

@ -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];

View File

@ -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);

View File

@ -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();

View File

@ -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) {

View File

@ -27,8 +27,7 @@ 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;

View File

@ -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

View File

@ -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()) {