From abeb5c8c49dc8fab200c70761a9b108384a04803 Mon Sep 17 00:00:00 2001 From: Kuba Birecki Date: Tue, 13 Jun 2023 15:19:59 +0200 Subject: [PATCH] Update the animation API for Zephyr 3.* --- app/include/drivers/animation.h | 4 +-- app/include/zmk/animation.h | 4 +-- app/include/zmk/animation/animation_control.h | 4 +-- app/src/animation/animation.c | 29 +++++++------------ app/src/animation/animation_compose.c | 16 ++++------ app/src/animation/animation_control.c | 27 ++++++++--------- app/src/animation/animation_ripple.c | 7 ++--- app/src/animation/animation_solid.c | 7 +++-- app/src/behaviors/behavior_animation.c | 9 +++--- 9 files changed, 47 insertions(+), 60 deletions(-) diff --git a/app/include/drivers/animation.h b/app/include/drivers/animation.h index df05d194..e0ee303b 100644 --- a/app/include/drivers/animation.h +++ b/app/include/drivers/animation.h @@ -7,8 +7,8 @@ #pragma once #include -#include -#include +#include +#include #include diff --git a/app/include/zmk/animation.h b/app/include/zmk/animation.h index c17dccf4..add3e5f5 100644 --- a/app/include/zmk/animation.h +++ b/app/include/zmk/animation.h @@ -6,8 +6,8 @@ #pragma once -#include -#include +#include +#include #define ZMK_ANIMATION_BLENDING_MODE_NORMAL 0 #define ZMK_ANIMATION_BLENDING_MODE_MULTIPLY 1 diff --git a/app/include/zmk/animation/animation_control.h b/app/include/zmk/animation/animation_control.h index 653afcf3..a21b4d77 100644 --- a/app/include/zmk/animation/animation_control.h +++ b/app/include/zmk/animation/animation_control.h @@ -6,8 +6,8 @@ #pragma once -#include -#include +#include +#include /** * Animation control commands diff --git a/app/src/animation/animation.c b/app/src/animation/animation.c index 64f385cd..3d94bfb2 100644 --- a/app/src/animation/animation.c +++ b/app/src/animation/animation.c @@ -6,18 +6,16 @@ #define DT_DRV_COMPAT zmk_animation -#include -#include -#include -#include - #include #include -#include +#include +#include +#include +#include +#include #include -#include #include #include @@ -25,17 +23,12 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -// Zephyr 2.7.0 comes with DT_INST_FOREACH_PROP_ELEM -// that we can't use quite yet as we're still on 2.5.* -#define ZMK_DT_INST_FOREACH_PROP_ELEM(inst, prop, fn) \ - UTIL_LISTIFY(DT_INST_PROP_LEN(inst, prop), fn, DT_DRV_INST(inst), prop) +#define PHANDLE_TO_DEVICE(node_id, prop, idx) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)), -#define PHANDLE_TO_DEVICE(idx, node_id, prop) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)), - -#define PHANDLE_TO_CHAIN_LENGTH(idx, node_id, prop) \ +#define PHANDLE_TO_CHAIN_LENGTH(node_id, prop, idx) \ DT_PROP_BY_PHANDLE_IDX(node_id, prop, idx, chain_length), -#define PHANDLE_TO_PIXEL(idx, node_id, prop) \ +#define PHANDLE_TO_PIXEL(node_id, prop, idx) \ { \ .position_x = DT_PHA_BY_IDX(node_id, prop, idx, position_x), \ .position_y = DT_PHA_BY_IDX(node_id, prop, idx, position_y), \ @@ -45,7 +38,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); * LED Driver device pointers. */ static const struct device *drivers[] = { - ZMK_DT_INST_FOREACH_PROP_ELEM(0, drivers, PHANDLE_TO_DEVICE)}; + DT_INST_FOREACH_PROP_ELEM(0, drivers, PHANDLE_TO_DEVICE)}; /** * Size of the LED driver device pointers array. @@ -56,7 +49,7 @@ static const size_t drivers_size = DT_INST_PROP_LEN(0, drivers); * Array containing the number of LEDs handled by each device. */ static const uint8_t pixels_per_driver[] = { - ZMK_DT_INST_FOREACH_PROP_ELEM(0, drivers, PHANDLE_TO_CHAIN_LENGTH)}; + DT_INST_FOREACH_PROP_ELEM(0, drivers, PHANDLE_TO_CHAIN_LENGTH)}; /** * Pointer to the root animation @@ -67,7 +60,7 @@ static const struct device *animation_root = DEVICE_DT_GET(DT_CHOSEN(zmk_animati * Pixel configuration. */ static struct animation_pixel pixels[] = { - ZMK_DT_INST_FOREACH_PROP_ELEM(0, pixels, PHANDLE_TO_PIXEL)}; + DT_INST_FOREACH_PROP_ELEM(0, pixels, PHANDLE_TO_PIXEL)}; /** * Size of the pixels array. diff --git a/app/src/animation/animation_compose.c b/app/src/animation/animation_compose.c index b946791f..79db7c0e 100644 --- a/app/src/animation/animation_compose.c +++ b/app/src/animation/animation_compose.c @@ -6,21 +6,17 @@ #define DT_DRV_COMPAT zmk_animation_compose -#include -#include +#include +#include +#include + #include -#include #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -// Zephyr 2.7.0 comes with DT_INST_FOREACH_PROP_ELEM -// that we can't use quite yet as we're still on 2.5.* -#define ZMK_DT_INST_FOREACH_PROP_ELEM(inst, prop, fn) \ - UTIL_LISTIFY(DT_INST_PROP_LEN(inst, prop), fn, DT_DRV_INST(inst), prop) - -#define PHANDLE_TO_DEVICE(idx, node_id, prop) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)), +#define PHANDLE_TO_DEVICE(node_id, prop, idx) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)), struct animation_compose_config { const struct device **animations; @@ -63,7 +59,7 @@ static const struct animation_api animation_compose_api = { #define ANIMATION_COMPOSE_DEVICE(idx) \ \ static const struct device *animation_compose_##idx##_animations[] = { \ - ZMK_DT_INST_FOREACH_PROP_ELEM(idx, animations, PHANDLE_TO_DEVICE)}; \ + DT_INST_FOREACH_PROP_ELEM(idx, animations, PHANDLE_TO_DEVICE)}; \ \ static struct animation_compose_config animation_compose_##idx##_config = { \ .animations = animation_compose_##idx##_animations, \ diff --git a/app/src/animation/animation_control.c b/app/src/animation/animation_control.c index a6311074..6e298ab3 100644 --- a/app/src/animation/animation_control.c +++ b/app/src/animation/animation_control.c @@ -7,27 +7,24 @@ #define DT_DRV_COMPAT zmk_animation_control #include -#include -#include + +#include +#include +#include +#include + #include -#include -#include #include #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -// Zephyr 2.7.0 comes with DT_INST_FOREACH_PROP_ELEM -// that we can't use quite yet as we're still on 2.5.* -#define ZMK_DT_INST_FOREACH_PROP_ELEM(inst, prop, fn) \ - UTIL_LISTIFY(DT_INST_PROP_LEN(inst, prop), fn, DT_DRV_INST(inst), prop) - -#define PHANDLE_TO_DEVICE(idx, node_id, prop) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)), +#define PHANDLE_TO_DEVICE(node_id, prop, idx) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)), struct animation_control_work_context { const struct device *animation; - struct k_delayed_work save_work; + struct k_work_delayable save_work; }; struct animation_control_config { @@ -85,9 +82,9 @@ static int animation_control_save_settings(const struct device *dev) { const struct animation_control_config *config = dev->config; struct animation_control_work_context *ctx = config->work; - k_delayed_work_cancel(&ctx->save_work); + k_work_cancel_delayable(&ctx->save_work); - return k_delayed_work_submit(&ctx->save_work, K_MSEC(CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE)); + return k_work_reschedule(&ctx->save_work, K_MSEC(CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE)); } #endif /* IS_ENABLED(CONFIG_SETTINGS) */ @@ -211,7 +208,7 @@ static int animation_control_init(const struct device *dev) { settings_register(config->settings_handler); - k_delayed_work_init(&config->work->save_work, animation_control_save_work); + k_work_init_delayable(&config->work->save_work, animation_control_save_work); settings_load_subtree(dev->name); #endif /* IS_ENABLED(CONFIG_SETTINGS) */ @@ -228,7 +225,7 @@ static const struct animation_api animation_control_api = { #define ANIMATION_CONTROL_DEVICE(idx) \ \ static const struct device *animation_control_##idx##_animations[] = { \ - ZMK_DT_INST_FOREACH_PROP_ELEM(idx, animations, PHANDLE_TO_DEVICE)}; \ + DT_INST_FOREACH_PROP_ELEM(idx, animations, PHANDLE_TO_DEVICE)}; \ \ static struct animation_control_work_context animation_control_##idx##_work = { \ .animation = DEVICE_DT_GET(DT_DRV_INST(idx)), \ diff --git a/app/src/animation/animation_ripple.c b/app/src/animation/animation_ripple.c index dc61c148..80cae740 100644 --- a/app/src/animation/animation_ripple.c +++ b/app/src/animation/animation_ripple.c @@ -6,13 +6,12 @@ #define DT_DRV_COMPAT zmk_animation_ripple -#include -#include - #include #include -#include +#include +#include +#include #include diff --git a/app/src/animation/animation_solid.c b/app/src/animation/animation_solid.c index b13a2835..02017b43 100644 --- a/app/src/animation/animation_solid.c +++ b/app/src/animation/animation_solid.c @@ -6,10 +6,11 @@ #define DT_DRV_COMPAT zmk_animation_solid -#include -#include +#include +#include +#include + #include -#include #include diff --git a/app/src/behaviors/behavior_animation.c b/app/src/behaviors/behavior_animation.c index 1f6823c8..fa086a9c 100644 --- a/app/src/behaviors/behavior_animation.c +++ b/app/src/behaviors/behavior_animation.c @@ -4,10 +4,11 @@ * SPDX-License-Identifier: MIT */ -#include -#include +#include +#include +#include + #include -#include #include @@ -89,5 +90,5 @@ static const struct behavior_driver_api behavior_animation_driver_api = { .binding_released = on_keymap_binding_released, }; -DEVICE_DT_INST_DEFINE(0, behavior_animation_init, device_pm_control_nop, NULL, NULL, APPLICATION, +DEVICE_DT_INST_DEFINE(0, behavior_animation_init, NULL, NULL, NULL, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_animation_driver_api);