diff options
Diffstat (limited to 'tmk_core/protocol/host.c')
-rw-r--r-- | tmk_core/protocol/host.c | 101 |
1 files changed, 72 insertions, 29 deletions
diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c index 453952049f..e785cb24cc 100644 --- a/tmk_core/protocol/host.c +++ b/tmk_core/protocol/host.c @@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "host.h" #include "util.h" #include "debug.h" +#include "usb_device_state.h" #ifdef DIGITIZER_ENABLE # include "digitizer.h" @@ -30,12 +31,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. # include "joystick.h" #endif -#ifdef BLUETOOTH_ENABLE -# ifndef CONNECTION_ENABLE -# error CONNECTION_ENABLE required and not enabled -# endif +#ifdef CONNECTION_ENABLE # include "connection.h" +#endif + +#ifdef BLUETOOTH_ENABLE # include "bluetooth.h" + +static void bluetooth_send_extra(report_extra_t *report) { + switch (report->report_id) { + case REPORT_ID_SYSTEM: + bluetooth_send_system(report->usage); + return; + case REPORT_ID_CONSUMER: + bluetooth_send_consumer(report->usage); + return; + } +} + +host_driver_t bt_driver = { + .keyboard_leds = bluetooth_keyboard_leds, + .send_keyboard = bluetooth_send_keyboard, + .send_nkro = bluetooth_send_nkro, + .send_mouse = bluetooth_send_mouse, + .send_extra = bluetooth_send_extra, +}; #endif #ifdef NKRO_ENABLE @@ -55,6 +75,39 @@ host_driver_t *host_get_driver(void) { return driver; } +static host_driver_t *host_get_active_driver(void) { +#ifdef CONNECTION_ENABLE + switch (connection_get_host()) { +# ifdef BLUETOOTH_ENABLE + case CONNECTION_HOST_BLUETOOTH: + return &bt_driver; +# endif + case CONNECTION_HOST_NONE: + return NULL; + default: + break; + } +#endif + return driver; +} + +bool host_can_send_nkro(void) { +#ifdef CONNECTION_ENABLE + switch (connection_get_host()) { +# ifdef BLUETOOTH_ENABLE + case CONNECTION_HOST_BLUETOOTH: + return bluetooth_can_send_nkro(); +# endif + case CONNECTION_HOST_NONE: + return false; + default: + break; + } +#endif + + return usb_device_state_get_protocol() == USB_PROTOCOL_REPORT; +} + #ifdef SPLIT_KEYBOARD uint8_t split_led_state = 0; void set_split_host_keyboard_leds(uint8_t led_state) { @@ -66,7 +119,10 @@ uint8_t host_keyboard_leds(void) { #ifdef SPLIT_KEYBOARD if (!is_keyboard_master()) return split_led_state; #endif - if (!driver) return 0; + + host_driver_t *driver = host_get_active_driver(); + if (!driver || !driver->keyboard_leds) return 0; + return (*driver->keyboard_leds)(); } @@ -76,14 +132,9 @@ led_t host_keyboard_led_state(void) { /* send report */ void host_keyboard_send(report_keyboard_t *report) { -#ifdef BLUETOOTH_ENABLE - if (connection_get_host() == CONNECTION_HOST_BLUETOOTH) { - bluetooth_send_keyboard(report); - return; - } -#endif + host_driver_t *driver = host_get_active_driver(); + if (!driver || !driver->send_keyboard) return; - if (!driver) return; #ifdef KEYBOARD_SHARED_EP report->report_id = REPORT_ID_KEYBOARD; #endif @@ -99,7 +150,9 @@ void host_keyboard_send(report_keyboard_t *report) { } void host_nkro_send(report_nkro_t *report) { - if (!driver) return; + host_driver_t *driver = host_get_active_driver(); + if (!driver || !driver->send_nkro) return; + report->report_id = REPORT_ID_NKRO; (*driver->send_nkro)(report); @@ -113,14 +166,9 @@ void host_nkro_send(report_nkro_t *report) { } void host_mouse_send(report_mouse_t *report) { -#ifdef BLUETOOTH_ENABLE - if (connection_get_host() == CONNECTION_HOST_BLUETOOTH) { - bluetooth_send_mouse(report); - return; - } -#endif + host_driver_t *driver = host_get_active_driver(); + if (!driver || !driver->send_mouse) return; - if (!driver) return; #ifdef MOUSE_SHARED_EP report->report_id = REPORT_ID_MOUSE; #endif @@ -136,7 +184,8 @@ void host_system_send(uint16_t usage) { if (usage == last_system_usage) return; last_system_usage = usage; - if (!driver) return; + host_driver_t *driver = host_get_active_driver(); + if (!driver || !driver->send_extra) return; report_extra_t report = { .report_id = REPORT_ID_SYSTEM, @@ -149,14 +198,8 @@ void host_consumer_send(uint16_t usage) { if (usage == last_consumer_usage) return; last_consumer_usage = usage; -#ifdef BLUETOOTH_ENABLE - if (connection_get_host() == CONNECTION_HOST_BLUETOOTH) { - bluetooth_send_consumer(usage); - return; - } -#endif - - if (!driver) return; + host_driver_t *driver = host_get_active_driver(); + if (!driver || !driver->send_extra) return; report_extra_t report = { .report_id = REPORT_ID_CONSUMER, |