aboutsummaryrefslogtreecommitdiffstats
path: root/tmk_core/protocol/host.c
diff options
context:
space:
mode:
authorJoel Challis2025-11-07 00:34:23 +0100
committerGitHub2025-11-07 00:34:23 +0100
commit01952bf39aadc42a70221f91d8cc0536ad458b04 (patch)
tree420abd3dd9ce60588cb564778fb122c21e1e5bbc /tmk_core/protocol/host.c
parent1a991ffd24b8a5414b72c10dfc0fbea0afc085c2 (diff)
Implement minimal connection update logic (#25334)
Diffstat (limited to 'tmk_core/protocol/host.c')
-rw-r--r--tmk_core/protocol/host.c44
1 files changed, 42 insertions, 2 deletions
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/>.
#include <stdint.h>
#include "keyboard.h"
#include "keycode.h"
+#include "action.h"
#include "host.h"
#include "util.h"
#include "debug.h"
@@ -78,9 +79,48 @@ host_driver_t *host_get_driver(void) {
return driver;
}
+#ifdef CONNECTION_ENABLE
+static connection_host_t active_host = CONNECTION_HOST_NONE;
+
+__attribute__((weak)) void host_disconnect_active_driver_user(connection_host_t host) {}
+__attribute__((weak)) void host_disconnect_active_driver_kb(connection_host_t host) {}
+
+__attribute__((weak)) void host_connect_active_driver_user(connection_host_t host) {}
+__attribute__((weak)) void host_connect_active_driver_kb(connection_host_t host) {}
+
+// TODO: Additionally have host_driver_t handle swap
+static void host_update_active_driver(connection_host_t current, connection_host_t next) {
+ host_disconnect_active_driver_user(current);
+ host_disconnect_active_driver_kb(current);
+
+ if (current != CONNECTION_HOST_NONE) {
+ clear_keyboard();
+ }
+
+ host_connect_active_driver_user(next);
+ host_connect_active_driver_kb(next);
+}
+
+#endif
+
+void host_init(void) {
+ // currently do nothing
+}
+
+void host_task(void) {
+#ifdef CONNECTION_ENABLE
+ connection_host_t next_host = connection_get_host();
+ if (next_host != active_host) {
+ host_update_active_driver(active_host, next_host);
+
+ active_host = next_host;
+ }
+#endif
+}
+
static host_driver_t *host_get_active_driver(void) {
#ifdef CONNECTION_ENABLE
- switch (connection_get_host()) {
+ switch (active_host) {
# ifdef BLUETOOTH_ENABLE
case CONNECTION_HOST_BLUETOOTH:
return &bt_driver;
@@ -96,7 +136,7 @@ static host_driver_t *host_get_active_driver(void) {
bool host_can_send_nkro(void) {
#ifdef CONNECTION_ENABLE
- switch (connection_get_host()) {
+ switch (active_host) {
# ifdef BLUETOOTH_ENABLE
case CONNECTION_HOST_BLUETOOTH:
return bluetooth_can_send_nkro();