Skip to content

Commit 2b856c5

Browse files
committed
fix(behavior_tri_state): support zephyr 3.5 and latest zmk
- use `k_work_delayable_from_work` for `CONTAINER_OF` see changes in `CONTAINER_OF` in kernel https://docs.zephyrproject.org/3.5.0/releases/migration-guide-3.5.html#kernel - migrate `DT_LABEL` to `DEVICE_DT_NAME` see 1499 and 2028 - migrate `DEVICE_DT_INST_DEFINE` to `BEHAVIOR_DT_INST_DEFINE`
1 parent bcda9bc commit 2b856c5

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

app/src/behaviors/behavior_tri_state.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define DT_DRV_COMPAT zmk_behavior_tri_state
88

99
#include <zephyr/device.h>
10+
#include <zephyr/drivers/kscan.h>
1011
#include <drivers/behavior.h>
1112
#include <zephyr/logging/log.h>
1213
#include <zmk/behavior.h>
@@ -20,6 +21,8 @@
2021

2122
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
2223

24+
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)
25+
2326
#define ZMK_BHV_MAX_ACTIVE_TRI_STATES 10
2427

2528
struct behavior_tri_state_config {
@@ -70,7 +73,8 @@ void trigger_end_behavior(struct active_tri_state *si) {
7073
}
7174

7275
void behavior_tri_state_timer_handler(struct k_work *item) {
73-
struct active_tri_state *tri_state = CONTAINER_OF(item, struct active_tri_state, release_timer);
76+
struct k_work_delayable *ditem = k_work_delayable_from_work(item);
77+
struct active_tri_state *tri_state = CONTAINER_OF(ditem, struct active_tri_state, release_timer);
7478
if (!tri_state->is_active || tri_state->timer_cancelled || tri_state->is_pressed) {
7579
return;
7680
}
@@ -274,7 +278,7 @@ static int tri_state_layer_state_changed_listener(const zmk_event_t *eh) {
274278

275279
#define _TRANSFORM_ENTRY(idx, node) \
276280
{ \
277-
.behavior_dev = DT_LABEL(DT_INST_PHANDLE_BY_IDX(node, bindings, idx)), \
281+
.behavior_dev = DEVICE_DT_NAME(DT_INST_PHANDLE_BY_IDX(node, bindings, idx)), \
278282
.param1 = COND_CODE_0(DT_INST_PHA_HAS_CELL_AT_IDX(node, bindings, idx, param1), (0), \
279283
(DT_INST_PHA_BY_IDX(node, bindings, idx, param1))), \
280284
.param2 = COND_CODE_0(DT_INST_PHA_HAS_CELL_AT_IDX(node, bindings, idx, param2), (0), \
@@ -294,8 +298,10 @@ static int tri_state_layer_state_changed_listener(const zmk_event_t *eh) {
294298
.start_behavior = _TRANSFORM_ENTRY(0, n), \
295299
.continue_behavior = _TRANSFORM_ENTRY(1, n), \
296300
.end_behavior = _TRANSFORM_ENTRY(2, n)}; \
297-
DEVICE_DT_INST_DEFINE(n, behavior_tri_state_init, NULL, NULL, &behavior_tri_state_config_##n, \
301+
BEHAVIOR_DT_INST_DEFINE(n, behavior_tri_state_init, NULL, NULL, &behavior_tri_state_config_##n, \
298302
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
299303
&behavior_tri_state_driver_api);
300304

301305
DT_INST_FOREACH_STATUS_OKAY(TRI_STATE_INST)
306+
307+
#endif

0 commit comments

Comments
 (0)