Skip to content

LED strips: wait for a frame as long as its own timing says, not a fixed 10us per byte - #59

Open
robdobsn wants to merge 1 commit into
mainfrom
fix/led-strip-wait-from-bit-timing
Open

robdobsn wants to merge 1 commit into
mainfrom
fix/led-strip-wait-from-bit-timing

Conversation

@robdobsn

Copy link
Copy Markdown
Owner

Problem

ESP32RMTLedStrip::waitUntilShowComplete() waited at most 150us + 10us per byte for the previous frame to finish. showPixels() calls it when a show arrives while the last frame is still going out, and drops the new frame if the wait times out.

That budget assumes WS2812B bit timing and a short reset. A strip configured with slower bits or a longer reset exceeds it: on CogPro, 14 pixels at 1.3 µs per bit with a 300 µs reset is a 737 µs frame against a 570 µs budget. Two shows in one loop pass (one LED off, the next on) lost the second frame every time, so alternate LEDs stayed dark in a step-through test. Nothing was logged.

Change

  • The wait is computed once in setup() from the strip's own config: the frame's bits at the longer of the 0 and 1 bit periods, plus the reset, plus a margin for the TX-done interrupt and the waiting task being late (a quarter of the frame time, at least 200 µs).
  • LEDStripRMTPlan gets frameTimeUs() and showWaitUs() so the arithmetic is Raft-free and host-tested next to the RMT memory plan.
  • The DEBUG_ESP32RMTLEDSTRIP_SETUP log now shows the frame time and the wait.

No config keys change. For WS2812B defaults the wait is close to what it was (a 14-pixel frame: 504 µs frame, 704 µs wait, versus 570 µs before); for longer resets or slower parts it grows to fit the frame.

Testing

  • make -C linux_unit_tests test_led_strip_rmt_plan: 261 checks pass, including the new testFrameTimeUs (WS2812B defaults, the CogPro timing that failed, 20 MHz ticks, a 300-pixel RGBWW strip, and the wait margin).
  • TestCogPro01 (ESP32-S3, IDF 6.1) built against this branch via raftdevlibs/RaftCore.

🤖 Generated with Claude Code

…xed 10us per byte

ESP32RMTLedStrip waited at most 150us + 10us per byte for the previous frame to finish before
giving up and dropping the new one. That budget was sized for WS2812B timing with a short reset,
so a strip configured with slower bits or a longer reset (CogPro: 14 pixels at 1.3us per bit with
a 300us reset, a 737us frame) hit the 570us limit whenever two shows came close together, and the
second frame was silently dropped: alternate LEDs stayed dark in a step-through test.

The wait is now computed in setup() from the strip's own config: the frame's bits at the longer of
the 0 and 1 bit periods, plus the reset, plus a margin (a quarter of the frame time, at least
200us) for the interrupt and the waiting task being late. LEDStripRMTPlan gets frameTimeUs() and
showWaitUs() so the arithmetic is host-tested alongside the RMT memory plan.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant