Repository navigation
refactor(rx): share the WS2812 decoder between Native + LPC SCT (#3035 Phase 3) - #3036
Conversation
…x/decode_ws2812.h
The NativeRxDevice (host stub) and LpcSctRxChannel (LPC845 SCT input-capture
backend) both carried verbatim copies of the same 4-phase WS2812 edge-pair →
byte decoder — reset-pulse breakout, gap-tolerance fallback, 10 % error gate.
A code comment in rx_sct_capture.h:14-15 already flagged the consolidation
as a follow-up; this lands it. ~150 lines of duplication removed.
The new header-only decoder lives at src/fl/channels/rx/decode_ws2812.h.
Per-driver wrappers keep the device-specific FL_WARN("…pin N…") messages
for the empty-buffer case (the shared decoder doesn't know the pin).
Behavior parity is exact for the Native + LPC paths. The FlexPWM
(decodeEdges) and FlexIO (decodeEdgesFlexIo) drivers use a different
variant (partial-byte left-shift, no reset detection, no gap tolerance,
different error counting) and are intentionally left alone — folding
those in is a separate change tracked under #3035 Phase 3.
Verification:
* tests/fl_channels_rx_sct_capture (5 cases) — pass
* tests/fl_channels_rx (15 cases) — pass
* Full 457-target host build — green
* bash lint --cpp — clean
Drive-by lint fixes (encountered during the lint pass per CLAUDE.md
"fix all encountered errors immediately"):
* src/platforms/shared/mock/arm/teensy4/drivers/_build.cpp.hpp:
alphabetise drivers/ includes (lpuart was appended out of order
when introduced).
* ci/tests/test_streaming_runner_artifact_validation.py: ruff
auto-collapse of a multi-line call.
Refs #3035 (Phase 3 — partial; FlexPWM/FlexIO follow-up still open).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughA new header-only ChangesWS2812 Shared Decoder Consolidation
Minor Build and CI Fixes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant LpcSctRxChannel
participant NativeRxDevice
participant decodeWs2812Edges
Caller->>LpcSctRxChannel: decode(out)
LpcSctRxChannel->>decodeWs2812Edges: decodeWs2812Edges(timing, mEdges, out)
decodeWs2812Edges-->>LpcSctRxChannel: result<u32, DecodeError>
LpcSctRxChannel-->>Caller: result<u32, DecodeError>
Caller->>NativeRxDevice: decode(out)
NativeRxDevice->>NativeRxDevice: check mEdges empty → INVALID_ARGUMENT
NativeRxDevice->>decodeWs2812Edges: decodeWs2812Edges(timing, mEdges, out)
decodeWs2812Edges-->>NativeRxDevice: result<u32, DecodeError>
NativeRxDevice-->>Caller: result<u32, DecodeError>
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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: 4
🤖 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/fl/channels/rx/decode_ws2812.h`:
- Around line 1-21: The header file `src/fl/channels/rx/decode_ws2812.h`
contains non-ASCII Unicode characters (such as the arrow `→` and em dash `—`) in
its comments, which violates the encoding requirement that this file must
contain only 7-bit ASCII. Replace all Unicode glyphs throughout the file with
their ASCII equivalents, specifically converting the right arrow `→` to `->` or
`=>` and the em dash `—` to `--` or `-`, ensuring all comment text uses only
ASCII characters.
- Around line 62-134: The function decodeWs2812Edges is currently defined
directly in the plain .h header file, but the coding guidelines require function
definitions to be kept in .cpp.hpp or .impl.hpp companion files. Move the entire
body of the decodeWs2812Edges function (from the opening brace to the closing
brace) to a new decode_ws2812.impl.hpp file and leave only the function
declaration in the .h file. Include the necessary header files in the .impl.hpp
file to make the function definition valid, and ensure the .h file includes the
.impl.hpp file at the end so the definition is available to callers.
- Around line 129-133: The error-rate threshold check in the condition comparing
error_count to bytes_written * 8 does not account for partial bits that may
exist in bit_index. Update the denominator to include both the complete bytes
and the remaining partial bits by calculating the total bits as bytes_written *
8 + bit_index, then use this total in the error rate comparison. This ensures
frames with low error rates are not incorrectly rejected when the capture ends
mid-byte or when a reset occurs on a partial byte.
- Around line 95-106: The reset pulse detection on line 96 breaks immediately
when low_ns exceeds the reset minimum threshold, preventing the gap-tolerance
logic from evaluating pulses that should be handled under tolerance.
Additionally, the gap_tolerance_ns check on line 99 only validates that low_ns
is below the tolerance threshold, incorrectly accepting short malformed LOW
phases. Fix this by adjusting the reset check to account for the gap-tolerance
window first before breaking on reset, and modify the condition to ensure the
LOW phase duration is within both a minimum and maximum valid range (not just
below tolerance) when evaluating gap-tolerant bits.
🪄 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: 702fa827-6301-4fb8-b724-3d9461870bdc
📒 Files selected for processing (6)
ci/tests/test_streaming_runner_artifact_validation.pysrc/fl/channels/rx/decode_ws2812.hsrc/platforms/arm/lpc/rx_sct_capture.cpp.hppsrc/platforms/arm/lpc/rx_sct_capture.hsrc/platforms/shared/mock/arm/teensy4/drivers/_build.cpp.hppsrc/platforms/shared/rx_device_native.cpp.hpp
…pp definition Addresses two CodeRabbit findings on #3036: 1. **ASCII-only header.** The previous header used Unicode glyphs (->, --, <=) in comments. Per the path-specific source-encoding rule for `src/fl/channels/rx/decode_ws2812.h`, that header must be 7-bit ASCII. Replaced all Unicode characters with ASCII equivalents. 2. **No function definitions in plain .h files.** The previous implementation defined `decodeWs2812Edges()` inline in the .h. Per the project convention used throughout fl/channels/rx (see channel.h <-> channel.cpp.hpp), function definitions go in a .cpp.hpp companion compiled exactly once into the FastLED unity build, while the .h carries only the declaration. Created `src/fl/channels/rx/decode_ws2812.cpp.hpp` and added the include to `src/fl/channels/rx/_build.cpp.hpp`. Behaviour unchanged: this is purely a file-layout split. The two CodeRabbit findings that flagged latent semantic bugs in the gap-tolerance ordering and the error-rate denominator are preserved from the original Native + LPC decoders and explicitly documented in the header's "Preserved-from-original quirks" block; fixing them is out of scope for the consolidation PR and tracked under #3035 follow-ups. Verification: * tests/fl_channels_rx_sct_capture (5 cases) -- pass * tests/fl_channels_rx (15 cases) -- pass * bash lint --cpp -- clean Refs #3035. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…pp definition (#3037) Addresses two CodeRabbit findings on #3036: 1. **ASCII-only header.** The previous header used Unicode glyphs (->, --, <=) in comments. Per the path-specific source-encoding rule for `src/fl/channels/rx/decode_ws2812.h`, that header must be 7-bit ASCII. Replaced all Unicode characters with ASCII equivalents. 2. **No function definitions in plain .h files.** The previous implementation defined `decodeWs2812Edges()` inline in the .h. Per the project convention used throughout fl/channels/rx (see channel.h <-> channel.cpp.hpp), function definitions go in a .cpp.hpp companion compiled exactly once into the FastLED unity build, while the .h carries only the declaration. Created `src/fl/channels/rx/decode_ws2812.cpp.hpp` and added the include to `src/fl/channels/rx/_build.cpp.hpp`. Behaviour unchanged: this is purely a file-layout split. The two CodeRabbit findings that flagged latent semantic bugs in the gap-tolerance ordering and the error-rate denominator are preserved from the original Native + LPC decoders and explicitly documented in the header's "Preserved-from-original quirks" block; fixing them is out of scope for the consolidation PR and tracked under #3035 follow-ups. Verification: * tests/fl_channels_rx_sct_capture (5 cases) -- pass * tests/fl_channels_rx (15 cases) -- pass * bash lint --cpp -- clean Refs #3035. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
NativeRxDevice::decode,LpcSctRxChannel::decode) into a single header-only functionfl::channels::rx::decodeWs2812Edges()atsrc/fl/channels/rx/decode_ws2812.h.FL_WARNfor the empty-buffer case (the shared function doesn't know the pin number).src/platforms/arm/lpc/rx_sct_capture.h:14-15that flagged the consolidation as a follow-up when the SCT driver landed.Scope decision
The codebase has four EdgeTime-based RX decoders today: Native, LPC SCT, FlexPWM, FlexIO. The first two are verbatim copies of each other and are merged here. The FlexPWM (
decodeEdges) and FlexIO (decodeEdgesFlexIo) variants have deliberately different semantics (partial-byte left-shift, no reset detection, no gap tolerance, different error-count target), so folding them into the same function would be a behavior change for those backends. That's intentionally left as a separate change tracked under #3035 Phase 3 with the deltas documented in the new header.Test plan
tests/fl_channels_rx_sct_capture— 5 cases pass (round-trips a synthetic GRB stream through LPC SCT)tests/fl_channels_rx— 15 cases pass (channel-level harness exercising NativeRxDevice)bash lint --cppclean (zero custom-checker violations)Drive-by lint fixes
Per CLAUDE.md "fix all encountered errors immediately" —
bash lintflagged two pre-existing issues that I addressed inline:src/platforms/shared/mock/arm/teensy4/drivers/_build.cpp.hpp: alphabetise the drivers/ includes (thelpuartline was appended out of order when introduced inbbf21f39f).ci/tests/test_streaming_runner_artifact_validation.py: ruff auto-collapse of a multi-line call.Refs #3035 (Phase 3 — partial).
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Refactor
Tests