Skip to content

refactor(channels): bind RMT5 pixel encoder at construction - #4563

Merged
zackees merged 1 commit into
masterfrom
fix/issue-2981-channel-writer-dispatch
Sep 24, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/issue-2981-channel-writer-dispatch

Conversation

@zackees

@zackees zackees commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Select the pixel encoder once for generic Channel instances.
  • Bind the compile-time ESP-IDF 5 RMT clockless adapter directly to WS2812, allowing unused encoders to be stripped from the Blink build. The generic runtime Channel::create(config) path retains runtime encoder selection.

Bloat analysis

Matched ESP32-S3 Blink before/after builds using bash bloat esp32s3 --example Blink --build --top 200 and Xtensa GCC 14.2. Both reports use base commit 26c60462.

Metric Before After Change
Channel::showPixels 4,164 B 2,584 B −1,580 B (−37.9%)
Symbol flash total 381,690 B 374,588 B −7,102 B
Symbol RAM total 41,887 B 41,339 B −548 B
Firmware flash 467,328 B 459,560 B −7,768 B
Firmware RAM 80,968 B 80,912 B −56 B

In the after Blink symbol report, only the WS2812 encoder callback/writer remain among the encoder symbols (Channel::encodeWS2812 15 B, ws2812PixelEncoder 8 B, and PixelIterator::writeWS2812 313 B); unused SPI and other encoder paths are stripped from this build.

These savings are specific to the compile-time RMT5 Blink path. showPixels remains above the issue's <1 KB criterion, and frame-time impact has not been benchmarked, so this PR references rather than closes #2981.

Validation

  • bash test channel --quick
  • bash test color_managed_source --quick
  • bash lint --cpp src/fl/channels/channel.cpp.hpp src/fl/channels/channel.h src/platforms/esp/32/drivers/rmt/rmt_5/idf5_clockless.h
  • ESP32-S3 Blink bloat before/after builds
  • ESP32-S3 Apa102 example build (generic SPI path smoke check)

Refs #2981

Summary by CodeRabbit

  • Performance
    • Pixel encoding is selected when a channel is created, reducing chipset dispatch work each time pixels are shown.
  • Bug Fixes
    • Color-managed encoding now works for MY9221 and other supported SPI chipsets when a color profile and encoding hook are available.

Select the encoder once for generic channels, and bind the compile-time RMT5 path directly to WS2812 so unused encoders can be stripped from Blink builds. Refs #2981.
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: FastLED/FastLED/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 13950c41-278c-4d3f-87d9-65a7add1a940

📥 Commits

Reviewing files that changed from the base of the PR and between 4a2e678 and 0811ca8.

📒 Files selected for processing (3)
  • src/fl/channels/channel.cpp.hpp
  • src/fl/channels/channel.h
  • src/platforms/esp/32/drivers/rmt/rmt_5/idf5_clockless.h

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

Channel now selects a pixel encoder from the chipset during construction. showPixels() calls the stored encoder when it is non-null. SPI encoders use the managed SPI hook when available and otherwise use legacy writers.

Changes

Channel Encoder Dispatch

Layer / File(s) Summary
Bind encoders at construction
src/fl/channels/channel.h, src/fl/channels/channel.cpp.hpp, src/platforms/esp/32/drivers/rmt/rmt_5/idf5_clockless.h
Channel declares the encoder callback type and selector, initializes the callback in its constructors, and exposes the WS2812 callback used by ClocklessIdf5.
Encode pixels by chipset
src/fl/channels/channel.cpp.hpp
Per-chipset callbacks use the managed SPI hook when it succeeds, then fall back to legacy writers where applicable. MY9221 uses only the managed hook.
Dispatch frame encoding
src/fl/channels/channel.cpp.hpp
showPixels() calls the stored encoder callback when it is non-null.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant Channel
  participant PixelEncoder
  participant PixelIterator
  participant encodeManagedSpi
  Channel->>PixelEncoder: invoke mPixelEncoder from showPixels
  alt Managed SPI hook succeeds
    PixelEncoder->>encodeManagedSpi: encode managed SPI pixels
  else Legacy writer path
    PixelEncoder->>PixelIterator: call chipset-specific write method
  end
Loading

Merge Risk: ⚪ Minimal · up to 0811c

No identified encoding regression remains; the change is mergeable after normal checks.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning For #2981, the PR implements construction-time PixelEncoder binding and moves writer calls into separate FL_NO_INLINE encoder functions. showPixels() therefore uses one bound call instead of the… Reduce the ESP32-S3 Blink Channel::showPixels symbol to approximately 1,000 B or less. Run and record the 60 Hz WS2812 100-LED frame-time comparison. Run and record the full bash test --cpp suite.
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main RMT5 pixel-encoder binding change implemented by the pull request.
Out of Scope Changes check ✅ Passed The changed files support #2981. channel.cpp.hpp and channel.h implement construction-time encoder binding and separated writer callbacks. idf5_clockless.h supplies the fixed WS2812 callback for…
Full details: Linked Issues check

Explanation

For #2981, the PR implements construction-time PixelEncoder binding and moves writer calls into separate FL_NO_INLINE encoder functions. showPixels() therefore uses one bound call instead of the per-frame chipset switch. The reported RMT5 result is 2,584 B, which does not meet the approximately 1,000 B acceptance target. The supplied validation does not establish the required no-regression result for 60 Hz WS2812 with 100 LEDs, and it does not establish that the full bash test --cpp suite passed.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bloat: virtualize per-chipset writer dispatch in fl::Channel::showPixels (stop inlining 3 writer templates into one symbol)

1 participant