Repository navigation
Description
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
LPSPIinstance 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— extendcanHandle()to accept clocked chipsets when the SPI mode is configured. Branch theshow()path to dispatch clockless vs SPI per channel. -
src/platforms/arm/teensy/teensy4_common/drivers/flexio/bus_traits.h— addBusSupports<Bus::FLEX_IO, ClockedChipset> : fl::true_typealongside 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— newflex_io_spi: boolfield + flag declaration. -
ci/autoresearch/phases.py— add"FLEX_IO_SPI"(or extendFLEX_IOwith a mode parameter) to the dispatch table. -
examples/AutoResearch/AutoResearchRemote.cpp— whendriver == "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-spidrives 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_IOclockless mode). -
ChannelManagerboot dump correctly shows FlexIO can handle both clockless AND clocked chipsets.
Out of scope
- ObjectFLED SPI support — tracked separately in its own issue (filed alongside this one).
- LPUART SPI support — structurally impossible per the #3157 positioning comment; not on the roadmap.
- Async multi-strip SPI streaming-ISR conversion — Phase 1 here is sync (all strips finish before
show()returns). Async follows the same path as the clockless async conversion under [meta] Teensy 4 channels-API driver coverage + verification fixtures (supersedes #2764, #3006) #3023 §D. - FlexPWM-based SPI — separate peripheral, separate driver. FlexIO is the right tool for this use case per the silicon design.
Cross-references
- Parent meta: [meta] Teensy 4 channels-API driver coverage + verification fixtures (supersedes #2764, #3006) #3023 (Teensy 4 channels-API driver coverage).
- LPUART clockless context: feat(lpuart): finish Teensy 4 LPUART engine + encoder + bus_traits + canHandle() host test (split from #3122 B1 / refs #3023) #3157 + its positioning comment.
- ObjectFLED SPI companion: filed alongside this issue.
- AutoResearch infrastructure: existing
--flex-ioflag wiring in fix(autoresearch): exercise both ObjectFLED and FlexIO on Teensy 4.x #3005 / fix(parlio): mock waitAllDone() pumps deferred ISR callbacks to mirror real-DMA semantics (#2992 follow-up) #3010.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Jun 16, 2026
Cross-reference: #3186 — declarative
DriverCapabilities+ central resolver. FlexIO SPI here will publish onePinGroupper 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 asNoPinPairrather than today's silent drop.zackees commentedon Jun 18, 2026
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 --allmatrix-green achievement (PR #3217) covers the autoresearch matrix entries this issue would feed into via the wrapper-skip pattern (SPIis among the skipped non-Teensy-supported drivers).Reopen if/when picking the FlexIO SPI driver feature back up.
zackees commentedon Jun 18, 2026
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.
zackees commentedon Jun 27, 2026
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.