aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/protocol.mk8
-rw-r--r--tmk_core/protocol/host.c101
-rw-r--r--tmk_core/protocol/host.h1
3 files changed, 75 insertions, 35 deletions
diff --git a/tmk_core/protocol.mk b/tmk_core/protocol.mk
index 8f01976548..2930efc283 100644
--- a/tmk_core/protocol.mk
+++ b/tmk_core/protocol.mk
@@ -46,12 +46,8 @@ else
endif
ifeq ($(strip $(NKRO_ENABLE)), yes)
- ifeq ($(strip $(BLUETOOTH_ENABLE)), yes)
- $(info NKRO is not currently supported with Bluetooth, and has been disabled.)
- else
- OPT_DEFS += -DNKRO_ENABLE
- SHARED_EP_ENABLE = yes
- endif
+ OPT_DEFS += -DNKRO_ENABLE
+ SHARED_EP_ENABLE = yes
endif
ifeq ($(strip $(NO_SUSPEND_POWER_DOWN)), yes)
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,
diff --git a/tmk_core/protocol/host.h b/tmk_core/protocol/host.h
index d824fca077..8e8a18e2ed 100644
--- a/tmk_core/protocol/host.h
+++ b/tmk_core/protocol/host.h
@@ -32,6 +32,7 @@ void host_set_driver(host_driver_t *driver);
host_driver_t *host_get_driver(void);
/* host driver interface */
+bool host_can_send_nkro(void);
uint8_t host_keyboard_leds(void);
led_t host_keyboard_led_state(void);
void host_keyboard_send(report_keyboard_t *report);