Update the animation API for Zephyr 3.*

This commit is contained in:
Kuba Birecki 2023-06-13 15:19:59 +02:00
parent e2cdd017e3
commit abeb5c8c49
9 changed files with 47 additions and 60 deletions

View file

@ -7,8 +7,8 @@
#pragma once
#include <zephyr/types.h>
#include <device.h>
#include <drivers/led_strip.h>
#include <zephyr/device.h>
#include <zephyr/drivers/led_strip.h>
#include <zmk/animation.h>

View file

@ -6,8 +6,8 @@
#pragma once
#include <device.h>
#include <drivers/led_strip.h>
#include <zephyr/device.h>
#include <zephyr/drivers/led_strip.h>
#define ZMK_ANIMATION_BLENDING_MODE_NORMAL 0
#define ZMK_ANIMATION_BLENDING_MODE_MULTIPLY 1

View file

@ -6,8 +6,8 @@
#pragma once
#include <zephyr.h>
#include <device.h>
#include <zephyr/device.h>
#include <zephyr/kernel.h>
/**
* Animation control commands

View file

@ -6,18 +6,16 @@
#define DT_DRV_COMPAT zmk_animation
#include <zephyr.h>
#include <device.h>
#include <init.h>
#include <kernel.h>
#include <stdlib.h>
#include <math.h>
#include <logging/log.h>
#include <zephyr/device.h>
#include <zephyr/drivers/led_strip.h>
#include <zephyr/init.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <drivers/animation.h>
#include <drivers/led_strip.h>
#include <zmk/animation.h>
#include <zmk/event_manager.h>
@ -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.

View file

@ -6,21 +6,17 @@
#define DT_DRV_COMPAT zmk_animation_compose
#include <zephyr.h>
#include <device.h>
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/logging/log.h>
#include <drivers/animation.h>
#include <logging/log.h>
#include <zmk/animation.h>
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, \

View file

@ -7,27 +7,24 @@
#define DT_DRV_COMPAT zmk_animation_control
#include <stdio.h>
#include <zephyr.h>
#include <device.h>
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/logging/log.h>
#include <zephyr/settings/settings.h>
#include <drivers/animation.h>
#include <logging/log.h>
#include <settings/settings.h>
#include <zmk/animation.h>
#include <zmk/animation/animation_control.h>
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)), \

View file

@ -6,13 +6,12 @@
#define DT_DRV_COMPAT zmk_animation_ripple
#include <zephyr.h>
#include <device.h>
#include <stdlib.h>
#include <math.h>
#include <logging/log.h>
#include <zephyr/device.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <drivers/animation.h>

View file

@ -6,10 +6,11 @@
#define DT_DRV_COMPAT zmk_animation_solid
#include <zephyr.h>
#include <device.h>
#include <zephyr/device.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <drivers/animation.h>
#include <logging/log.h>
#include <zmk/animation.h>

View file

@ -4,10 +4,11 @@
* SPDX-License-Identifier: MIT
*/
#include <zephyr.h>
#include <device.h>
#include <zephyr/device.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <drivers/behavior.h>
#include <logging/log.h>
#include <zmk/animation/animation_control.h>
@ -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);