Skip to content

api(rgbw): encapsulate Rgbw/Rgbww activation so the RGBW encoder can be link-on-use (prereq for #4795) #4815

Closed

Description

@zackees

Prerequisite for #4795 (about 2 KB of RGBW/RGBWW code linked into every RGB-only ESP32 sketch). Split out from #4801 because it is a public API change.

Problem

RGBW can't be link-on-use today because there is no single point where it becomes active:

  • A default-constructed fl::Rgbw is active (RGBW_MODE::kRGBWExactColors), and RgbwInvalid derives from Rgbw.
  • rgbw_mode (and the Rgbww equivalent) is a public field, so RGBW can be switched on by assignment.
  • Activation also arrives through Channel options and LegacySettings, not only CLEDController::setRgbw().

As a result PixelIterator takes the address of the per-type RGBW/RGBWW thunks for every source type, and writeWS2812() keeps ScaledPixelIteratorRGBW(W)::advance, rgb_2_rgbw_* and rgbw(w)_partial_reorder reachable.

Measured on master 50c99f0210, esp32dev Blink:

  • loadAndScaleRGBW 296 B, loadAndScaleRGBWW 219 B;
  • ScaledPixelIteratorRGBW(W)::advance 175 / 219 B;
  • rgb_2_rgbw_* modes and the reorder helpers.

The total is about 2.0 KB.

Proposal

  1. Encapsulate activation: make the mode private behind a setter/getter. Keep a deprecated compatibility path for one release, since user code may assign rgbw_mode directly.
  2. Install the encoder from the setter: the setter installs the RGBW encode path (link-on-use, as in perf(esp32): APA102 SPI sketches link the clockless half of the unified FLEX_IO engine (~8-10 KB flash) #4793) behind a pointer, so RGB-only programs never name it.
  3. Thinner per-type code: replace the per-type RGBW/RGBWW thunks with one small "raw pixel + premixed scale" thunk, and do the conversion plus reorder in the type-erased layer.

Acceptance

  • Byte-exact golden tests across all colour orders, W placements and RGBW modes, before and after.
  • RGB-only esp32dev/esp32s3 Blink drops about 2 KB flash; RGBW examples are unchanged.
  • The migration note covers direct rgbw_mode assignment.

Activity

  1. added
    type: feature
    platform: esp32
    area: core
    on Oct 9, 2026
  2. zackees commented on Oct 9, 2026

    @zackees
    MemberAuthor

    Resolved by #4819 without the public API change this issue proposed. Active Rgbw/Rgbww constructors, plus setRgbw()/setRgbww() and Channel::syncLegacySettings(), install the type-erased conversion. The inactive sentinels use a non-hooking tag constructor. rgbw_mode stays public; the one remaining hole (an active value made by assigning rgbw_mode and placed in a variant without any of those entry points) takes the inactive fallback, as noted in #4819.

  3. moved this from Triage to Done in FastLED Trackeron Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreplatform: esp32type: feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions