Skip to content

feat(flexio): parallel synchronized SPI driver for APA102/SK9822 on Teensy 4 (refs #3023, #3157) #3175

Closed

Description

@zackees

Background

FastLED's Teensy 4 driver lineup has three clockless backends (BIT_BANG, OBJECT_FLED, FLEX_IO) but no dedicated multi-strip parallel SPI driver for clocked chipsets (APA102, SK9822). Users with N parallel SPI strips today have to either:

  • Serialize them via Bus::BIT_BANG (slow, CPU-bound)
  • Use one LPSPI instance per strip (4 instances available on iMXRT1062, each runs its own clock — not parallel-synchronized)
  • Bit-bang manually with tight CPU timing (terrible)

The iMXRT1062's FlexIO peripheral was designed for exactly this case: N parallel shifters all clocked by one shared timer. The existing Bus::FLEX_IO driver uses FlexIO in clockless mode (for WS281x-family timing); this issue adds the clocked / SPI mode using the same peripheral.

Why this is the canonical FlexIO use case

From the iMXRT1062 reference manual:

Each FlexIO module contains an array of timers, shifters, pins, and registers. The shifters can be configured for serial transmit/receive functions including SPI, I2C, UART, I2S, etc.

The clockless mode we already use (single timer driving N shifters in parallel for WS2812-style output) and the SPI mode (single timer + clock-out shifter + N data shifters) are sibling configurations of the same hardware. The plumbing for one mostly works for the other.

LPUART cannot do this — see the LPUART clockless-only positioning on #3157 for the silicon-level reasons (phase-independent baud generators, UART framing breaks the SPI bitstream).

Scope

Add a SPI/clocked mode to the existing Bus::FLEX_IO driver path on Teensy 4 (iMXRT1062). The mode auto-selects based on the chipset traits — clockless chipsets keep using the existing clockless path; clocked chipsets (APA102, SK9822, etc.) route to the new SPI shifter config.

Hardware shape

  • 1 FlexIO timer generating the SPI clock at the configured baud (typical 10-20 MHz for APA102).
  • 1 FlexIO shifter outputting the clock signal driven by the timer (or use the timer's output pin directly if the FlexIO instance supports timer-output pins, depending on FlexIO1/2/3 differences).
  • N FlexIO shifters outputting the data signals, all clocked off the single timer for bit-perfect synchrony across strips.
  • eDMA feeding each data shifter's buffer.

Pin allocation

FlexIO1 and FlexIO3 each have 8 shifters; FlexIO2 has 4. So the available "data shifters per FlexIO instance" is:

  • FlexIO1: 7 data + 1 clock = 7 parallel SPI strips
  • FlexIO2: 3 data + 1 clock = 3 parallel SPI strips
  • FlexIO3: 7 data + 1 clock = 7 parallel SPI strips

If a sketch wires across multiple FlexIO instances, you can stack instances for more parallel strips (each instance gets its own clock pin — strips on different instances are NOT phase-locked to each other, but strips within one instance are bit-perfect synchronized).

Files

  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/spi_mode.{h,cpp.hpp} (new) — the SPI shifter config + the per-frame DMA setup. Mirror the structure of the existing clockless mode files.
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.cpp.hpp — extend canHandle() to accept clocked chipsets when the SPI mode is configured. Branch the show() path to dispatch clockless vs SPI per channel.
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/bus_traits.h — add BusSupports<Bus::FLEX_IO, ClockedChipset> : fl::true_type alongside the existing clockless support.
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/_build.cpp.hpp — pick up the new TU.
  • tests/platforms/arm/teensy/teensy4_common/drivers/flexio/spi_mode.cpp (new) — parameterized host test against the existing mock peripheral. Asserts SPI bitstream + clock alignment for {APA102, SK9822, ...}.

AutoResearch wiring

Add a --flex-io-spi flag analogous to the existing --flex-io:

  • ci/autoresearch/args.py — new flex_io_spi: bool field + flag declaration.
  • ci/autoresearch/phases.py — add "FLEX_IO_SPI" (or extend FLEX_IO with a mode parameter) to the dispatch table.
  • examples/AutoResearch/AutoResearchRemote.cpp — when driver == "FLEX_IO_SPI", configure the engine in SPI mode and run the loopback test with APA102 timing.
  • Loopback fixture: confirm byte-for-byte capture via the existing FlexIO RX path (or via direct DMA-buffer readback if RX loopback doesn't yet handle the clock-line case).

Acceptance

  • bash autoresearch teensy40 --flex-io-spi drives one APA102 / SK9822 strip via FlexIO with the new SPI mode, captured byte-for-byte via the existing RX fixture (or a new clocked-capture fixture if needed).
  • bash autoresearch teensy40 --flex-io-spi --tx-pin <pin> works for at least 3 different FlexIO1 data pins.
  • Multi-strip test: drive N=2..7 strips concurrently on FlexIO1, capture all simultaneously, assert no inter-strip data crosstalk and all strips' bitstreams arrive at the receiver at the same time (within one SPI bit cell).
  • Mixed-mode test: drive 1 clockless strip on FlexIO2 + 1 SPI strip on FlexIO1 + 1 LPUART clockless strip concurrently. All three should complete a full frame without interfering.
  • Host test parameterized over clocked chipsets passes.
  • Existing FlexIO clockless tests still pass (no regression in Bus::FLEX_IO clockless mode).
  • ChannelManager boot dump correctly shows FlexIO can handle both clockless AND clocked chipsets.

Out of scope

Cross-references

Activity

  1. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    Cross-reference: #3186 — declarative DriverCapabilities + central resolver. FlexIO SPI here will publish one PinGroup per FlexIO instance (data_pins = the instance's shifter-capable pins, clock_pin = the instance's timer pin, max_concurrent = shifter count). Pin-pair rejection ({data, clock} from different instances) surfaces as NoPinPair rather than today's silent drop.

  2. zackees commented on Jun 18, 2026

    @zackees
    MemberAuthor

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

    The FlexIO parallel-synchronized SPI driver work for APA102/SK9822 on Teensy 4 is a discrete bench-required feature that was never started in this loop. The bash autoresearch teensy40 --all matrix-green achievement (PR #3217) covers the autoresearch matrix entries this issue would feed into via the wrapper-skip pattern (SPI is among the skipped non-Teensy-supported drivers).

    Reopen if/when picking the FlexIO SPI driver feature back up.

  3. moved this from Triage to Done in FastLED Trackeron Jun 18, 2026
  4. 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.

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

    @zackees
    MemberAuthor

    Closing as deferred future work. APA102/SK9822 parallel-SPI driver on Teensy 4 FlexIO is a substantial new feature (not a follow-up to existing bring-up); no design or bench commitment in scope right now. Re-open when there's a concrete user request or maintainer commitment. Tracked at meta level under #3023.

  7. 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