Skip to content

Commit 8ecb8a6

Browse files
committed
feat(split): add split transport changed event
1 parent 7738924 commit 8ecb8a6

7 files changed

Lines changed: 61 additions & 0 deletions

File tree

app/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ target_sources_ifdef(CONFIG_ZMK_BATTERY_REPORTING app PRIVATE src/battery.c)
9696
target_sources_ifdef(CONFIG_ZMK_HID_INDICATORS app PRIVATE src/events/hid_indicators_changed.c)
9797

9898
target_sources_ifdef(CONFIG_ZMK_SPLIT app PRIVATE src/events/split_peripheral_status_changed.c)
99+
target_sources_ifdef(CONFIG_ZMK_SPLIT app PRIVATE src/events/split_transport_changed.c)
99100
add_subdirectory_ifdef(CONFIG_ZMK_SPLIT src/split)
100101

101102
target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/usb.c)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2025 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
#pragma once
8+
9+
#include <zephyr/kernel.h>
10+
#include <zmk/event_manager.h>
11+
#include <zmk/split/transport/types.h>
12+
13+
struct zmk_split_transport_changed {
14+
uint32_t addr;
15+
struct zmk_split_transport_status status;
16+
};
17+
18+
ZMK_EVENT_DECLARE(zmk_split_transport_changed)

app/include/zmk/split/central.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ int zmk_split_central_update_hid_indicator(zmk_hid_indicators_t indicators);
4646
int zmk_split_central_get_peripheral_battery_level(uint8_t source, uint8_t *level);
4747

4848
#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING)
49+
50+
bool zmk_split_transport_get_available(uint32_t addr);

app/include/zmk/split/peripheral.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
#include <zmk/split/transport/types.h>
1010

1111
int zmk_split_peripheral_report_event(const struct zmk_split_transport_peripheral_event *event);
12+
13+
bool zmk_split_transport_get_available(uint32_t addr);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) 2025 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zmk/events/split_transport_changed.h>
9+
10+
ZMK_EVENT_IMPL(zmk_split_transport_changed);

app/src/split/central.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <zmk/events/position_state_changed.h>
2020
#include <zmk/events/sensor_event.h>
2121

22+
#include <zmk/events/split_transport_changed.h>
23+
2224
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
2325

2426
const struct zmk_split_transport_central *active_transport;
@@ -198,6 +200,8 @@ static int select_first_available_transport(void) {
198200

199201
static int transport_status_changed_cb(const struct zmk_split_transport_central *central,
200202
struct zmk_split_transport_status status) {
203+
raise_zmk_split_transport_changed(
204+
(struct zmk_split_transport_changed){.addr = (uint32_t)central, .status = status});
201205
if (central == active_transport) {
202206
LOG_DBG("Central at %p changed status: enabled %d, available %d, connections %d", central,
203207
status.enabled, status.available, status.connections);
@@ -212,6 +216,16 @@ static int transport_status_changed_cb(const struct zmk_split_transport_central
212216
return 0;
213217
}
214218

219+
bool zmk_split_transport_get_available(uint32_t addr) {
220+
STRUCT_SECTION_FOREACH(zmk_split_transport_central, t) {
221+
if ((uint32_t)t == addr) {
222+
return t->api->get_status().available;
223+
}
224+
}
225+
226+
return 0;
227+
}
228+
215229
static int central_init(void) {
216230
STRUCT_SECTION_FOREACH(zmk_split_transport_central, t) {
217231
if (!t->api->set_status_callback) {

app/src/split/peripheral.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <zmk/events/sensor_event.h>
1919
#include <zmk/events/battery_state_changed.h>
2020

21+
#include <zmk/events/split_transport_changed.h>
22+
2123
#if IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)
2224
#include <zmk/events/hid_indicators_changed.h>
2325
#endif
@@ -115,6 +117,8 @@ static int select_first_available_transport(void) {
115117

116118
static int transport_status_changed_cb(const struct zmk_split_transport_peripheral *p,
117119
struct zmk_split_transport_status status) {
120+
raise_zmk_split_transport_changed(
121+
(struct zmk_split_transport_changed){.addr = (uint32_t)p, .status = status});
118122
if (p == active_transport) {
119123
LOG_DBG("Peripheral at %p changed status: enabled %d, available %d, connections %d", p,
120124
status.enabled, status.available, status.connections);
@@ -130,6 +134,16 @@ static int transport_status_changed_cb(const struct zmk_split_transport_peripher
130134
return 0;
131135
}
132136

137+
bool zmk_split_transport_get_available(uint32_t addr) {
138+
STRUCT_SECTION_FOREACH(zmk_split_transport_peripheral, t) {
139+
if ((uint32_t)t == addr) {
140+
return t->api->get_status().available;
141+
}
142+
}
143+
144+
return 0;
145+
}
146+
133147
static int peripheral_init(void) {
134148
STRUCT_SECTION_FOREACH(zmk_split_transport_peripheral, t) {
135149
if (!t->api->set_status_callback) {

0 commit comments

Comments
 (0)