feat: configurable multi-LED effects engine#16
Conversation
|
Thanks for this — it's a genuinely nice feature and the PR is well put together (clean Must address
Worth considering (not blockers)
Happy to help iron out any of these — especially the phy-tag plumbing for #2, which mirrors |
f32892d to
c4e335f
Compare
|
I have made the improvements based on your feedback and resolved some issues with the committing. The on-device testing has also been re-run successfully. It's now ready for the next round of review! |
4408447 to
55b5c96
Compare
The PIO state machine and frame buffers are sized to this compile-time ceiling (default 8, range 1-64). The actual connected LED count is configurable at runtime via the phy record (rsk hw --led-num) and must be <= MAX_LEDS.
Replace the single-colour broadcast in ws2812_task with a dispatch-based effect system. Five effects (LEGACY, VAPOR, BOUNCE, FLOW, SPARKLE) are selectable per status via STATUS_EFFECT/STATUS_SPEED atomics. MAX_LEDS is the compile-time buffer ceiling; RUNTIME_LEDS is the runtime count. Effect functions are pure fn(status, tick) -> [RGB8; MAX_LEDS], dispatched from ws2812_task each tick. The Blinker is kept for gpio/pimoroni backends (unchanged). EF_LED_CONF extended from 9 to 17 bytes: [steady, (effect, color, brightness, speed) x 4] load_block handles four wire formats (17/13/9/2 bytes).
New TLV tag TAG_LED_NUM (0x0E) stores the number of physically-connected addressable LEDs. At boot, main.rs reads it and calls led::set_runtime_leds(n). Zero/unset = use the build's MAX_LEDS default. Also adds the led_num field to PhyData with parse/serialize support, updates PHY_MAX_SIZE, and extends the Kani proof and roundtrip test.
vendor: INS_SET_LED accepts optional data bytes for effect (data[0]) and speed (data[1]), backward compatible. rsk led: new --effect and --speed flags; parses 17-byte GET LED block with adaptive stride. Color spelling kept as 'color' (American English) to match firmware identifiers. rsk hw: new --led-num flag writes TAG_LED_NUM (0x0E) to the phy record. rsk-tui: led_get and led_cycle_idle parse 17/13/9-byte block formats with correct stride; led_get displays effect per status.
guides/led.md: rewrite with build-time knobs (MAX_LEDS, LED_KIND, LED_PIN, LED_ORDER), effects table with default mapping, customisation examples with --effect/--speed, updated wire-format reference, troubleshooting entries. build.md: add MAX_LEDS build knob, update boot-defaults sentence. hardware.md: add MAX_LEDS knob, update three-LED-knobs wording to four.
55b5c96 to
9149133
Compare

What
Add support for boards with multiple daisy-chained WS2812 addressable LEDs. Previously
NUM_LEDSwas hardcoded to 1, so only the first LED ever received data.Since I wasn't sure if this improvement fits into your long-term plans for the project, I decided to open it as a draft PR. Please let me know if you have any concerns regarding the scope, design, or implementation; I'm more than happy to adjust it based on your feedback. If you'd rather implement this feature yourself, you can absolutely use this draft as a reference, and I'd be glad to help iron out the details. That said, if this doesn't align with the project's goals, no worries at all if you want to close it. Thanks for all your hard work on this project!
The main additions:
LED_NUM(build.rs) — sets the number of addressable LEDs at compile time (default1, range1..=256). Boards with e.g. 4 LEDs build withLED_NUM=4.led.rs) — replaces the single-colour broadcast with a dispatch-based system. Five effects are defined (LEGACY,VAPOR,BOUNCE,FLOW,SPARKLE), each a pure function of(status, tick). Per-statusSTATUS_EFFECTandSTATUS_SPEEDatomics control the active effect.[steady, (color, brightness) × 4]) to 13 bytes ([steady, (effect, color, brightness) × 4]).load_blockhandles all three wire formats (13/9/2 bytes) for seamless upgrade.vendor.rs) — accepts 1–2 optional data bytes for effect and speed. No data = unchanged behaviour (backward compatible).rsk ledupdated (tools/rsk/led.py) — parses the new 13-byte block; new--effectand--speedflags.docs/guides/led.md,docs/hardware.md) —LED_NUMbuild knob, effects table with default per-status mapping, customisation examples.How it was tested
nix develop -c ./scripts/check.shpasses locallyLED_NUM=4 LED_ORDER=grb— all four LEDs light, each status shows its default effect (idle = breathing, processing = warm flow, touch = smooth bounce, boot = random sparkle).rsk led --getreports correct effect IDs.Checklist
config.device_release(bcdDevice) bumped by one (hex)in
firmware/src/main.rs— needs bump (not done in this PR)rollback epoch (
docs/production.md, stage 3) — a seal-time--rollbackcall, not a code bumpunsafe→ justified indocs/unsafe.mddocs/updatedAGPL-3.0-only)fido:,piv:,rsk:,docs:, …)