Skip to content

feat(channels): gate driver aggregator + pre-bind remaining legacy clockless (Phase 5c of #2428) - #2450

Merged
zackees merged 1 commit into
masterfrom
feat/channels-gate-aggregator-phase-5c-2428
May 11, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/channels-gate-aggregator-phase-5c-2428

Conversation

@zackees

@zackees zackees commented May 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Phase 5c of #2428 completes the binary-size fix from #2420 by:

  1. Gating per-driver ESP32 _build.cpp.hpp aggregators against FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY. When the macro is enabled (opt-in), only the per-platform default driver TUs compile; all other driver TUs become empty.
  2. Pre-binding the remaining legacy clockless controllers to their default BusTraits<Bus::X>::instancePtr() singleton — mirroring what 5b did for RMT5 / stub. Covers RMT4 (idf4_clockless_rmt_esp32.h), ESP32 clockless-over-SPI (idf5_clockless_spi_esp32.h), WASM clockless + SPI, and host stub SPI.

ClocklessBlockingGeneric (pure CPU bitbang) does not use a Channel/Driver and is intentionally untouched.

Default behavior is byte-for-byte unchanged: with the macro at its default value of 0, every driver TU still compiles and registers exactly as before.

Per-platform default routing

Variant Default clockless Default true-SPI
ESP32-P4 / C6 / H2 / C5 Bus::PARLIO unspecified
ESP32-S3 Bus::RMT Bus::LCD_SPI
ESP32dev Bus::RMT Bus::I2S_SPI
Other ESP32 Bus::RMT unspecified

Each driver subdir's _build.cpp.hpp is unconditional on its default variant(s) and gated by the macro everywhere else. ble/, gpio_isr_rx/, rmt_rx/ are non-LED-output drivers and remain unconditional.

Why the conditional logic lives in each subdir's _build.cpp.hpp

The unity-build linter (ci/lint_cpp/test_unity_build.py) requires the top-level _build.cpp.hpp aggregator to list every subdir alphabetically in a single // begin sub directory includes block. Wrapping the parent in #if blocks fails the alphabetization check. Pushing the conditional gating into each subdir's _build.cpp.hpp keeps the parent linter-clean while still removing the unused TUs from compilation.

Expected binary-size impact

For the #2420 reproducer (NEOPIXEL-only sketch on ESP32-S3 with -DFASTLED_DISABLE_LEGACY_DRIVER_REGISTRY=1):

  • Default (macro=0): ~783 KB (unchanged from master HEAD).
  • Opt-in (macro=1): expected to drop toward the ~344 KB baseline from 3.10.3.

Local ESP32-S3 platform measurement was deferred — the fbuild daemon in this worktree environment hung repeatedly (daemon error: stream error: error decoding response body, watchdog timeouts). CI will produce the authoritative before/after numbers.

Verification

  • bash test --cpp — 303/303 pass on the default (macro=0) build.
  • bash compile wasm --examples Blink — succeeds.
  • bash lint — clean (Python, C++, JavaScript, meson).
  • New mDriverPreBound flag from 5b stays unchanged; default-mode tests don't observe the new code paths.

Files changed (14)

  • src/platforms/esp/32/drivers/_build.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/_build.cpp.hpp
  • src/platforms/esp/32/drivers/i2s_spi/_build.cpp.hpp
  • src/platforms/esp/32/drivers/lcd_cam/_build.cpp.hpp
  • src/platforms/esp/32/drivers/lcd_spi/_build.cpp.hpp
  • src/platforms/esp/32/drivers/parlio/_build.cpp.hpp
  • src/platforms/esp/32/drivers/rmt/_build.cpp.hpp
  • src/platforms/esp/32/drivers/rmt/rmt_4/idf4_clockless_rmt_esp32.h
  • src/platforms/esp/32/drivers/spi/_build.cpp.hpp
  • src/platforms/esp/32/drivers/spi/idf5_clockless_spi_esp32.h
  • src/platforms/esp/32/drivers/uart/_build.cpp.hpp
  • src/platforms/stub/spi_channel_stub.h
  • src/platforms/wasm/clockless_channel_wasm.h
  • src/platforms/wasm/spi_channel_wasm.h

Constraints honored

  • No touch to src/fl/channels/{channel.h,config.h,_build.cpp.hpp} — Phase 3b (templatize ChannelConfig / Channel) is in flight on a parallel branch.
  • No new macros introduced; the existing FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY from 5a/5b is the sole opt-in flag.

Test plan

  • CI: verify bash test --cpp passes (303/303).
  • CI: bash compile wasm --examples Blink passes.
  • CI: bash compile esp32s3 --examples Blink passes on default macro state — confirms backward compatibility.
  • CI: bash compile esp32s3 --examples Blink --defines FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY=1 passes and produces a smaller binary ([Bug] Compounded timing inaccuracy on master compared to 3.10.3 #2420 reproducer).
  • Bin-bloat measurement: confirm the opt-in size drops back toward the ~344 KB 3.10.3 baseline.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved driver loading architecture with optional legacy driver registry disabling. When the legacy registry is disabled, the system uses direct driver instantiation, reducing overhead and binary footprint. Platform-specific default drivers remain available while auxiliary drivers can be selectively excluded.

Review Change Stack

…ockless (Phase 5c of #2428)

Phase 5c of #2428 completes the binary-size fix for #2420 by gating the
ESP32 driver-aggregator includes against `FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY`
and pre-binding the remaining legacy clockless controllers to their default
`BusTraits<Bus::X>::instancePtr()` singletons.

Default behavior is byte-for-byte unchanged: with the macro at its default
value of 0, every driver TU still compiles and registers, every test passes
identically, and every existing sketch links the same way it does on master.

What changed:

1) Per-driver `_build.cpp.hpp` self-gating
   Each LED-output driver subdir under `src/platforms/esp/32/drivers/` now
   self-gates against the macro:
   - `i2s/`, `lcd_cam/`, `spi/`, `uart/` — never a platform default; the TU
     becomes empty when the macro is on.
   - `parlio/` — default on ESP32-P4 / C6 / H2 / C5; always compiled there.
     Gated by the macro on every other ESP32 variant.
   - `rmt/` — default on every ESP32 variant EXCEPT P4 / C6 / H2 / C5;
     always compiled there. Gated by the macro on the PARLIO-default
     variants.
   - `lcd_spi/` — default true-SPI on ESP32-S3; always compiled there.
     Gated by the macro on every other ESP32 variant.
   - `i2s_spi/` — default true-SPI on ESP32dev; always compiled there.
     Gated by the macro on every other ESP32 variant.
   - `ble/`, `gpio_isr_rx/`, `rmt_rx/` — not LED-output channel drivers;
     remain unconditional.

   The top-level `src/platforms/esp/32/drivers/_build.cpp.hpp` aggregator
   stays as a single alphabetical list (one include per subdir) so the
   unity-build linter is satisfied. All conditional logic moves into each
   subdir's `_build.cpp.hpp`.

2) Legacy clockless controllers pre-bound to BusTraits singletons
   Phase 5b already wired this up for RMT5 (`idf5_clockless.h`) and stub
   (`clockless_channel_stub.h`). Phase 5c extends the pattern to:
   - `idf4_clockless_rmt_esp32.h` — RMT4 legacy clockless. Now binds to
     `BusTraits<Bus::RMT>::instancePtr()` when the macro is on instead of
     calling `ChannelManager::instance().getDriverByName("RMT")`.
   - `idf5_clockless_spi_esp32.h` — ESP32 clockless-over-SPI. Binds to
     `BusTraits<Bus::SPI>::instancePtr()`.
   - `clockless_channel_wasm.h` / `spi_channel_wasm.h` — WASM clockless +
     SPI. Both bind to `BusTraits<Bus::STUB>::instancePtr()` (WASM uses
     stub driver for both chipset families).
   - `spi_channel_stub.h` — host SPI stub. Binds to `BusTraits<Bus::STUB>`.

   `ClocklessBlockingGeneric` (the pure CPU-bitbang fallback in
   `platforms/shared/clockless_blocking.h`) does not use a Channel/Driver
   at all and is intentionally left unmodified.

Mechanism (recap from 5a/5b):

When `FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY=1` is defined:
  - `initChannelDrivers()` becomes a no-op (5a) — no eager
    `addDriver()` calls to manager.
  - Each per-platform legacy clockless controller ODR-uses ONLY
    `BusTraits<Bus::DefaultClocklessBus>::instancePtr()` in its
    constructor (5b + 5c) — the default driver is the only one that
    survives `--gc-sections`.
  - Each non-default driver subdir's `_build.cpp.hpp` is empty (5c) —
    those TUs are not compiled at all.

For the #2420 reproducer (NEOPIXEL-only sketch on ESP32-S3 with
`-DFASTLED_DISABLE_LEGACY_DRIVER_REGISTRY=1`), the expected behavior is:
RMT5 + LCD_SPI driver TUs compile; PARLIO / I2S / I2S_SPI / LCD_CAM /
clockless-SPI / UART / RMT4 driver TUs do not. Binary size should drop
from ~783 KB toward the 344 KB baseline from 3.10.3.

Constraints honored:
  - No touch to `src/fl/channels/{channel.h,config.h,_build.cpp.hpp}` —
    Phase 3b (templatize ChannelConfig/Channel) is in-flight on a
    parallel branch.
  - No new macros introduced; the existing `FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY`
    from 5a/5b is the sole opt-in flag.
  - Unity-build linter passes (top-level aggregator stays alphabetical;
    each subdir's _build.cpp.hpp has its own gate that the linter
    treats as a single conditional block).

Verification:
  - `bash test --cpp` — 303/303 pass on default (macro=0) build.
  - `bash compile wasm --examples Blink` — succeeds.
  - `bash lint` — clean.
  - ESP32-S3 platform compile + size measurement deferred to CI (the
    local platform build infrastructure was unstable during this
    session — daemon errors and watchdog timeouts). The opt-in macro
    is gated behind an explicit user define, so no shipping binaries
    change unless the user opts in.

Files touched: 14
  src/platforms/esp/32/drivers/_build.cpp.hpp
  src/platforms/esp/32/drivers/i2s/_build.cpp.hpp
  src/platforms/esp/32/drivers/i2s_spi/_build.cpp.hpp
  src/platforms/esp/32/drivers/lcd_cam/_build.cpp.hpp
  src/platforms/esp/32/drivers/lcd_spi/_build.cpp.hpp
  src/platforms/esp/32/drivers/parlio/_build.cpp.hpp
  src/platforms/esp/32/drivers/rmt/_build.cpp.hpp
  src/platforms/esp/32/drivers/rmt/rmt_4/idf4_clockless_rmt_esp32.h
  src/platforms/esp/32/drivers/spi/_build.cpp.hpp
  src/platforms/esp/32/drivers/spi/idf5_clockless_spi_esp32.h
  src/platforms/esp/32/drivers/uart/_build.cpp.hpp
  src/platforms/stub/spi_channel_stub.h
  src/platforms/wasm/clockless_channel_wasm.h
  src/platforms/wasm/spi_channel_wasm.h

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented May 11, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d98abef7-9266-4396-bdbf-ed56ac6800e3

📥 Commits

Reviewing files that changed from the base of the PR and between 196f054 and e2e0424.

📒 Files selected for processing (14)
  • src/platforms/esp/32/drivers/_build.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/_build.cpp.hpp
  • src/platforms/esp/32/drivers/i2s_spi/_build.cpp.hpp
  • src/platforms/esp/32/drivers/lcd_cam/_build.cpp.hpp
  • src/platforms/esp/32/drivers/lcd_spi/_build.cpp.hpp
  • src/platforms/esp/32/drivers/parlio/_build.cpp.hpp
  • src/platforms/esp/32/drivers/rmt/_build.cpp.hpp
  • src/platforms/esp/32/drivers/rmt/rmt_4/idf4_clockless_rmt_esp32.h
  • src/platforms/esp/32/drivers/spi/_build.cpp.hpp
  • src/platforms/esp/32/drivers/spi/idf5_clockless_spi_esp32.h
  • src/platforms/esp/32/drivers/uart/_build.cpp.hpp
  • src/platforms/stub/spi_channel_stub.h
  • src/platforms/wasm/clockless_channel_wasm.h
  • src/platforms/wasm/spi_channel_wasm.h

📝 Walkthrough

Walkthrough

This PR implements Phase 5c of the legacy driver registry opt-in feature: conditionally gates platform-specific driver unity-build translation units and updates driver selection methods to bypass ChannelManager when FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY is enabled, allowing selective driver omission while preserving platform defaults.

Changes

Legacy Driver Registry Opt-In Gating (Phase 5c)

Layer / File(s) Summary
Build Gating Strategy Documentation
src/platforms/esp/32/drivers/_build.cpp.hpp
Parent unity-build header documents Phase 5c: non-default driver translation units self-gate based on FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY; auxiliary subdirectories and platform defaults remain unconditional.
ESP32 I2S Driver Gating
src/platforms/esp/32/drivers/i2s/_build.cpp.hpp
Wraps I2S implementation headers in #if !FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY conditional; includes fl/channels/bus.h for macro access; translation unit becomes empty when opt-in mode enabled.
ESP32 I2S_SPI Driver Gating
src/platforms/esp/32/drivers/i2s_spi/_build.cpp.hpp
Conditionally compiles I2S_SPI driver based on FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY || FL_IS_ESP_32DEV, making it always-included default on ESP32dev while optional elsewhere.
ESP32 LCD_CAM Driver Gating
src/platforms/esp/32/drivers/lcd_cam/_build.cpp.hpp
Conditionally includes LCD_RGB implementation headers via #if !FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY guard; driver omitted when opt-in mode enabled.
ESP32 LCD_SPI Driver Gating
src/platforms/esp/32/drivers/lcd_spi/_build.cpp.hpp
Conditionally compiles LCD_SPI based on FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY || FL_IS_ESP_32S3, making it default on ESP32-S3 while optional on other variants.
ESP32 PARLIO Driver Gating
src/platforms/esp/32/drivers/parlio/_build.cpp.hpp
Conditionally includes PARLIO driver when legacy mode enabled or on PARLIO-default platforms (P4/C6/H2/C5); includes platform detection macros and registry macro.
ESP32 RMT Driver Gating
src/platforms/esp/32/drivers/rmt/_build.cpp.hpp
Conditionally includes RMT subdirectories when legacy mode enabled or not on PARLIO-default platforms; RMT is platform default on most ESP32 variants.
ESP32 UART Driver Gating
src/platforms/esp/32/drivers/uart/_build.cpp.hpp
Wraps UART implementation headers and bus_traits.h in #if !FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY guard; translation unit becomes empty when opt-in mode enabled.
ESP32 SPI Driver Gating
src/platforms/esp/32/drivers/spi/_build.cpp.hpp
Conditionally includes SPI clockless driver implementation headers based on FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY; gated includes exclude driver when opt-in mode enabled.
ESP32 RMT Driver Selection Logic
src/platforms/esp/32/drivers/rmt/rmt_4/idf4_clockless_rmt_esp32.h
ClocklessIdf4::getRmtEngine() branches on FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY: returns BusTraits<Bus::RMT>::instancePtr() when enabled, else ChannelManager::instance().getDriverByName("RMT"). Adds channel/bus infrastructure includes.
ESP32 SPI Driver Selection Logic
src/platforms/esp/32/drivers/spi/idf5_clockless_spi_esp32.h
ClocklessSPI::getClocklessSpiEngine() branches on FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY: returns BusTraits<Bus::SPI>::instancePtr() when enabled, else ChannelManager::instance().getDriverByName("SPI").
Stub Platform SPI Driver Selection
src/platforms/stub/spi_channel_stub.h
ClocklessSPI::getStubSpiEngine() returns BusTraits<Bus::STUB>::instancePtr() when FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY enabled, else ChannelManager::getDriverByName("SPI").
WASM Platform Clockless Driver Selection
src/platforms/wasm/clockless_channel_wasm.h
ClocklessController::getWasmEngine() returns BusTraits<Bus::STUB>::instancePtr() when FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY enabled, else ChannelManager::getDriverByName("STUB"). Adds channel integration includes.
WASM Platform SPI Driver Selection
src/platforms/wasm/spi_channel_wasm.h
ClocklessSPI::getWasmSpiEngine() returns BusTraits<Bus::STUB>::instancePtr() when FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY enabled, else ChannelManager::getDriverByName("SPI").

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • FastLED/FastLED#2428: This PR directly implements Phase 5c of the legacy driver registry opt-in feature, which is the primary objective of issue #2428.

Possibly related PRs

  • FastLED/FastLED#2441: Phase 5b PR that introduces FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY macro and pre-bind/setDriver logic; Phase 5c in this PR gates unity-build includes and updates driver selection to use BusTraits when the macro is enabled.
  • FastLED/FastLED#2437: Introduces the BusTraits, instancePtr(), and registerWithManager() infrastructure that this PR directly uses to bypass ChannelManager and access BusTraits singletons.
  • FastLED/FastLED#2448: Implements fl::enableAllDrivers() to populate ChannelManager with per-platform BusTraits; this PR's conditional opt-in bypass complements that registration mechanism.

Poem

🐰 A Rabbit's Registry Refrain

When legacy flags take their final bow,
Each driver now chooses its own way now,
BusTraits direct or ChannelManager's call,
Platforms and stubs—we've optimized them all!
— From the Warren of Code 🌙✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately captures the main change: gating driver aggregators and pre-binding legacy clockless drivers as part of Phase 5c of issue #2428, directly addressing the core binary-size optimization work described in the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/channels-gate-aggregator-phase-5c-2428

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 and usage tips.

@zackees
zackees merged commit 1823fca into master May 11, 2026
6 of 8 checks passed
@zackees
zackees deleted the feat/channels-gate-aggregator-phase-5c-2428 branch May 30, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant