Skip to content

docs(channels): require unified clockless+SPI engine for parallel-IO peripherals - #3430

Merged
zackees merged 1 commit into
masterfrom
docs/parallel-io-unified-driver-rule
Jun 28, 2026
Merged

zackees merged 1 commit into
masterfrom
docs/parallel-io-unified-driver-rule

Conversation

@zackees

@zackees zackees commented Jun 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Captures the architectural rule established during the #3428 FlexIO-SPI / ObjectFLED-SPI driver implementation: any parallel-IO peripheral (FlexIO, ObjectFLED, ESP32 PARLIO, LCD_CAM, I2S, etc.) MUST handle both its clockless and its SPI mode in a single ChannelEngine — not as forked sibling engines.

The initial #3428 draft introduced Bus::FLEX_IO_SPI / Bus::OBJECT_FLED_SPI enum slots plus separate ChannelEngineFlexIOSPI / ChannelEngineObjectFLEDSPI classes, which 4×ed the maintenance surface (Bus enum entries, priority-table rows, registration calls, _build.cpp.hpp includes, BusTraits<> specializations, channel-manager name lookups) for zero behavioral benefit — the peripheral can only run one mode at a time anyway, so the mode switch belongs inside show().

What's in the rule

  • getCapabilities() returns Capabilities(true, true) for unified engines (both clockless AND SPI)
  • BusSupports<Bus::X, ClocklessChipset> AND BusSupports<Bus::X, SpiChipsetConfig> both specialize to fl::true_type
  • canHandle() accepts both chipset families, gated by per-mode pin/timing routability
  • show() routes per-channel via data->isClockless() vs data->isSpi() and reconfigures the peripheral on mode change
  • One Bus::X selector serves both modes

Exception (still get separate drivers)

Genuinely separate peripherals — e.g. ESP32 LPSPI vs I2S_SPI are different silicon, register surfaces, DMA channels, clock trees. Two drivers is correct there. The rule covers different-mode-same-peripheral, not different-peripheral-same-protocol.

Files changed

File What
src/fl/channels/README.md Full pattern + reference code under "Implementing a Custom Channel Engine"
agents/docs/cpp-standards.md Coding-standard entry "Parallel-IO Driver: Unified Clockless + SPI Engine (REQUIRED)"
.coderabbit.yaml path_instructions for src/fl/channels/bus.h and src/platforms/**/drivers/**/channel_engine_*.{h,cpp.hpp} so CodeRabbit flags forking PRs
.claude/agents/architecture-reviewer-agent.md Subagent checklist section "Channel Driver Architectural Checks (Parallel-IO peripherals)"

Why ship this as a separate PR

So CodeRabbit + the architecture-reviewer subagent start enforcing the rule on the same review pass as the #3428 driver PRs that introduce the pattern, rather than landing in one bundle where the rule and its violations would be reviewed against each other.

Test plan

  • CI green (docs-only, no code touched)
  • CodeRabbit picks up the new path_instructions on next PR touching bus.h or any channel_engine_*

Refs #3428.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Added clearer guidance for building and reviewing parallel-IO peripheral drivers.
    • Documented how clockless and SPI modes should be handled within a single engine, including capability reporting, channel handling, and mode switching behavior.
    • Expanded review rules and standards notes with additional checks for platform, build, and configuration consistency.
    • Clarified the exception for genuinely separate peripherals and added reference examples for implementers.

…peripherals

Capture the architectural rule established during the #3428 FlexIO-SPI /
ObjectFLED-SPI implementation: any parallel-IO peripheral (FlexIO,
ObjectFLED, ESP32 PARLIO, LCD_CAM, I2S, etc.) MUST handle both its
clockless and its SPI mode in a single ChannelEngine.

The initial #3428 draft forked into separate Bus::FLEX_IO_SPI /
Bus::OBJECT_FLED_SPI enum slots plus parallel ChannelEngineXxxSPI
classes. That 4xed the maintenance surface (Bus enum, priority table,
registration, _build.cpp.hpp, BusTraits specializations, channel
manager lookup) for zero behavioral benefit -- the peripheral can only
run one mode at a time anyway, so the mode switch belongs in show().

Files updated:
- src/fl/channels/README.md           full pattern + reference code
- agents/docs/cpp-standards.md        coding-standard rule entry
- .coderabbit.yaml                    auto-flag forks in PR review
- .claude/agents/architecture-reviewer-agent.md  subagent checklist

Exception (still get separate drivers): genuinely separate peripherals
e.g. ESP32 LPSPI vs I2S_SPI are different silicon, different register
surfaces, different DMA. The rule covers different-mode-same-peripheral,
not different-peripheral-same-protocol.

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

Warning

Ignoring CodeRabbit configuration file changes. For security, only the configuration from the base branch is applied for open source repositories.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bae82882-f8dc-4fe5-bd8b-dc3f968d5710

📥 Commits

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

📒 Files selected for processing (4)
  • .claude/agents/architecture-reviewer-agent.md
  • .coderabbit.yaml
  • agents/docs/cpp-standards.md
  • src/fl/channels/README.md

📝 Walkthrough

Walkthrough

Adds documentation and automated review enforcement for a rule requiring parallel-IO peripheral drivers to implement a single ChannelEngine for both clockless (WS281x-style) and clocked SPI modes. The rule is documented in src/fl/channels/README.md, agents/docs/cpp-standards.md, and .claude/agents/architecture-reviewer-agent.md, and enforced via new path_instructions in .coderabbit.yaml.

Changes

Parallel-IO Unified ChannelEngine Rule

Layer / File(s) Summary
Unified engine rule in README and cpp-standards
src/fl/channels/README.md, agents/docs/cpp-standards.md
Documents the requirement that parallel-IO peripherals use one ChannelEngine for both clockless and SPI modes, specifying getCapabilities(), canHandle(), and show() behavior, plus exception for separate silicon blocks and historical rationale.
Architecture reviewer agent and coderabbit enforcement
.claude/agents/architecture-reviewer-agent.md, .coderabbit.yaml
Adds the parallel-IO channel driver checks to the architecture reviewer agent and extends .coderabbit.yaml path_instructions with rules covering macro naming, binary-size lockdown, platformio.ini change requirements, FL_* prefix enforcement, header constraints, public settings wrappers, and logging visibility.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related PRs

  • FastLED/FastLED#2462: Updates src/fl/channels/README.md with canHandle()/show() dispatch semantics that align with this PR's unified parallel-IO engine rule.
  • FastLED/FastLED#3054: Also updates .coderabbit.yaml to enforce FL_* naming and prohibit FASTLED_* macros, overlapping directly with the new path_instructions added here.

Poem

🐇 One engine to rule the wires,
Clockless pulses and SPI fires —
No splitting buses, no doubled enum names,
One show() to switch all the channel frames.
The rabbit hops through unified lanes! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main documentation change about unified clockless+SPI engines for parallel-IO peripherals.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docs/parallel-io-unified-driver-rule

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.

zackees added a commit that referenced this pull request Jun 27, 2026
…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]>
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
zackees merged commit dbbe395 into master Jun 28, 2026
7 of 14 checks passed
@zackees
zackees deleted the docs/parallel-io-unified-driver-rule branch June 28, 2026 01:24
zackees added a commit that referenced this pull request Jun 28, 2026
* feat(flexio): unified clockless + SPI engine scaffolding (#3428)

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

* feat(flexio-spi): implement FlexIO2 SPI master hardware programming (#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]>

* test(flexio-spi): add hardware bring-up smoke test (#3428)

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

* fix(flexio-spi): address coderabbitai PR #3431 review (ceiling div, state 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]>

* fix(ci): guard against __doc__ being None in test_flexio_spi_smoke

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

* feat(channels): set DefaultBus<SpiChipsetConfig> = Bus::FLEX_IO on Teensy 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]>

* fix(flexio-spi): address coderabbitai second-pass review (PR #3431)

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

* docs(flexio-spi): update bus_traits comment to reflect working SPI runtime

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 28, 2026
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