Repository navigation
feat(rx/lpc): scaffold LPC8xx SCT-capture RX backend + WS2812 decoder - #3016
Conversation
…#3015) Lays down the contract everything else in #3015's WS2812 loopback test needs while leaving the hardware-bench-required SCT/DMA register programming as a documented follow-up. What ships: * `RxBackend::LPC_SCT_CAPTURE` enum + `RxDeviceType::LPC_SCT_CAPTURE` — dispatchable on every platform (real `LpcSctRxChannel` on LPC8xx, `NativeRxDevice` on stub for host tests, `DummyRxDevice` elsewhere). Default backend on LPC maps to `LPC_SCT_CAPTURE`. Updated `toString` for both enums. * `src/platforms/arm/lpc/rx_sct_capture.{h,cpp.hpp}` — `LpcSctRxChannel` implementing the full `RxDevice` interface: - `injectEdges()` / `getRawEdgeTimes()` — fully functional against an in-RAM `fl::vector<EdgeTime>` buffer (same pattern as `NativeRxDevice`). - `decode()` — fully functional 4-phase WS2812 edge-pair → byte decoder. Kept in-TU per the existing FlexPWM / FlexIO convention; the follow-up consolidation target is `src/fl/channels/rx/decode_ws2812.h`. - `begin()` — stores config, clears buffer. The actual SCT input- capture + DMA register sequence is sketched in detail as a documented `TODO` block referencing UM11029 §16 (SCT EVENTCTRL / CAPTURE / DMA mux setup) so a follow-up bench session can fill it in without re-reading the manual. * `src/fl/channels/rx_sct_capture.h` — thin public re-export so callers (and the matching unit test) reference the driver via a stable `fl/channels/...` path without reaching into `platforms/arm/lpc/`. * `tests/fl/channels/rx_sct_capture.cpp` — five host unit tests that lock down the contract this PR ships: 1. `RxBackend` / `RxDeviceType` `toString` includes the new entry. 2. `RxDevice::create<LPC_SCT_CAPTURE>(pin)` returns a non-null device on every platform. 3. injectEdges → decode round-trips a 9-byte GRB payload across 3 LEDs at WS2812B nominal timing (T0H=400/T0L=850, T1H=800/ T1L=450 ns, ±150 ns tolerance). 4. Decoder rejects an empty edge buffer with `INVALID_ARGUMENT`. 5. `getRawEdgeTimes()` faithfully mirrors what was injected (8 bits × 2 edges = 16 entries; spot-checked alternating bit pattern 0xA5). What does NOT ship (deferred to a follow-up): * The actual SCT input-capture + DMA register programming in `begin()`. The peripheral path needs a scope/LA on a real LPC845-BRK to validate event-mux routing, capture-register polarity, and DMA transfer sizing. The contract above is deliberately complete enough that the follow-up only has to populate `mEdges` from the SCT/DMA ISR — every other surface (`finished`, `wait`, `decode`, `getRawEdgeTimes`, `injectEdges`) is host-tested today and won't change. Test plan: * `bash test rx_sct_capture --cpp` — all 5 cases pass on host (decoder + dispatch contract). * `bash lint` — clean. * `bash autoresearch lpc845brk --upload-port COM10 --skip-lint --timeout 5` — LPC845 firmware still builds (text 62.16 KB / 64.00 KB) and the existing bring-up test (serial + JSON-RPC echo + FL_WARN_LIT) still passes on real hardware. The new RX driver adds zero flash on this sketch because nothing references `RxBackend::LPC_SCT_CAPTURE` yet — LTO drops it. Closes #3015 *item 2* (the `rx_sct_capture.h` scaffold). Item 1 (the `fl::json` fixed-point refactor that frees the ~4 KB flash margin needed for the full loopback sketch) is still tracked by #3002. Items 3-4 (loopback test wiring + auto-detect via `probePair`) ship in a follow-up once both 1 and 2 are bench- verified. Co-Authored-By: Claude Opus 4.7 <[email protected]>
📝 WalkthroughWalkthroughAdds ChangesLPC SCT Capture RX Backend
Sequence Diagram(s)sequenceDiagram
participant Test as Test / Application
participant RxDevice
participant LpcSctRxChannel
participant EdgeBuffer as mEdges
Test->>RxDevice: create<LPC_SCT_CAPTURE>(pin)
RxDevice->>LpcSctRxChannel: LpcSctRxChannel::create(pin)
LpcSctRxChannel-->>Test: shared_ptr<LpcSctRxChannel>
Test->>LpcSctRxChannel: begin(config)
LpcSctRxChannel->>EdgeBuffer: clear()
Note over LpcSctRxChannel: SCT+DMA hw setup TODO
Test->>LpcSctRxChannel: injectEdges(edgeTimes)
LpcSctRxChannel->>EdgeBuffer: append EdgeTime entries
Test->>LpcSctRxChannel: wait(timeout_ms)
LpcSctRxChannel-->>Test: SUCCESS / TIMEOUT
Test->>LpcSctRxChannel: decode(WS2812Timing, outputSpan)
LpcSctRxChannel->>EdgeBuffer: iterate alternating HIGH/LOW pairs
LpcSctRxChannel-->>Test: result<u32, DecodeError>
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/platforms/arm/lpc/rx_sct_capture.cpp.hpp (1)
47-103: Note ISR synchronization requirements when the TODO is implemented.The TODO block (lines 52-100) describes the future SCT+DMA+ISR setup. When that ISR lands and begins mutating
mFinished(line 95) and populatingmEdgesvia DMA, both fields will become ISR-shared state. Per the C++ standards guideline, they must then be protected withfl::atomic<bool>formFinished(with explicit memory order) and either atomics or critical sections formEdgesaccess; plain member variables are not safe for cross-context (main thread ↔ ISR) communication.Currently there is no ISR, so this is not a defect in the present PR. Flag for the follow-up that implements the register programming.
🤖 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/lpc/rx_sct_capture.cpp.hpp` around lines 47 - 103, When the follow-up PR implements the TODO (lines 52-100) with the actual SCT register programming and ISR, add a comment flagging that mFinished must be changed from a plain bool to fl::atomic<bool> with explicit memory order specifications, and mEdges access must be protected with either atomics or critical sections, since both fields will become ISR-shared state that requires safe cross-context (main thread ↔ ISR) synchronization per C++ standards guidelines.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 `@tests/fl/channels/rx_sct_capture.cpp`:
- Around line 10-18: Replace all Unicode glyphs and characters in comments with
ASCII-only equivalents throughout the file tests/fl/channels/rx_sct_capture.cpp.
In the comment block at lines 10-18, replace the Unicode arrow (→) with ASCII
arrow (->). In the comment sections at lines 36-40 and lines 106-109, replace
any Unicode micro sign (µ) with ASCII text (us) and replace any other Unicode
punctuation characters with their ASCII equivalents to ensure the entire file
meets the source-integrity requirement of being ASCII-only with no Unicode
glyphs in comments.
---
Nitpick comments:
In `@src/platforms/arm/lpc/rx_sct_capture.cpp.hpp`:
- Around line 47-103: When the follow-up PR implements the TODO (lines 52-100)
with the actual SCT register programming and ISR, add a comment flagging that
mFinished must be changed from a plain bool to fl::atomic<bool> with explicit
memory order specifications, and mEdges access must be protected with either
atomics or critical sections, since both fields will become ISR-shared state
that requires safe cross-context (main thread ↔ ISR) synchronization per C++
standards guidelines.
🪄 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: f3a56805-8e31-4fa7-9f5b-e2cc917a7e27
📒 Files selected for processing (9)
src/fl/channels/rx.cpp.hppsrc/fl/channels/rx.hsrc/fl/channels/rx/channel.cpp.hppsrc/fl/channels/rx/types.hsrc/fl/channels/rx_sct_capture.hsrc/platforms/arm/lpc/_build.cpp.hppsrc/platforms/arm/lpc/rx_sct_capture.cpp.hppsrc/platforms/arm/lpc/rx_sct_capture.htests/fl/channels/rx_sct_capture.cpp
| /// 1. `RxBackend::LPC_SCT_CAPTURE` is dispatchable on every platform | ||
| /// (real device on LPC, NativeRxDevice on stub, DummyRxDevice | ||
| /// elsewhere). Tested implicitly via the toString round-trip and | ||
| /// the factory's non-null guarantee. | ||
| /// 2. The WS2812 edge-pair → byte decoder accepts a synthetic edge | ||
| /// stream and round-trips it to the original GRB bytes. | ||
| /// 3. `injectEdges()` is fully functional on the LPC backend (the | ||
| /// hardware-side capture path will populate the same buffer once | ||
| /// the SCT/DMA setup lands). |
There was a problem hiding this comment.
Replace Unicode glyphs with ASCII-only text in comments.
Line 14 uses a Unicode arrow and Line 108 uses a Unicode micro sign; this file also uses Unicode punctuation in comment text. Please normalize these to plain ASCII (->, us, -) to meet source-integrity requirements.
As per coding guidelines, "Source integrity: all C++/Python code must be ASCII-only (no emoji or Unicode glyphs in identifiers/prints/comments)."
Also applies to: 36-40, 106-109
🤖 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 `@tests/fl/channels/rx_sct_capture.cpp` around lines 10 - 18, Replace all
Unicode glyphs and characters in comments with ASCII-only equivalents throughout
the file tests/fl/channels/rx_sct_capture.cpp. In the comment block at lines
10-18, replace the Unicode arrow (→) with ASCII arrow (->). In the comment
sections at lines 36-40 and lines 106-109, replace any Unicode micro sign (µ)
with ASCII text (us) and replace any other Unicode punctuation characters with
their ASCII equivalents to ensure the entire file meets the source-integrity
requirement of being ASCII-only with no Unicode glyphs in comments.
Source: Coding guidelines
…3024) * feat(rx/lpc): SCT input-capture + pin-toggle loopback (#3021 Phase 1) Closes Phase 1 of FastLED #3021 — wires real SCT input-capture register programming into the LPC SCT-RX scaffold landed by #3015/#3016, adds the `pinToggleRx` JSON-RPC handler to the LPC845-BRK bring-up sketch, and adds an `--pin-toggle-rx` autoresearch subcommand + Python orchestrator that exercises the full loopback at 1 / 10 / 100 kHz. Driver implementation (src/platforms/arm/lpc/rx_sct_capture.{h,cpp.hpp}) ----------------------------------------------------------------------- Behind a new `FASTLED_LPC_RX_SCT` compile gate (default off — preserves the existing flash budget for sketches that don't opt in): * `begin()` powers up SCT + SWM in SYSCON, routes the user's pin to SCT0_GPIO_IN_A_I via SWM PINASSIGN6, programs a 32-bit unified free-running counter, and wires events EV0/EV1 to capture into CAP[0]/CAP[1] on rising / falling edges of the input. * `pollOnce()` (new public method) drains the SCT EVFLAG/CAP[0..1] pair into the EdgeTime ring buffer. Designed to be called from a TX bit-bang loop on the M0+ — without inline polling the SCT overwrites each CAP register on every edge before user code can read it. Phase 2's SCT->DMA upgrade will reduce `pollOnce()` to a no-op; the API stays for compatibility. * `wait()` spins on `pollOnce()` until timeout or buffer full. * Destructor halts the SCT and unmaps the SWM pin so a follow-up driver can claim it. All register offsets / bit positions cross-checked against UM11029 Rev 1.7 §8 (SYSCON), §10 (SWM), §21 (SCT). Hardware-validated SYSCON layout matched against `watchdog_lpc.impl.hpp`. Existing PWM_DMA TX driver shim has known offset bugs (REGMODE width, SYSCON offset, DMA CFG.HWTRIGEN bit position) — RX driver uses its own anonymous namespace of correct constants instead of reusing the broken shim. Sketch (examples/AutoResearchLpc/AutoResearchLpc.ino) ----------------------------------------------------- Adds `pinToggleRx(tx, rx, freq_hz, dur_ms) -> CSV string` JSON-RPC binding. The CSV-string return shape (instead of the FlexIO-style fl::json object) keeps flash overhead minimal on the 64 KB LPC845 budget: 7 integer fields packed as `success,edges,periods,mean_ns,sigma_ns,min_ns,max_ns`. The handler bit-bangs a software square wave on tx_pin while concurrently calling rx->pollOnce() between each digitalWrite, then computes period mean / σ / min / max stats over the captured edges. `#define FASTLED_LPC_RX_SCT 1` is set at the top of the sketch so the real SCT register programming activates. Autoresearch runner (ci/autoresearch/{args,phases}.py) ------------------------------------------------------ * New `--pin-toggle-rx` CLI flag in args.py. * New `_run_lpc_pin_toggle_rx_tests()` dispatch in phases.py that routes lpc845brk + --pin-toggle-rx to a fresh subprocess running the Python bench script. Python orchestrator (ci/autoresearch/test_lpc_pin_toggle_rx.py) --------------------------------------------------------------- Mirrors `test_flexio_rx_squarewave.py` but adapted to the LPC sketch's positional-args + CSV-string RPC contract: Case 1.1 — 1 kHz / 200 ms — σ < 1000 ns, mean ±2 % Case 1.2 — 10 kHz / 100 ms — σ < 500 ns, mean ±2 % Case 1.3 — 100 kHz/ 100 ms — σ < 500 ns, mean ±2 % (Looser σ vs the Teensy 4 FlexIO bench because M0+ polling adds 1–2 µs of capture jitter per edge — see pollOnce() timing budget.) Wiring: jumper P0_10 ↔ P0_11 on the LPC845-BRK header. Hardware validation ------------------- Code is bench-ready but NOT yet validated on real LPC845 silicon — this PR ships the implementation contract so Phase 1 acceptance can be confirmed in a follow-up bench session against the LPC845-BRK attached to COM10. To run on hardware once the board is connected: bash autoresearch lpc845brk --pin-toggle-rx --upload-port COM10 * fix(lpc): rename fl::strstream -> fl::sstream (file header is misleading) CI caught: `examples/AutoResearchLpc/AutoResearchLpc.ino:233:17: error: no type named 'strstream' in namespace 'fl'; did you mean 'sstream'?`. The header file is `fl/stl/strstream.h` but the class inside is `fl::sstream` — file name is misleading. Fix the four use sites in the pinToggleRx handler. The uno CI failure on the same run is pre-existing (`math.cpp.hpp:162` F(1.0/6.0) initializer fails on AVR g++ — not introduced by this PR). * fix(lpc): gate pinToggleRx handler behind FL_IS_ARM_LPC for host stub CI surfaced: the example DLL host-stub build (Linux example tests) compiles AutoResearchLpc.ino with STUB_PLATFORM, where `fl::LpcSctRxChannel`, `fl::RxConfig`, `fl::EdgeTime`, and the Arduino-native `delayMicroseconds` all do not exist. Wrap the pinToggleRx handler body + helpers in `#if defined(FL_IS_ARM_LPC)` so the host build still gets a valid empty-handler sketch. The runtime behavior on real LPC845 silicon is unchanged — FL_IS_ARM_LPC evaluates true there. Host stub now skips the RX section cleanly.
Summary
First slice of #3015's WS2812 loopback work — the bit that's independent of #3002's flash refactor and host-testable today.
src/platforms/arm/lpc/rx_sct_capture.himplementingRxDeviceprobePair-driven pin auto-detectWhat ships
RxBackend::LPC_SCT_CAPTUREenum +RxDeviceType::LPC_SCT_CAPTURE. Default backend on LPC (PLATFORM_DEFAULT→LPC_SCT_CAPTURE). Dispatchable everywhere — realLpcSctRxChannelon LPC,NativeRxDeviceon stub for host tests,DummyRxDeviceelsewhere.src/platforms/arm/lpc/rx_sct_capture.{h,cpp.hpp}—LpcSctRxChannel:injectEdges()/getRawEdgeTimes()— fully functional against an in-RAMfl::vector<EdgeTime>buffer (same shapeNativeRxDeviceuses).decode()— fully functional 4-phase WS2812 edge-pair → byte decoder. Kept in-TU per the existing FlexPWM / FlexIO convention; the follow-up consolidation target issrc/fl/channels/rx/decode_ws2812.h.begin()— stores config, clears buffer. The actual SCT input-capture + DMA register sequence is documented as a register-by-registerTODOblock referencing UM11029 §16 (SCT EVENTCTRL / CAPTURE / DMA mux setup) so a follow-up bench session can fill it in.src/fl/channels/rx_sct_capture.h— thin public re-export so callers (and tests) reference the driver via a stablefl/channels/...path without reaching intoplatforms/arm/lpc/.tests/fl/channels/rx_sct_capture.cpp— five host unit tests:RxBackend/RxDeviceTypetoStringincludes the new entry.RxDevice::create<LPC_SCT_CAPTURE>(pin)is non-null on every platform.injectEdges→decoderound-trips a 9-byte GRB payload across 3 LEDs at WS2812B nominal timing (T0H=400/T0L=850, T1H=800/T1L=450 ns, ±150 ns tolerance).INVALID_ARGUMENT.getRawEdgeTimes()faithfully mirrors what was injected.What does NOT ship (deferred)
The actual SCT + DMA register programming in
begin(). The peripheral path needs a scope/LA on a real LPC845-BRK to validate event-mux routing, capture-register polarity, and DMA transfer sizing. The contract above is deliberately complete enough that the follow-up only has to populatemEdgesfrom the SCT/DMA ISR — every other surface (finished,wait,decode,getRawEdgeTimes,injectEdges) is host-tested today and won't change shape.Test plan
bash test rx_sct_capture --cpp— all 5 cases pass.bash lint— clean.bash autoresearch lpc845brk --upload-port COM10 --skip-lint --timeout 5— LPC845 firmware still builds (text 62.16 KB / 64 KB) and the existing bring-up test (Serial.println+ JSON-RPC echo +FL_WARN_LIT) still passes on real hardware. The new RX driver adds zero flash on this sketch because nothing referencesRxBackend::LPC_SCT_CAPTUREyet — LTO drops it.Refs: #3002, #3004, #3012, #3013, #3014, #3015.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests