summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2025-11-06 23:34:23 +0000
committerGitHub <noreply@github.com>2025-11-06 23:34:23 +0000
commit01952bf39aadc42a70221f91d8cc0536ad458b04 (patch)
tree420abd3dd9ce60588cb564778fb122c21e1e5bbc
parent1a991ffd24b8a5414b72c10dfc0fbea0afc085c2 (diff)
Implement minimal connection update logic (#25334)
-rw-r--r--quantum/keyboard.c4
-rw-r--r--tmk_core/protocol/host.c44
-rw-r--r--tmk_core/protocol/host.h3
3 files changed, 49 insertions, 2 deletions
diff --git a/quantum/keyboard.c b/quantum/keyboard.c
index 173c696e2d..ce8c8efa68 100644
--- a/quantum/keyboard.c
+++ b/quantum/keyboard.c
@@ -29,6 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
29#include "debug.h" 29#include "debug.h"
30#include "command.h" 30#include "command.h"
31#include "util.h" 31#include "util.h"
32#include "host.h"
32#include "sendchar.h" 33#include "sendchar.h"
33#include "eeconfig.h" 34#include "eeconfig.h"
34#include "action_layer.h" 35#include "action_layer.h"
@@ -471,6 +472,7 @@ void keyboard_init(void) {
471#ifdef CONNECTION_ENABLE 472#ifdef CONNECTION_ENABLE
472 connection_init(); 473 connection_init();
473#endif 474#endif
475 host_init();
474 led_init_ports(); 476 led_init_ports();
475#ifdef BACKLIGHT_ENABLE 477#ifdef BACKLIGHT_ENABLE
476 backlight_init_ports(); 478 backlight_init_ports();
@@ -699,6 +701,8 @@ void quantum_task(void) {
699#ifdef LAYER_LOCK_ENABLE 701#ifdef LAYER_LOCK_ENABLE
700 layer_lock_task(); 702 layer_lock_task();
701#endif 703#endif
704
705 host_task();
702} 706}
703 707
704/** \brief Main task that is repeatedly called as fast as possible. */ 708/** \brief Main task that is repeatedly called as fast as possible. */
diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c
index 4874d7c1d3..f4fa9064e0 100644
--- a/tmk_core/protocol/host.c
+++ b/tmk_core/protocol/host.c
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18#include <stdint.h> 18#include <stdint.h>
19#include "keyboard.h" 19#include "keyboard.h"
20#include "keycode.h" 20#include "keycode.h"
21#include "action.h"
21#include "host.h" 22#include "host.h"
22#include "util.h" 23#include "util.h"
23#include "debug.h" 24#include "debug.h"
@@ -78,9 +79,48 @@ host_driver_t *host_get_driver(void) {
78 return driver; 79 return driver;
79} 80}
80 81
82#ifdef CONNECTION_ENABLE
83static connection_host_t active_host = CONNECTION_HOST_NONE;
84
85__attribute__((weak)) void host_disconnect_active_driver_user(connection_host_t host) {}
86__attribute__((weak)) void host_disconnect_active_driver_kb(connection_host_t host) {}
87
88__attribute__((weak)) void host_connect_active_driver_user(connection_host_t host) {}
89__attribute__((weak)) void host_connect_active_driver_kb(connection_host_t host) {}
90
91// TODO: Additionally have host_driver_t handle swap
92static void host_update_active_driver(connection_host_t current, connection_host_t next) {
93 host_disconnect_active_driver_user(current);
94 host_disconnect_active_driver_kb(current);
95
96 if (current != CONNECTION_HOST_NONE) {
97 clear_keyboard();
98 }
99
100 host_connect_active_driver_user(next);
101 host_connect_active_driver_kb(next);
102}
103
104#endif
105
106void host_init(void) {
107 // currently do nothing
108}
109
110void host_task(void) {
111#ifdef CONNECTION_ENABLE
112 connection_host_t next_host = connection_get_host();
113 if (next_host != active_host) {
114 host_update_active_driver(active_host, next_host);
115
116 active_host = next_host;
117 }
118#endif
119}
120
81static host_driver_t *host_get_active_driver(void) { 121static host_driver_t *host_get_active_driver(void) {
82#ifdef CONNECTION_ENABLE 122#ifdef CONNECTION_ENABLE
83 switch (connection_get_host()) { 123 switch (active_host) {
84# ifdef BLUETOOTH_ENABLE 124# ifdef BLUETOOTH_ENABLE
85 case CONNECTION_HOST_BLUETOOTH: 125 case CONNECTION_HOST_BLUETOOTH:
86 return &bt_driver; 126 return &bt_driver;
@@ -96,7 +136,7 @@ static host_driver_t *host_get_active_driver(void) {
96 136
97bool host_can_send_nkro(void) { 137bool host_can_send_nkro(void) {
98#ifdef CONNECTION_ENABLE 138#ifdef CONNECTION_ENABLE
99 switch (connection_get_host()) { 139 switch (active_host) {
100# ifdef BLUETOOTH_ENABLE 140# ifdef BLUETOOTH_ENABLE
101 case CONNECTION_HOST_BLUETOOTH: 141 case CONNECTION_HOST_BLUETOOTH:
102 return bluetooth_can_send_nkro(); 142 return bluetooth_can_send_nkro();
diff --git a/tmk_core/protocol/host.h b/tmk_core/protocol/host.h
index a0b1e73dcc..7ff6d0df08 100644
--- a/tmk_core/protocol/host.h
+++ b/tmk_core/protocol/host.h
@@ -27,6 +27,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
27extern "C" { 27extern "C" {
28#endif 28#endif
29 29
30void host_init(void);
31void host_task(void);
32
30/* host driver */ 33/* host driver */
31void host_set_driver(host_driver_t *driver); 34void host_set_driver(host_driver_t *driver);
32host_driver_t *host_get_driver(void); 35host_driver_t *host_get_driver(void);