Skip to content

feat(rx): I2S-RX 1-bit oversampling capture backend — breaks the classic-ESP32 10-LED capture ceiling (#3576 Phase 3) - #3581

Merged
zackees merged 1 commit into
masterfrom
feat/i2s-rx-oversampler-3576
Jul 2, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/i2s-rx-oversampler-3576

Conversation

@zackees

@zackees zackees commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

Phase 3 of #3576. Classic ESP32's RMT receiver is one-shot (no ping-pong, no DMA): ~256 symbols ≈ 10 WS2812 LEDs per capture (#3571). This PR adds RxBackend::I2S_RX — an I2S0-based 1-bit oversampler — bench-verified byte-exact at 100 and 160 LEDs (16× the ceiling).

How it works

  • I2S0 in standard master-RX serial mode samples the RX pin at 16 MHz (62.5 ns/sample) straight into a 16 KB circular DMA ring; one pin sample costs one bit.
  • CLZ-based run-length extraction on the draining task (a per-bit loop cannot keep up at 16 Msps — bench showed mid-frame gaps past ~50 LEDs).
  • 4-phase pair decode with RMT-equivalent semantics; packed 4-byte runs capped at 8000 (~165 LEDs / 32 KB, sized against classic's free heap).
  • I2S0 arbitration via the Phase-1 port-claim registry — begin() fails cleanly to the RMT fallback when the second clockless bank or clocked-SPI owns the block.

Bench-derived silicon findings (encoded as code comments)

  • The RX serial sampler clocks SD at the CLKM rate directly (80 MHz / clkm_div_num); rx_bck_div only shapes the unused BCK output. Measured pulse durations pinned this: 12 samples for a 735 ns UART pulse.
  • Above ~16 MHz the input path tops out: real pads sample as all-zeros while the matrix constant-source still captures (datapath-vs-pad discriminator test).
  • rx_msb_shift=1 (Philips) required; PDM block must be forced off; SD-in rides the I2S0I_DATA_IN15 matrix signal; bit31 of each FIFO word is the earliest sample.

Root-cause fix included

RxChannel::begin() recreates its device whenever config.backend differs — so any consumer that re-armed with a fresh default config silently reverted an explicitly-selected backend to PLATFORM_DEFAULT/RMT. Added RxChannel::backend() and made the AutoResearch capture path carry it. runSingleTest gains an optional rxBackend param (RMT/ISR/I2S_RX).

Verification

  • Bench (WROOM COM11, GPIO33→34): I2S_RX 4/4 byte-exact at 10, 100, and 160 LEDs; full regression I2S/I2S0/RMT/UART/SPI (default RMT capture) 4/4 each.
  • Host: 345/345; lint clean.

Refs #3576, #3571.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a new RX capture backend option for supported ESP32 builds, expanding how input signals can be captured.
    • RX channels now expose their selected backend, helping preserve capture behavior when re-arming or reusing a channel.
  • Bug Fixes
    • Fixed cases where a chosen RX backend could be lost and replaced with a default one during capture setup.
    • Improved handling for unsupported backend selections with clearer failure responses.

…#3576 Phase 3)

Classic ESP32's RMT receiver has no ping-pong and no DMA — captures are
one-shot into channel RAM, ~256 symbols ≈ 10 WS2812 LEDs (#3571). This
adds an I2S0-based oversampling backend that removes the ceiling:
bench-verified byte-exact at 100 and 160 LEDs (16x the RMT limit).

Backend (RxBackend::I2S_RX / RxDeviceType::I2S_RX, classic only):
- I2S0 standard master-RX serial mode samples the RX pin (via the
  I2S0I_DATA_IN15 matrix signal — the classic SD-in quirk) at 16 MHz
  into a 16 KB circular DMA ring; CLZ-based run-length extraction on
  the draining task; 4-phase pair decode matching RMT semantics.
- Packed level runs (4 bytes each) capped at 8000 (~165 LEDs, 32 KB) —
  sized against classic's free heap; unbounded storage OOM'd at 500.
- Claims I2S0 through the cross-driver port-claim registry; begin()
  fails cleanly (fall back to RMT) when the second clockless bank or
  clocked-SPI owns the block.

Bench-derived silicon findings (all encoded as comments):
- The RX serial sampler clocks SD at the CLKM rate directly
  (80/clkm_div_num); rx_bck_div only shapes the unused BCK output.
- Rates above ~16 MHz (clkm_div_num < 5) capture only zeros from real
  pads; the matrix-constant source still samples — input path ceiling.
- rx_msb_shift=1 (Philips) required; PDM block forced off.
- Bit order: bit31 of each 32-bit FIFO word is the earliest sample.
- Per-bit extraction cannot keep up at 16 Msps (mid-frame gaps past
  ~50 LEDs) — CLZ word-run scanning fixes it.

Plumbing:
- RxChannel::begin() recreates the device when config.backend differs;
  a fresh default config silently reverted explicit backends to
  PLATFORM_DEFAULT/RMT. New RxChannel::backend() accessor; the
  AutoResearch capture path now carries it (root-cause fix).
- runSingleTest gains an optional rxBackend param (RMT/ISR/I2S_RX).
- g_i2s_rx_debug[] bench counters (peekMem-able, 32 bytes) kept for
  future bring-up.
- fl/channels/README.md: RX capture backends section.

Bench (WROOM COM11, GPIO33->34): I2S_RX byte-exact 4/4 at 10, 100 and
160 LEDs; regression I2S/I2S0/RMT/UART/SPI (RMT backend) 4/4 each.
Host: 345/345, lint clean.

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 12271383-1038-4f30-8f11-e90f4b4f56e4

📥 Commits

Reviewing files that changed from the base of the PR and between 1044957 and 2055d6a.

📒 Files selected for processing (14)
  • build_info.json
  • build_info_lpc845.json
  • examples/AutoResearch/AutoResearchRemoteRunSingleTest.cpp
  • examples/AutoResearch/AutoResearchTest.cpp
  • src/fl/channels/README.md
  • src/fl/channels/rx.cpp.hpp
  • src/fl/channels/rx.h
  • src/fl/channels/rx/channel.cpp.hpp
  • src/fl/channels/rx/channel.h
  • src/fl/channels/rx/types.h
  • src/platforms/esp/32/drivers/_build.cpp.hpp
  • src/platforms/esp/32/drivers/i2s_rx/_build.cpp.hpp
  • src/platforms/esp/32/drivers/i2s_rx/i2s_rx_sampler.cpp.hpp
  • src/platforms/esp/32/drivers/i2s_rx/i2s_rx_sampler.h

📝 Walkthrough

Walkthrough

This PR adds an I2S_RX capture backend for classic ESP32 devices. It extends the RxBackend/RxDeviceType enums, factory dispatch, and RxChannel with a backend() accessor, implements the ESP32 I2S sampler, updates AutoResearch examples/RPC handling, adds documentation, and includes generated build_info JSON files.

Changes

I2S RX Backend Feature

Layer / File(s) Summary
Enum and toString updates
src/fl/channels/rx/types.h, src/fl/channels/rx.h
RxBackend and RxDeviceType gain a new I2S_RX = 6 enumerator; both toString helpers add matching cases.
Channel factory dispatch and backend accessor
src/fl/channels/rx/channel.cpp.hpp, src/fl/channels/rx/channel.h
createBackendDevice handles RxBackend::I2S_RX; RxChannel gains a backend() accessor returning mConfig.backend.
Per-platform RxDevice::create<I2S_RX> specializations
src/fl/channels/rx.h, src/fl/channels/rx.cpp.hpp
Declares and implements the I2S_RX create specialization for ESP32 (real sampler when FASTLED_ESP32_HAS_I2S), Teensy 4.x, ARM LPC, stub, and fallback platforms (all returning DummyRxDevice).
ESP32 I2S RX sampler implementation
src/platforms/esp/32/drivers/i2s_rx/i2s_rx_sampler.h, .cpp.hpp
Implements I2sRxSampler (RxDevice) using I2S0 DMA-ring capture, run-length sample processing, decode/inject interfaces, debug counters, and the createI2sRxSampler factory.
Unity build wiring
src/platforms/esp/32/drivers/i2s_rx/_build.cpp.hpp, src/platforms/esp/32/drivers/_build.cpp.hpp
Adds unity-build include for the sampler and wires it into the ESP32 drivers aggregator.
AutoResearch backend selection and docs
examples/AutoResearch/AutoResearchRemoteRunSingleTest.cpp, examples/AutoResearch/AutoResearchTest.cpp, src/fl/channels/README.md
Adds rxBackend RPC parameter handling, preserves selected backend across re-arming in capture(), and documents RX capture backends.
Generated build metadata
build_info.json, build_info_lpc845.json
Adds toolchain path/flag/alias metadata for the lpc845 environment.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RemoteRunner as AutoResearchRemoteRunSingleTest
  participant FastLED
  participant RxChannel
  participant RxDevice as RxDevice::create<I2S_RX>
  participant I2sRxSampler

  RemoteRunner->>RemoteRunner: parse rxBackend from RPC config
  alt rxBackend override provided
    RemoteRunner->>FastLED: addRx(RxChannelConfig(pin_rx, backend))
    FastLED->>RxChannel: begin(config)
    RxChannel->>RxDevice: create<I2S_RX>(pin)
    RxDevice->>I2sRxSampler: createI2sRxSampler(pin)
    I2sRxSampler-->>RxDevice: sampler instance
    RxDevice-->>RxChannel: device
    RxChannel-->>RemoteRunner: rx_channel_to_use
  else no override
    RemoteRunner->>RemoteRunner: reuse mState->rx_channel or rx_factory
  end
  RemoteRunner->>RxChannel: backend()
  RxChannel-->>RemoteRunner: configured backend
Loading

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2300: Both PRs modify the capture(...) RX config setup in examples/AutoResearch/AutoResearchTest.cpp.
  • FastLED/FastLED#2400: Both PRs build on the fl::RxChannel API, with this PR extending its backend/channel layer with I2S_RX support.
  • FastLED/FastLED#3016: Both PRs extend RxBackend/RxDeviceType enums and the createBackendDevice factory switch to add new capture backends.
✨ 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/i2s-rx-oversampler-3576

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.

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