Skip to content

feat(flexio): unified clockless+SPI engine scaffolding (#3428) - #3431

Merged
zackees merged 8 commits into
masterfrom
feat/flexio-spi-driver
Jun 28, 2026
Merged

zackees merged 8 commits into
masterfrom
feat/flexio-spi-driver

Conversation

@zackees

@zackees zackees commented Jun 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Lands the unified-engine architectural pattern for FlexIO2 per the rule in #3430, with real FlexIO2 SPI master-mode hardware programming + hardware-verified bring-up smoke test on a Teensy 4.1.

Same ChannelEngineFlexIO, same Bus::FLEX_IO enum slot, both clockless WS2812 and APA102/SK9822-class SPI modes routed inside show() based on ChannelData::isClockless() vs isSpi().

Hardware-verified on Teensy 4.1 (COM20)

uv run python ci/autoresearch/test_flexio_spi_smoke.py — 3 pass / 0 fail:

Case MOSI SCLK Flex pins Clock Bytes wait_ms
1 10 12 0/1 1 MHz 4 0
2 10 12 0/1 6 MHz 16 0
3 11 13 2/3 12 MHz 64 0

This rules out: firmware crash on SPI init, DMA hang past 50 ms timeout, pin-routing bugs, clockless-mode regression. Still TODO (in-code markers): scope-verify byte-level MOSI bit pattern + TIMPOL polarity + SHIFTBUFBBS-vs-BIS on first APA102 strip bring-up.

What changes

Component Before After
getCapabilities() (true, false) (true, true)
canHandle() clockless only clockless + SPI
show() one clockless path per-channel routing
BusSupports<Bus::FLEX_IO, _> only Clockless both Clockless + Spi
flexio_spi_* helpers — Real FlexIO2 SPI master programming
flexio_internal.h — Shared kFlexIOPins lookup + flexio_ensure_clock() across both modes (no forking)
flexioSpiSelfTest RPC — AutoResearch bring-up smoke test
ci/autoresearch/test_flexio_spi_smoke.py — Host-side driver script

Hardware programming highlights

  • Shifter 0: SMOD=2 (transmit), TIMPOL=1 (shift on falling edge for Mode 0 stable-at-rising-edge), PINCFG=3 drives MOSI.
  • Timer 0: TIMOD=1 (dual 8-bit baud), TRIGGER_SHIFTER(0)+TRGPOL_ACTIVE_LOW (run while shifter has data), TIMOUT=1 (SCLK idle LOW — note: TIMOUT encoding is inverted; TIMOUT(1)=LOW per imxrt.h:4146-4147), PINCFG=3 drives SCLK.
  • DMA TCD: 1-byte beats into SHIFTBUFBBS[0] (byte+bit-swap alias) — streams bytes MSB-first as required by APA102 / Mode 0 SPI.
  • Cache coherence: arm_dcache_flush() when the buffer lives in cached memory (>= 0x20200000).
  • Bounded timeouts: 50 ms DMA wait + 5 ms shifter-drain wait, both with force-recovery.
  • Clock clamped to [100 kHz, 25 MHz] (APA102 spec is 30 MHz; margin for cable/chipset variance).

Reference: NXP i.MX RT1060 Reference Manual rev 2, chapter 50 (FlexIO). Cross-checked against Teensyduino's canonical libraries/FlexIO_t4/src/FlexIOSPI.cpp.

What does NOT change

  • Existing clockless behavior is untouched — canHandle()'s clockless branch is byte-equivalent to the previous code; show()'s clockless reinit path is the same logic guarded by mCurrentMode != Clockless.
  • DefaultBus<SpiChipsetConfig> for Teensy 4.x stays intentionally unspecified — flip to Bus::FLEX_IO in a follow-up after broader APA102 strip testing.

Test plan

Refs #3428, #3430.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added unified FlexIO2 support on Teensy 4.x for both clockless LED output and SPI-based output, automatically selecting the right mode per channel.
    • Expanded capability reporting to advertise dual-mode operation; SPI is available only when the selected MOSI/SCLK pins have a valid FlexIO routing.
  • Tests

    • Updated FlexIO capability tests for the new unified dual-mode expectations.
    • Added a FlexIO2 SPI master self-test RPC plus a serial smoke test runner to validate lookup/init/show/wait end-to-end.

Lands the unified-engine architectural pattern for FlexIO2 per the rule
in PR #3430 ("Parallel-IO peripherals -- one engine for both clockless
and SPI modes"). The hardware SPI programming itself is a follow-up;
this PR puts the engine, capabilities, BusSupports specialization, and
mode-routing in place so the type-system and dispatch story is in code.

What changes
- ChannelEngineFlexIO::getCapabilities() now returns Capabilities(true, true).
- canHandle() accepts both ClocklessChipset and SpiChipsetConfig channels
  (the SPI branch is gated by flexio_spi_lookup_pins() which currently
  stub-returns false, so SPI channels still fall through today).
- show() routes per-channel between the existing clockless path and a
  new SPI path. The peripheral is deinit'd and reinit'd on mode change
  -- one peripheral, two modes, never both at once.
- New `Mode` enum + per-mode tracking fields (current pin/timing for
  clockless, current MOSI/SCLK/clock_hz for SPI) detect when the
  hardware can be reused vs needs reprogramming.
- BusSupports<Bus::FLEX_IO, SpiChipsetConfig> specialization: lets users
  write FastLED.add<Bus::FLEX_IO, SpiChipsetConfig>(cfg) and have it
  type-check at compile time.
- flexio_spi_mode.{h,cpp.hpp}: new TU declaring the SPI-mode hardware
  shim API (flexio_spi_lookup_pins / init / show / wait / deinit) with
  stub implementations that all return false. Real FlexIO2 SPI master
  mode register programming (shifter 0 = MOSI, timer 0 = SCLK baud)
  lands in a follow-up PR.

What does NOT change
- Existing clockless behavior is untouched -- canHandle()'s clockless
  branch is byte-equivalent to the previous code; show()'s clockless
  reinit path is the same logic guarded by mCurrentMode != Clockless.
- DefaultBus<SpiChipsetConfig> for Teensy 4.x stays intentionally
  unspecified (per user directive: "single strip should not default
  LPSPI"; flip to Bus::FLEX_IO once the SPI hardware is verified
  working on device).

Test updates
- `FlexIO engine - capabilities are clockless only` flipped to
  `... are unified clockless + SPI (#3428)` and asserts both bits true.
- 338/338 host tests pass; lint clean.

Refs #3428, #3430.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 27, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds Teensy 4.x FlexIO2 SPI mode support, shared pin/clock helpers, compile-time SPI bus support, mode-aware channel engine validation and transmit routing, plus RPC and smoke-test coverage.

Changes

FlexIO Unified Clockless + SPI Engine

Layer / File(s) Summary
Shared pin lookup and clock shims
src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_internal.h, src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_driver.cpp.hpp
Defines cross-TU FlexIO pin entries plus lookup and clock-ensure helpers, and exposes them from the Teensy FlexIO driver.
FlexIO2 SPI mode API and implementation
src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.h, src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.cpp.hpp, src/platforms/arm/teensy/teensy4_common/drivers/flexio/_build.cpp.hpp
Declares the Teensy 4.x SPI helper API, wires it into the unity build, and implements pin lookup, initialization, DMA transfer, wait, and teardown for FlexIO2 SPI mode.
Bus support and engine state
src/platforms/arm/teensy/teensy4_common/drivers/flexio/bus_traits.h, src/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.h, tests/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.cpp
Marks FlexIO as supporting SPI chipsets, updates engine documentation and capability reporting to include SPI, and updates the capability test to expect both clockless and SPI support.
ChannelEngineFlexIO canHandle and show dispatch
src/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.cpp.hpp
Reworks canHandle() to validate clockless or SPI channels separately, and replaces the single-path transmit loop with per-channel clockless or SPI initialization, transfer, and cleanup.
RPC binding and smoke test
examples/AutoResearch/AutoResearchRemoteDriverMethods.cpp, ci/autoresearch/test_flexio_spi_smoke.py
Adds the AutoResearch FlexIO SPI self-test RPC and the serial smoke test that calls it across multiple pin and clock cases.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3191: Both PRs touch the AutoResearch remote RPC binding wiring in examples/AutoResearch/AutoResearchRemoteDriverMethods.*.
  • FastLED/FastLED#3411: Both PRs modify the Teensy FlexIO channel-engine transmit path and its wait behavior.

Poem

🐇 Hop, hop—FlexIO found its SPI beat,
Clockless and shiny now share the same seat.
Pins whirl and DMA darts through the night,
With Teensy 4.x humming just right.
A rabbit approves with a twitch of delight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the unified FlexIO clockless+SPI engine work and is concise enough for a PR log.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/flexio-spi-driver

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.h (1)

42-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use fl::span for the transmit buffer API.

Line 45 introduces a new pointer+length pair in a header API. Please make this fl::span<const u8> now so callers cannot pass mismatched pointers and sizes, and the interface stays aligned with the repo’s span convention. As per coding guidelines, "Use fl::span for function parameters instead of fl::vector or raw arrays".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.h`
around lines 42 - 45, The transmit API in flexio_spi_show currently exposes a
raw pointer and length pair, which can allow mismatched buffer sizes; update
this header interface to accept fl::span<const u8> instead so callers pass a
single bounded view. Adjust any corresponding declarations/definitions and call
sites to use the span-based signature, keeping the DMA transmit behavior and
flexio_spi_wait() guidance unchanged.

Sources: Coding guidelines, Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/platforms/arm/teensy/teensy4_common/drivers/flexio/bus_traits.h`:
- Around line 41-48: `BusSupports<Bus::FLEX_IO, SpiChipsetConfig>` is exposing a
FLEX_IO+SPI combination that the current shim still cannot execute at runtime.
Keep the internal FlexIO SPI scaffolding, but remove or disable this
specialization in `bus_traits.h` until `flexio_spi_lookup_pins()`,
`flexio_spi_init()`, and `flexio_spi_show()` can succeed for a real pin pair, so
`FastLED.add<Bus::FLEX_IO, SpiChipsetConfig>(cfg)` does not compile into a no-op
path.

In
`@src/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.cpp.hpp`:
- Around line 157-184: After mPeripheral->deinit() in
ChannelEngineFlexIO::reinit logic, immediately clear the cached hardware state
so it cannot reflect the old configuration if validation or init later fails.
Update the affected reinit paths in channel_engine_flexio.cpp.hpp to reset
mHwInitialized and mCurrentMode (and any related cached pin/timing state if
needed) right after deinit, before canHandlePin() or mPeripheral->init() can
return false. Keep the state changes localized around the existing need_reinit
block and the analogous second reinit path referenced in the comment.
- Around line 243-247: The channel advancement logic in
channel_engine_flexio.cpp.hpp currently assumes flexio_spi_show() always starts
DMA, but it can return false. In the code path around the payload handling in
the channel execution loop, check the return value of flexio_spi_show() before
calling flexio_spi_wait(), and only continue to the next step when the start
succeeds; if it fails, skip the wait and keep the current iteration from
completing as if transmission began. Use the existing payload handling flow in
this channel engine method to gate advancement on the success of
flexio_spi_show().
- Around line 166-176: The FlexIO logging in ChannelEngineFlexIO is using string
format specifiers for integer pin values, which can cause undefined behavior in
the logging path. Update the FL_LOG_FLEXIO_F calls in ChannelEngineFlexIO::init
and the related setup path (including the pin-capability and init-failure logs)
to use the correct integer specifiers such as %d or %u for pin and other numeric
fields, keeping the message text unchanged while matching the argument types.

In
`@src/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.h`:
- Around line 90-91: Move the ChannelEngineFlexIO::getCapabilities()
implementation out of the header and leave only the declaration in
channel_engine_flexio.h. Define the method in channel_engine_flexio.cpp.hpp with
the same signature, since the inline body currently in the header violates the
header-only declaration rule for src/**/*.h. Keep the behavior unchanged by
returning Capabilities(true, true) in the out-of-line definition.

---

Nitpick comments:
In `@src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.h`:
- Around line 42-45: The transmit API in flexio_spi_show currently exposes a raw
pointer and length pair, which can allow mismatched buffer sizes; update this
header interface to accept fl::span<const u8> instead so callers pass a single
bounded view. Adjust any corresponding declarations/definitions and call sites
to use the span-based signature, keeping the DMA transmit behavior and
flexio_spi_wait() guidance unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 67c689dd-7e09-467e-8138-c0b29cc7b98b

📥 Commits

Reviewing files that changed from the base of the PR and between cab1619 and 857b0b2.

📒 Files selected for processing (7)
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/_build.cpp.hpp
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/bus_traits.h
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.cpp.hpp
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.h
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.cpp.hpp
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.h
  • tests/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.cpp

…3428)

Replaces the stubbed flexio_spi_* helpers from the scaffolding commit
with the real i.MX RT1062 FlexIO2 SPI master mode register programming.
With this commit, ChannelEngineFlexIO can actually serve APA102 /
SK9822-class SPI channels in addition to its existing clockless WS2812
mode -- one peripheral, one engine, two modes (unified-engine rule per
PR #3430).

Hardware programming
- Shifter 0: transmit mode (SMOD=2), TIMSEL=0, TIMPOL=1 (shift on
  falling edge for Mode 0 stable-at-rising-edge), PINCFG=3 (drives
  MOSI), PINSEL=MOSI flexio pin index.
- Timer 0: dual 8-bit baud mode (TIMOD=1), trigger from shifter 0
  status flag (TRIGGER_ACTIVE_LOW so timer runs while shifter has
  data), PINCFG=3 (drives SCLK), TIMOUT=1 (SCLK idle LOW for Mode 0
  CPOL=0 -- note: TIMOUT encoding is inverted from intuition; TIMOUT(1)
  = LOW per imxrt.h:4146-4147).
- TIMCMP = (15 << 8) | baud_div_field. 15 = (8 bits * 2 transitions) -
  1. baud_div = (120 MHz / (2 * clock_hz)) - 1, clamped to [0, 255].
  Effective SCLK range: ~234 kHz to ~12 MHz at baud_div=4 (12 MHz =
  120 / 10).
- Pin mux: ALT4 + SION on both MOSI and SCLK pads; SION is critical
  for routing the pin to the FlexIO peripheral (same SION investigation
  that fixed the clockless mode in #3416 FX-CRIT-1).
- DMA TCD: 1-byte beats from user buffer to SHIFTBUFBBS[0] (byte+bit-
  swap alias) -- streams bytes out MSB-first as required by APA102 /
  Mode 0 SPI. DMAMUX_SOURCE_FLEXIO2_REQUEST0 triggers per shifter-empty.
- Cache coherence: arm_dcache_flush() on the user buffer when it lives
  in cached memory (>= 0x20200000).
- DSB barrier before kicking DMA.
- Bounded 50 ms DMA wait + bounded 5 ms shifter-drain wait, both with
  force-recovery on timeout (same pattern as flexio_wait FX-MED-4).

Architectural notes
- flexio_internal.h: new shared header exposing the FlexIOPinEntry
  struct + flexio_lookup_pin_entry() + flexio_ensure_clock(). Both
  the clockless mode (flexio_driver.cpp.hpp) and the SPI mode share
  the same pin table and the same CCM clock-gate sequence -- no
  forking.
- Mutually exclusive at runtime: each mode's _init() asserts the
  peripheral is in its expected state, and each mode's _deinit() is
  called by the unified engine before switching modes.
- Same FASTACC=OFF + SION mux + #undef FLEXIO2_* dance as the
  clockless side.
- Clamps clock to [100 kHz, 25 MHz]; APA102 spec is 30 MHz max but
  we keep margin for cable + chipset variance.

Reference
- NXP i.MX RT1060 Reference Manual rev 2, chapter 50 (FlexIO).
- Teensyduino libraries/FlexIO_t4/src/FlexIOSPI.cpp (canonical
  NXP-blessed reference cross-checked for all field encodings).

Build / test
- bash test --cpp: 338/338 host tests pass.
- bash compile teensy40 --examples AutoResearch: succeeds (flash 18.6%).
- bash compile teensy41 --examples AutoResearch: succeeds.
- bash lint --cpp: clean.
- Hardware loopback validation pending -- TODO comments in the file
  mark the two register fields (TIMPOL polarity, SHIFTBUFBBS vs
  SHIFTBUFBIS) to scope-verify on first bring-up.

Refs #3428, #3430. Builds on the scaffolding from this branch's prior
commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.cpp.hpp`:
- Around line 439-480: flexio_spi_wait currently exits as soon as
sSpiDmaComplete is set, which can skip the final wire-drain phase and also
force-recover long frames too early. Update the transfer state handling in
flexio_spi_wait and the related SPI DMA start path so the code knows whether a
transfer is active, how many bytes were launched, and what the effective clock
rate is. Use that state to always wait for the shifter/timer drain after DMA
completion, and replace the fixed timeout with one derived from the active
transfer’s byte count and clock speed so slow transfers are not cut off. Keep
the existing recovery behavior only for true stalls, not for legitimate long
transfers.
- Around line 239-241: The SPI baud divider calculation in
flexio_spi_mode.cpp.hpp is flooring the divider, which can produce an actual
SCLK above the requested or clamped rate. Update the divider logic around the
baud calculation to use ceiling division for the
kFlexIO2BaseClockHz/(2*clock_hz) step before deriving baud_div_field, and keep
the existing minimum-of-1 guard so the resulting clock never exceeds the target.
Use the surrounding baud-divider code in the SPI mode path to locate and adjust
the calculation.
- Around line 332-337: The DMA allocation failure path in flexio_spi_init leaves
MOSI/SCLK switched to FlexIO ALT4, so restore the previously saved pin mux state
before returning false or move the DMAChannel allocation earlier than the mux
changes. Update the flexio_spi_init flow around sSpiDmaChannel and the pin-mux
setup/cleanup logic so a failed DMAChannel allocation does not leave the pads
stolen by a partial init.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0ae7d647-9b27-4a91-a0f9-a491d9e2ce1e

📥 Commits

Reviewing files that changed from the base of the PR and between 857b0b2 and 070316d.

📒 Files selected for processing (4)
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_driver.cpp.hpp
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_internal.h
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.cpp.hpp
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.h

Comment on lines +439 to +480
void flexio_spi_wait() FL_NO_EXCEPT {
if (sSpiDmaComplete) return;

// Bounded 50 ms wait for the DMA major-loop completion.
// 25 MHz SCLK * 8 bits/byte means worst-case 320 ns/byte, so even a
// 4096-byte frame finishes in ~1.3 ms -- 50 ms is far more headroom
// than any plausible APA102 frame needs.
const u32 start = millis();
const u32 timeout_ms = 50;
while (!sSpiDmaComplete) {
if ((u32)(millis() - start) >= timeout_ms) {
// Force-recover so the next show() is not blocked forever.
// Matches the flexio_wait() FX-MED-4 recovery pattern.
if (sSpiDmaChannel) {
sSpiDmaChannel->disable();
sSpiDmaChannel->clearComplete();
sSpiDmaChannel->clearError();
}
SPI_FLEXIO2_SHIFTSDEN = 0;
sSpiDmaComplete = true;
FL_LOG_FLEXIO_F("FlexIO_SPI: wait timed out after %s ms -- recovering",
(int)timeout_ms);
return;
}
}

// DMA major-loop complete, but the shifter may still be clocking out
// the last byte. Wait for TIMSTAT[0] (timer 0 reached compare) to
// confirm the wire has actually drained. Bounded 5 ms -- one
// 8-bit beat at the slowest supported 234 kHz takes ~34 us, so 5 ms
// = ~146 byte-times of slack.
const u32 drain_start = millis();
const u32 drain_timeout_ms = 5;
while (!(SPI_FLEXIO2_TIMSTAT & 0x1u)) {
if ((u32)(millis() - drain_start) >= drain_timeout_ms) {
FL_LOG_FLEXIO_F("FlexIO_SPI: shifter drain timeout after %s ms",
(int)drain_timeout_ms);
break;
}
}
SPI_FLEXIO2_TIMSTAT = 0xFFu; // W1C the timer status latch
}

@coderabbitai coderabbitai Bot Jun 27, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Track transfer state through wire drain.

Line 440 returns as soon as the DMA ISR has fired, but the final byte can still be clocking out; fast short transfers can hit this path before the caller’s immediate flexio_spi_wait(), so deinit/reinit may cut off the tail. The fixed 50 ms timeout is also based on the fastest SCLK; at the effective ~234 kHz floor, a 4096-byte frame takes ~140 ms and will be force-recovered mid-transfer. Store active byte count/effective clock and always drain when a transfer was started.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.cpp.hpp`
around lines 439 - 480, flexio_spi_wait currently exits as soon as
sSpiDmaComplete is set, which can skip the final wire-drain phase and also
force-recover long frames too early. Update the transfer state handling in
flexio_spi_wait and the related SPI DMA start path so the code knows whether a
transfer is active, how many bytes were launched, and what the effective clock
rate is. Use that state to always wait for the shifter/timer drain after DMA
completion, and replace the fixed timeout with one derived from the active
transfer’s byte count and clock speed so slow transfers are not cut off. Keep
the existing recovery behavior only for true stalls, not for legitimate long
transfers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked as a follow-up rather than fixed in this PR. The current 50 ms wait + 5 ms shifter-drain bound covers the smoke-test payloads (<=64 B at >=1 MHz: ~0.5 ms total) and the realistic APA102 frame sizes the FlexIO SPI engine is being introduced for, with verified 3/3 pass on real hardware. The proper fix (track active byte count + effective clock, derive timeout, always drain after a started transfer) is a behavior-changing rework of flexio_spi_wait() that belongs in a dedicated PR with its own smoke-test coverage at the slowest 234 kHz floor. Filing as a follow-up issue under #3428 -- not blocking #3431 merge.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zackees, that makes sense — thanks for clarifying the tested envelope and the intended scope for #3431.

Given the current hardware validation (3/3 pass) and the stated operating window here, I’m OK deferring the transfer-state/derived-timeout rework to the follow-up under #3428. That deeper change does sound better suited to a dedicated PR with explicit low-clock smoke coverage rather than expanding this bring-up PR further.

I won’t push further on this thread for the current PR.

(ᵔᴥᵔ)


🧠 Learnings used
Learnt from: zackees
Repo: FastLED/FastLED PR: 3256
File: src/fl/gfx/colorimetric_response.cpp.hpp:14-24
Timestamp: 2026-06-19T02:25:59.632Z
Learning: In the FastLED/FastLED repository, `FASTLED_RGBW_COLORIMETRIC` is an already-established build-gate macro. During review, do not flag new/added files that only reference/reuse this existing guard for unity-build consistency as a violation of the “new-macro-prefix” rule. Only flag when code introduces a genuinely new macro (or a new/renamed guard) rather than reusing this pre-existing `FASTLED_RGBW_COLORIMETRIC` macro.

Learnt from: zackees
Repo: FastLED/FastLED PR: 3327
File: src/fl/system/file_system.cpp.hpp:1-1
Timestamp: 2026-06-20T07:32:56.303Z
Learning: FastLED/FastLED `.cpp.hpp` files should include the IWYU pragma `// IWYU pragma: private` only when the `.cpp.hpp` file is newly introduced in the current PR (i.e., it is a new file in the diff). Do not require or flag the missing IWYU pragma for `.cpp.hpp` files that already existed prior to the PR, even if they are touched/modified; defer those to a separate dedicated IWYU sweep PR.

Learnt from: zackees
Repo: FastLED/FastLED PR: 3431
File: src/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.cpp.hpp:0-0
Timestamp: 2026-06-28T01:22:18.092Z
Learning: In FastLED Teensy FlexIO driver code that logs via `FL_LOG_FLEXIO_F` (which ultimately uses the type-safe `fl::printf` streaming-based template, not C-style varargs), reviewers should still correct mismatched `%`/format specifiers (e.g., using `%s` for non-string types) for clarity and consistency, but they should not describe the mismatch as undefined behavior caused by C-style variadic formatting.

Adds the `flexioSpiSelfTest` AutoResearch RPC binding plus a Python
host-side driver script `ci/autoresearch/test_flexio_spi_smoke.py` that
exercises the full FlexIO2 SPI master-mode hardware path -- pin lookup,
init, DMA-driven show, wait, deinit -- without needing a logic analyzer
or APA102 strip wired up.

Hardware-verified on a real Teensy 4.1 (COM20). Three test cases pass:
  - 1 MHz @ pins 10/12 (flex 0/1), 4 bytes
  - 6 MHz @ pins 10/12, 16 bytes
  - 12 MHz @ pins 11/13 (flex 2/3), 64 bytes

This rules out the worst-case failures (firmware crash on SPI init, DMA
hang past the 50 ms timeout, wrong pin routing) and confirms that:
  - flexio_spi_lookup_pins correctly maps (MOSI, SCLK) pin pairs against
    the shared kFlexIOPins table.
  - flexio_spi_init successfully programs shifter 0 + timer 0 at multiple
    clock rates (1, 6, 12 MHz).
  - flexio_spi_show + flexio_spi_wait round-trip cleanly for buffers
    from 4 to 64 bytes (all complete in <1 ms vs the 50 ms budget).
  - The clockless mode is unaffected -- the AutoResearch firmware still
    boots with the new SPI hardware code linked in.

What this does NOT verify (still TODO per the in-code markers in
flexio_spi_mode.cpp.hpp):
  - Byte-level MOSI bit pattern (need a scope to confirm 0xA5 streams
    out as 1010 0101 MSB-first).
  - SCLK polarity / TIMPOL / SHIFTBUFBBS vs SHIFTBUFBIS questions --
    these need scope-on-the-wire verification on first APA102 strip
    bring-up. The test pattern (0xA5 0x5A 0xFF 0x00) was chosen for
    easy scope visual inspection.

Implementation note: the RPC binding parses args from `args.is_object()`
(the framework strips the outer params array and passes params[0]
directly). Several existing bindings in this file use the wrong
`args.is_array()` check and silently use their defaults -- pre-existing
bug, fix tracked separately so this PR stays focused on the SPI work.

Refs #3428.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
ci/autoresearch/test_flexio_spi_smoke.py (2)

98-122: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Return a named dataclass result instead of a tuple.

evaluate() returns two values as tuple[bool, str]; use a small result dataclass so the call site reads named fields. As per coding guidelines, "**/*.py: Return dataclass structs instead of tuples or dicts for functions with multiple return values."

Also applies to: 165-172

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/autoresearch/test_flexio_spi_smoke.py` around lines 98 - 122, The
evaluate() helper currently returns an unnamed tuple of (bool, str), which
should be replaced with a small named dataclass result so callers can access
fields explicitly. Update evaluate(case, result) in test_flexio_spi_smoke.py to
return a result dataclass with clear fields for success/status and message, and
adjust the call site(s) that consume its return value to use the named
attributes instead of tuple unpacking; use the evaluate symbol to locate the
function and keep the PASS/FAILED message construction unchanged.

Source: Coding guidelines


43-49: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add @typechecked to SmokeCase. SmokeCase is a new dataclass in ci/, and it should use runtime type validation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/autoresearch/test_flexio_spi_smoke.py` around lines 43 - 49, Add runtime
type validation to the new SmokeCase dataclass by decorating SmokeCase with
`@typechecked`. Update the SmokeCase definition in test_flexio_spi_smoke.py so its
fields still use the existing annotations while enabling typeguard-style
checking for instances created in ci/.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/autoresearch/test_flexio_spi_smoke.py`:
- Around line 111-113: The smoke test currently treats a missing or malformed
wait_ms as 0, which can let an incomplete firmware response pass. Update the
result parsing in the FlexIO SPI smoke test to explicitly validate the wait_ms
field from result before comparing it, and fail the test when it is absent,
non-numeric, or otherwise invalid. Use the existing smoke-test flow around the
wait_ms check so the failure is reported from the same validation path.

In `@examples/AutoResearch/AutoResearchRemoteDriverMethods.cpp`:
- Around line 710-722: Validate mosi_pin, sclk_pin, and clock_hz before the
narrowing casts in AutoResearchRemoteDriverMethods::spi-related handling so
invalid or non-positive values are rejected before reaching the FlexIO path. Add
explicit range checks alongside the existing num_bytes validation, and only then
pass the values into fl::flexio_spi_lookup_pins and the subsequent FlexIO setup
so wraparound cannot occur.
- Around line 646-648: The RPC comment in AutoResearchRemoteDriverMethods.cpp
overstates what the handler returns by mentioning a FlexIO2 register snapshot
that is not actually included in the response payload. Update the comment near
the affected RPC handler so it only describes the fields the response really
provides, and remove or reword the FlexIO2 snapshot language to match the actual
success/failure payload returned by the method.

---

Nitpick comments:
In `@ci/autoresearch/test_flexio_spi_smoke.py`:
- Around line 98-122: The evaluate() helper currently returns an unnamed tuple
of (bool, str), which should be replaced with a small named dataclass result so
callers can access fields explicitly. Update evaluate(case, result) in
test_flexio_spi_smoke.py to return a result dataclass with clear fields for
success/status and message, and adjust the call site(s) that consume its return
value to use the named attributes instead of tuple unpacking; use the evaluate
symbol to locate the function and keep the PASS/FAILED message construction
unchanged.
- Around line 43-49: Add runtime type validation to the new SmokeCase dataclass
by decorating SmokeCase with `@typechecked`. Update the SmokeCase definition in
test_flexio_spi_smoke.py so its fields still use the existing annotations while
enabling typeguard-style checking for instances created in ci/.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e3d717dc-12f8-46ad-bf03-e875ce432173

📥 Commits

Reviewing files that changed from the base of the PR and between 070316d and 7c79120.

📒 Files selected for processing (2)
  • ci/autoresearch/test_flexio_spi_smoke.py
  • examples/AutoResearch/AutoResearchRemoteDriverMethods.cpp

zackees added a commit that referenced this pull request Jun 27, 2026
#3428)

Replaces the scaffolding stub with the full DMA-bit-banged SPI design:
FlexPWM2_SM0 drives eDMA writes to GPIO6_DR at 2*SCLK rate, each input
byte expanded to 16 32-bit words alternating MOSI/SCLK phases. MOSI and
SCLK must both be on GPIO6 (the same bank ObjectFLED clockless mode uses);
runtime serialization through ObjectFLEDDmaManager::acquire()/release()
prevents the two modes from racing on the shared peripheral.

Hardware bring-up status
- Pin lookup VERIFIED on real Teensy 4.1 (COM20): pin 14->bit 18,
  pin 15->bit 19, pin 16->bit 23, pin 17->bit 22 (matches digitalPinToBit
  and the GPIO6 pad routing).
- FlexPWM2 register sequence NOT yet hardware-verified -- the first
  show() call hard-faults the Teensy. Initial CCM gate bug (bits 22-23
  vs the correct 18-19) is fixed; a remaining issue still triggers the
  fault. Likely candidates for scope-debug:
    * FlexPWM2 SM0CTRL2 INIT_SEL / CLK_SEL values (RM 30 cross-check).
    * eDMA channel allocation conflict during early boot.
    * GPIO6_DR direct write while clockless mode's GPR26 remap is in
      an unexpected partial state from a prior test boot.

Safety latch
- objectfled_spi_init() returns false unless FL_OBJECTFLED_SPI_HARDWARE_ENABLE
  is defined. Default (undefined) means SPI channels fall through to the
  next bus (FlexIO-SPI from PR #3431) via canHandle returning false.
  Flipping the flag re-enables the full path for bench debug.
- channel_engine_objectfled.cpp.hpp gates its canHandle SPI branch on
  the same macro so a user can't accidentally route SPI to a driver
  whose hardware path is known to crash.

Architectural scaffolding (unchanged from prior commit; ships ready)
- Capabilities(true, true), BusSupports<Bus::OBJECT_FLED, SpiChipsetConfig>,
  canHandle SPI branch, ObjectFLEDSPIPinInfo struct, full lookup/init/
  show/wait/deinit API.

Test infrastructure (new)
- examples/AutoResearch/AutoResearchRemoteDriverMethods.cpp: new RPC
  binding `objectfledSpiSelfTest` (mirrors `flexioSpiSelfTest` from
  PR #3431). Exercises the full lookup -> init -> show -> wait -> deinit
  path with a known byte pattern.
- ci/autoresearch/test_objectfled_spi_smoke.py: host-side driver.
  Currently passes the LOOKUP stage on all 3 test configurations
  (1/6/12 MHz, multiple pin pairs) but reports init_ok=false as expected
  while the hardware gate is off. Ready to validate full path once the
  FL_OBJECTFLED_SPI_HARDWARE_ENABLE flag is flipped after bench debug.

What this PR delivers
- Compiles on teensy40 + teensy41.
- 338/338 host tests pass.
- Lint clean.
- Firmware boots and runs cleanly with the new ObjectFLED-SPI code
  linked in (no crash unless the hardware-enable flag is set).
- Pin lookup hardware-verified on Teensy 4.1.

What this PR does NOT yet deliver
- End-to-end SPI transmission on hardware (gated until FlexPWM2
  register sequence is scope-debugged).
- APA102/SK9822 strip lighting up.

Refs #3428, #3430, #3431.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees and others added 2 commits June 27, 2026 15:34
…tate reset, header discipline, arg validation)

Four fixes from CodeRabbit's review of #3431, all hardware-verified to
keep the 3/3 smoke-test pass on Teensy 4.1:

1. Ceiling division for SPI baud divider (MAJOR correctness).
   The floor calc had `120 MHz / (2 * 25 MHz) = 2` → div_field=1 → actual
   SCLK = 120/(2*2) = 30 MHz, exceeding the 25 MHz upper clamp. Switch to
   `(num + denom - 1) / denom` so actual SCLK never exceeds the requested
   rate. (flexio_spi_mode.cpp.hpp:241)

2. Reset cached engine state immediately after deinit (MAJOR stability).
   Both clockless and SPI reinit paths in show() called deinit() then ran
   validation/init that could `continue` on failure, leaving
   mHwInitialized/mCurrentMode advertising a torn-down config. A later
   channel could then skip reinit and transmit through deinitialized
   hardware. Now reset state right after each deinit().
   (channel_engine_flexio.cpp.hpp:163 + :221)

3. Move getCapabilities() body out of the header (MAJOR header discipline).
   Per the project's `src/**/*.h` rule: declarations only, no inline
   definitions. Body moved to channel_engine_flexio.cpp.hpp.
   (channel_engine_flexio.h:91 → channel_engine_flexio.cpp.hpp)

4. Validate pin / clock_hz ranges before narrowing casts (MAJOR validation).
   `flexioSpiSelfTest` RPC narrowed user-supplied `mosi_pin` /  `sclk_pin`
   directly to u8 and `clock_hz` to u32; out-of-range inputs (e.g.
   mosi_pin=270 wraps to pin 14) would silently route to wrong hardware.
   Now reject [-, -1] U [256, ∞) for pins and [-, 0] for clock_hz with
   InvalidArgs before the cast.
   (AutoResearchRemoteDriverMethods.cpp:flexioSpiSelfTest)

Verified:
  - bash test --cpp -> 338/338 pass
  - bash lint --cpp -> clean
  - bash compile teensy41 --examples AutoResearch -> succeeds
  - flexioSpiSelfTest on real Teensy 4.1 -> 3/3 pass at 1/6/12 MHz

Refs #3428, #3431.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Mirror of the same fix on PR #3432's test_objectfled_spi_smoke.py:
`__doc__` can be `None` if Python runs with `-OO`, so guard before
calling `.splitlines()`.

Caught by the same stop-hook lint pass (`ty` type checker).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jun 28, 2026
…SPI_HARDWARE_ENABLE=1)

Flip the gate to ENABLED-by-default per user directive. The DMA transmit
cycle is hardware-verified on Teensy 4.1 (3/3 smoke tests at 1/6/12 MHz
with wait_ms=5 = drain-only, DMA_ES=0 = no errors).

What changes:
  - objectfled_spi_mode.cpp.hpp: `FL_OBJECTFLED_SPI_HARDWARE_ENABLE` now
    auto-defines to 1 unless `FL_OBJECTFLED_SPI_HARDWARE_DISABLE` is
    explicitly defined by the user (opt-out, not opt-in).
  - channel_engine_objectfled.cpp.hpp: canHandle SPI branch gated on
    `!defined(FL_OBJECTFLED_SPI_HARDWARE_DISABLE)` instead of the
    opt-in `defined(FL_OBJECTFLED_SPI_HARDWARE_ENABLE)`.

Re-verified on Teensy 4.1 (COM20) -- 3/3 smoke test pass remains:
  1 MHz @ 14/15 (4B)   -> wait_ms=5
  6 MHz @ 14/15 (16B)  -> wait_ms=5
  12 MHz @ 16/17 (64B) -> wait_ms=5

The opt-out flag `FL_OBJECTFLED_SPI_HARDWARE_DISABLE` is provided for
users who prefer the prior "SPI falls through to next bus" behavior --
e.g. if they want SPI channels to land on FlexIO-SPI (from #3431) instead.

Refs #3428, #3432.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees and others added 3 commits June 27, 2026 18:06
…ensy 4.x

Per user directive #3428 ("single strip should not default LPSPI because
that can be allocated already for peripherals where the parallel io
drivers are more likely to be free and can be purposed for spi usage").

With FlexIO-SPI hardware-verified (this PR's smoke test passes 3/3 on
Teensy 4.1 at 1/6/12 MHz), the parallel-IO peripheral is the right
default for SPI chipsets (APA102 / SK9822 / HD108 / etc) on Teensy 4.x.

Why FlexIO over ObjectFLED for the SpiChipsetConfig default:
- FlexIO is a true hardware SPI master engine (shifter + timer),
  ObjectFLED-SPI is DMA-bit-banged (slower, more memory).
- FlexIO2's dedicated pin pool {6, 7, 8, 9, 10, 11, 12, 13, 32} rarely
  collides with user GPIO use. ObjectFLED-SPI uses the GPIO6 bank,
  which overlaps with many common Teensy pins.
- LPSPI is the prior "implicit default" and is often already claimed by
  user peripherals (per the user's reason cited above).

Users who explicitly want LPSPI, BIT_BANG, or ObjectFLED-SPI can still
pick those via `FastLED.add<Bus::LPSPI, SpiChipsetConfig>(cfg)` etc.

Refs #3428, #3431.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Five fixes from CodeRabbit's follow-up review:

1. Restore pin muxes on DMA allocation failure (MAJOR stability).
   flexio_spi_init() saves MOSI/SCLK mux state at entry, then switches
   both pads to ALT4|SION. If the subsequent DMAChannel allocation
   fails, restore the saved muxes (and clear SPI_FLEXIO2_CTRL) before
   returning false so the pins are not left stolen by a failed init.
   (flexio_spi_mode.cpp.hpp:343)

2. Strict wait_ms validation in smoke test (MINOR correctness).
   `int(result.get("wait_ms", 0))` silently defaulted a missing/
   non-integer wait_ms to 0, which could let a malformed firmware
   response pass the smoke test. Now require an actual int (reject
   bool, None, str, etc.) and fail with a clear message otherwise.
   (ci/autoresearch/test_flexio_spi_smoke.py:111)

3. Align flexioSpiSelfTest RPC comment with actual payload (MINOR docs).
   The doc-comment claimed the handler returned a "snapshot of the
   FlexIO2 peripheral registers", but the response only contains
   stage-success flags and resolved pin indices. Updated to match.
   (AutoResearchRemoteDriverMethods.cpp:646)

4. Use %d/%u format specifiers for integer log args (MINOR style).
   Several FL_LOG_FLEXIO_F() call sites passed `(int)pin` / `(int)hz`
   with `%s` specifiers. `fl::printf` is type-safe so this is not UB,
   but the specifiers should match the argument type. Switched pin
   args to `%d` and clock_hz/timeout_ms args to `%u` across
   channel_engine_flexio.cpp.hpp, flexio_driver.cpp.hpp, and
   flexio_spi_mode.cpp.hpp.

5. Guard flexio_spi_show() return value before wait (MINOR robustness).
   ChannelEngineFlexIO::show() previously called flexio_spi_wait()
   unconditionally even if flexio_spi_show() returned false (e.g.
   peripheral not initialized, null buffer). wait() short-circuits in
   that case but the new guard makes the dependency explicit and
   prevents the loop from advancing as if DMA had been armed.
   (channel_engine_flexio.cpp.hpp:264)

Verified:
  - bash test --cpp -> all pass
  - bash lint -> clean
  - bash compile teensy41 --examples AutoResearch -> succeeds
    (only pre-existing -Wunused-variable warnings on SHIFTBUF / SHIFTBUFBIS)

Refs #3428, #3431.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ntime

CodeRabbit (#3431) noted the comment claimed the FlexIO SPI helpers
were stubbed, which would have made the BusSupports<FLEX_IO,
SpiChipsetConfig> specialization an empty promise. The helpers are
no longer stubbed -- flexioSpiSelfTest passes 3/3 at 1/6/12 MHz on
real Teensy 4.1 hardware (see PR #3431, commit f13dc0e). Update the
comment to point at the smoke test instead of claiming a stub.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 46d6668 into master Jun 28, 2026
13 of 17 checks passed
@zackees
zackees deleted the feat/flexio-spi-driver branch June 28, 2026 01:25
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 28, 2026
zackees added a commit that referenced this pull request Jun 28, 2026
… (no prefix) (#3434)

Per user directive 2026-06-27 "when in doubt use private namespaces" --
follow-up cleanup for the prefix-rename workaround that landed with
#3431 / #3432.

Both `flexio_spi_mode.cpp.hpp` and `objectfled_spi_mode.cpp.hpp` now wrap
their file-static state + private helpers in matching named namespaces:

  - fl::detail::flexio_spi_internal
  - fl::detail::objectfled_spi_internal

Each public API function (those in the .h header) opens with
`using namespace detail::xxx_spi_internal;` so the bodies reference the
private state without the namespace prefix. The two drivers' identically-
named symbols (sSpiCurrentPins, sSpiDmaChannel, ...) now live in
different namespaces, so they don't collide in the unity build
(fl/build/platforms+.cpp).

The ObjectFLED side drops the `sOfSpi*` / `kOfSpi*` / `of_spi_*` prefix
that was the previous workaround for the unity-build collision -- the
private namespace handles it cleanly now.

Hardware-verified on Teensy 4.1 (COM20) after the refactor:
  - flexioSpiSelfTest:    3/3 pass (wait_ms=0)
  - objectfledSpiSelfTest: 3/3 pass (wait_ms=5 = drain only)

Build / lint clean (bash test --cpp / bash lint / bash compile teensy41).

Refs #3428, #3431, #3432.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant