Skip to content

feat(channels): addLeds<..., fl::Bus B> trailing parameter (closes #2460) - #2465

Merged
zackees merged 1 commit into
masterfrom
feat/channels-addleds-bus-trailing-param
May 12, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/channels-addleds-bus-trailing-param

Conversation

@zackees

@zackees zackees commented May 12, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Adds optional trailing fl::Bus B = fl::Bus::AUTO template parameter to every FastLED.addLeds<> variant; default-AUTO call sites are byte-for-byte unchanged.
  • New fl::busKeepAlive<B>() helper (in src/fl/channels/bus_traits.h) ODR-uses BusTraits<B>::instance when B != AUTO so --gc-sections retains the named driver TU.
  • For the FASTLED_SPI_USES_CHANNEL_API SPI variants, the body also sets config.options.mBus = B to pin runtime routing through the named driver.
  • Runtime miss diagnostic in channel.cpp.hpp now lists the third remediation alongside enableDrivers<> / enableAllDrivers().

Issue acceptance criteria (from #2460)

  • Every FastLED.addLeds<> variant accepts the trailing fl::Bus B = fl::Bus::AUTO parameter.
  • B = AUTO (the default) leaves existing call sites byte-for-byte unchanged.
  • B != AUTO ODR-uses fl::BusTraits<B>::instance so --gc-sections keeps only the named driver TU.
  • Miss diagnostic in channel.cpp.hpp lists the new addLeds<..., fl::Bus::X>(...) remediation.
  • Tests cover at least one clockless (WS2812) and one SPI (APA102) variant with the new trailing parameter.

Strategy (hybrid)

  • Channel-API SPI variants (FASTLED_SPI_USES_CHANNEL_API branch): set cfg.options.mBus = B to route through the named driver. One-line addition to bodies that already build a ChannelConfig.
  • All other variants (legacy SPI #else branch, clockless, FIBCC, OctoWS2811, WS2812Serial, SmartMatrix, Block parallel): emit fl::busKeepAlive<B>() for linker keep-alive only; runtime routing stays on the platform default. This avoids retrofitting setDriver() into every legacy controller (out-of-scope per the issue's Option B con).

Full README walkthrough added to src/fl/channels/README.md under the compile-time bus selection section.

Test plan

  • bash test --cpp — 303/303 host tests pass (covers clockless STUB + legacy SPI body changes via new test cases in tests/fl/channels/bus_traits.cpp).
  • bash lint — clean.
  • bash compile uno --examples Blink — AVR C++11 path compiles cleanly (verifies the C++11-compatible struct-specialization helper).
  • ESP32 platform compile — blocked by unrelated toolchain cache breakage (framework-arduinoespressif32 cache is missing Arduino.h / WString.h / soc/soc_caps.h). The FASTLED_SPI_USES_CHANNEL_API body change is a single-line write to the mBus field that has been the canonical field since feat(channels): non-template FastLED.add() + typed mBus + remove mAffinity (closes #2459) #2461; reviewers may want to verify on their own ESP32 setup.

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Extended addLeds() API across all controller types to accept an optional bus parameter for explicit hardware bus selection and legacy bus pinning support.
  • Documentation

    • Updated API documentation with new legacy bus pinning configuration guidance and enhanced error diagnostics to resolve driver initialization issues more effectively.

Review Change Stack

)

Adds an optional trailing `fl::Bus B = fl::Bus::AUTO` template parameter
to every `FastLED.addLeds<>` variant. `B = AUTO` (the default) leaves
existing call sites byte-for-byte unchanged; `B != AUTO` ODR-uses
`fl::BusTraits<B>::instance` via a new `fl::busKeepAlive<B>()` helper so
`--gc-sections` retains the named driver TU.

For the `FASTLED_SPI_USES_CHANNEL_API` SPI variants (which already
construct a `ChannelConfig`), the body also sets
`config.options.mBus = B` so the channel routes through the named
driver at runtime. Legacy non-Channel-API controllers keep their
platform-default routing and rely on linker keep-alive alone — for
full runtime routing through a specific Bus, prefer `FastLED.add(cfg)`
with `cfg.options.mBus = B`.

The runtime miss diagnostic in `channel.cpp.hpp` now lists three
remediations: `fl::enableDrivers<>()`, `FastLED.enableAllDrivers()`,
and the new `FastLED.addLeds<..., fl::Bus::X>(...)` shape.

Tests cover the helper plus one clockless (WS2812) and one SPI
(APA102) variant in `tests/fl/channels/bus_traits.cpp`, with default-
AUTO regression guards.

Verification:
- bash test --cpp: 303/303 host tests pass
- bash lint: clean
- bash compile uno --examples Blink: AVR C++11 path compiles
- ESP32 platform compile blocked by unrelated toolchain cache
  breakage (missing Arduino.h / WString.h / soc_caps.h in the
  framework-arduinoespressif32 cache); CHANNEL_API SPI path body
  change is textually a single-line write to the existing
  `mBus` field added in #2461

Closes #2460. Refs #2459, #2428.

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

coderabbitai Bot commented May 12, 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: 50bf4495-6474-4b28-813a-35d7298a51d2

📥 Commits

Reviewing files that changed from the base of the PR and between bedde50 and 0092965.

📒 Files selected for processing (5)
  • src/FastLED.h
  • src/fl/channels/README.md
  • src/fl/channels/bus_traits.h
  • src/fl/channels/channel.cpp.hpp
  • tests/fl/channels/bus_traits.cpp

📝 Walkthrough

Walkthrough

Extends all FastLED.addLeds<>() template overloads with an optional fl::Bus B = fl::Bus::AUTO parameter for compile-time driver pinning. Introduces fl::busKeepAlive<B>() helper that ODR-uses BusTraits<B>::instance to prevent linker garbage collection. Updates SPI Channel API paths to route via config.options.mBus = B. Documentation and diagnostics guide users to this legacy API as a third driver enrollment option.

Changes

Legacy Bus pinning for addLeds templates

Layer / File(s) Summary
Bus keep-alive foundation mechanism
src/fl/channels/bus_traits.h
Introduces fl::detail::BusKeepAliveImpl<B> template that ODR-uses BusTraits<B>::instance for linker keep-alive, with a Bus::AUTO specialization that is a no-op; exports public fl::busKeepAlive<B>() helper.
SPI addLeds variants
src/FastLED.h
Adds fl::Bus B = fl::Bus::AUTO trailing parameter to all SPI-based addLeds overloads (fake-forward, Channel API, legacy, convenience #ifdef SPI_DATA paths); fake-forward delegates to clockless with B threaded; Channel API calls busKeepAlive<B>() and sets config.options.mBus = B; legacy paths call busKeepAlive<B>(); convenience overloads forward B.
Clockless and third-party controller addLeds variants
src/FastLED.h
Adds fl::Bus B = fl::Bus::AUTO to clockless (3-wire), SmartMatrix, OctoWS2811, WS2812Serial, and generic third-party controller overloads; each calls busKeepAlive<B>() and forwards/constructs the underlying controller.
Blockless and parallel output controller addLeds variants
src/FastLED.h
Adds fl::Bus B = fl::Bus::AUTO to EBlockChipsets parallel output and forwarding overloads; implementations call busKeepAlive<B>() and thread B through nested addLeds calls.
Documentation and runtime error messaging
src/fl/channels/README.md, src/fl/channels/channel.cpp.hpp
Updates README to document new FastLED.addLeds<..., fl::Bus B> legacy pinning API (replacing prior "planned" note); enhances Channel::showPixels() miss diagnostic to list FastLED.addLeds<..., fl::Bus::X>(...) as third remediation option alongside enableDrivers and enableAllDrivers.
Test coverage and compilation checks
tests/fl/channels/bus_traits.cpp
Adds FastLED.h include to bus_traits test; includes new compile-time regression test cases verifying busKeepAlive<Bus::AUTO>() is a no-op, busKeepAlive<Bus::STUB>() ODR-uses BusTraits singleton, and both clockless and SPI addLeds accept the trailing fl::Bus::STUB parameter while omitting it remains valid.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • FastLED/FastLED#2460: This PR fully implements the design described in issue #2460, adding the trailing fl::Bus B template parameter to all legacy addLeds<> variants with the ODR-use linker keep-alive mechanism and Channel API mBus routing as acceptance criteria.
  • FastLED/FastLED#2459: Parent issue that proposes the non-template FastLED.add() API and update to the runtime miss diagnostic; this PR implements the complementary legacy addLeds<..., Bus> template API mentioned as deferred in #2459.
  • FastLED/FastLED#2428: Grand-parent meta-issue introducing the fl::Bus enum and BusTraits<B>::instance singleton pattern; this PR leverages that infrastructure to enable template-based bus pinning.

Possibly related PRs

  • FastLED/FastLED#2438: Both modify tests/fl/channels/bus_traits.cpp and driver registration infrastructure for the fl::Bus system.
  • FastLED/FastLED#2441: Both manipulate BusTraits singleton ODR-use and driver linkage via the busKeepAlive mechanism and explicit fl::Bus threading through addLeds.
  • FastLED/FastLED#2429: Both extend CFastLED::addLeds with fl::Bus template parameters and introduce linker keep-alive patterns for driver instantiation control.

Poem

🐰 A rabbit hops through templates vast,
With buses pinned at compile-cast,
No linker ghosts shall fade away—
Keep-alive glows, the drivers stay!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.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 'feat(channels): addLeds<..., fl::Bus B> trailing parameter (closes #2460)' accurately and concisely describes the main change: adding an optional trailing fl::Bus template parameter to addLeds variants.
Linked Issues check ✅ Passed The pull request meets all acceptance criteria from #2460: every addLeds variant accepts an optional trailing fl::Bus B = fl::Bus::AUTO parameter, AUTO preserves existing behavior, B != AUTO ODR-uses BusTraits::instance for linker keep-alive, the runtime miss diagnostic includes the new addLeds remediation, and tests cover clockless and SPI variants.
Out of Scope Changes check ✅ Passed All changes are directly scoped to #2460: the trailing fl::Bus parameter infrastructure in bus_traits.h, addLeds variants in FastLED.h, runtime diagnostic updates in channel.cpp.hpp, documentation in README.md, and test coverage are all integral to the feature requirement.

✏️ 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-addleds-bus-trailing-param

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 80e047c into master May 12, 2026
6 of 8 checks passed
zackees added a commit that referenced this pull request May 12, 2026
Refresh the channels README and one related code docstring against the
current API surface (post #2459 / #2460 / #2465):

README:
  - Compile-time bus binding now lists both entry points equally
    (`fl::TypedChannel<...>::create()` and `addLeds<..., fl::Bus::X>`).
    The "planned addLeds<..., fl::Bus::X> — see #2460" note is gone:
    that feature shipped via #2465.
  - Drop "Backwards Compatible API" framing for `addLeds<>` — both the
    Channel API and the template `addLeds<>` API are first-class; pick by
    call-site shape, not by maturity.
  - Drop "Legacy `addLeds<>` Bus pinning" / "legacy FastLED.addLeds<...>
    shape" labels — these are the actively-supported entry points.
  - Expand the Engine Priority table to match `fl/channels/bus_priorities.h`
    exactly: I2S_SPI / LCD_SPI (10), PARLIO (4), LCD_RGB (3), RMT / LCD_CLOCKLESS
    (2), I2S / FLEX_IO / OBJECT_FLED (1), SPI / BIT_BANG / STUB (0),
    UART (-1). Split by platform family (ESP32 / Teensy 4.x / Portable).
  - Rename "Engine Affinity" section to "Per-Channel Bus Pinning (Mixed-
    Timing Parallel Output)" — the section was named after the removed
    string `mAffinity` field. Update internal back-references.
  - Trim 3.10.3-era "backstory" framing on `enableDrivers<>` /
    `FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY` — describe what the toggle
    does today, not what it restores from history.
  - Update bus-miss diagnostic description to list all three remediations
    the actual `FL_ERROR` emits (enableDrivers / enableAllDrivers /
    addLeds<..., fl::Bus::X>).
  - Reference section: add `fl/channels/bus_priorities.h`, list
    `busKeepAlive<B>()`, expand the `ChannelManager` method list to
    include `setDriverPriority` / `setDriverEnabled` / `setExclusiveDriver`.

src/fl/channels/channel.h:
  - `Channel::create()` docstring no longer references the removed
    `config.affinity` field. Replace with current `cfg.options.mBus`
    behavior + the showPixels() fallback semantics.

No code behavior change.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the feat/channels-addleds-bus-trailing-param branch May 30, 2026 20:01
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.

Channel API: legacy FastLED.addLeds<..., fl::Bus B> trailing template parameter

1 participant