Partially implement connection update logic

This commit is contained in:
zvecr 2025-06-05 05:11:18 +01:00
parent 5bf8248dd3
commit c9824094c6
3 changed files with 36 additions and 2 deletions

View File

@ -29,6 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "debug.h" #include "debug.h"
#include "command.h" #include "command.h"
#include "util.h" #include "util.h"
#include "host.h"
#include "sendchar.h" #include "sendchar.h"
#include "eeconfig.h" #include "eeconfig.h"
#include "action_layer.h" #include "action_layer.h"
@ -471,6 +472,7 @@ void keyboard_init(void) {
#ifdef CONNECTION_ENABLE #ifdef CONNECTION_ENABLE
connection_init(); connection_init();
#endif #endif
host_init();
led_init_ports(); led_init_ports();
#ifdef BACKLIGHT_ENABLE #ifdef BACKLIGHT_ENABLE
backlight_init_ports(); backlight_init_ports();
@ -715,6 +717,8 @@ void quantum_task(void) {
#ifdef LAYER_LOCK_ENABLE #ifdef LAYER_LOCK_ENABLE
layer_lock_task(); layer_lock_task();
#endif #endif
host_task();
} }
/** \brief Main task that is repeatedly called as fast as possible. */ /** \brief Main task that is repeatedly called as fast as possible. */

View File

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h> #include <stdint.h>
#include "keyboard.h" #include "keyboard.h"
#include "keycode.h" #include "keycode.h"
#include "action.h"
#include "host.h" #include "host.h"
#include "util.h" #include "util.h"
#include "debug.h" #include "debug.h"
@ -78,9 +79,35 @@ host_driver_t *host_get_driver(void) {
return driver; return driver;
} }
#ifdef CONNECTION_ENABLE
static connection_host_t active_host = CONNECTION_HOST_NONE;
static void host_update_active_driver(connection_host_t current, connection_host_t next) {
if (current != CONNECTION_HOST_NONE) {
// TODO: Additionally have host_driver_t handle swap
clear_keyboard();
}
}
#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) { static host_driver_t *host_get_active_driver(void) {
#ifdef CONNECTION_ENABLE #ifdef CONNECTION_ENABLE
switch (connection_get_host()) { switch (active_host) {
# ifdef BLUETOOTH_ENABLE # ifdef BLUETOOTH_ENABLE
case CONNECTION_HOST_BLUETOOTH: case CONNECTION_HOST_BLUETOOTH:
return &bt_driver; return &bt_driver;
@ -96,7 +123,7 @@ static host_driver_t *host_get_active_driver(void) {
bool host_can_send_nkro(void) { bool host_can_send_nkro(void) {
#ifdef CONNECTION_ENABLE #ifdef CONNECTION_ENABLE
switch (connection_get_host()) { switch (active_host) {
# ifdef BLUETOOTH_ENABLE # ifdef BLUETOOTH_ENABLE
case CONNECTION_HOST_BLUETOOTH: case CONNECTION_HOST_BLUETOOTH:
return bluetooth_can_send_nkro(); return bluetooth_can_send_nkro();

View File

@ -27,6 +27,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern "C" { extern "C" {
#endif #endif
void host_init(void);
void host_task(void);
/* host driver */ /* host driver */
void host_set_driver(host_driver_t *driver); void host_set_driver(host_driver_t *driver);
host_driver_t *host_get_driver(void); host_driver_t *host_get_driver(void);