Skip to content

feat(channels): per-driver BusTraits specializations + DefaultBus (Phase 2 of #2428) - #2431

Merged
zackees merged 1 commit into
masterfrom
feat/channels-bus-traits-drivers
May 9, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/channels-bus-traits-drivers

Conversation

@zackees

@zackees zackees commented May 9, 2026

Copy link
Copy Markdown
Member

Summary

Phase 2 of the compile-time channel-bus binding work tracked in #2428. Adds BusTraits<Bus::X> specializations for all 13 first-party channel drivers (ESP32 + Teensy 4.x + shared bit-bang) and per-platform DefaultBus<Chipset> specializations.

Stacked on top of #2429 (Phase 1: fl::Bus enum + foundational traits). Re-target this PR's base to master once #2429 merges.

What's in this PR

13 per-driver bus_traits.h (1 per driver subdirectory)

Bus Driver Path
Bus::RMT (RMT5) ChannelEngineRMT platforms/esp/32/drivers/rmt/rmt_5/bus_traits.h
Bus::RMT (RMT4) ChannelEngineRMT4 platforms/esp/32/drivers/rmt/rmt_4/bus_traits.h
Bus::PARLIO ChannelDriverPARLIO platforms/esp/32/drivers/parlio/bus_traits.h
Bus::SPI ChannelEngineSpi platforms/esp/32/drivers/spi/bus_traits.h
Bus::I2S IChannelDriver (factory) platforms/esp/32/drivers/i2s/bus_traits.h
Bus::I2S_SPI IChannelDriver (factory) platforms/esp/32/drivers/i2s_spi/bus_traits.h
Bus::LCD_RGB IChannelDriver (factory) platforms/esp/32/drivers/lcd_cam/bus_traits.h
Bus::LCD_SPI + Bus::LCD_CLOCKLESS IChannelDriver (factory) platforms/esp/32/drivers/lcd_spi/bus_traits.h
Bus::UART ChannelEngineUART (with peripheral) platforms/esp/32/drivers/uart/bus_traits.h
Bus::FLEX_IO ChannelEngineFlexIO platforms/arm/teensy/teensy4_common/drivers/flexio/bus_traits.h
Bus::OBJECT_FLED ChannelEngineObjectFLED platforms/arm/teensy/teensy4_common/drivers/objectfled/bus_traits.h
Bus::BIT_BANG BitBangChannelDriver platforms/shared/bitbang/bus_traits.h

Each bus_traits.h is wired into the sibling _build.cpp.hpp aggregator so it parses during the platform compile. The headers are otherwise dormant — nothing names BusTraits<Bus::X>::instance() yet (Phase 3 will), so the lazy singletons stay uninstantiated.

DefaultBus<Chipset> per-platform specializations in src/fl/channels/bus.h

  • ESP32-P4 / C6 / H2 / C5 clockless → Bus::PARLIO (matches priority 4 in channel_manager_esp32.cpp.hpp).
  • Other ESP32 variants clockless → Bus::RMT.
  • ESP32-S3 SPI → Bus::LCD_SPI.
  • ESP32-dev SPI → Bus::I2S_SPI.
  • Teensy 4.x clockless → Bus::OBJECT_FLED.
  • Other platforms intentionally leave DefaultBus<SpiChipsetConfig> undefined so the templated API surfaces a clear "specify Bus::X explicitly" compile error.

Pattern detail

All instance() accessors use a Meyers singleton holding a fl::shared_ptr<Driver> — the existing create*Engine() factories or make_shared<Driver> calls are reused unchanged. Naming BusTraits<Bus::X>::instance() from any TU is what causes the linker to keep that driver's TU alive (the tree-shaking lever Phase 4/5 will pull).

C++11-clean throughout (no auto template params, no fold expressions, no variable templates).

Why

Foundation for the templated Channel<Bus, Chipset> and add<Bus>(cfg) API ratified in #2428 — drivers will only link when their Bus value is named. Eliminates the 344 KB → 783 KB binary bloat from #2421 / #2420 (Phase 5) and makes bus/chipset mismatches compile errors.

Verification

  • bash lint clean.
  • bash test --cpp passes (221/221).
  • ESP32 / Teensy compilation deferred to Phase 3+ — the new headers are dormant in this PR (no template instantiations name them yet), so adding them to _build.cpp.hpp only verifies they parse, not that the singletons run correctly. Phase 3 will exercise them through Channel<B, Chipset>::showPixels().

Note on flaky test infrastructure

While running verification I hit the issue filed as #2430 — a previous test process held the libfastled_build SQLite lock for 800+ seconds, blocking new runs for 120 s. Worked around by taskkill. The test results above are from a clean run after recovery.

Test plan

  • Phase 1 unit test (tests/fl/channels/bus_traits.cpp) still passes.
  • No regressions in host suite.
  • Phase 3 will exercise BusTraits<Bus::STUB>::instance().enqueue(...) end-to-end via the templated Channel<>::showPixels().
  • Phase 5 will compile NEOPIXEL ESP32-S3 sketch and measure binary size delta.

Related

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented May 9, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fef5060d-fabe-47e7-ae75-f9b7fd2b46c6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/channels-bus-traits-drivers

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.

…ase 2 of #2428)

Adds BusTraits<Bus::X> specializations for all 13 first-party channel drivers
across ESP32, Teensy 4.x, and shared platforms. Each specialization provides
a Driver type alias, a lazy singleton accessor that constructs the driver
on first call, and one or more BusSupports<Bus::X, Chipset> true_type
declarations marking which chipset families the driver can drive.

Each driver's bus_traits.h is wired into its sibling _build.cpp.hpp unity-build
aggregator so it parses during the platform compile. No existing code changes;
no behavior changes.

ESP32 specializations (10):
- Bus::RMT          -> ChannelEngineRMT (RMT5 path)
- Bus::RMT          -> ChannelEngineRMT4 (RMT4 path, mutually exclusive)
- Bus::PARLIO       -> ChannelDriverPARLIO (P4/C6/H2/C5)
- Bus::SPI          -> ChannelEngineSpi (clockless-over-SPI)
- Bus::I2S          -> IChannelDriver via createI2sEngine() (S3 LCD_CAM)
- Bus::I2S_SPI      -> IChannelDriver via createI2sSpiEngine() (ESP32-dev)
- Bus::LCD_RGB      -> IChannelDriver via createLcdRgbEngine() (P4)
- Bus::LCD_SPI      -> IChannelDriver via createLcdSpiEngine() (S3)
- Bus::LCD_CLOCKLESS-> IChannelDriver via createLcdClocklessEngine() (S3)
- Bus::UART         -> ChannelEngineUART(UartPeripheralEsp)

Teensy 4.x specializations (2):
- Bus::FLEX_IO      -> ChannelEngineFlexIO
- Bus::OBJECT_FLED  -> ChannelEngineObjectFLED

Shared (1):
- Bus::BIT_BANG     -> BitBangChannelDriver (cross-platform fallback,
                       supports both clockless and SPI chipsets)

DefaultBus<Chipset> per-platform specializations added to fl/channels/bus.h:
- ESP32-P4/C6/H2/C5 clockless -> Bus::PARLIO (matches priority 4 in
                                   channel_manager_esp32.cpp.hpp)
- Other ESP32 variants clockless -> Bus::RMT
- ESP32-S3 SPI -> Bus::LCD_SPI
- ESP32-dev SPI -> Bus::I2S_SPI
- Teensy 4.x clockless -> Bus::OBJECT_FLED
- Other platforms intentionally leave DefaultBus<SpiChipsetConfig> undefined,
  so the templated API surfaces a clear "specify Bus::X explicitly" error.

Verification:
- bash lint clean
- bash test --cpp passes (221/221, fingerprint cache)
- ESP32 platform compilation deferred to Phase 3 verification (the new headers
  are dormant in this PR -- nothing names BusTraits<Bus::X>::instance() yet,
  so the lazy singletons stay uninstantiated even though they parse).

C++11-clean throughout (matches project floor in meson.build:5). All
shared_ptr-returning factory functions are reused from the existing driver
headers; no redundant declarations.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees force-pushed the feat/channels-bus-traits-drivers branch from a0cb86f to 82849a6 Compare May 9, 2026 23:13
@zackees
zackees changed the base branch from feat/channels-bus-enum to master May 9, 2026 23:14
@zackees
zackees merged commit 2f7d133 into master May 9, 2026
zackees added a commit that referenced this pull request May 10, 2026
…3a of #2428) (#2433)

Adds a non-template polymorphic anchor `fl::IChannel` so ChannelEvents callbacks
keep working after `Channel<Bus, Chipset>` becomes a template in Phase 3b.

Phase 3a is purely an API surface refactor -- no behavior changes:

- New: src/fl/channels/ichannel.h. Minimal ABC with virtual `id()` and `name()`,
  noexcept special members, non-copyable/movable. Holds the public surface that
  any callback might reasonably want.
- Channel now derives from CPixelLEDController<RGB> AND IChannel; existing
  `id()` / `name()` accessors marked `override`.
- ChannelEvents callbacks change from `function_list<void(const Channel&, ...)>`
  to `function_list<void(const IChannel&, ...)>`. Callsites that fire events
  pass `*this` which upcasts implicitly via the new inheritance.
- Test/doc lambdas migrated: tests/fastled_core.cpp EventTracker stores
  `const IChannel*`; lambdas in fastled_core.cpp, fl/channels/driver.cpp,
  fl/chipsets/ucs7604.cpp updated. README and FastLED.h docstrings refreshed.

Also fixes pre-existing KBI checker failures in test.py (lines 186/193/211)
flagged by lint -- the test-lock fix from #2432 introduced try-except blocks
catching Exception without KeyboardInterrupt re-raise. Added the standard
`except KeyboardInterrupt as ki: handle_keyboard_interrupt(ki); raise`
clause before each `except Exception`.

Verification:
- bash lint clean.
- bash test --cpp passes (286/286).
- ChannelEvents tests verified: pointer-identity comparisons
  `tracker.mLastChannel == channel.get()` still work because Channel inherits
  from IChannel (implicit upcast).

Stacked on top of Phase 2 (#2431). When Phase 3b lands, Channel<B, Chipset>
will simply derive from IChannel the same way -- no further event-system
changes needed.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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