Skip to content

feat(rgbww): 5-channel RGB+WW (warm/cool white) support via Channels API (Phase 3 of #2545) #2558

Closed

Description

@zackees

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 the kRGBWInvalid sentinel.
  • 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 variant Empty alternative is the canonical "off"
  • kRGBWWColorimetric — uses solve_rgbcct with strict sub-gamut math
  • kRGBWWColorimetricBoosted — uses solve_rgbcct with wx_lp-style W maximization
  • kRGBWWUserFunction — escape hatch (parallel to kRGBWUserFunction)
  • (No min(RGB) / ExactColors mode — those don't generalize meaningfully to two whites; colorimetric is the only sensible path)

Phased breakdown

Phase A — Types only

  • Add Rgbww struct, RGBWW_MODE enum, EOrderWW enum.
  • Add BYTES_PER_PIXEL_RGBWW = 5 to src/fl/chipsets/encoders/encoder_constants.h.
  • Add RGBWWPixel { u8 r, g, b, ww, wc; } to a new src/fl/gfx/rgbww_pixel.h (mirroring rgbw_pixel.h).
  • Migrate ChannelOptions::mRgbw → ChannelOptions::mWhiteCfg. Update setRgbw / getRgbw to wrap/unwrap the variant. Add setRgbww / getRgbww.
  • Add the FASTLED_RGBWW compile 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_function typedef (5 output pointers).
  • Add void rgb_2_rgbww(RGBWW_MODE, ...) dispatcher to src/fl/gfx/rgbww.h.
  • Stub each mode: emit FL_WARN_ONCE and output 5 zero bytes. (Real bodies arrive in Phase D.)
  • Mirror the FASTLED_SUPPRESS_COLORIMETRIC_FALLBACK_WARNING pattern with FASTLED_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 output u8* parameters) in src/fl/chipsets/encoders/pixel_iterator.h:42–88.
  • Add loadAndScaleRGBWWFunction typedef and storage slot.
  • Add ScaledPixelIteratorRGBWW (yields array<u8, 5>) in src/fl/chipsets/encoders/pixel_iterator_adapters.h:119–187.
  • Add rgbww_partial_reorder() to handle the W-pair byte insertion.
  • Add PixelController::loadAndScaleRGBWW() in src/pixel_controller.h:589–627.
  • Update ReorderingPixelIteratorAny in src/fl/channels/channel.cpp.hpp to dispatch on mWhiteCfg.holds_alternative<...>():
    • Empty → existing RGB path
    • Rgbw → existing RGBW path
    • Rgbww → 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 colorimetric RGBWW_MODE variants.
  • Ship kRgbwwDefaultProfile — two DiodeProfiles for typical SK6812-style 2700K/6500K diodes.
  • Add a profile-setter API: set_rgbww_colorimetric_profile(const RgbcctProfile*).
  • Honor Rgbww::warm_cct and Rgbww::cool_cct for the eta computation 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.ino harness (per CLAUDE.md: "On-device / hardware tests go through examples/AutoResearch/AutoResearch.ino — prefer reusing or augmenting its existing test harness rather than creating a new .ino in examples/"). Add examples/AutoResearch/AutoResearchRgbww.h analogous to AutoResearchSimd.h.

Phase F — Power model

  • PowerModelRGBWW exists at src/power_mgt.h:88–126 but its toRGB() 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_rgbcct math 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 / RGBWWPixel defined behind FASTLED_RGBWW.
  • ChannelOptions::mWhiteCfg variant migration complete.
  • setRgbw / getRgbw backward-compatible; existing tests pass byte-for-byte.
  • Sketches compile unchanged with FASTLED_RGBWW undefined.

Phase B

  • rgb_2_rgbww() dispatcher present; stubs warn-once and zero-output.
  • Public API kRGBWWColorimetric etc. linkable in user code without FASTLED_RGBWW.

Phase C

  • PixelControllerVtable carries loadAndScaleRGBWW.
  • ScaledPixelIteratorRGBWW emits 5 bytes per pixel in the documented order.
  • ReorderingPixelIteratorAny correctly routes by variant alternative.
  • Test: a Channel configured with Rgbww produces 5N bytes for N pixels.

Phase D

  • solve_rgbcct is the per-pixel math for kRGBWWColorimetric.
  • set_rgbww_colorimetric_profile works; default profile ships.
  • Test: chromaticity preservation across the warm↔cool blend (mirrors the existing solve_rgbcct test in tests/fl/gfx/rgbw_colorimetric.cpp).

Phase E

  • One RGBWW chipset wrapper compiles and runs through Channels.
  • AutoResearchRgbww.h validates 5-channel output on real hardware.

Phase F

  • PowerModelRGBWW::toRGB() accounts for both white channels.
  • Brightness limiter respects RGBWW power budget.

Related issues / PRs

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions