Skip to content

feat(objectfled): investigate SPI/clocked-LED support for APA102/SK9822 (refs #3023, #3157) #3176

Closed

Description

@zackees

Background

FastLED's Teensy 4 Bus::OBJECT_FLED driver wraps the PaulStoffregen ObjectFLED library for any-pin DMA-driven clockless output. It's currently clockless-only — it cannot drive SPI/clocked chipsets (APA102, SK9822).

This issue investigates whether ObjectFLED's underlying timer+DMA architecture can be extended to support clocked output, and if so, adds SPI support behind the same Bus::OBJECT_FLED driver.

Why this matters

ObjectFLED's value proposition over FlexIO is any-GPIO pin support. FlexIO's SPI mode (filed in the companion issue alongside this one) restricts pin selection to the FlexIO-capable subset; ObjectFLED has no such restriction. For users with board layouts where the desired APA102 data/clock pins don't align with FlexIO's pin mux, ObjectFLED-SPI would be the user-friendly option.

LPUART cannot do SPI on Teensy 4 — see #3157's positioning comment for the silicon-level reasons. So between FlexIO-SPI (restricted pins, parallel sync) and ObjectFLED-SPI (any pin, possibly less parallel sync), users get a choice.

Investigation required first

Status: ⏳ design-investigation, not implementation. Before this is implementable, we need to answer three questions about ObjectFLED's internal architecture:

Question 1: Can ObjectFLED's timer drive a clock output pin?

ObjectFLED uses a hardware timer + DMA to shift bits onto a GPIO pin. For clockless, the timer's compare events directly determine bit edges. For SPI we'd need:

  • The timer to generate a clock signal at the SPI baud (probably via a hardware PWM output or a second compare channel)
  • That clock signal to be routed to a configurable GPIO pin (the SPI clock pin)
  • The data DMA to be re-synchronized with the clock so each data byte settles before the corresponding clock rising edge

If ObjectFLED's timer only generates DMA triggers (not actual pin-output clock signals), then SPI support requires either:

  • Adding a second timer for clock generation (changes the resource budget)
  • Using a different output peripheral entirely for clock (FlexPWM, FTM)

Action: read the ObjectFLED source carefully; determine which approach the library's architecture supports.

Question 2: Can it drive multiple strips with a shared clock?

Even if ObjectFLED can generate a clock for one strip, the more interesting question is whether N strips can share one clock pin. This requires:

  • All N data DMA channels to be phase-synchronized with the clock
  • Hardware support for "this DMA's transfer triggers on the clock signal" (or all DMAs are triggered by the same master)

If ObjectFLED's per-pin architecture doesn't have a master synchronization signal, then SPI support is single-strip per pin — each APA102 strip uses one ObjectFLED "slot" for data and a second one for clock. That's not interesting compared to FlexIO's parallel-sync mode.

Action: determine whether ObjectFLED's DMA channels can be triggered off a shared master timer.

Question 3: Is upstream willing to add SPI support?

ObjectFLED is upstream maintained by PaulStoffregen. FastLED wraps it but doesn't own the library code. Three paths if the upstream library doesn't already support SPI:

  1. Send upstream a PR adding SPI mode (preferred if the architecture allows it).
  2. Fork ObjectFLED inside FastLED (creates a maintenance fork to track).
  3. Use a different driver on the same pin pool (e.g., extend the existing BIT_BANG driver with a more efficient SPI bitbang for Teensy 4).

Action: survey ObjectFLED's upstream issue tracker for SPI requests; open a discussion if none exists.

Implementation scope (conditional on investigation outcomes)

If Questions 1+2 resolve favorably:

  • src/platforms/arm/teensy/teensy4_common/drivers/objectfled/spi_mode.{h,cpp.hpp} (new) — the SPI configuration of the underlying ObjectFLED library.
  • src/platforms/arm/teensy/teensy4_common/drivers/objectfled/channel_engine_objectfled.cpp.hpp — extend canHandle() to accept clocked chipsets; branch show() to dispatch clockless vs SPI per channel.
  • src/platforms/arm/teensy/teensy4_common/drivers/objectfled/bus_traits.h — add BusSupports<Bus::OBJECT_FLED, ClockedChipset> : fl::true_type.
  • Tests + AutoResearch wiring (--object-fled-spi flag, RX loopback fixture).

If Q1 or Q2 resolves negatively:

  • Document the finding as a closing comment on this issue.
  • Update the #3157 positioning comment to note that ObjectFLED can't do SPI either, leaving FlexIO as the sole SPI-capable Teensy 4 backend.

AutoResearch wiring (if implementation proceeds)

Add a --object-fled-spi flag analogous to the existing --object-fled:

  • ci/autoresearch/args.py — new object_fled_spi: bool field + flag declaration.
  • ci/autoresearch/phases.py — add "OBJECT_FLED_SPI" to dispatch table.
  • examples/AutoResearch/AutoResearchRemote.cpp — when driver == "OBJECT_FLED_SPI", configure SPI mode and run loopback with APA102 timing.
  • RX loopback fixture for clocked chipsets (may need extension beyond the current clockless fixture).

Acceptance (conditional on Q1+Q2 favorable)

  • bash autoresearch teensy40 --object-fled-spi drives an APA102 strip via ObjectFLED's SPI mode on a configurable pin, captured byte-for-byte.
  • Pin flexibility: tested with at least 3 different GPIO pin combinations for data + clock — confirms the "any GPIO" promise vs FlexIO's restricted pool.
  • Mixed-mode test: drive 1 clockless strip + 1 SPI strip both via ObjectFLED concurrently. Both should complete without interfering.
  • Existing ObjectFLED clockless tests pass (no regression in Bus::OBJECT_FLED clockless mode).
  • If multi-strip-shared-clock works: drive 2-N strips with shared clock pin, confirm bit-perfect alignment.

Out of scope

Cross-references

Activity

  1. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    Follow-up: pin rejection + driver-capability predicates

    This was raised while triaging the SPI follow-ups for FlexIO (#3175), LPUART (#3157), and ObjectFLED (this issue). The current driver-selection pipeline has a gap that ObjectFLED-SPI surfaces especially sharply.

    Today's predicate surface (audit)

    src/fl/channels/driver.h:150-161 exposes only:

    struct Capabilities {
        bool supportsClockless;  // e.g. WS2812, SK6812
        bool supportsSpi;        // e.g. APA102, SK9822
    };

    And IChannelDriver::canHandle(ChannelData*) is implemented across the drivers as:

    • RMT5: return !data->isSpi(); — src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp:203
    • PARLIO: return !data->isSpi(); — src/platforms/esp/32/drivers/parlio/channel_driver_parlio.cpp.hpp:98
    • SPI: return data->isSpi(); — src/platforms/esp/32/drivers/spi/channel_driver_spi.cpp.hpp:271

    That's it. There is no per-driver predicate for:

    1. Pin validity. A driver can't say "I can drive pins {2,3,4,5} on FlexIO1 but not pin 7." Each platform driver has internal pin tables (e.g. isValidParlioOutputPin() at parlio.cpp.hpp:42) but they're not exposed via the public IChannelDriver interface.
    2. Specific chipset / timing. A driver can't say "I support WS2812 and SK6812 but not UCS7604" — supportsClockless is binary.
    3. Timing-range validity. A driver can't say "I can hit T1=300ns ± 20ns but not 800ns" — timing isn't validated at all today.

    Today's failure mode

    When selectDriverForChannel() (src/fl/channels/manager.cpp.hpp:380-420) finds no driver that returns true from canHandle(), the manager logs "No compatible driver found - cannot transmit" and silently drops the frame (channel.cpp.hpp:437-439). There is no fallback to software bitbang.

    Why ObjectFLED SPI surfaces this gap

    ObjectFLED today is any-pin clockless via timer + DMA per pin. SPI conversion would need two pins per strip (data + clock) AND those two pins must be electrically related through ObjectFLED's timer/DMA wiring. The set of (data, clock) pin pairs ObjectFLED can drive in SPI mode is going to be strictly smaller than the set it can drive in clockless mode, and may have weird "this clock pin can be shared by this set of data pins, but not that one" constraints (similar to FlexIO's "all data shifters on one FlexIO instance share the timer's clock pin" wiring in #3175).

    Without a per-pin/per-pair validity API, a sketch that does:

    FastLED.addLeds<APA102, /*data=*/9, /*clock=*/10, BGR>(leds, NUM_LEDS);

    …would silently no-op at runtime if the {9,10} pair isn't an ObjectFLED-SPI-supported combo, and the user would have no idea why.

    Proposed predicate surface additions

    Three new methods on IChannelDriver would let each driver answer the questions cleanly without forcing every caller to know each platform's quirks:

    namespace fl {
    
    // Existing — kept.
    struct Capabilities {
        bool supportsClockless;
        bool supportsSpi;
    };
    
    class IChannelDriver {
    public:
        // Existing — kept. Binary clockless vs SPI.
        virtual bool canHandle(const ChannelData* data) const = 0;
    
        // NEW: Pin-level validity.
        // For clockless drivers: pass a single-element span [data_pin].
        // For SPI drivers: pass [data_pin, clock_pin].
        // Returns true iff this driver can physically drive that pin configuration.
        // Default impl: returns canHandle(...) — preserves today's behavior for
        // drivers that don't override.
        virtual bool supportsPinSet(span<const int> pins, const ChannelData* data) const {
            return canHandle(data);
        }
    
        // NEW: Chipset-level granularity.
        // Lets drivers reject specific chipsets they can't time-encode (e.g. a
        // FlexIO encoder that supports WS2812 but not UCS7604's wide T2).
        // Default impl: returns canHandle(...) — preserves today's behavior.
        virtual bool supportsChipset(ChipsetId id) const {
            return true;  // delegated to canHandle's clockless/spi gate
        }
    
        // NEW: Timing-range validity. Optional — drivers without timing
        // constraints (DMA-fed PARLIO/I2S) just return true.
        // Catches: "this driver's PWM divider can't hit T1=300ns at the current
        // clock tree" before silently dropping the frame.
        virtual bool supportsTiming(const ChipsetTimingConfig& t) const {
            return true;
        }
    };
    
    }  // namespace fl

    Behavior contract for the manager

    ChannelManager::selectDriverForChannel() would call them in order of cheapness:

    1. canHandle(data) — fast clockless/spi gate (today).
    2. supportsChipset(data->chipsetId()) — chipset granularity.
    3. supportsTiming(data->timing()) — timing granularity.
    4. supportsPinSet(data->pins(), data) — pin granularity.

    First driver that passes all four wins. If none pass, log a richer error than today's "No compatible driver found" — name which check failed and on which driver, so users can see "ObjectFLED rejected {data=9,clock=10}: pin pair not in driver's SPI table."

    ObjectFLED-specific impact

    For this issue specifically:

    • If ObjectFLED-SPI ships, override supportsPinSet(...) to test the data+clock pair against ObjectFLED's actual SPI-capable pin set.
    • Override supportsChipset(...) to whitelist the APA102/SK9822/HD107 family ObjectFLED-SPI can drive.
    • AutoResearch test --object-fled-spi should include a "rejected pin pair logs a clear error and doesn't silently drop" scenario.

    Out of scope for this issue (but worth filing)

    The predicate-API additions themselves are a cross-cutting Channel Manager change. If the user wants them landed before the SPI driver-by-driver work, a separate meta issue for the predicate surface might be cleaner — the ObjectFLED-SPI issue would then become a consumer of that API once it exists. Flagging here so the question is captured; happy to file a sibling issue if that path looks better.

  2. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    The predicate-API design from my earlier comment has been promoted to its own issue: #3186 — declarative DriverCapabilities + pinGroups() + central resolver. ObjectFLED-SPI here will be a consumer of that API once it lands (each ObjectFLED SPI-capable {data, clock} pair → one PinGroup entry with max_concurrent=1).

  3. zackees commented on Jun 18, 2026

    @zackees
    MemberAuthor

    Closing per the 2026-06-18 session closeout — see #3023 for the meta context.

    ObjectFLED SPI investigation for APA102/SK9822 on Teensy 4 is a discrete feature investigation that was never started in this loop. bash autoresearch teensy40 --all reports PASS (PR #3217) — the matrix-green achievement covers the autoresearch surface this issue feeds into.

    Reopen if/when picking ObjectFLED SPI back up.

  4. moved this from Triage to Done in FastLED Trackeron Jun 18, 2026
  5. zackees commented on Jun 18, 2026

    @zackees
    MemberAuthor

    Reopening — the 2026-06-18 closure was premature. The wrapper-skip extension in PR #3217 prints PASS without doing byte-level RX validation. See #3066 acknowledgement for the full context. Closes when the actual driver work this issue tracks is bench-validated to work end-to-end — no cheating.

  6. moved this from Done to Triage in FastLED Trackeron Jun 18, 2026
  7. zackees commented on Jun 27, 2026

    @zackees
    MemberAuthor

    Closing as deferred future work. ObjectFLED SPI/clocked-LED extension is new-feature territory beyond the WS281x-family scope ObjectFLED was originally built for; #3175 covers the FlexIO parallel-SPI angle. Re-open when there's a concrete user request or maintainer commitment. Tracked at meta level under #3023.

  8. moved this from Triage to Done in FastLED Trackeron Jun 27, 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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions