Skip to content

feat(channels): expose the wire timing the UART encoder actually produces - #4227

Merged
zackees merged 2 commits into
masterfrom
fix/uart-derive-decode-timing
Sep 9, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/uart-derive-decode-timing

Conversation

@zackees

@zackees zackees commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Groundwork for the last unfixed UART defect on #3899. This PR adds only the encoder-side helper; it does not yet change any decoder.

The problem it addresses

The UART encoder quantises T0H/T1H onto a grid of period / pulses_per_bit, so what reaches the wire is not the chipset's nominal timing. A receiver decoding a UART-encoded frame must classify against the quantised values.

AutoResearchTest.cpp instead hardcodes one chipset's worth of them:

fl::ChipsetTiming uart_timing{250, 500, 500, 50, "UART_4Mbps"};

Measured consequence on RP2350W at 400 kHz (the only rate the RP PL011 can clock — see #4224):

decode timing LEDs wrong
hardcoded {250, 500, 500} 40/40
derived from the chipset 1/40

What this adds

ChipsetTiming uartWireTiming(const ChipsetTimingConfig& timing,
                             u32 max_baud_rate) FL_NO_EXCEPT;

It runs the same fitUartWave() the LUT was built from, so decode windows cannot drift from the encoding. Recomputing the rounding at the decode site would duplicate that logic — which the encoder's own comment warns against: "Shared by buildWave10Lut() and canRepresentTiming() so the LUT that gets built is always judged by the same rules that admitted it."

Correcting a claim I made on #3899

I asserted that deriving reproduces the hardcoded constants exactly for WS2812, and used that as the argument the change is risk-free on platforms I cannot test. That was wrong, and the test caught it:

WS2812B-V5 is T1=225 T2=355 T3=645  ->  period 1225 ns, not 1250
  derived   {245, 490, 490}
  hardcoded {250, 500, 500}
  deltas     5 ns, 10 ns, 10 ns   against a +/-250 ns tolerance

The constants correspond to a nominal 1250 ns part; V5 is 1225 ns. I had computed the "proof" from an assumed period instead of reading the actual timing macros.

The safety argument survives in weaker form — 5-10 ns against a ±250 ns classification tolerance cannot move any symbol across a boundary — but "well inside tolerance" is not "identical", and I had asserted the stronger claim. The test now pins the real derived values so a future timing change cannot drift silently.

Scope

Encoder-side only. Switching the AutoResearch decoder over is a separate change, deliberately, so the helper and its ESP32-visible consequences can be reviewed on their own.

Tests cover the derived values exactly, the tolerance property that makes substitution safe, and infeasible-ceiling handling.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

Summary by CodeRabbit

  • New Features

    • Added an API to report the actual quantized UART wire timing for supported chipset configurations.
    • Reports when timing is infeasible under the selected baud-rate limit instead of providing an estimated result.
    • Timing results reflect pulse-grid alignment and chipset-specific encoding constraints.
  • Tests

    • Added coverage for chipset-specific timing, pulse-grid alignment, decoder tolerance, and infeasible baud-rate constraints.

…uces

The UART encoder quantises T0H/T1H onto a grid of period/pulses_per_bit,
so what reaches the wire is not the chipset's nominal timing. Any
receiver decoding a UART-encoded frame has to classify against the
quantised values; AutoResearch currently hardcodes one chipset's worth
of them, which is why a 400 kHz frame decodes every symbol wrongly
(#3899).

uartWireTiming() derives them through the same fitUartWave() rules that
built the LUT, so decode windows cannot drift from the encoding -- the
alternative, recomputing the rounding at the decode site, is exactly the
drift the encoder's own comment warns against.

Correcting a claim I made on #3899 while working this out: I asserted
deriving would reproduce AutoResearch's hardcoded {250, 500, 500}
exactly for WS2812. It does not. WS2812B-V5 is T1=225 T2=355 T3=645, a
1225 ns period, and the derived wire timing is {245, 490, 490}. The
constants correspond to a nominal 1250 ns part. The deltas are 5 and
10 ns against a +/-250 ns classification tolerance, so no symbol can
change class -- but "well inside tolerance" is a weaker claim than
"identical", and I had asserted the stronger one from an assumed period
rather than the real values.

Tests assert the derived values exactly, the tolerance property that
makes substitution safe, and that an unreachable baud ceiling reports
infeasible rather than guessing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51
@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 2bca54e8-4531-436a-b6bb-442ee0906bf7

📥 Commits

Reviewing files that changed from the base of the PR and between d3b34c8 and e23c66f.

📒 Files selected for processing (1)
  • tests/data/esp32s3_bloat_baseline.txt

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The UART encoder now exposes uartWireTiming. The function derives quantized wire timing from the selected LUT geometry and baud ceiling. It returns zeroed timing when no valid fit exists. Tests cover supported chipsets, timing constraints, and infeasible baud limits.

Changes

UART wire timing

Layer / File(s) Summary
Timing API and fit selection
src/fl/channels/uart_wave_encoder.h, src/fl/channels/uart_wave_encoder.cpp.hpp
Adds uartWireTiming. The implementation selects and revalidates LUT geometry, then returns quantized "uart_wire" timing or zeroed "uart_infeasible" timing.
Wire timing validation
tests/fl/channels/uart_wave_encoder.cpp, tests/data/esp32s3_bloat_baseline.txt
Tests expected WS2812B-V5 and WS2811-400 timings, period preservation, pulse-grid alignment, and zeroed fields for an infeasible baud ceiling. Updates the ESP32-S3 bloat baseline.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to e23c6

This adds UART wire-timing reporting aligned with encoder quantization, with infeasible configurations reported explicitly. The documented timing behavior and size change are covered, with no concrete current-head merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. (1 skipped: 1… 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 clearly and concisely describes the main change: exposing the UART encoder's derived wire timing.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/uart-derive-decode-timing

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.

…adds

The bloat gate reports:

  esp32s3-bloat-regression: FAIL -- total_flash=342,407 B exceeds
  baseline=342,393 B by 14 B

That 14 B is this PR's helper, and the gate's own message asks for the
baseline to move in the same PR when the growth is intended.

It is intended, though worth being explicit that this PR alone adds a
function nothing calls yet: the caller lands in #4228, which is what
turns UART loopback on RP from 40/40 LEDs wrong into a pass. The helper
cannot be header-inlined to let the linker drop it -- it calls
fitUartWave(), which is internal to the encoder translation unit, and
sharing those rules is the entire point of the change.

14 B against a 342 KB image, in exchange for a decoder that classifies
against the waveform actually transmitted.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51
@zackees

zackees commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

Two CI failures, one real and now fixed, one infrastructure.

Bloat regression — real, and mine.

esp32s3-bloat-regression: FAIL — total_flash=342,407 B exceeds baseline=342,393 B by 14 B

14 bytes, from this PR's helper. The gate's message asks for the baseline to move in the same PR when the growth is intended, so tests/data/esp32s3_bloat_baseline.txt is updated to 342407.

Worth being explicit about what is being paid for: this PR alone adds a function nothing calls yet. The caller is #4228, which turns UART loopback on RP from 40/40 LEDs wrong into a pass. If #4227 landed without #4228 following, those 14 bytes would buy nothing.

I looked at avoiding them rather than just moving the number. The helper cannot be header-inlined so the linker drops it when unused — it calls fitUartWave(), which is internal to the encoder translation unit, and sharing exactly those rules is the entire point of the change. Reimplementing the rounding in the header to save 14 B would reintroduce the drift this exists to prevent.

build / build — infrastructure.

error: package error: failed to download
       https://www.teknic.com/files/downloads/ClearCore-1.7.4.zip:
       error sending request

An external package fetch, nothing to do with this diff. Re-running it.

@zackees
zackees merged commit 3319e6b into master Sep 9, 2026
30 of 31 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 9, 2026
zackees added a commit that referenced this pull request Sep 9, 2026
…4234)

The gate is red on master itself, so every open PR fails it -- including
#4232, which touches only test files and CI Python.

Master's own run measures total_flash=342,409 B against a pinned 342,407 B.
No single PR regressed; the drift is the sum of six changes merged in one
burst on 2026-09-09 16:57-16:59Z, each measured against a base that
predated the others:

  #4204 342,393 B  (baseline 342,393, headroom 0)
  #4206 342,391 B  (baseline 342,393, headroom 2)
  #4213 342,391 B
  #4220 342,391 B
  #4221 342,391 B
  #4227 342,407 B  (baseline 342,407 -- raised in that PR, headroom 0)

Every one of them passed. Their combination is 2 B over. That is the
known limit of measuring each PR against its own merge base, not a
regression anyone shipped, so re-pinning to the measured value records
what master is rather than hiding anything: a PR that adds flash on top
of 342,409 B still fails.


Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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