mirror of https://github.com/zmkfirmware/zmk.git
feat(split): add split transport changed event
This commit is contained in:
parent
7738924349
commit
8ecb8a6404
|
|
@ -96,6 +96,7 @@ target_sources_ifdef(CONFIG_ZMK_BATTERY_REPORTING app PRIVATE src/battery.c)
|
||||||
target_sources_ifdef(CONFIG_ZMK_HID_INDICATORS app PRIVATE src/events/hid_indicators_changed.c)
|
target_sources_ifdef(CONFIG_ZMK_HID_INDICATORS app PRIVATE src/events/hid_indicators_changed.c)
|
||||||
|
|
||||||
target_sources_ifdef(CONFIG_ZMK_SPLIT app PRIVATE src/events/split_peripheral_status_changed.c)
|
target_sources_ifdef(CONFIG_ZMK_SPLIT app PRIVATE src/events/split_peripheral_status_changed.c)
|
||||||
|
target_sources_ifdef(CONFIG_ZMK_SPLIT app PRIVATE src/events/split_transport_changed.c)
|
||||||
add_subdirectory_ifdef(CONFIG_ZMK_SPLIT src/split)
|
add_subdirectory_ifdef(CONFIG_ZMK_SPLIT src/split)
|
||||||
|
|
||||||
target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/usb.c)
|
target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/usb.c)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025 The ZMK Contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zmk/event_manager.h>
|
||||||
|
#include <zmk/split/transport/types.h>
|
||||||
|
|
||||||
|
struct zmk_split_transport_changed {
|
||||||
|
uint32_t addr;
|
||||||
|
struct zmk_split_transport_status status;
|
||||||
|
};
|
||||||
|
|
||||||
|
ZMK_EVENT_DECLARE(zmk_split_transport_changed)
|
||||||
|
|
@ -46,3 +46,5 @@ int zmk_split_central_update_hid_indicator(zmk_hid_indicators_t indicators);
|
||||||
int zmk_split_central_get_peripheral_battery_level(uint8_t source, uint8_t *level);
|
int zmk_split_central_get_peripheral_battery_level(uint8_t source, uint8_t *level);
|
||||||
|
|
||||||
#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING)
|
#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING)
|
||||||
|
|
||||||
|
bool zmk_split_transport_get_available(uint32_t addr);
|
||||||
|
|
@ -9,3 +9,5 @@
|
||||||
#include <zmk/split/transport/types.h>
|
#include <zmk/split/transport/types.h>
|
||||||
|
|
||||||
int zmk_split_peripheral_report_event(const struct zmk_split_transport_peripheral_event *event);
|
int zmk_split_peripheral_report_event(const struct zmk_split_transport_peripheral_event *event);
|
||||||
|
|
||||||
|
bool zmk_split_transport_get_available(uint32_t addr);
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025 The ZMK Contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zmk/events/split_transport_changed.h>
|
||||||
|
|
||||||
|
ZMK_EVENT_IMPL(zmk_split_transport_changed);
|
||||||
|
|
@ -19,6 +19,8 @@
|
||||||
#include <zmk/events/position_state_changed.h>
|
#include <zmk/events/position_state_changed.h>
|
||||||
#include <zmk/events/sensor_event.h>
|
#include <zmk/events/sensor_event.h>
|
||||||
|
|
||||||
|
#include <zmk/events/split_transport_changed.h>
|
||||||
|
|
||||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||||
|
|
||||||
const struct zmk_split_transport_central *active_transport;
|
const struct zmk_split_transport_central *active_transport;
|
||||||
|
|
@ -198,6 +200,8 @@ static int select_first_available_transport(void) {
|
||||||
|
|
||||||
static int transport_status_changed_cb(const struct zmk_split_transport_central *central,
|
static int transport_status_changed_cb(const struct zmk_split_transport_central *central,
|
||||||
struct zmk_split_transport_status status) {
|
struct zmk_split_transport_status status) {
|
||||||
|
raise_zmk_split_transport_changed(
|
||||||
|
(struct zmk_split_transport_changed){.addr = (uint32_t)central, .status = status});
|
||||||
if (central == active_transport) {
|
if (central == active_transport) {
|
||||||
LOG_DBG("Central at %p changed status: enabled %d, available %d, connections %d", central,
|
LOG_DBG("Central at %p changed status: enabled %d, available %d, connections %d", central,
|
||||||
status.enabled, status.available, status.connections);
|
status.enabled, status.available, status.connections);
|
||||||
|
|
@ -212,6 +216,16 @@ static int transport_status_changed_cb(const struct zmk_split_transport_central
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool zmk_split_transport_get_available(uint32_t addr) {
|
||||||
|
STRUCT_SECTION_FOREACH(zmk_split_transport_central, t) {
|
||||||
|
if ((uint32_t)t == addr) {
|
||||||
|
return t->api->get_status().available;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int central_init(void) {
|
static int central_init(void) {
|
||||||
STRUCT_SECTION_FOREACH(zmk_split_transport_central, t) {
|
STRUCT_SECTION_FOREACH(zmk_split_transport_central, t) {
|
||||||
if (!t->api->set_status_callback) {
|
if (!t->api->set_status_callback) {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
#include <zmk/events/sensor_event.h>
|
#include <zmk/events/sensor_event.h>
|
||||||
#include <zmk/events/battery_state_changed.h>
|
#include <zmk/events/battery_state_changed.h>
|
||||||
|
|
||||||
|
#include <zmk/events/split_transport_changed.h>
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)
|
#if IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)
|
||||||
#include <zmk/events/hid_indicators_changed.h>
|
#include <zmk/events/hid_indicators_changed.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -115,6 +117,8 @@ static int select_first_available_transport(void) {
|
||||||
|
|
||||||
static int transport_status_changed_cb(const struct zmk_split_transport_peripheral *p,
|
static int transport_status_changed_cb(const struct zmk_split_transport_peripheral *p,
|
||||||
struct zmk_split_transport_status status) {
|
struct zmk_split_transport_status status) {
|
||||||
|
raise_zmk_split_transport_changed(
|
||||||
|
(struct zmk_split_transport_changed){.addr = (uint32_t)p, .status = status});
|
||||||
if (p == active_transport) {
|
if (p == active_transport) {
|
||||||
LOG_DBG("Peripheral at %p changed status: enabled %d, available %d, connections %d", p,
|
LOG_DBG("Peripheral at %p changed status: enabled %d, available %d, connections %d", p,
|
||||||
status.enabled, status.available, status.connections);
|
status.enabled, status.available, status.connections);
|
||||||
|
|
@ -130,6 +134,16 @@ static int transport_status_changed_cb(const struct zmk_split_transport_peripher
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool zmk_split_transport_get_available(uint32_t addr) {
|
||||||
|
STRUCT_SECTION_FOREACH(zmk_split_transport_peripheral, t) {
|
||||||
|
if ((uint32_t)t == addr) {
|
||||||
|
return t->api->get_status().available;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int peripheral_init(void) {
|
static int peripheral_init(void) {
|
||||||
STRUCT_SECTION_FOREACH(zmk_split_transport_peripheral, t) {
|
STRUCT_SECTION_FOREACH(zmk_split_transport_peripheral, t) {
|
||||||
if (!t->api->set_status_callback) {
|
if (!t->api->set_status_callback) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue