Skip to content

feat(rx): FlexIO RX backend skeleton (Phase 1A of #2764) - #2765

Merged
zackees merged 1 commit into
masterfrom
feat/flexio-rx-backend-skeleton
Jun 5, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/flexio-rx-backend-skeleton

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Phase 1A of #2764 — lands the public API surface for the Teensy 4.x FlexIO RX backend without touching FLEXIO1 hardware programming yet.

Splits Phase 1 of the parent issue into two reviewable PRs:

  • 1A (this PR): stable API surface — enums, dispatcher, skeleton driver, platform specializations
  • 1B (next PR): FLEXIO1 pin-mapping table, shifter + timer config, DMAMUX/eDMA wiring, capture-buffer → edge-time decoder

This split unblocks Phase 2 (the RPC flexioRxBenchmark harness can already select RxBackend::FLEXIO) and Phase 3 (the ObjectFLED loopback test can wire up the backend) without coupling them to the hardware bring-up cycle.

Diff at a glance

File Change
src/fl/channels/rx/types.h Added RxBackend::FLEXIO = 4 + toString() mapping
src/fl/channels/rx.h Added RxDeviceType::FLEXIO = 4 + toString() mapping
src/fl/channels/rx/channel.cpp.hpp Dispatcher case for RxBackend::FLEXIO
src/fl/channels/rx.cpp.hpp Per-platform RxDevice::create<FLEXIO> specializations (Teensy 4 → real, Stub → NativeRxDevice, ESP32 → dummy, other → dummy). PLATFORM_DEFAULT on Teensy stays on FLEXPWM.
src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.h New FlexIoRxChannel class
src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp Skeleton impl — all RxDevice methods return safe placeholders (TIMEOUT/success(0)/empty/false) so callers correctly treat the channel as inactive
src/platforms/arm/teensy/teensy4_common/_build.cpp.hpp Wired into the unity build

Why the skeleton-first split

The FlexPWM RX driver (the reference design) is 776 lines of register programming. Doing the full FlexIO RX port + verification in one PR would:

  • Couple API design review with hardware bring-up debugging
  • Block Phase 2/3 progress on hardware iteration cycles
  • Make the diff hard to review (small protocol changes hidden in large register listings)

Splitting at the API boundary means:

  • This PR is a stable interface review — clear what's exposed, easy to spot regressions
  • Phase 1B's diff is only hardware programming, easier to bring up and bisect
  • Phase 2's RPC harness already has a real RxBackend::FLEXIO enum to call against

Behavior on each platform

  • Teensy 4.0 / 4.1: RxDevice::create<RxDeviceType::FLEXIO>(pin) returns a real FlexIoRxChannel whose methods report inactive — begin() returns false with a FL_WARN referencing [meta] Bootstrap AutoResearch driver development for Teensy 4.0 — FlexIO RX + first LED driver verification #2764, wait() returns TIMEOUT, decode() returns success(0), getRawEdgeTimes() returns 0, injectEdges() returns false
  • Host stub: routes to NativeRxDevice (same as the other RX backends) so host-stub tests can exercise RxBackend::FLEXIO against the synthetic capture buffer
  • ESP32: DummyRxDevice with message "FLEXIO RX not supported on ESP32"
  • Other platforms: DummyRxDevice via createDummy() singleton

PLATFORM_DEFAULT on Teensy 4.x deliberately still resolves to FLEXPWM — the default switch waits until Phase 3 verifies the end-to-end loopback, per the parent-issue plan.

Verification

  • ✅ Host C++ tests pass (226/226)
  • ✅ C++ lint clean (bash lint --cpp)
  • ✅ Teensy 4.0 release build clean for examples/AutoResearch via fbuild (~1m 07s)
  • ✅ The dev-bench Teensy 4.0 AutoResearch sketch + RPC harness was confirmed alive (96+ min uptime, findConnectedPins returns GPIO 3↔4, drivers lists FLEX_IO + SPI_UNIFIED + OBJECT_FLED + BIT_BANG) before this change; selection of the new backend remains opt-in (explicit RxBackend::FLEXIO)

Refs

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added FLEXIO receiver backend support for Teensy 4.x platforms as a Phase 1A skeleton implementation.
    • FLEXIO backend can now be selected and dispatched, with placeholder functionality pending full hardware integration in Phase 1B.
  • Documentation

    • Updated platform documentation to clarify Teensy 4.x default receiver settings.

Lands the public API surface for the Teensy 4.x FlexIO RX backend without
touching FLEXIO1 hardware programming yet. This unblocks Phase 2 (the RPC
benchmark harness can already select RxBackend::FLEXIO) and Phase 3 (the
ObjectFLED loopback test can wire up the backend) without coupling them to
the hardware bring-up cycle.

Skeleton design:
- `RxBackend::FLEXIO` enum value added in `src/fl/channels/rx/types.h`
- `RxDeviceType::FLEXIO` enum value + `toString()` mapping added in
  `src/fl/channels/rx.h`
- `createBackendDevice()` dispatcher in `src/fl/channels/rx/channel.cpp.hpp`
  routes the new case
- `src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.{h,cpp.hpp}`
  contains the FlexIoRxChannel class with the full RxDevice interface; all
  methods currently return safe placeholders (`TIMEOUT`/`success(0)`/empty)
  so the channel reports inactive until Phase 1B replaces the bodies with
  FLEXIO1 + DMAMUX + eDMA programming
- Per-platform `RxDevice::create<RxDeviceType::FLEXIO>` specializations in
  `src/fl/channels/rx.cpp.hpp`:
    - Teensy 4.x  → constructs the new FlexIoRxChannelImpl
    - Stub        → routes to NativeRxDevice (host-stub tests can exercise it)
    - ESP32       → DummyRxDevice with explanatory message
    - Unsupported → DummyRxDevice (createDummy() singleton)
- Unity build wired in
  `src/platforms/arm/teensy/teensy4_common/_build.cpp.hpp`

Notably the Teensy `PLATFORM_DEFAULT` deliberately still resolves to FLEXPWM
— switching the default to FLEXIO is held back to a separate PR after Phase
3 verifies the end-to-end loopback (per the issue plan, to keep the existing
FlexPWM-based AutoResearch flows untouched).

Verification:
- Host C++ tests pass (226/226)
- C++ lint clean (`bash lint --cpp`)
- Teensy 4.0 release build clean for `examples/AutoResearch` via fbuild
- AutoResearch RPC harness on the dev-bench Teensy 4.0 was confirmed alive
  before this change; behavior is unchanged since the new backend is
  selectable only by explicit RxBackend::FLEXIO request

Phase 1B (next PR): FLEXIO1 pin-mapping table, shifter + timer config,
DMAMUX/eDMA wiring, capture-buffer → edge-time decoder.

Refs #2764

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

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a new FLEXIO RX backend for Teensy 4.x following a Phase 1A skeleton pattern. It introduces RxBackend::FLEXIO and RxDeviceType::FLEXIO enums, wires dispatch in the device creation path, implements platform-specific factories (with graceful fallbacks on unsupported platforms), and provides a complete but inert FlexIoRxChannel driver class for Teensy 4.x that will receive hardware register wiring in Phase 1B.

Changes

FLEXIO RX Backend Initialization

Layer / File(s) Summary
Backend and device type enum definitions
src/fl/channels/rx/types.h, src/fl/channels/rx.h
Enum RxBackend adds FLEXIO = 4 with toString() case; enum RxDeviceType adds FLEXIO = 4 with toString() case.
RxBackend dispatch wiring
src/fl/channels/rx/channel.cpp.hpp
createBackendDevice switch adds case RxBackend::FLEXIO to create RxDeviceType::FLEXIO device for configured pin.
Platform-specific RxDevice::create<FLEXIO> factories
src/fl/channels/rx.cpp.hpp
Template specializations across all platforms: ESP32 returns unsupported DummyRxDevice, Teensy 4.x creates FlexIoRxChannel or falls back to DummyRxDevice, stub/native maps to NativeRxDevice for testing, unsupported platforms return DummyRxDevice. Teensy 4.x include and platform-default comment updated.
Teensy 4.x FlexIO RX driver skeleton
src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.h, src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp, src/platforms/arm/teensy/teensy4_common/_build.cpp.hpp
FlexIoRxChannel class header declares factory and full RxDevice interface. Phase 1A implementation provides inert stubs: begin() logs unimplemented warning and returns false, finished() always false, wait() always TIMEOUT, decode() returns 0 bytes, getRawEdgeTimes() returns no times, injectEdges() returns false. Factory always constructs shared FlexIoRxChannelImpl instance. Build unity header includes implementation file.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

  • FastLED/FastLED#2764: This PR implements the exact FLEXIO RX backend bootstrap and Phase 1A skeleton checkpoint described in the meta-issue tracking FLEXIO RX support.

Possibly related PRs

  • FastLED/FastLED#2400: This PR extends fl::RxChannel backend/device dispatch with a new RxBackend::FLEXIO, directly complementing the prior PR's introduction of the RxChannel API built around backend selection.

Poem

🐰 The FLEXIO returns with phase-one grace,
Backend enums in their rightful place,
Teensy skeletons wait for wires to bind,
Platform paths dispatch by design—
Phase 1B approaches, hardware in mind! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.45% 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 'feat(rx): FlexIO RX backend skeleton (Phase 1A of #2764)' clearly and specifically summarizes the main change - adding a FlexIO RX backend skeleton implementation as Phase 1A of issue #2764, which is the primary objective of this pull request.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/flexio-rx-backend-skeleton

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 and usage tips.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/fl/channels/rx.h (1)

438-440: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Missing template specialization declaration for FLEXIO.

The file declares explicit specializations for PLATFORM_DEFAULT, RMT, ISR, and FLEXPWM (lines 435-438), but the FLEXIO specialization declaration is missing. Without it, call sites may implicitly instantiate the primary template, causing ODR violations when the explicit specialization definition in rx.cpp.hpp is linked.

🔧 Proposed fix

Add the FLEXIO template specialization declaration after line 438:

 template <> fl::shared_ptr<RxDevice> RxDevice::create<RxDeviceType::FLEXPWM>(int pin) FL_NOEXCEPT;
+template <> fl::shared_ptr<RxDevice> RxDevice::create<RxDeviceType::FLEXIO>(int pin) FL_NOEXCEPT;
 
 } // namespace fl
🤖 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/fl/channels/rx.h` around lines 438 - 440, Add the missing explicit
specialization declaration for RxDevice::create for RxDeviceType::FLEXIO to the
header so callers don't implicitly instantiate the primary template; locate the
RxDevice::create specializations (e.g., the existing declarations for
RxDeviceType::PLATFORM_DEFAULT, RMT, ISR, FLEXPWM) and add a matching
declaration for RxDeviceType::FLEXIO (template <> fl::shared_ptr<RxDevice>
RxDevice::create<RxDeviceType::FLEXIO>(int pin) FL_NOEXCEPT;) adjacent to them.
🤖 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.

Outside diff comments:
In `@src/fl/channels/rx.h`:
- Around line 438-440: Add the missing explicit specialization declaration for
RxDevice::create for RxDeviceType::FLEXIO to the header so callers don't
implicitly instantiate the primary template; locate the RxDevice::create
specializations (e.g., the existing declarations for
RxDeviceType::PLATFORM_DEFAULT, RMT, ISR, FLEXPWM) and add a matching
declaration for RxDeviceType::FLEXIO (template <> fl::shared_ptr<RxDevice>
RxDevice::create<RxDeviceType::FLEXIO>(int pin) FL_NOEXCEPT;) adjacent to them.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 01e141e6-6e4b-4e3d-8671-3c049452965f

📥 Commits

Reviewing files that changed from the base of the PR and between ee3e7bd and dcb66a2.

📒 Files selected for processing (7)
  • src/fl/channels/rx.cpp.hpp
  • src/fl/channels/rx.h
  • src/fl/channels/rx/channel.cpp.hpp
  • src/fl/channels/rx/types.h
  • src/platforms/arm/teensy/teensy4_common/_build.cpp.hpp
  • src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp
  • src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.h

@zackees
zackees merged commit 3b8838f into master Jun 5, 2026
9 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 5, 2026
zackees added a commit that referenced this pull request Jun 5, 2026
Replaces the Phase 1A skeleton (PR #2765) bodies with real FLEXIO1 register
programming, IOMUXC pin muxing, and an eDMA-driven capture pipeline. The
public RxDevice API is unchanged.

Capture strategy (input-edge timing measurement, per NXP AN12686 §4 +
iMXRT1062 reference manual chapter 50):

  Timer 0: 16-bit counter, TRGSEL = 2*pin+1 (external pin edge), TIMRST =
           trigger-rising → counter restarts on every input edge so the
           latched value equals the inter-edge tick count. Counts at the
           FlexIO functional clock (~120 MHz on Teensy 4 → ~8.3 ns/tick).

  Shifter 0: receive mode (SMOD=1), TIMSEL=0, PINSEL=N. Each Timer 0
             restart latches the elapsed ticks into SHIFTBUF[0].

  DMAMUX_SOURCE_FLEXIO1_REQUEST0 → eDMA streams SHIFTBUF[0] reads into a
  user-sized capture buffer (default 1024 deltas, capped at 4096).

Pin-map (`kFlexIo1Pins[]`): initial entry for Teensy pin 4 (GPIO_EMC_06 →
FLEXIO1_FLEXIO06 via ALT4) — this matches the GPIO 3↔4 jumper on the dev
bench so Phase 2's square-wave validation can target pin 4 immediately.
The table is set up for trivial expansion as bench tests qualify the rest
of the GPIO_EMC_* bank.

Clock-gate setup: enables FLEXIO1 via CCM_CCGR5_FLEXIO1, divides PLL3_PFD3
(480 MHz) by PRED=2 / PODF=2 → ~120 MHz to match the FlexIO TX driver's
divider. This keeps the ns-per-tick conversion identical across both
backends.

`begin()` allocates the DMA channel, configures FLEXIO1 + the pin pad
(ALT4 + 100 kΩ pull-up keeper + hysteresis for clean edge detection),
arms the DMA, and enables the FlexIO module.

`wait()` polls `mReceiveDone` (set by the DMA-completion ISR) with the
caller-provided timeout. `decode()` walks the capture buffer, converts each
16-bit tick count to nanoseconds, and emits one `EdgeTime{level, ns}` per
segment. `getRawEdgeTimes()` exposes the same edge stream to callers (e.g.
the AutoResearch RPC) that prefer raw access.

Unity-build hygiene:
- `#undef FLEXIO1_*` macros from imxrt.h before declaring our typed
  register accessors (same pattern as the FlexIO TX driver does for
  FLEXIO2).
- `lookupPin()` renamed to `lookupFlexIo1Pin()` and `kIOMUXC_BASE` renamed
  to `kFlexIo1IomuxcBase` so anonymous-namespace symbols don't collide
  with the FlexPWM RX driver (same translation unit in the platforms+ TU).

Behavioural scope:
- `RxBackend::PLATFORM_DEFAULT` on Teensy 4.x deliberately STILL resolves
  to FLEXPWM per the #2764 plan — the default switch waits for Phase 3
  end-to-end verification.
- All capture decisions go through the existing `RxDevice` interface, so
  no consumer needs to change.

Verification:
- ✅ Teensy 4.0 release build clean for `examples/AutoResearch`
- ✅ Host C++ tests pass (309/309)
- ✅ C++ lint clean (`bash lint --cpp`)
- ⏳ Hardware-side bench validation is Phase 2 (RPC `flexioRxBenchmark`)
- ⏳ End-to-end ObjectFLED loopback decode is Phase 3

Refs #2764

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jun 5, 2026
…#2764) (#2767)

* feat(autoresearch): flexioRxBenchmark RPC + square-wave Python harness (Phase 2 of #2764)

Adds the bench-validation surface for the FlexIO RX backend from PRs #2765
(skeleton) and #2766 (FLEXIO1 hardware programming).

Firmware side — new `flexioRxBenchmark` RPC binding in AutoResearchRemote.cpp
(Teensy 4.x only; other platforms return `PlatformNotSupported` cleanly):

  Args:
    { "frequency_hz": int = 1000,
      "duration_ms":  int = 100,
      "tx_pin":       int = 3,   // matches GPIO 3↔4 jumper
      "rx_pin":       int = 4 }

  Behavior:
    1. Drives tx_pin with a square wave via analogWriteFrequency() +
       analogWrite(pin, 128) (Teensy core PWM, 50% duty)
    2. Creates an RxChannel with backend = RxBackend::FLEXIO on rx_pin
    3. Captures for duration_ms
    4. Stops the PWM
    5. Pulls captured edges via getRawEdgeTimes() and pairs them into
       periods (period = high_segment_ns + low_segment_ns)
    6. Returns { edges_captured, periods, period_mean_ns, period_sigma_ns,
                 period_min_ns, period_max_ns }

  Integer sqrt is used for σ — adequate for the Phase 2 tolerance ranges
  (σ < 100 ns at 100 kHz).

Python harness side — `ci/autoresearch/test_flexio_rx_squarewave.py`:

  Standalone pyserial-based test driver (no fbuild WebSocket daemon
  needed). Runs three cases matching the parent-issue table:

    | Frequency | Period      | σ tolerance | Mean tolerance |
    |-----------|-------------|-------------|----------------|
    | 1   kHz   | 1 000 000ns | < 1 000 ns  | ±1 %           |
    | 10  kHz   |   100 000ns | <   500 ns  | ±1 %           |
    | 100 kHz   |    10 000ns | <   100 ns  | ±1 %           |

  Exits 0 on all pass, 1 on any failure. Default port COM20 + tx/rx
  pins 3/4 match the dev-bench Teensy 4.0 setup.

Verification:
- ✅ Teensy 4.0 release build clean (`examples/AutoResearch`, ~1m 05s)
- ✅ Host C++ tests pass (309/309)
- ✅ C++ lint clean
- ⏳ Live bench-validation on the dev Teensy 4.0 lands once the firmware
     is reflashed with this RPC

Note: the firmware still has to be flashed onto the Teensy 4.0 before the
Python harness can validate the FlexIO RX capture path end-to-end. That's
a separate hardware step held out of this PR to keep the diff focused on
the software surface.

Refs #2764

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

* fix(autoresearch): address CodeRabbit review on PR #2767

Three fixes from the review:

1. **Help registry sync** (CodeRabbit minor):
   - Added `flexioRxBenchmark` to the `help()` function manifest with args,
     returns, phase, and description fields matching the binding above
   - Bumped `totalFunctions` 25 → 26 so any client that relies on `help()`
     gets the up-to-date contract

2. **Capture buffer too small at 10/100 kHz** (CodeRabbit major):
   - At 100 kHz × 100 ms the harness expects ~20 000 edges but the buffer
     was capped at 1024 — sample set was being truncated to ~5 ms.
   - `flexioRxBenchmark` now sizes `edge_capacity` from
     `2 * frequency_hz * duration_ms / 1000` with 50 % headroom, clamped
     to `[1024, 16384]` so RAM use is bounded but the requested window is
     honored.
   - Raised the matching internal cap in `rx_flexio_channel.cpp.hpp`
     `begin()` from 4096 → 16384 (64 KiB, comfortably fits 100 ms at
     100 kHz with headroom) so the channel honors the new larger requests.

3. **`sys.exit(2)` at module import** (CodeRabbit minor):
   - Moved the pyserial dependency check from the import block into
     `main()` so that test-collection (e.g. pytest on a CI runner without
     `pyserial`) doesn't abort the interpreter before the caller can
     decide to skip the hardware bench. The check now reports the same
     error and returns 2 from `main()` instead.

Verification:
- ✅ Teensy 4.0 release build clean (`examples/AutoResearch`, ~1m 10s)
- ✅ C++ lint clean
- Pyright still flags a handful of pre-existing type-narrowing warnings
  on the pyserial wrapper; left as-is since they're not from this change.

Refs #2764, PR #2767 review

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jun 5, 2026
…(Phase 3 of #2764) (#2769)

* feat(autoresearch): ObjectFLED -> FlexIO RX loopback + WS2812 decoder (Phase 3 of #2764)

End-to-end TX -> RX byte verification for the FlexIO RX backend landed in
PRs #2765 / #2766 / #2767. Three pieces:

1. **WS2812 bit decoder wired into FlexIO RX**
   (`src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp`)
   - Phase 1B's `decode()` returned `success(0)` as a placeholder; this PR
     replaces the body with a real edge-pair decoder that walks the captured
     `EdgeTime` stream, classifies each (HIGH, LOW) duration pair as bit 0
     or bit 1 via the `ChipsetTiming4Phase` thresholds, packs the bits into
     bytes MSB-first, and reports buffer-overflow / high-error-rate failures
     identically to the FlexPWM RX path.
   - Static helpers `decodeBitFlexIo` / `decodeEdgesFlexIo` live in the same
     TU rather than extracting to a shared header; the consolidation
     into `src/fl/channels/rx/decode_ws2812.h` is a separate refactor that
     can land after both backends are bench-validated against the same
     test matrix.

2. **`flexioObjectFledTest` RPC**
   (`examples/AutoResearch/AutoResearchRemote.cpp`)
   - Drives WS2812 frames through `Bus::OBJECT_FLED` on `tx_pin`, captures
     via `RxBackend::FLEXIO` on `rx_pin`, decodes against `TIMING_WS2812B_V5`
     4-phase timing, and returns per-byte match counts. Teensy-4-only;
     other platforms return `PlatformNotSupported` cleanly.
   - Five fixed test patterns matching the parent-issue Phase 3 table:
     0 = Red single LED, 1 = RGB three-LED chain, 2 = all zeros,
     3 = all ones, 4 = 100-LED alternating R/G/B.
   - Args: `{ test_case, tx_pin, rx_pin, capture_ms }` (all optional).
   - Returns: `{ success, test_case, tx_pin, rx_pin, num_leds,
                 expected_bytes, decoded_bytes, matched, mismatched,
                 edges_captured }`.
   - Sizes the RX edge buffer from `num_leds * 24 * 2 + 25%`, clamped to the
     16384-entry cap from PR #2767.
   - `help()` manifest updated (totalFunctions 26 -> 27) with full
     args/returns/description so any client relying on `help()` gets the
     up-to-date contract.

3. **Python harness**
   (`ci/autoresearch/test_flexio_rx_objectfled.py`)
   - Standalone pyserial driver, no fbuild daemon dependency.
   - Runs the five test cases in sequence, asserts on
     `decoded == expected && mismatched == 0`, prints PASS/FAIL per case.
   - Same `pyserial`-import-deferred-to-main() pattern from PR #2767 review.
   - Exits 0 on all pass, 1 on any failure.

Compile-side fixups during bring-up (visible in commit diff):
- `fl::ClearFlags::CHANNELS` -> `ClearFlags::CHANNELS` (global enum, not in `fl::`)
- `NamedTimingConfig{resolved_timing, name, encoder}` wrapper around
  `makeTimingConfig<>()` for the TX path; `to_runtime_timing<>()` for the
  RX 4-phase converter
- `fl::span<T>(container)` constructor instead of pointer-pair form
  (fixes the SpanFromPointerChecker hit on the decoder edge stream)

Verification:
- Host C++ tests pass (309/309)
- C++ lint clean
- Teensy 4.0 release build clean for `examples/AutoResearch`
- Hardware-side end-to-end run is the next step — once the firmware is
  flashed to the dev-bench Teensy 4.0, the harness asserts each case in
  under 1 s

Refs #2764

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

* fix(autoresearch): address CodeRabbit review on PR #2769

Three fixes from the Phase 3 review:

1. **TX-completion margin** (CodeRabbit major):
   `capture_ms` allows values down to 1 ms, but for case 4 (100 LEDs) the
   WS2812 transmission alone takes ~3 ms (24 bits × 1.25 µs × 100 + reset).
   If the caller passed a short capture_ms, `FastLED.clear(CHANNELS)` could
   tear the channel down mid-frame and leave hardware in a bad state.

   `flexioObjectFledTest` now computes a minimum capture window from the
   actual WS2812 timing:
     ws2812_tx_us = num_leds * 24 * 1.25 + 100 (reset gap)
     min_capture_ms = ceil(ws2812_tx_us / 1000) + 10
   …and uses `max(caller_capture_ms, min_capture_ms)` for the RX wait.
   At 100 LEDs that's ~13 ms minimum; the caller can still request
   larger windows for noisy environments.

2. **`totalFunctions` stale** (CodeRabbit minor):
   The help() manifest had 28 functions.push_back() calls but
   `totalFunctions` was still 27 (off-by-one — `wave8ExpandBenchmark_fn`
   was added between Phase 2 and Phase 3 and I missed it). Bumped to 28
   so clients relying on `help().totalFunctions` get an accurate count.

3. **Python `main()` testability + Ctrl-C handling**
   (CodeRabbit refactor suggestions):
   - `main()` now accepts an optional `argv: list[str] | None` parameter
     so unit tests can inject argument lists without touching `sys.argv`.
     `argparse.parse_args(argv)` interprets None as "use sys.argv[1:]" so
     CLI behavior is unchanged.
   - The serial-open `try/except` block now catches `KeyboardInterrupt`
     before `SerialException`, so interactive users can Ctrl-C out of
     the harness without dumping a stack trace.

The remaining CodeRabbit Python suggestions (add runtime type validation
to the dataclass, remove default values from send_rpc, return a dataclass
from evaluate() instead of a tuple) are intentionally not adopted — they
are pure-style refactors and the existing patterns match
test_flexio_rx_squarewave.py and ci/precheck_pins.py for consistency
across the autoresearch harness.

Verification:
- ✅ Teensy 4.0 release build clean
- ✅ C++ lint clean

Refs #2764, PR #2769 review

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

* fix(autoresearch): Python @TypeChecked + EvaluationResult dataclass (PR #2769 review)

Two CodeRabbit-flagged repo coding-guideline conformances on the Phase 3
Python harness:

1. `@typechecked` on the `@dataclass TestCase` (per repo guideline
   "Use @TypeChecked decorator with @DataClass for runtime type validation").
2. `evaluate()` now returns a typed `EvaluationResult` dataclass with `ok`
   and `message` fields, replacing the previous `(bool, str)` tuple (per
   repo guideline "Return dataclass structs instead of tuples or dicts for
   functions with multiple return values"). Callsite in `main()` updated
   to read `result.ok` / `result.message`.

Both changes are pure-additive — same call shape, same RPC contract,
same CLI behavior.

Refs #2764, PR #2769 review

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jun 5, 2026
… 4 of #2764) (#2770)

* docs(rx/flexio): FlexIO RX backend docs + enum-comment refresh (Phase 4 of #2764)

Final phase of #2764 — documents the new FlexIO RX backend now that
the skeleton (#2765), hardware (#2766), bench harness (#2767), and
ObjectFLED loopback (#2769) have all landed on master.

Three changes, all documentation-side; no runtime behaviour changes:

1. `src/fl/channels/rx/types.h`:
   - `RxBackend::PLATFORM_DEFAULT` comment now mentions FLEXIO as an opt-in
     alternative on Teensy 4 with a pointer to #2764.
   - `RxBackend::FLEXIO` comment notes that hardware verification ran via
     `flexioRxBenchmark` (1/10/100 kHz square wave) and
     `flexioObjectFledTest` (5-pattern ObjectFLED loopback).

2. `src/fl/channels/rx.h`:
   - Matching `RxDeviceType::PLATFORM_DEFAULT` comment refreshed.

3. `agents/docs/hardware-autoresearch.md`:
   - New top-level section "FlexIO RX Backend (Teensy 4 — opt-in)" covering:
     * How to select the backend in C++ and Python
     * Pin map (Teensy pin -> FLEXIO1 input -> IOMUXC offsets)
     * Peripheral resource budget (Shifter 0, Timer 0, DMA, FLEXIO1
       functional clock)
     * Verification surface (flexioRxBenchmark + flexioObjectFledTest with
       acceptance criteria)
     * Explicit note that `PLATFORM_DEFAULT` stays on FlexPWM until the
       follow-up default-switch PR

Intentionally NOT in this PR (per the #2764 parent-issue plan):
- Switching `PLATFORM_DEFAULT` to FLEXIO on Teensy 4 — separate PR after
  both backends are equally exercised in the dev-bench matrix.
- Adding `bash autoresearch teensy40 --rx-backend=flexio` to the nightly
  hardware test matrix — gated on the Teensy 4.1 RTV-silicone hardware
  issue (#2760) being resolved.

Verification:
- ✅ C++ lint clean
- Docs-only changes; no host-test regressions possible

Refs #2764

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

* fix(autoresearch): KBI002 — route KeyboardInterrupt through project handler

PR #2769 introduced a `try/except KeyboardInterrupt` block on the serial-open
path of `test_flexio_rx_objectfled.py` that re-raised the signal directly.
The project-wide KBI002 lint requires that KeyboardInterrupt handlers either
call `_thread.interrupt_main()` or route through
`handle_keyboard_interrupt(ki)` from `ci.util.global_interrupt_handler`.

Importing the helper and calling it before the re-raise keeps the original
abort-without-stack-trace UX while satisfying the lint check.

The KBI002 violation was surfaced by the post-stop hook on the Phase 4
branch, which lints the master state pulled into the docs branch.

Refs #2764, PR #2769 review

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the feat/flexio-rx-backend-skeleton branch August 21, 2026 19:15
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