mirror of
https://github.com/zmkfirmware/zmk.git
synced 2026-03-20 04:55:20 -05:00
feat(split): Runtime selection of split transport (#2886)
feat(split): Runtime selection of split transport Allow building multiple split transports, and select an active one based on the transport availability. Wired split availability depends on additional `detect-gpios` which must be a GPIO pin that goes active when a wired connection is present. feat(split): Suspend/resume wired UART devices. To better support runtime split support, suspend/resume the UART as necessary to save power when not using the UART. docs(split): Document adjusting nRF52 UART interrupt priorities For wired split on nRF52, you may need to adjust the priority for UART interrupts lower, to ensure the interrupts used for timing sensitive BT operations can run when needed, so document this in our pinctrl docs. refactor(split): Restore use of aync UART on nRF52. With fixes for Zephyr UART driver, re-enable using async API on nRF52. fix(split): Minor wired split fixes. Various minor fixes for wired split to avoid spurious TX in half duplex, etc. fix: Unconditionally define HID payloads to avoid error. Don't conditionally define HID indicator payload, to avoid compilation errors. docs(split): Expand on details of split transports. Expand the split keyboard documentation with a more fleshed out section on the available split trasnports, and what is and isn't supported by each, including the runtime selection functionality. --------- Co-authored-by: Nicolas Munnich <98408764+nmunnich@users.noreply.github.com>
This commit is contained in:
@@ -22,9 +22,7 @@
|
||||
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
// TODO: Active transport selection
|
||||
|
||||
struct zmk_split_transport_peripheral *active_transport;
|
||||
const struct zmk_split_transport_peripheral *active_transport;
|
||||
|
||||
int zmk_split_transport_peripheral_command_handler(
|
||||
const struct zmk_split_transport_peripheral *transport,
|
||||
@@ -69,12 +67,67 @@ int zmk_split_peripheral_report_event(const struct zmk_split_transport_periphera
|
||||
return active_transport->api->report_event(event);
|
||||
}
|
||||
|
||||
static int peripheral_init(void) {
|
||||
STRUCT_SECTION_GET(zmk_split_transport_peripheral, 0, &active_transport);
|
||||
static int select_first_available_transport(void) {
|
||||
// Transports are sorted by priority, so find the first
|
||||
// One that's available, and enable it. Any transport that
|
||||
// Doesn't support `get_status` is assumed to be always
|
||||
// available and fully connected.
|
||||
STRUCT_SECTION_FOREACH(zmk_split_transport_peripheral, t) {
|
||||
if (!t->api->get_status || t->api->get_status().available) {
|
||||
if (active_transport == t) {
|
||||
LOG_DBG("First available is already selected, moving on");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (active_transport && active_transport->api->set_enabled) {
|
||||
int err = active_transport->api->set_enabled(false);
|
||||
if (err < 0) {
|
||||
LOG_WRN("Error disabling previously selected split transport (%d)", err);
|
||||
}
|
||||
}
|
||||
|
||||
active_transport = t;
|
||||
int err = 0;
|
||||
if (active_transport->api->set_enabled) {
|
||||
err = active_transport->api->set_enabled(true);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
static int transport_status_changed_cb(const struct zmk_split_transport_peripheral *p,
|
||||
struct zmk_split_transport_status status) {
|
||||
if (p == active_transport) {
|
||||
LOG_DBG("Peripheral at %p changed status: enabled %d, available %d, connections %d", p,
|
||||
status.enabled, status.available, status.connections);
|
||||
if (status.connections == ZMK_SPLIT_TRANSPORT_CONNECTIONS_STATUS_DISCONNECTED) {
|
||||
LOG_DBG("Find us a new active transport!");
|
||||
|
||||
return select_first_available_transport();
|
||||
}
|
||||
} else {
|
||||
select_first_available_transport();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int peripheral_init(void) {
|
||||
STRUCT_SECTION_FOREACH(zmk_split_transport_peripheral, t) {
|
||||
if (!t->api->set_status_callback) {
|
||||
continue;
|
||||
}
|
||||
|
||||
t->api->set_status_callback(transport_status_changed_cb);
|
||||
}
|
||||
|
||||
return select_first_available_transport();
|
||||
}
|
||||
|
||||
SYS_INIT(peripheral_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
|
||||
|
||||
int split_peripheral_listener(const zmk_event_t *eh) {
|
||||
|
||||
Reference in New Issue
Block a user