Repository navigation
Description
Summary
Improve API fluidity between fl::ScreenMap (2D layout-per-strip) and fl::MultiChannelConfig / fl::ChannelConfig (per-strip hardware binding) by promoting the already-documented-but-unwired pin field on screen-map strip entries to a first-class typed value, and using it to bridge the two systems.
Cross-references: #3311 (the fl::Fled bundle format that carries BOTH fl::ScreenMap and fl::MultiChannelConfig as section payloads — the bridge defined here is what lets one bundle round-trip both halves coherently).
What is broken today
1. pin is documented in the screen-map JSON envelope but never read.
src/fl/math/screenmap.cpp.hpp documents the segment shape at two places:
// line 104
{ "id": "<unique>", "pin": <int|str>, "group": "<name>",
"x": [...], "y": [...], "z": [...], ... }// line 384
"segments": [ { "id": "<name>", "pin": "pin1", "group": "<name>",
"x": [...], "y": [...], "diameter": ... } ]But the only references in the parser to a "pin" key are the comments above and a hard-coded segmentObj.set("pin", fl::json(fl::string("pin1"))) in the V2 writer (line 428) — there is no read path, no field on ScreenMap to store it, and no public accessor. A user who writes "pin": "D0" in their JSON gets it silently dropped.
2. fl::ChannelConfig::pin is int, not a pin name.
src/fl/channels/config.h (lines 33, 103) types data pin and clock pin as plain int. Arduino sketches commonly write D0, A2, LED_BUILTIN — those are board-specific macros (mostly int on most platforms, but the resolution is non-trivial on a few cores). A typed pin that round-trips through JSON has to handle both forms.
3. ScreenMap and ChannelConfig have no shared key.
fl::Fled::screenMap() returns a fl::ScreenMap (coord LUT keyed by strip index). fl::Fled::channels() returns fl::MultiChannelConfig (vector of ChannelConfig keyed by add-order). They are two independent enumerations of "strips". A user who loads a .fled bundle has no canonical way to ask "which screen-map segment corresponds to the channel I just added at pin D5?" — they have to match by ordinal, and one re-order in either file silently shears the binding.
This is the seam that #3311 carves around but doesn't close. If the bundle is supposed to be "drop one file, sketch self-instantiates," the bridge between coord layout and hardware binding has to be implicit.
Proposal
A. Type pin as a small union variant
// src/fl/sys/arduino_pin.h (new)
namespace fl {
// A pin reference that accepts either a numeric GPIO number or an
// Arduino-style symbolic name ("D0", "A2", "LED_BUILTIN"). Resolves to
// an integer pin number on the active platform via a platform-provided
// resolveArduinoPin(string_view) -> optional<int>.
class ArduinoPin {
public:
ArduinoPin() FL_NOEXCEPT = default;
ArduinoPin(int gpio) FL_NOEXCEPT; // numeric form
ArduinoPin(string_view name) FL_NOEXCEPT; // symbolic form
ArduinoPin(const char* name) FL_NOEXCEPT; // convenience
bool isSymbolic() const FL_NOEXCEPT;
int gpio() const FL_NOEXCEPT; // resolved (cached); -1 if unresolved
string_view symbol() const FL_NOEXCEPT; // raw form (for round-tripping)
bool resolve() FL_NOEXCEPT; // try platform resolver; idempotent
// JSON round-trip: emits {"pin": 5} or {"pin": "D0"} depending on source.
void toJson(fl::json* out) const FL_NOEXCEPT;
static bool fromJson(const fl::json& v, ArduinoPin* out, string* err) FL_NOEXCEPT;
};
}Notes:
- Resolution is opt-in. A bundle parsed from disk holds
"D0"until a sketch on a known platform calls.resolve()— which lets WASM / studio tooling keep the symbolic form. - The resolver lives in
platforms/<arch>/pin_names.cpp(one table per board). Most platforms already have macros; this just exposes the inverse map. - Backwards compatible: integer literals deserialize as before; old code reading
pinasintkeeps compiling via implicit conversion.
B. Wire pin into both ScreenMap entries and ChannelConfig
// src/fl/math/screenmap.h — add the field
class ScreenMap {
...
// Optional pin binding for the strip this map describes. Default: empty
// (no binding — legacy / ordinal-matched bundles).
fl::optional<ArduinoPin> pin() const FL_NOEXCEPT;
void setPin(ArduinoPin p) FL_NOEXCEPT;
...
};// src/fl/channels/config.h — promote pin
struct ClocklessChipset {
ArduinoPin pin; // was: int
...
};
struct SpiChipsetConfig {
ArduinoPin dataPin; // was: int
ArduinoPin clockPin; // was: int
...
};C. Bridge ScreenMap and ChannelConfig by pin
// helper alongside MultiChannelConfig (config.h:366)
namespace fl {
// Match a ScreenMap to one of the channels by pin, returning nullptr
// when no channel binds the same pin (or when either side has no pin).
ChannelConfigPtr findChannelForScreenMap(
const MultiChannelConfig& cfg, const ScreenMap& sm) FL_NOEXCEPT;
}Once both sides carry the same ArduinoPin value, fl::Fled::load(...) can wire them up implicitly — FastLED.load(fled) walks MultiChannelConfig, calls addLeds<>(...) per channel, then matches the ScreenMap segment by pin and broadcasts via EngineEvents::onCanvasUiSet. No ordinal coupling.
Alternatives considered
- Match by
"id"strings instead ofpin. Cleaner separation (UI label vs hardware), but doubles the source of truth — users have to remember to keepidconsistent across two files.pinis the natural primary key for "the same physical strip." - A new
bindingfield on each strip entry that names the channel by index. Brittle on reorder. Worse for.fledportability. - Embed the channel config inside the screen map. Conflates two concerns; breaks the "passive layout / active hardware" split that feat(fl/fled): create new fl::Fled bundle subsystem (value + runner + section accessors) under src/fl/fled/ #3311 deliberately keeps.
pin-as-bridge is the lightest-weight option that maps onto FastLED's existing mental model (every strip has a pin) without inventing a new key.
Out of scope (track separately if pursued)
- Multi-pin chipsets (SPI clock + data) — the bridge resolves by data pin only in the first pass; SPI strips that need clock-pin disambiguation use the
idfallback. - Pin-name resolution on platforms FastLED doesn't currently know about — those land per-platform PRs against
src/platforms/<arch>/pin_names.cpp. - WASM/studio side of
ArduinoPinrendering (the UI keeps the symbolic form in the document; the resolver runs on-target only).
Acceptance
-
fl::ArduinoPintype lives atsrc/fl/sys/arduino_pin.hand round-trips through JSON (int<->string). -
fl::ScreenMapexposespin()/setPin()and the parser reads"pin"(currently dropped silently). -
fl::ClocklessChipset::pinandfl::SpiChipsetConfig::dataPin/clockPinareArduinoPin(with implicitintctor so existing call sites compile). -
findChannelForScreenMap(MultiChannelConfig, ScreenMap)returns the right channel when pins match. - A
.fledbundle round-trips: load ->FastLED.load(fled)-> channels addLeds-ed AND screen maps bound, no ordinal coupling. - Tests cover: numeric
5, symbolic"D0", missing pin (legacy ordinal fallback), pin present on screen-map side only (warning), pin present on channels side only (warning), mismatch (warning).
Why this is on the critical path for #3311
Without the bridge defined here, fl::Fled::load(fled) in #3311 either (a) silently matches channels and screen maps by index — which works only as long as the JSON author keeps the two arrays in lock-step — or (b) refuses to bind screen maps automatically, pushing the work back to the sketch (which defeats the "drop one file" promise). A typed pin on both sides closes that gap before the bundle format ships.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
zackees commentedon Jun 20, 2026
Scope update — bridge lives behind
FastLED.load(fled)only, free functions, opt-in resolverWhat changes vs the original proposal
ChannelConfig::pin.int pinstaysint pinonfl::ClocklessChipset/fl::SpiChipsetConfig. No source-level change to the channels API, no implicit-conversion ctor needed, no widening ofMultiChannelConfig's footprint.fl::ScreenMap. The screen-map parser stays as it is. The"pin"JSON key gets read by the bundle loader, not byScreenMap::ParseJson.FastLED.load(fled). Free functions insrc/fl/fled/detail/pin_bridge.cpp.hpp(or similar) do the work. They take the parsedfl::Fled, walk the screen-map segments + channel configs, match by pin, and dispatch thesetScreenMapbroadcast. Nothing on the public ScreenMap / ChannelConfig surface area moves.Why this shape
addLeds<...>(int, ...)call site, every chipset header, every test. Not worth it for a feature that today lives only inside the.fledloader.Free-function shape
FastLED.load(fled)is the only caller. It walkschannelsfirst (callsFastLED.add(*cfg)), then runsextractScreenMapPins+matchScreenMapsToChannelsto dispatchcontroller.setScreenMap(...)for the matched pairs. Unmatched segments warn and fall back to ordinal binding for backwards compat with bundles that lack"pin".Arduino.h include safety
Rules:
FL_HAS_INCLUDE(<Arduino.h>)guards the include — keeps the loader buildable on stub / host-test targets where Arduino.h isn't on the include path.#ifdef … #else FL_WARN … return 0 #endifblock, so a platform that definesD0but notA0works partially without breaking other names.static bool warnedinside each helper) to avoid log spam when a bundle references the same unknown pin many times.0is the documented fallback, not-1. Returning-1triggered subtle bugs in callers that didif (pin >= 0);0is a valid (if often wrong) GPIO and lights the failure mode early.Unit testability
All three free functions take parsed values (no Arduino runtime, no global state). Tests live at
tests/fl/fled/pin_bridge.cppand exercise:resolvePinToken(json(5))→{pin: 5, resolved: true}resolvePinToken(json("D0"))→ on a host build whereD0is undefined,{pin: 0, resolved: false}+ a single FL_WARNresolvePinName("LED_BUILTIN")→ same fallback semanticsmatchScreenMapsToChannels({5, 6, fl::nullopt}, channels_with_pins{5, 6, 7})→{0, 1, fl::nullopt}matchScreenMapsToChannelswith a pin that matches two channels → matches the first and warnsextractScreenMapPinson a bundle with mixed numeric + symbolic + missing pins — returns the expectedvector<optional<int>>No Arduino mock, no platform faking. The fallback-to-0 path is exactly what test coverage validates, since the host build is by definition a platform where
D0etc. are undefined.Updated acceptance
fl/fled/detail/pin_bridge.{h,cpp.hpp}exists with the three free functions above.Arduino.hinclude is guarded byFL_HAS_INCLUDE(<Arduino.h>).D0,D1, ...,A0,A1, ...,LED_BUILTIN) is wrapped in#ifdef … #else FL_WARN + return 0 #endif.FL_WARNfor an unknown macro fires once per macro per process, not per call.FastLED.load(fled)(in feat(fl/fled): create new fl::Fled bundle subsystem (value + runner + section accessors) under src/fl/fled/ #3311) calls intopin_bridgeonly — no public ScreenMap / ChannelConfig API changes land in this issue.tests/fl/fled/pin_bridge.cppcover the matrix above; host builds (which lackArduino.h) exercise the fallback path.{"pin": "D5"}segments +ChannelConfig{pin=5, ...}channels →FastLED.load(fled)binds the matched pair, no ordinal coupling.Out of scope (still)
ChannelConfig::pinto a typedArduinoPin— explicitly dropped. If/when a future caller outside the.fledloader needs the typed form, we revisit.pin()accessor toScreenMap— explicitly dropped. The bundle loader is the only caller that needs the value, and it reads it directly from thefl::jsonsegment view.zackees commentedon Jun 20, 2026
Scope update 2 — also auto-bind when
screenmap/channelsare loaded separately (WASM-only)The previous scope-update assumed the only path was
FastLED.load(fled)(bundle-driven). Add a second path: separateFastLED.load(screenmap)/FastLED.load(channelconfig)calls also have to auto-bind their counterpart once both halves arrive. Driven by an event listener — and WASM-only, so embedded / native builds don't carry the matchmaker code.Why WASM-only
FastLED.addLeds<...>(pin, leds)already have the controller in hand and can call.setScreenMap(...)directly. They never need the matchmaker.screenmapandchannelsin independent loads (often out of order, often in response to user edits). That's WASM.FL_PLATFORM_WASM(or whatever the active guard is — verify the macro name before landing) keeps the matchmaker out of every other binary so the esp32dev / lpc845brk / teensy size budgets don't move at all.Event-driven matchmaker shape
fl::EngineEventsalready exposes the right hook surface:EngineEvents::Listener::onCanvasUiSet(strip, screenmap)— fires when a controller has a screenmap bound (already exists;controller.setScreenMap(...)broadcasts it).What's missing is the symmetric "a controller was just added" and "a free-standing screenmap was just loaded but not bound yet" signals. Two new listener callbacks (or one new event each) — names tentative, finalise during implementation:
onControllerAdded(strip)— fired fromFastLED.add(channel_cfg)after the controller is registered, before any auto-binding.onScreenMapLoaded(screenmap)— fired fromFastLED.load(screenmap)when no.fledbundle wrapped it. Carries the segment-level"pin"token along with the value (sincefl::ScreenMapitself stays pin-less per the previous scope update — the loader pulls the pin off the JSON and carries it on the event).The matchmaker is one singleton that lives in
fl/fled/detail/(WASM build only). Its construction registers it on the EngineEvents bus. From there it's pure event-driven; no globals beyond the listener pointer.What changes in the public API
Almost nothing.
FastLED.load(screenmap)andFastLED.load(channelconfig)already need to exist for #3311's "passive value → mutation nexus" split. They just gain WASM-only side effects:FastLED.load(screenmap)on WASM emitsonScreenMapLoaded(pin, screenmap)(pulling the pin off the JSON that produced the value — see the previous scope update'sextractScreenMapPins).FastLED.load(channelconfig)on WASM callsaddLeds<...>(...)as before, then emitsonControllerAdded(strip, pin).Embedded builds get neither emission. Same code path, different translation-unit gate.
What changes in
FastLED.load(fled)The bundle path becomes a thin layer over the matchmaker:
On WASM the matchmaker observes the two streams and binds. On embedded the bundle path keeps its current explicit-ordinal binding (since the matchmaker isn't compiled in). Same one-call ergonomics either way, no
#ifs leaking into user code.Test plan
Host tests already exercise the WASM matchmaker because the gate is one macro:
#if FL_PLATFORM_WASMfalse): the matchmaker symbol must not appear in the linked binary. Add anm | grep AutoBindPinMatchmakerassertion to the size-check workflow so this can't regress silently.Updated acceptance (delta on top of the previous comment)
fl/fled/detail/pin_matchmaker.{h,cpp.hpp}(or similar), behind#if FL_PLATFORM_WASM.EngineEvents::Listenercallbacks (or two new event broadcasts):onScreenMapLoaded(pin, screenmap)andonControllerAdded(strip, pin). The exact signatures are an implementation detail; finalise during PR review.FastLED.load(screenmap)on WASM emitsonScreenMapLoaded(...); embedded builds don't.FastLED.load(channelconfig)on WASM emitsonControllerAdded(...); embedded builds don't.check_esp32_size,check_teensy*_size, etc.) stay flat — the matchmaker compiles out cleanly.Out of scope (still / new)
controller.setScreenMap(...)themselves; the bundle loader already serves the common path.ChannelConfigas one binding target.zackees commentedon Jun 20, 2026
Correction: the macro is
FL_IS_WASM(defined atsrc/platforms/wasm/is_wasm.h:20), notFL_PLATFORM_WASM(doesn't exist). Matches the codebase's broaderFL_IS_*platform-detection convention.The matchmaker gate in the previous comment should read:
Same in every other gating block referenced earlier in this issue.
zackees commentedon Aug 20, 2026
Deferred under the active bug-burn-down policy after validating the latest scope against current
master.Current evidence:
ArduinoPin,pin_bridge,AutoBindPinMatchmaker,resolvePinToken,extractScreenMapPins,onControllerAdded, oronScreenMapLoadedimplementation exists insrc/ortests/.ScreenMap::ParseJsonstill explicitly documents thatpinis discarded as editor/wiring metadata; v2 serialization still emits the placeholder stringpin1.ClocklessChipset::pinandSpiChipsetConfig::{dataPin,clockPin}remain plainint, consistent with scope update 1.FastLED.load(fled),FastLED.load(screenmap), andFastLED.load(channelconfig), but PR refactor(fl/fled): focus on header/json/blob/objects + FledBuilder + full FLED_FORMAT.md spec coverage (#3311) #3334 deliberately removed the half-implementedCFastLED::load*surface from feat(fl/fled): create new fl::Fled bundle subsystem (value + runner + section accessors) under src/fl/fled/ #3311.The current issue has three incompatible designs in one thread (public typed pin, private Fled bridge, and WASM event-driven matchmaker), and its required caller no longer exists. Implementing any one without an authoritative scope choice would manufacture a new public architecture.
Restart criteria:
CFastLED::load*mutation surface; if not, close this issue as obsolete.deferredonly when the chosen caller and integration contract exist.The issue remains open as the design record and is excluded from the actionable queue while labeled
deferred.zackees commentedon Sep 10, 2026
Your defect 1 has teeth: the emitter was rewriting pins, not dropping them (#4278)
True, and the parser says so deliberately. What is worse is the other half you noted in passing — the hard-coded
segmentObj.set("pin", fl::json(fl::string("pin1")))at line 474.That string is the example value from the shape comment directly above the emitter, copied into the code as data. The commit that introduced it (#3100) does not mention
pinanywhere in its message; it came in as part of matching the v2 shape.So the round trip does not drop the field, it rewrites it. Measured before touching anything:
"pin1""pin1""pin2""pin1"7"pin1"Two of three segments come back on the wrong pin, and a numeric pin comes back as a string.
examples/hydropack/data/el-shapes-triangles-wire.jsonis exactly that shape — pin1/pin2/pin3 — so a file in this tree loses its wiring on a round trip today.#4278 stops the fabrication, and deliberately does not do more
Nothing is emitted now. Wrong is worse than absent: a consumer reading a rewritten pin mis-wires a strip with no way to tell, while a missing optional key is visible. FastLED's parser ignores the key either way.
Carrying the value through is this issue, not that PR. It needs somewhere on
ScreenMapto store it and a decision about the<int|str>union — andscreenmap.hcurrently forward-declaresfl::stringrather than including it (the include is annotated at 129.4 ms), so even the storage question has a cost attached. That is a design call, and it is yours.One aside from the same emitter, recorded rather than fixed: it writes
"diameter":-1.000for a map with no diameter set, while the field's own comment says "Only serialized if it's not > 0.0f". Same shape of problem, different field, and changing it moves what the parser reads back.fix(screenmap): stop writing a fabricated pin into every v2 segment (#…
zackees commentedon Sep 10, 2026
The second sentinel in the same emitter is gone too (#4282)
#4278 recorded this and left it: alongside the fabricated pin,
ScreenMap::toJsonwrites"diameter":-1.000for a map with no diameter, while the field's own comment asks for it to be skipped.-1is the "unset" sentinel. Writing it out publishes an impossible physical size and makes every consumer responsible for knowing FastLED's sentinel. One step milder than the pin — that one was wrong (pin2 came back as pin1), this is the real internal value that simply should not leave the process.Omitting round-trips identically, which is what makes it safe rather than a judgement call: both parser paths already default an absent key to -1 (
screenmap.cpp.hpp:206for v2,:364for v1). The test walks one segment with a diameter and one without throughtoJsonStr→ParseJsonand checks both survive.The comment had its sense inverted — "Only serialized if it's not > 0.0f" — which is presumably how the writer came to do the opposite.
That is both emitter defects this issue's first section led to. What remains for #3322 proper is unchanged: carrying
pinthrough needs somewhere onScreenMapto store it and a decision about the<int|str>union, andscreenmap.hforward-declaresfl::stringrather than including it (annotated at 129.4 ms), so even the storage question has a cost attached.fix(screenmap): stop publishing the unset-diameter sentinel (#3322) (#…