Repository navigation
fix(my9221): enforce DDR setup/phase and latch/stop timing (#5066) - #5371
Conversation
Add explicit fl::delayNanoseconds waits for DI setup (10 ns), DCKI phase (50 ns, also covering DI hold), the four latch DI pulses (80 ns high, 240 ns low) and the cascade stop interval (210 ns + N*10 ns) per the MY9221 datasheet. The stub delayMicroseconds now reports to the existing nanosecond-delay observer so host tests see the 230 us latch quiet time. Adds a host timing-oracle test in spi_legacy_golden.
|
Caution Review failedThe pull request is closed. Note
|
| Layer / File(s) | Summary |
|---|---|
Controller data and latch timing src/fl/chipsets/my9221.h |
writeBit adds data setup, hold, and clock phase delays. latch adds timed DI pulses and a stop interval based on the number of transmitted chips. showPixels counts chips and passes the count to latch. |
Host timing recorder and checks src/platforms/stub/platform_time.cpp.hpp, tests/fl/channels/spi_legacy_golden.cpp |
The stub records microsecond delays as nanoseconds. The MY9221 test records DI and DCKI transitions and checks timing intervals, latch pulses, cascade stop time, and clock-edge counts across two frames. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Possibly related issues
- Issue 5024 — Umbrella issue for the software SPI audit work that includes the MY9221 timing slice.
Possibly related PRs
- FastLED/FastLED#4710 — Both PRs change the host stub’s
delayMicrosecondsbehavior.
Suggested reviewers: gitbruno
Merge Risk: 
Minimal · up to ef1df
-
The change adds minimum timing waits and host timeline checks without an established merge-blocking defect. It is ready for normal checks, but physical timing compliance remains unverified.
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.
Memory usage (this PR vs. its merge base)Change in
|
Fixes #5066
Problem
MY9221Controller(src/fl/chipsets/my9221.h) drives DI/DCKI through FastPin. Until now it relied on incidental GPIO and compiler overhead for every datasheet interval. Nothing enforced DI setup/hold, DCKI phase width, the four latch-pulse widths, or the cascade stop interval.Fix
This adds explicit minimum waits using the existing
fl::delayNanosecondsprimitives. They are the same onesclockless_blocking.huses on every platform, AVR included. The values follow the MY-Semi MY9221 datasheet v1.0, pp 6-7 and 15:delayNanoseconds<10>delayNanoseconds<50>after each toggledelayNanoseconds(210 + 10*N), where N = chips shifted this frameDual-edge operation, command/payload order, RGB mapping, zero padding of a partial chip and the latch sequence are unchanged. The hot path adds two constant waits per bit.
The stub
delayMicrosecondsnow also reports the requested wait, in ns, to the existingfl::stub::setNanosecondDelayCallbackobserver. Host tests can then see the 230 us latch quiet time. This is a host-only change with no production effect.Test (TDD)
New case in
tests/fl/channels/spi_legacy_golden.cpp:MY9221 controller enforces DDR setup/hold, clock phase and latch timing. FastPin<92>/<93> specializations, the same pattern as the existing #4636 MY9221 wire capture, record each DI/DCKI write on a single timeline. Model time advances only through requested waits, observed with the existing nanosecond-delay callback. GPIO writes cost 0 ns, so incidental latency can never satisfy a datasheet interval. The case drives the production controller fromFastLED.addLedsSpiChannel<MY9221,92,93,RGB>with 17 LEDs (N = 5 chips, stop bound 250 ns). It runs two frames and checks the following:RED (unchanged
my9221.h;bash test spi_legacy_golden, then again with--debug: same failures, no sanitizer reports):GREEN (with the fix, and again after rebasing on
origin/master):All tests passed (1/1).Mutation: deleting only the cascade-stop
delayNanoseconds(...)line fails the focused test withspi_legacy_golden.cpp:873: 250 > 250. With N = 5, the 240 ns latch-low wait alone cannot meet the chain-dependent bound. Restoring the header byte-for-byte (cmp) passes again.bash lint: all stages pass.Relationship to #5058
This PR supersedes the MY9221 slice of #5058 (
src/fl/chipsets/my9221.h) as a small, independent change. It does not include #5058's platform emitters, frame pre-staging or IRQ masking.Not claimed / out of scope
delayNanosecondsrounds up to whole cycles.Blink.inoonly mentions it in a comment. A board compile would not exercise this controller, so none was run.Summary by CodeRabbit