Skip to content

Commit a8e285c

Browse files
committed
Merge branch 'feature/animations'
2 parents dddf12e + 180882c commit a8e285c

7 files changed

+22
-24
lines changed

app/dts/bindings/animations/animation_base.yaml

+8-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ properties:
99
Pixel positions to which the animation should apply.
1010
1111
blending-mode:
12-
type: int
13-
required: false
12+
type: string
1413
enum:
15-
- 0
16-
- 1
17-
- 2
18-
- 3
19-
- 4
20-
- 5
21-
default: 0
14+
- "normal"
15+
- "multiply"
16+
- "lighten"
17+
- "darken"
18+
- "screen"
19+
- "subtract"
20+
default: "normal"
2221
description: |
2322
Blending mode for the animation to use during render.

app/dts/bindings/animations/zmk,animation-control.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ properties:
2121
2222
brightness-steps:
2323
type: int
24-
required: false
2524
default: 5
2625
description: |
2726
How many brightness steps should be supported.

app/dts/bindings/animations/zmk,animation-ripple.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ include: animation_base.yaml
1111
properties:
1212
duration:
1313
type: int
14-
required: false
1514
default: 1000
1615
description: |
1716
Approximate ripple travel time in milliseconds.
@@ -20,7 +19,7 @@ properties:
2019
type: int
2120
required: true
2221
description: |
23-
Ripple color.
22+
Ripple color in HSL format.
2423
2524
buffer-size:
2625
type: int

app/dts/bindings/animations/zmk,animation-solid.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ include: animation_base.yaml
1111
properties:
1212
duration:
1313
type: int
14-
required: false
1514
default: 5
1615
description: |
1716
Animation duration in seconds.
@@ -22,4 +21,4 @@ properties:
2221
type: array
2322
required: true
2423
description: |
25-
The colors to cycle through during the animation.
24+
The colors to cycle through during the animation in HSL format.

app/dts/bindings/zmk,animation.yaml

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ properties:
1111
required: true
1212
description: |
1313
This array should contain all driver devices responsible for illuminating animated LEDs.
14-
The devices must implement Zephyr's LED Strip Interface and expose a chain-lenght devicetree property.
14+
The devices must implement Zephyr's LED Strip Interface.
15+
16+
chain-lengths:
17+
type: array
18+
required: true
19+
description: |
20+
This field contains the number of LEDs controlled by each driver device.
1521
1622
pixels:
1723
type: phandle-array
@@ -23,7 +29,6 @@ properties:
2329
2430
key-pixels:
2531
type: array
26-
required: false
2732
description: |
2833
Use this field to specify the pixel index corresponding to each key
2934
following the order used in your keymap.

app/src/animation/animation.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
2525

2626
#define PHANDLE_TO_DEVICE(node_id, prop, idx) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)),
2727

28-
#define PHANDLE_TO_CHAIN_LENGTH(node_id, prop, idx) \
29-
DT_PROP_BY_PHANDLE_IDX(node_id, prop, idx, chain_length),
30-
3128
#define PHANDLE_TO_PIXEL(node_id, prop, idx) \
3229
{ \
3330
.position_x = DT_PHA_BY_IDX(node_id, prop, idx, position_x), \
@@ -47,8 +44,7 @@ static const size_t drivers_size = DT_INST_PROP_LEN(0, drivers);
4744
/**
4845
* Array containing the number of LEDs handled by each device.
4946
*/
50-
static const uint8_t pixels_per_driver[] = {
51-
DT_INST_FOREACH_PROP_ELEM(0, drivers, PHANDLE_TO_CHAIN_LENGTH)};
47+
static const size_t pixels_per_driver[] = DT_INST_PROP(0, chain_lengths);
5248

5349
/**
5450
* Pointer to the root animation
@@ -125,7 +121,7 @@ static void zmk_animation_tick(struct k_work *work) {
125121
for (size_t i = 0; i < drivers_size; ++i) {
126122
led_strip_update_rgb(drivers[i], &px_buffer[pixels_updated], pixels_per_driver[i]);
127123

128-
pixels_updated += (size_t)pixels_per_driver;
124+
pixels_updated += pixels_per_driver[i];
129125
}
130126
}
131127

app/src/animation/animation_ripple.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ static void animation_ripple_render_frame(const struct device *dev, struct anima
9999

100100
// Render all pixels for each event
101101
for (int j = 0; j < config->pixel_map_size; ++j) {
102-
uint8_t pixel_distance = zmk_animation_get_pixel_distance(event->pixel_id, j);
102+
uint8_t pixel_distance =
103+
zmk_animation_get_pixel_distance(event->pixel_id, pixel_map[j]);
103104

104105
if (config->ripple_width > abs(pixel_distance - event->distance)) {
105106
float intensity = 1.0f - (float)abs(pixel_distance - event->distance) /
@@ -184,7 +185,7 @@ static const struct animation_api animation_ripple_api = {
184185
.pixel_map = &animation_ripple_##idx##_pixel_map[0], \
185186
.pixel_map_size = DT_INST_PROP_LEN(idx, pixels), \
186187
.event_buffer_size = DT_INST_PROP(idx, buffer_size), \
187-
.blending_mode = DT_INST_PROP(idx, blending_mode), \
188+
.blending_mode = DT_INST_ENUM_IDX(idx, blending_mode), \
188189
.distance_per_frame = \
189190
(255 * 1000 / DT_INST_PROP(idx, duration)) / CONFIG_ZMK_ANIMATION_FPS, \
190191
.ripple_width = DT_INST_PROP(idx, ripple_width) / 2, \

0 commit comments

Comments
 (0)