summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2025-05-05 04:05:04 +0100
committerGitHub <noreply@github.com>2025-05-05 04:05:04 +0100
commit842c8401452f83e691a9df97ffba52a389c885c8 (patch)
tree39cc609985e6d8bb6cfa859520ee062cb4793805 /tmk_core
parent614b631ee2649de67a830a39393af416acee58a8 (diff)
Bind Bluetooth driver to `host_driver_t` (#25199)
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/protocol/host.c83
1 files changed, 54 insertions, 29 deletions
diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c
index 453952049f..4f3867df08 100644
--- a/tmk_core/protocol/host.c
+++ b/tmk_core/protocol/host.c
@@ -30,12 +30,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30# include "joystick.h" 30# include "joystick.h"
31#endif 31#endif
32 32
33#ifdef BLUETOOTH_ENABLE 33#ifdef CONNECTION_ENABLE
34# ifndef CONNECTION_ENABLE
35# error CONNECTION_ENABLE required and not enabled
36# endif
37# include "connection.h" 34# include "connection.h"
35#endif
36
37#ifdef BLUETOOTH_ENABLE
38# include "bluetooth.h" 38# include "bluetooth.h"
39
40static void bluetooth_send_extra(report_extra_t *report) {
41 switch (report->report_id) {
42 case REPORT_ID_SYSTEM:
43 bluetooth_send_system(report->usage);
44 return;
45 case REPORT_ID_CONSUMER:
46 bluetooth_send_consumer(report->usage);
47 return;
48 }
49}
50
51host_driver_t bt_driver = {
52 .keyboard_leds = bluetooth_keyboard_leds,
53 .send_keyboard = bluetooth_send_keyboard,
54 .send_nkro = bluetooth_send_nkro,
55 .send_mouse = bluetooth_send_mouse,
56 .send_extra = bluetooth_send_extra,
57};
39#endif 58#endif
40 59
41#ifdef NKRO_ENABLE 60#ifdef NKRO_ENABLE
@@ -55,6 +74,22 @@ host_driver_t *host_get_driver(void) {
55 return driver; 74 return driver;
56} 75}
57 76
77static host_driver_t *host_get_active_driver(void) {
78#ifdef CONNECTION_ENABLE
79 switch (connection_get_host()) {
80# ifdef BLUETOOTH_ENABLE
81 case CONNECTION_HOST_BLUETOOTH:
82 return &bt_driver;
83# endif
84 case CONNECTION_HOST_NONE:
85 return NULL;
86 default:
87 break;
88 }
89#endif
90 return driver;
91}
92
58#ifdef SPLIT_KEYBOARD 93#ifdef SPLIT_KEYBOARD
59uint8_t split_led_state = 0; 94uint8_t split_led_state = 0;
60void set_split_host_keyboard_leds(uint8_t led_state) { 95void set_split_host_keyboard_leds(uint8_t led_state) {
@@ -66,7 +101,10 @@ uint8_t host_keyboard_leds(void) {
66#ifdef SPLIT_KEYBOARD 101#ifdef SPLIT_KEYBOARD
67 if (!is_keyboard_master()) return split_led_state; 102 if (!is_keyboard_master()) return split_led_state;
68#endif 103#endif
69 if (!driver) return 0; 104
105 host_driver_t *driver = host_get_active_driver();
106 if (!driver || !driver->keyboard_leds) return 0;
107
70 return (*driver->keyboard_leds)(); 108 return (*driver->keyboard_leds)();
71} 109}
72 110
@@ -76,14 +114,9 @@ led_t host_keyboard_led_state(void) {
76 114
77/* send report */ 115/* send report */
78void host_keyboard_send(report_keyboard_t *report) { 116void host_keyboard_send(report_keyboard_t *report) {
79#ifdef BLUETOOTH_ENABLE 117 host_driver_t *driver = host_get_active_driver();
80 if (connection_get_host() == CONNECTION_HOST_BLUETOOTH) { 118 if (!driver || !driver->send_keyboard) return;
81 bluetooth_send_keyboard(report);
82 return;
83 }
84#endif
85 119
86 if (!driver) return;
87#ifdef KEYBOARD_SHARED_EP 120#ifdef KEYBOARD_SHARED_EP
88 report->report_id = REPORT_ID_KEYBOARD; 121 report->report_id = REPORT_ID_KEYBOARD;
89#endif 122#endif
@@ -99,7 +132,9 @@ void host_keyboard_send(report_keyboard_t *report) {
99} 132}
100 133
101void host_nkro_send(report_nkro_t *report) { 134void host_nkro_send(report_nkro_t *report) {
102 if (!driver) return; 135 host_driver_t *driver = host_get_active_driver();
136 if (!driver || !driver->send_nkro) return;
137
103 report->report_id = REPORT_ID_NKRO; 138 report->report_id = REPORT_ID_NKRO;
104 (*driver->send_nkro)(report); 139 (*driver->send_nkro)(report);
105 140
@@ -113,14 +148,9 @@ void host_nkro_send(report_nkro_t *report) {
113} 148}
114 149
115void host_mouse_send(report_mouse_t *report) { 150void host_mouse_send(report_mouse_t *report) {
116#ifdef BLUETOOTH_ENABLE 151 host_driver_t *driver = host_get_active_driver();
117 if (connection_get_host() == CONNECTION_HOST_BLUETOOTH) { 152 if (!driver || !driver->send_mouse) return;
118 bluetooth_send_mouse(report);
119 return;
120 }
121#endif
122 153
123 if (!driver) return;
124#ifdef MOUSE_SHARED_EP 154#ifdef MOUSE_SHARED_EP
125 report->report_id = REPORT_ID_MOUSE; 155 report->report_id = REPORT_ID_MOUSE;
126#endif 156#endif
@@ -136,7 +166,8 @@ void host_system_send(uint16_t usage) {
136 if (usage == last_system_usage) return; 166 if (usage == last_system_usage) return;
137 last_system_usage = usage; 167 last_system_usage = usage;
138 168
139 if (!driver) return; 169 host_driver_t *driver = host_get_active_driver();
170 if (!driver || !driver->send_extra) return;
140 171
141 report_extra_t report = { 172 report_extra_t report = {
142 .report_id = REPORT_ID_SYSTEM, 173 .report_id = REPORT_ID_SYSTEM,
@@ -149,14 +180,8 @@ void host_consumer_send(uint16_t usage) {
149 if (usage == last_consumer_usage) return; 180 if (usage == last_consumer_usage) return;
150 last_consumer_usage = usage; 181 last_consumer_usage = usage;
151 182
152#ifdef BLUETOOTH_ENABLE 183 host_driver_t *driver = host_get_active_driver();
153 if (connection_get_host() == CONNECTION_HOST_BLUETOOTH) { 184 if (!driver || !driver->send_extra) return;
154 bluetooth_send_consumer(usage);
155 return;
156 }
157#endif
158
159 if (!driver) return;
160 185
161 report_extra_t report = { 186 report_extra_t report = {
162 .report_id = REPORT_ID_CONSUMER, 187 .report_id = REPORT_ID_CONSUMER,