Repository navigation
Description
Summary
Introduce a strongly-typed fl::Bus enum and a ChannelConfig<Chipset> template so each Channel is bound to its driver at compile time. This:
- Eliminates the Channel API binary bloat from [Tracking] ESP32-S3 timing regression + binary bloat from Channel API (from #2420) #2421 — drivers only link when their
Busis named. - Closes FastLED Channels API #2167 (
Channel::create<EngineType>(config)becomes a real template). - Makes bus/chipset mismatches compile errors instead of runtime warnings.
Problem
Today, every ESP32 driver (RMT, PARLIO, SPI, I2S, LCD_RGB, LCD_SPI, BLE, UART, …) is unconditionally compiled and registered with ChannelManager via initChannelDrivers() in src/platforms/esp/32/drivers/channel_manager_esp32.cpp.hpp. Driver selection happens at runtime through IChannelDriver::canHandle() virtual dispatch, so --gc-sections cannot strip unused drivers. A NEOPIXEL-only sketch links every driver and grew from 344 KB → 783 KB between 3.10.3 and master (see #2420 reproducer).
Additionally, the new Channel API in #2167 has two papercuts:
Channel::create<fl::ChannelEngineSpi>(config)doesn't compile —create()isn't a template.- The string-based
mAffinity = "RMT"is typo-prone and heap-allocates.
Proposed API
Single source of truth: fl::Bus enum
namespace fl {
enum class Bus : fl::u8 {
AUTO, // sentinel — pick DefaultBus<Chipset>
RMT,
PARLIO,
SPI,
I2S, // LCD_CAM clockless on S3
LCD_RGB,
LCD_SPI,
OBJECT_FLED, // Teensy
STUB,
};
// Per-platform default per chipset family
template<typename Chipset> struct DefaultBus;
template<> struct DefaultBus<ClocklessChipset> {
static constexpr Bus value = /* ESP32-P4: PARLIO, S3/dev: RMT, Teensy: OBJECT_FLED, ... */;
};
template<> struct DefaultBus<SpiChipsetConfig> {
static constexpr Bus value = /* ESP32: SPI, S3: LCD_SPI, ... */;
};
} // namespace flTemplated ChannelConfig<Chipset> carries the chipset family as a type
template<typename Chipset> // ClocklessChipset or SpiChipsetConfig
struct ChannelConfig { /* same fields, no ChipsetVariant erasure */ };BusTraits<B> exposes capability
template<fl::Bus B> struct BusTraits; // primary undefined → unsupported = compile error
template<> struct BusTraits<fl::Bus::PARLIO> {
using Driver = ChannelDriverPARLIO;
static Driver& instance(); // Meyers singleton — naming this is what links the driver
template<typename Chipset>
static constexpr bool supports = fl::is_same_v<Chipset, ClocklessChipset>;
};
template<> struct BusTraits<fl::Bus::SPI> {
using Driver = ChannelEngineSpi;
static Driver& instance();
template<typename Chipset>
static constexpr bool supports = fl::is_same_v<Chipset, SpiChipsetConfig>;
};
// ...one specialization per driver, lives next to the driver headerChannel<B, Chipset> is templated; add() and create() deduce Chipset from the config
template<fl::Bus B, typename Chipset>
class Channel : public CPixelLEDController<RGB> {
public:
static fl::shared_ptr<Channel<B, Chipset>> create(const ChannelConfig<Chipset>& cfg);
protected:
void showPixels(...) override {
BusTraits<B>::instance().enqueue(mChannelData); // direct, no virtual, no manager
}
};
template<auto B = fl::Bus::AUTO, typename Chipset>
auto CFastLED::add(const ChannelConfig<Chipset>& cfg) {
constexpr fl::Bus actual = (B == fl::Bus::AUTO) ? DefaultBus<Chipset>::value : B;
static_assert(BusTraits<actual>::template supports<Chipset>,
"This Bus does not support this chipset family (clockless vs SPI)");
auto ch = Channel<actual, Chipset>::create(cfg);
ch->addToDrawList();
return ch;
}Minimal usage
#include "FastLED.h"
CRGB leds[60];
void setup() {
fl::ChannelConfig cfg{fl::ClocklessChipset(4, fl::makeTimingConfig<fl::TIMING_WS2812_800KHZ>()),
fl::span<CRGB>(leds, 60), GRB};
FastLED.add(cfg); // platform default clockless bus
FastLED.add<fl::Bus::RMT>(cfg); // OK — RMT supports clockless
FastLED.add<fl::Bus::SPI>(cfg); // ❌ compile error: SPI bus, clockless chipset
}
void loop() { FastLED.show(); }Parallel multi-channel
FastLED.add<fl::Bus::PARLIO>({cfg_strip1, cfg_strip2, ..., cfg_strip16});
FastLED.add<fl::Bus::SPI>(cfg_apa102);
// → only PARLIO + SPI driver TUs linkRuntime-flexible mode (opt-in)
For users who genuinely need runtime driver selection (third-party drivers, dynamic switching, MoonLight-style flexibility from #2167), explicit enrollment forces linking AND registers with ChannelManager:
void setup() {
FastLED.enableDrivers<fl::Bus::RMT, fl::Bus::PARLIO, fl::Bus::SPI>();
FastLED.add(cfg); // manager picks best of {RMT, PARLIO, SPI}
cfg.options.mAffinity = fl::Bus::PARLIO; // mAffinity is now fl::Bus, not fl::string
FastLED.add(cfg); // explicit runtime override
FastLED.setExclusiveDriver(fl::Bus::RMT); // disable others
}
// Convenience for prototyping / 3.10.3-style behavior:
FastLED.enableAllDrivers();
// or:
#include "fl/channels/all_drivers.h"Implementation:
template<fl::Bus... Buses>
void CFastLED::enableDrivers() {
(BusTraits<Buses>::registerWithManager(), ...); // C++17 fold
// Each call ODR-uses BusTraits<B>::instance() (links the TU) AND
// registers with ChannelManager for runtime selection.
}Deletions / simplifications
| Removed (default path) | Replaced by |
|---|---|
Bus::AUTO runtime dispatch through ChannelManager |
DefaultBus<Chipset>::value compile-time |
ChannelOptions::mAffinity as fl::string |
fl::Bus enum (1 byte, no heap, type-safe) |
IChannelDriver virtual dispatch on hot path |
Direct BusTraits<B>::instance().enqueue() |
ChannelManager::addDriver / selectDriverForChannel (eager) |
Lazy via enableDrivers<...>() opt-in |
initChannelDrivers() + addParlioIfPossible / addRmtIfPossible / etc. |
Nothing — driver TUs link when their BusTraits<B>::instance() is named |
setExclusiveDriver / setDriverEnabled / setDriverPriority |
Available only in registry mode (still works, takes fl::Bus not string) |
IChannelDriver::getName() / getBus() virtual |
Encoded in the type (Channel<B, Chipset>) |
EngineEvents::onBeginFrame waitForReady() floor (the vTaskDelay(1) from #2421) |
Gone in default path — manager isn't on the call chain |
src/platforms/esp/32/drivers/_build.cpp.hpp aggregator |
Per-driver _build.cpp.hpp files only included via header chain |
Compile-time enforcement examples
// Mismatch: compile error, not runtime warning
ChannelConfig cfg_spi{SpiChipsetConfig(23, 18, apa102), leds};
FastLED.add<fl::Bus::PARLIO>(cfg_spi);
// ❌ static_assert: "This Bus does not support this chipset family"
// Typo: compile error, not silent fallthrough
FastLED.add<fl::Bus::RTM>(cfg);
// ❌ no member named 'RTM' in 'fl::Bus'
// Naming an undefined driver on this platform: compile error
FastLED.add<fl::Bus::PARLIO>(cfg); // on ESP32-dev (no PARLIO peripheral)
// ❌ implicit instantiation of undefined template 'BusTraits<Bus::PARLIO>'Migration path
- Existing
addLeds<>sketches: zero source change.addLeds<WS2812, 4, GRB>(leds, n)keeps its current signature; internally it instantiatesChannel<DefaultBus<ClocklessChipset>::value, ClocklessChipset>. NEOPIXEL-only sketches link one driver. - Existing
Channel::create(cfg)callers: source-compatible —create()defaults toBus::AUTO, which resolves to the platform default for the chipset. - Existing affinity-string callers (README examples in
src/fl/channels/README.mdlines 333–345): one-line s/"RMT"/fl::Bus::RMT/. Old string form can be kept as a deprecated overload for one release. - MoonLight integration (FastLED Channels API #2167): gets its requested template form:
Channel<fl::Bus::SPI>::create(cfg)orFastLED.add<fl::Bus::SPI>(cfg).
Expected size impact
For the #2420 reproducer (NEOPIXEL on ESP32-S3): ~783 KB → ~344 KB (back to 3.10.3 baseline).
Combined with #2424's source-level cleanup of cross-TU references, total recovery exceeds 400 KB on that build.
Implementation phasing
- Phase 1 — Add
fl::Busenum,BusTraits<B>skeleton,DefaultBus<Chipset>. No behavior change yet (parallel API alongside existing). - Phase 2 — Templatize
ChannelConfig<Chipset>andChannel<B, Chipset>. AddFastLED.add<>()template. ExistingChannel::create(ChannelConfig)becomes a deprecated wrapper aroundChannel<AUTO, ClocklessChipset>::create(). - Phase 3 — Implement
enableDrivers<>()andenableAllDrivers(). MakeChannelManager/IChannelDriveropt-in viaFASTLED_ENABLE_DRIVER_REGISTRY. - Phase 4 — Drop the
_build.cpp.hppaggregator default; gate behindFASTLED_REGISTER_ALL_DRIVERS. Remove eagerinitChannelDrivers()registration. ConvertmAffinityfromfl::stringtofl::Bus. - Phase 5 — Measure binary size on [Bug] Compounded timing inaccuracy on master compared to 3.10.3 #2420 reproducer + Teensy 3.0/LC (Teensy 3.0 / LC link-time RAM overflow (.dmabuffers / .bss) across all examples #2406). Validate timing on the [Tracking] ESP32-S3 timing regression + binary bloat from Channel API (from #2420) #2421 reproducer (manager-side
vTaskDelay(1)floor should be gone in default path).
Related
- Root cause: [Tracking] ESP32-S3 timing regression + binary bloat from Channel API (from #2420) #2421 (Channel API binary bloat + timing regression)
- Original report: [Bug] Compounded timing inaccuracy on master compared to 3.10.3 #2420 (344 KB → 783 KB on NEOPIXEL-only sketch)
- API papercuts: FastLED Channels API #2167 (
Channel::create<EngineType>must be a template;mAffinitystrings) - Complementary cleanup: [Tracking] Break unwanted cross-TU references that drag optional subsystems into all builds (follow-up to #2421) #2424 (cross-TU reference cascades)
- Adjacent: Teensy 3.0 / LC link-time RAM overflow (.dmabuffers / .bss) across all examples #2406 (Teensy 3.0/LC DMA buffer overflow — same root cause)
- Adjacent: ESP32-S3: I2S driver starves websockets, SPI output incorrect, Audio driver FPS impact #2254 (I2S websocket starvation — manager-side wait architecture)
Activity
feat(channels): add fl::Bus enum + BusTraits foundation (Phase 1 of #…
feat(channels): per-driver BusTraits specializations + DefaultBus (Ph…
feat(channels): per-driver BusTraits specializations + DefaultBus (Ph…
feat(channels): introduce IChannel ABC base for ChannelEvents (Phase …
feat(channels): introduce IChannel ABC base for ChannelEvents (Phase …
feat(channels): introduce IChannel ABC base for ChannelEvents (Phase …
feat(channels): introduce IChannel ABC base for ChannelEvents (Phase …
zackees commentedon May 10, 2026
Status check per @zackees:
Done:
fl::Busenum + foundational traits): feat(channels): add fl::Bus enum + BusTraits foundation (Phase 1 of #2428) #2429 merged.BusTraitsspecializations): feat(channels): per-driver BusTraits specializations + DefaultBus (Phase 2 of #2428) #2431 merged.IChannelABC base for events): Feat/channels bus traits drivers #2435 merged.enableDrivers<Bus...>()opt-in registry +registerWithManager()traits): feat(channels): add enableDrivers<Bus...>() opt-in registry API (Phase 4 of #2428) #2437 open — purely additive, default behavior unchanged.Outstanding:
ChannelConfig<Chipset>andChannel<Bus, Chipset>, addFastLED.add<Bus, Chipset>(cfg). Big breaking refactor (~17 files). Compile-time chipset/bus mismatch enforcement is the deliverable._build.cpp.hppdriver aggregator + retarget legacyaddLeds<>clockless path to callBusTraits<DefaultBus>::instance()directly instead of going throughChannelManager. This is the change that delivers the binary bloat fix from [Bug] Compounded timing inaccuracy on master compared to 3.10.3 #2420 / [Tracking] ESP32-S3 timing regression + binary bloat from Channel API (from #2420) #2421 — NEOPIXEL-only sketches drop from ~783 KB back to ~344 KB.Phase 5 is the highest-value remaining work. Phase 3b is API ergonomics polish that can ship later.
feat(channels): add enableDrivers<Bus...>() opt-in registry API (Phas…
feat(channels): unify singletons + opt-in disable macro (Phase 5a of #…
feat(channels): pre-bind legacy clockless to BusTraits singleton (Pha…
feat(channels): add fl::enableAllDrivers() one-shot driver enrollment (…
feat(channels): add fl::enableAllDrivers() one-shot driver enrollment (…
feat(channels): gate driver aggregator + pre-bind remaining legacy cl…
feat(channels): templatize Channel<Bus, Chipset> + FastLED.add<B, Chi…
feat(channels): templated Channel::create<Bus B>() / FastLED.add<Bus …
feat(channels): templated Channel::create<Bus B>() / FastLED.add<Bus …
docs(channels): refresh README for the #2428 dual-mode API (Bus + ena…
feat(channels): addLeds<..., fl::Bus B> trailing parameter (closes #2460
feat(channels): remove FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY macro (…
feat(channels): remove FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY macro (…
zackees commentedon May 24, 2026
Closing as completed. Audit of the codebase against each phase below.
Phase 1 —
fl::Busenum +BusTraits<B>foundation ✅src/fl/channels/bus.h:44definesenum class Bus : fl::u8 { AUTO, RMT, PARLIO, SPI, I2S, LCD_RGB, LCD_SPI, OBJECT_FLED, STUB, ... }.src/fl/channels/bus_traits.hprovidesBusTraits<B>+BusSupports<B, Chipset>.DefaultBus<Chipset>specializations per platform exist insrc/fl/channels/bus.h(lines 82, 86, 97, 101, 111, 115, 122 — one per platform/chipset pair).Phase 2 — Per-driver
BusTraits<B>specializations ✅Phase 3a —
IChannelABC base ✅Phase 3b — Templated channel + config ✅ (with API walkback)
Channel<Bus, Chipset>+FastLED.add<B, Chipset>(cfg))Channel::create<Bus B>()/FastLED.add<Bus B>(), closes FastLED Channels API #2167)FastLED.add(fl::Bus, cfg)dispatch, closes Channel API: dual-mode dispatch — templated link-and-bind AND runtime-only selection after enableAllDrivers() #2453)non-template FastLED.add() + typed mBus + remove mAffinity(closes Channel API: collapse to non-template FastLED.add(), Bus-typed affinity, addLeds<..., fl::Bus> trailing parameter #2459). The final API is non-templateFastLED.add(cfg)withcfg.options.mBus = fl::Bus::PARLIOfor pinning; the templated form is kept asTypedChannel<Bus, Chipset>(src/fl/channels/channel_typed.h:64) consumingChannelConfigOf<Chipset>(src/fl/channels/config.h:303) with thestatic_assert(BusSupports<B, Chipset>::value, ...)compile-time chipset/bus mismatch enforcement still in place atchannel_typed.h:76.addLeds<..., fl::Bus B>trailing parameter, closes Channel API: legacy FastLED.addLeds<..., fl::Bus B> trailing template parameter #2460)Phase 4 —
enableDrivers<Bus...>()opt-in registry ✅b0be2b4749).fl::enableAllDrivers()one-shot enrollment.FastLED.setExclusiveDriver(fl::Bus)typed (lowered the string form).enableAllDriversinto per-platform bundles.Phase 5 — Drop unconditional driver aggregator + retarget legacy
addLeds<>✅BusTraitssingleton)FASTLED_DISABLE_LEGACY_DRIVER_REGISTRYmacro removed; opt-in IS the default (src/fl/channels/README.md:214).src/platforms/esp/32/drivers/_build.cpp.hppheader comment now reads: "Post-feat(channels): compile-time Bus binding via templated ChannelConfig (eliminates Channel API binary bloat) #2428 (binary-size fix for [Bug] Compounded timing inaccuracy on master compared to 3.10.3 #2420 / [Tracking] ESP32-S3 timing regression + binary bloat from Channel API (from #2420) #2421): Each LED-output driver subdirectory's_build.cpp.hpponly compiles its implementation on platforms where the driver is the platform default ... All other drivers are pure opt-in viafl::enableDrivers<fl::Bus::X>()orFastLED.enableAllDrivers()."vTaskDelay(1)wait floor was the lingering ESP32-P4 PARLIO: FastLED.show() appears to block for ~16.7 ms before WS2812 data burst begins #2493 surface; addressed by fix(channels): register pre-bound legacy driver with ChannelManager (closes #2493) #2498 (register pre-bound legacy driver with ChannelManager) + fix(channels): skip vTaskDelay(1) floor in wait-loop on ESP32-P4 (#2493 follow-up) #2503 (skipvTaskDelay(1)floor in wait-loop on ESP32-P4).Deletions / simplifications from the issue body
Bus::AUTOruntime dispatch through ChannelManagerDefaultBus<Chipset>::value✅ChannelOptions::mAffinityasfl::stringmBus : fl::Bus✅IChannelDrivervirtual dispatch on hot pathBusTraits<B>::instance()direct call ✅ChannelManager::addDriver/selectDriverForChannelenableDrivers<...>()opt-in ✅initChannelDrivers()+addParlioIfPossibleetc.BusTraits<B>::instancePtr()is named ✅setExclusiveDriverstring formfl::Bus(#2472) ✅IChannelDriver::getName()/getBus()virtualEngineEvents::onBeginFrame waitForReady()floor (vTaskDelay(1))_build.cpp.hppaggregatorSub-issues closed by this work
Channel::create<EngineType>template formFastLED.show()blockingStill outstanding (separate from #2428)
Minor doc loose end
src/fl/channels/channel.h:47still has the comment "afterChannel<Bus, Chipset>becomes templated in Phase 3b. See #2428" — which predates the #2461 walkback (the templated form lives asTypedChannel, whileChannelstays non-template). Worth a one-line cleanup but doesn't block closing this issue.🤖 Reviewed with Claude Code
refactor(fs): expose embedded storage generically as fl::getEmbeddedFs()
refactor(fs): expose embedded storage generically as fl::getEmbeddedF…
feat(esp8266): expose hardware HSPI as Bus::SPI, retire FASTLED_ALL_P…
feat(esp8266): UART WS2812 engine as Bus::UART; retire FASTLED_ESP826…