Repository navigation
Description
Context
PR #2552 / #2554 landed the colorimetric RGB→RGBW path (4-channel). They also shipped a math-only helper fl::colorimetric_detail::solve_rgbcct() that produces 5 channels for RGB + warm-W + cool-W strips — but nothing in the FastLED driver pipeline currently consumes that fifth channel. Issue #2545 explicitly deferred Phase 3 ("layered simplex … track in a follow-up issue once the 4-channel path lands"). This is that follow-up.
The math is in-tree and validated. What's missing is the driver-layer plumbing: pixel struct, byte-count constant, encoder vtable slot, adapter, dispatcher, config wiring, and at least one chipset wrapper + example.
Scope: Channels API only (deliberate)
Legacy FastLED.addLeds<>() controllers (CPixelLEDController<RGB>) will not gain RGBWW support. Each compile-time chipset instantiation pays a flash cost for the encoder vtable; adding a fifth slot for every controller doubles the encoder surface for a feature only a small percentage of users need. The Channels API already uses the right idioms for runtime-configurable per-channel pixel formats — see fl::variant<ClocklessChipset, SpiChipsetConfig> at src/fl/channels/config.h:55 and fl::variant<ConfigI2S, ConfigPdm> in src/fl/audio/input.h — and --gc-sections keeps unused encoder TUs out of binaries that don't reference them.
Concrete rule: every change in this issue is gated behind the new compile flag FASTLED_RGBWW and applies to src/fl/channels/... and the encoder layer only. The legacy CPixelLEDController<RGB> subclasses are out of scope.
Config-storage upgrade: fl::variant<fl::Empty, Rgbw, Rgbww>
Today, ChannelOptions.mRgbw at src/fl/channels/options.h:34 is a plain Rgbw. The "off" state is encoded by the sentinel Rgbw::rgbw_mode == RGBW_MODE::kRGBWInvalid. That conflates two questions — "do we extract a white channel at all?" and "if yes, how?" — into one enum value, and leaves no room for a parallel 5-channel Rgbww configuration.
Replace it with:
// src/fl/channels/options.h
struct ChannelOptions {
// ...
fl::variant<fl::Empty, Rgbw, Rgbww> mWhiteCfg; // was: Rgbw mRgbw;
// ...
};Three semantics, cleanly separated:
holds_alternative<fl::Empty>()— plain 3-channel RGB output. Replaces thekRGBWInvalidsentinel.holds_alternative<Rgbw>()— 4-channel RGBW. Existing modes and encoder path.holds_alternative<Rgbww>()— 5-channel RGB + warm-W + cool-W. New path.
fl::variant<> is already in-tree at src/fl/stl/variant.h (O(1) visitor dispatch); fl::Empty is used internally by fl::Optional for the "empty" alternative.
Migration: setRgbw(...) keeps working — it just becomes shorthand for mWhiteCfg = rgbw_arg. Existing callers don't change. A new setRgbww(const Rgbww&) setter is added. getRgbw() returns the Rgbw alternative if present, else RgbwInvalid::value() for compatibility.
Rgbww struct sketch
Mirrors Rgbw but carries two CCTs and a profile:
// src/fl/gfx/rgbww.h (new file)
struct Rgbww {
explicit Rgbww(u16 warm = 2700, u16 cool = 6500,
RGBWW_MODE mode = RGBWW_MODE::kRGBWWColorimetric,
EOrderWW placement = EOrderWW::WWDefault) FL_NOEXCEPT;
u16 warm_cct; // typical 2700
u16 cool_cct; // typical 6500
RGBWW_MODE rgbww_mode;
EOrderWW w_placement; // 5! = 120 possible orderings; we ship the
// typical few and let users name their own
const colorimetric_detail::RgbcctProfile* profile; // nullptr -> kRgbwwDefaultProfile
};EOrderWW is a parallel enum to EOrderW describing where the two W bytes sit inside the 5-byte output stream. Common chipsets use RGBWwWc or GRBWwWc; the enum covers the documented sub-set.
RGBWW_MODE mirrors RGBW_MODE:
kRGBWWInvalid— kept for sentinel compatibility; the variantEmptyalternative is the canonical "off"kRGBWWColorimetric— usessolve_rgbcctwith strict sub-gamut mathkRGBWWColorimetricBoosted— usessolve_rgbcctwith wx_lp-style W maximizationkRGBWWUserFunction— escape hatch (parallel tokRGBWUserFunction)- (No
min(RGB)/ExactColorsmode — those don't generalize meaningfully to two whites; colorimetric is the only sensible path)
Phased breakdown
Phase A — Types only
- Add
Rgbwwstruct,RGBWW_MODEenum,EOrderWWenum. - Add
BYTES_PER_PIXEL_RGBWW = 5tosrc/fl/chipsets/encoders/encoder_constants.h. - Add
RGBWWPixel { u8 r, g, b, ww, wc; }to a newsrc/fl/gfx/rgbww_pixel.h(mirroringrgbw_pixel.h). - Migrate
ChannelOptions::mRgbw→ChannelOptions::mWhiteCfg. UpdatesetRgbw/getRgbwto wrap/unwrap the variant. AddsetRgbww/getRgbww. - Add the
FASTLED_RGBWWcompile gate; default OFF. - No runtime behavior change. Library still compiles byte-for-byte equivalent without
FASTLED_RGBWW.
Phase B — Dispatch shells
- Add
rgb_2_rgbww_functiontypedef (5 output pointers). - Add
void rgb_2_rgbww(RGBWW_MODE, ...)dispatcher tosrc/fl/gfx/rgbww.h. - Stub each mode: emit
FL_WARN_ONCEand output 5 zero bytes. (Real bodies arrive in Phase D.) - Mirror the
FASTLED_SUPPRESS_COLORIMETRIC_FALLBACK_WARNINGpattern withFASTLED_SUPPRESS_RGBWW_FALLBACK_WARNING. - Without
FASTLED_RGBWW: dispatch falls through to all-zero output (RGBWW is a strict opt-in; nothing to fall back to).
Phase C — Encoder pipeline
- Add
PixelControllerVtable::loadAndScaleRGBWW(5 outputu8*parameters) insrc/fl/chipsets/encoders/pixel_iterator.h:42–88. - Add
loadAndScaleRGBWWFunctiontypedef and storage slot. - Add
ScaledPixelIteratorRGBWW(yieldsarray<u8, 5>) insrc/fl/chipsets/encoders/pixel_iterator_adapters.h:119–187. - Add
rgbww_partial_reorder()to handle the W-pair byte insertion. - Add
PixelController::loadAndScaleRGBWW()insrc/pixel_controller.h:589–627. - Update
ReorderingPixelIteratorAnyinsrc/fl/channels/channel.cpp.hppto dispatch onmWhiteCfg.holds_alternative<...>():Empty→ existing RGB pathRgbw→ existing RGBW pathRgbww→ new RGBWW path
Phase D — Wire the math
- Connect
solve_rgbcct()+rgbcct_eta_for_cct()(src/fl/gfx/rgbw_colorimetric.h:144,211) into the colorimetricRGBWW_MODEvariants. - Ship
kRgbwwDefaultProfile— twoDiodeProfiles for typical SK6812-style 2700K/6500K diodes. - Add a profile-setter API:
set_rgbww_colorimetric_profile(const RgbcctProfile*). - Honor
Rgbww::warm_cctandRgbww::cool_cctfor theetacomputation per-pixel.
Phase E — First chipset wrapper + example
- Pick one SK6812-RGBWW-style 5-channel clockless chipset and add a Channels-API wrapper.
- Build the example inside the existing
examples/AutoResearch/AutoResearch.inoharness (per CLAUDE.md: "On-device / hardware tests go throughexamples/AutoResearch/AutoResearch.ino— prefer reusing or augmenting its existing test harness rather than creating a new.inoinexamples/"). Addexamples/AutoResearch/AutoResearchRgbww.hanalogous toAutoResearchSimd.h.
Phase F — Power model
PowerModelRGBWWexists atsrc/power_mgt.h:88–126but itstoRGB()discards W/WW with the note "Future API enhancement — not yet implemented in power calculations." This phase makes it real.- Account for warm-W and cool-W mW in the brightness limiter when
mWhiteCfg.holds_alternative<Rgbww>().
Out of scope
- Legacy
addLeds<>/CPixelLEDController<RGB>controllers. Channels API only — see scoping section above. - 6+ channel support. True RGBCCT + amber, violet, lime, etc. is a separate generalization; this issue is specifically for the 5-channel RGBWW case the existing
solve_rgbcctmath already solves. - Auto-CCT estimation from a single white point. Users provide warm/cool CCTs explicitly.
- Color-space transforms beyond native gamut (Rec709, Rec2020). Native gamut input only; consistent with Phase 1.
Acceptance criteria
Each phase has its own checkable list; high-level:
Phase A
-
Rgbww/RGBWW_MODE/EOrderWW/RGBWWPixeldefined behindFASTLED_RGBWW. -
ChannelOptions::mWhiteCfgvariant migration complete. -
setRgbw/getRgbwbackward-compatible; existing tests pass byte-for-byte. - Sketches compile unchanged with
FASTLED_RGBWWundefined.
Phase B
-
rgb_2_rgbww()dispatcher present; stubs warn-once and zero-output. - Public API
kRGBWWColorimetricetc. linkable in user code withoutFASTLED_RGBWW.
Phase C
-
PixelControllerVtablecarriesloadAndScaleRGBWW. -
ScaledPixelIteratorRGBWWemits 5 bytes per pixel in the documented order. -
ReorderingPixelIteratorAnycorrectly routes by variant alternative. - Test: a Channel configured with
Rgbwwproduces 5N bytes for N pixels.
Phase D
-
solve_rgbcctis the per-pixel math forkRGBWWColorimetric. -
set_rgbww_colorimetric_profileworks; default profile ships. - Test: chromaticity preservation across the warm↔cool blend (mirrors the existing
solve_rgbccttest intests/fl/gfx/rgbw_colorimetric.cpp).
Phase E
- One RGBWW chipset wrapper compiles and runs through Channels.
-
AutoResearchRgbww.hvalidates 5-channel output on real hardware.
Phase F
-
PowerModelRGBWW::toRGB()accounts for both white channels. - Brightness limiter respects RGBWW power budget.
Related issues / PRs
- feat(rgbw): sub-gamut white-extraction algorithm for chromaticity-accurate RGBW output #2545 — parent specification (RGBW colorimetric).
- feat(rgbw): colorimetric solvers + LUT + CCT + RGBCCT (full #2545) #2552 — Phase 1 + 2 implementation (merged): math, dispatch, CCT shift, LUT,
solve_rgbcctmath helper that this issue's encoder layer will consume. - fix(rgbw): address CodeRabbit findings from #2552 #2554 — CodeRabbit follow-up fixes (merged).
src/fl/gfx/rgbw_colorimetric.h— already carriesRgbcctProfile,solve_rgbcct,rgbcct_eta_for_cct. No changes needed; just call them.
Critical files to touch (reference map)
| File | Role in this issue |
|---|---|
src/fl/channels/options.h:34 |
mRgbw field → variant migration target |
src/fl/channels/config.h:55 |
Existing ChipsetVariant precedent |
src/fl/channels/channel.cpp.hpp |
ReorderingPixelIteratorAny variant dispatch |
src/fl/chipsets/encoders/pixel_iterator.h:42–88 |
Vtable gains loadAndScaleRGBWW slot |
src/fl/chipsets/encoders/pixel_iterator_adapters.h:119–187 |
ScaledPixelIteratorRGBW gains a 5-byte peer |
src/fl/chipsets/encoders/encoder_constants.h |
BYTES_PER_PIXEL_RGBW gains BYTES_PER_PIXEL_RGBWW = 5 |
src/fl/gfx/rgbw.h |
Rgbw / RGBW_MODE patterns to mirror as Rgbww / RGBWW_MODE |
src/fl/gfx/rgbw_colorimetric.h:144,211 |
RgbcctProfile + solve_rgbcct already shipped; new dispatch consumes them |
src/power_mgt.h:88–126 |
PowerModelRGBWW stub completed in Phase F |
examples/AutoResearch/AutoResearch.ino |
Phase E hooks the new test mode in alongside existing AutoResearch harnesses |
Activity
feat(rgbww): 5-channel RGB+WW pipeline via Channels API (Phases A-F of …
feat(rgbww): 5-channel RGB+WW pipeline via Channels API (Phases A-F of …
feat(rgbww): 5-channel RGB+WW pipeline via Channels API (Phases A-F of …
feat(rgbww): 5-channel RGB+WW pipeline via Channels API (Phases A-F of …
feat(lint): enforce Public Settings Pattern for fl:: global setters (…
feat(lint): enforce Public Settings Pattern for fl:: global setters (…
docs(cpp): enforce Public Settings Pattern for global setters (#2715)