Skip to content

feat(channels): templatize Channel<Bus, Chipset> + FastLED.add<B, Chipset>(cfg) (#2428) - #2449

Merged
zackees merged 1 commit into
masterfrom
feat/channels-templatize-phase-3b-2428
May 11, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/channels-templatize-phase-3b-2428

Conversation

@zackees

@zackees zackees commented May 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Phase 3b of #2428 — adds compile-time bus/chipset enforcement to the Channel API without disturbing any existing callers.

  • New fl::ChannelConfigOf<Chipset> template — strongly-typed channel configuration that carries the chipset family as a type parameter. Implicitly converts to/from the existing non-template fl::ChannelConfig so all current call sites keep working unchanged.
  • New fl::TypedChannel<Bus, Chipset> template — thin facade around the existing non-template fl::Channel runtime object. create() is guarded by FL_STATIC_ASSERT(BusSupports<B, Chipset>::value) so a mismatched bus/chipset combination is a compile error rather than a runtime warning. Naming an undefined BusTraits<Bus::X> on the current platform produces a clean "implicit instantiation of undefined template" diagnostic.
  • New FastLED.add<fl::Bus = AUTO, typename Chipset>(const ChannelConfigOf<...>&) template overload. Bus::AUTO resolves to DefaultBus<Chipset>::value per platform. The static_assert rejects nonsense combinations at instantiation time, before the call reaches the runtime manager.

Compile-time enforcement examples that now hold:

FastLED.add(clockless_cfg);                // OK -- platform default clockless bus
FastLED.add<fl::Bus::RMT>(clockless_cfg);  // OK -- RMT supports clockless
FastLED.add<fl::Bus::SPI>(clockless_cfg);  // ❌ FL_STATIC_ASSERT failure
FastLED.add<fl::Bus::RTM>(clockless_cfg);  // ❌ no member 'RTM' in fl::Bus
FastLED.add<fl::Bus::PARLIO>(cfg);         // ❌ on platforms without PARLIO --
                                           //    "implicit instantiation of
                                           //    undefined template BusTraits<...>"

Backwards compatibility

  • addLeds<WS2812, 4, GRB>(leds, n) unchanged.
  • Channel::create(const ChannelConfig&) unchanged.
  • FastLED.add(const ChannelConfig&) (non-template) unchanged.
  • ClocklessIdf5 : public Channel (and any other Channel subclass) unchanged because the non-template fl::Channel is preserved.
  • IChannel ABC unchanged (still the polymorphic anchor for ChannelEvents).
  • FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY semantics unchanged (Phase 5c handles that separately).

Test plan

  • New positive test: TypedChannel<Bus::AUTO, ClocklessChipset>::create resolves to host Bus::STUB and produces a working channel
  • New positive test: FastLED.add<Bus::STUB>(clockless_cfg) compiles and binds the channel (pin survives the round trip)
  • New positive test: FastLED.add(cfg) (default Bus::AUTO) resolves to DefaultBus<ClocklessChipset> == Bus::STUB
  • Implicit-conversion test: ChannelConfigOf<ClocklessChipset> → ChannelConfig preserves chipset/pin/order/leds
  • Compile-time FL_STATIC_ASSERT proofs that BusSupports<Bus::STUB, SpiChipsetConfig>::value and BusSupports<Bus::PARLIO, SpiChipsetConfig>::value are false — the same predicate that guards the FastLED.add<>() static_assert
  • Existing tests still pass: fl_channels_bus_traits, fl_channels_channel, fl_channels_channel_manager, fl_channels_all_drivers, fl_channels_spi, fl_channels_data, fl_channels_driver, fl_channels_manager, fl_channels_wave8, fl_channels_wave8_spi, fl_channels_validation, fastled_core
  • bash lint clean for all changed files
  • bash compile wasm --examples Blink succeeds — the WASM build still includes the templated APIs through FastLED.h

Closes a portion of #2428 (Phase 3b of N). Phases 1, 2, 3a, 4, 5a, 5b are already merged. Phase 5c (binary-size opt-in macro semantics) is handled separately.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Introduced strongly-typed channel configuration API with compile-time validation of bus and chipset compatibility.
    • Added automatic bus detection and validation for LED chipsets.
  • Tests

    • Added comprehensive test coverage for compile-time type validation and channel creation workflows.

Review Change Stack

…pset>(cfg) (#2428)

Phase 3b of issue #2428. Adds compile-time bus/chipset enforcement to the
Channel API without disturbing any existing callers:

- New `fl::ChannelConfigOf<Chipset>` template — strongly-typed channel
  configuration that carries the chipset family as a type parameter. Implicitly
  converts to/from the existing non-template `fl::ChannelConfig` so all current
  call sites (`Channel::create(cfg)`, the non-template `FastLED.add(cfg)`
  overloads, the 16+ examples/tests using `fl::ChannelConfig`) keep working
  unchanged.

- New `fl::TypedChannel<Bus, Chipset>` template — thin facade around the
  existing non-template `fl::Channel` runtime object. `Channel::create()` is
  guarded by a `FL_STATIC_ASSERT(BusSupports<B, Chipset>::value)` so routing a
  clockless config to an SPI-only bus (or vice versa) is a compile error.
  Naming an undefined `BusTraits<Bus::X>` on the current platform produces a
  clean "implicit instantiation of undefined template" diagnostic.

- New `FastLED.add<fl::Bus = AUTO, typename Chipset>(const ChannelConfigOf<...>&)`
  template overload. `Bus::AUTO` resolves to `DefaultBus<Chipset>::value` per
  platform. The `static_assert` rejects nonsense combinations at instantiation
  time before the call reaches the runtime manager.

- Tests in `tests/fl/channels/channel_typed.cpp` cover:
    * Positive — host-default path (`Bus::AUTO` → `Bus::STUB`) and explicit
      `Bus::STUB` both resolve and produce a working `ChannelPtr`.
    * Negative — `FL_STATIC_ASSERT` proofs that `BusSupports<Bus::STUB,
      SpiChipsetConfig>::value` and `BusSupports<Bus::PARLIO,
      SpiChipsetConfig>::value` are `false`, which is exactly the predicate
      guarding the `FastLED.add<>()` static_assert. Compiling a real
      `FastLED.add<Bus::STUB>(spi_cfg)` would fail at the static_assert site,
      so the test verifies the predicate without inducing a build failure.
    * Implicit conversion `ChannelConfigOf<ClocklessChipset>` → `ChannelConfig`
      preserves chipset/pin/order/leds.
    * `ChannelConfigOf<ClocklessChipset>` deduced via CTAD.

Backwards compatibility:
- `addLeds<WS2812, 4, GRB>(leds, n)` unchanged — does not touch this path.
- `Channel::create(const ChannelConfig&)` unchanged.
- `FastLED.add(const ChannelConfig&)` (non-template) unchanged.
- `ClocklessIdf5 : public Channel` (and any other Channel subclass) unchanged
  because the non-template `fl::Channel` class is preserved.
- `IChannel` ABC unchanged (still the polymorphic anchor).
- `FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY` semantics unchanged (Phase 5c).

Verified: `bash test fl_channels_channel_typed --cpp` and the broader
`fl_channels_*` + `fastled_core` test suites pass, lint clean,
`bash compile wasm --examples Blink` succeeds.

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: f81532d8-b95b-4ce8-9488-b37505751695

📥 Commits

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

📒 Files selected for processing (4)
  • src/FastLED.h
  • src/fl/channels/channel_typed.h
  • src/fl/channels/config.h
  • tests/fl/channels/channel_typed.cpp

📝 Walkthrough

Walkthrough

This PR introduces compile-time typed bus and chipset binding for FastLED's channel API. It adds ChannelConfigOf<Chipset> to encode chipset type, TypedChannel<Bus, Chipset> to enforce bus/chipset compatibility and resolve AUTO buses, and a templated CFastLED::add() overload for type-safe channel creation with automatic driver linkage.

Changes

Typed Bus/Chipset Binding API

Layer / File(s) Summary
Typed Configuration Data Model
src/fl/channels/config.h
ChannelConfigOf<Chipset> template struct stores typed chipset and mirrors ChannelConfig payload; provides implicit conversion and explicit toErased() method for interop.
Typed Channel Facade
src/fl/channels/channel_typed.h
TypedChannel<Bus, Chipset> resolves Bus::AUTO via resolve_bus helper, enforces BusSupports at compile time, ODR-uses BusTraits for driver linkage, and delegates to Channel::create().
Public Templated Add API
src/FastLED.h
Added includes and CFastLED::add<B, Chipset>(cfg) overload that resolves default bus, validates compatibility, ensures driver linkage, and forwards erased config to existing add implementation.
Compile-time & Runtime Tests
tests/fl/channels/channel_typed.cpp
Static asserts validate BusSupports behavior and DefaultBus resolution; runtime tests cover config conversion, TypedChannel creation with automatic/explicit bus selection, and compile-fail proof for incompatible bus/chipset pairs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • FastLED/FastLED#2428: Both changes implement the same compile-time Bus/Chipset binding: introducing a templated ChannelConfig/TypedChannel and a templated CFastLED::add that resolves DefaultBus and uses BusTraits/static-asserts for enforcement.

Possibly related PRs

  • FastLED/FastLED#2429: The main PR builds on and directly uses the fl::Bus/DefaultBus and BusTraits/BusSupports types introduced in PR #2429 to implement typed channel APIs and templated CFastLED::add with compile-time bus–chipset compatibility.
  • FastLED/FastLED#2438: Both PRs interact with BusTraits singletons; the main PR ODR-uses fl::BusTraits<...>::instance while the retrieved PR routes driver registration through BusTraits::instancePtr().
  • FastLED/FastLED#2441: Both PRs introduce/require ODR-use of BusTraits to ensure platform bus driver linkage; the typed channel changes complement the retrieved PR's pre-bind driver mechanism.

Poem

🐰 A typed path to channel creation,
With buses resolved at compile-time inception,
Static checks guard chipset selection,
While drivers link via BusTraits injection—
No runtime guessing, just safe connection! 🔧✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 title clearly and specifically describes the main change: templatizing the Channel API with Bus and Chipset template parameters, and adding a templated FastLED.add overload.
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-templatize-phase-3b-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 f030180 into master May 11, 2026
6 of 8 checks passed
@zackees
zackees deleted the feat/channels-templatize-phase-3b-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