|
|
@@ -30,12 +30,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 +74,22 @@ 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;
|
|
|
+}
|
|
|
+
|
|
|
#ifdef SPLIT_KEYBOARD
|
|
|
uint8_t split_led_state = 0;
|
|
|
void set_split_host_keyboard_leds(uint8_t led_state) {
|
|
|
@@ -66,7 +101,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 +114,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 +132,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 +148,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 +166,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 +180,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,
|