Repository navigation
Description
Important
SUPERSEDED BY #3023 — see that meta for the current status of Bus::LPUART.
The full content of this issue (the Bus::LPUART wave8-generic spec, backend strategy, canHandle() design, Phase 1/2/3 plan, acceptance criteria) is folded inline into the new meta as workstream A. Closed for history; body preserved below.
Why
The iMXRT1062 LPUART peripheral, driven by eDMA with the inverted-TX trick (TX idle low, start bit becomes the leading rising edge, 8 data bits shape the bit cell, stop bit forces the trailing low), is a third, completely disjoint clockless TX peripheral on Teensy 4 — orthogonal to the two already wired into the channels API:
| Driver | Peripheral path |
|---|---|
Bus::FLEX_IO (channel_engine_flexio.{h,cpp.hpp}) |
FlexIO2 module — 4 timers + 1 shifter per strip |
Bus::OBJECT_FLED (channel_engine_objectfled.{h,cpp.hpp}) |
QTimer + XBAR + eDMA + GPIO scatter writes |
Bus::LPUART (this issue) |
LPUART + eDMA — one LPUART per strip; iMXRT1062 has 8 LPUARTs (LPUART1..LPUART8) |
A Teensy 4 sketch could run strips on all three hardware paths simultaneously without peripheral contention: clockless strips through FlexIO2, ObjectFLED's parallel DMA fan-out on any free GPIO, plus up to ~8 additional strips through LPUART-DMA — all asynchronous with respect to each other.
That makes the LPUART path a real third channel-API driver on this platform.
Why Bus::LPUART and not Bus::WS2812_SERIAL
Earlier framing of this issue (and the legacy PaulStoffregen WS2812Serial library it would port from) was WS2812-specific. The peripheral isn't. The legacy library hard-codes:
- Two fixed UART byte patterns (
0x88for a "0" bit,0xEEfor a "1" bit), and - A fixed baud rate (~3.2 Mbaud, chosen so each UART frame = one WS2812 bit cell).
But the only real constraint the inverted-LPUART imposes on the wire shape is:
Every output bit cell must start HIGH (start bit, inverted) and end LOW (stop bit, inverted), with 8 freely-programmable pulses in between.
That topology covers every WS281x-family clockless protocol (WS2811, WS2812, WS2812B, WS2812B-V5, SK6812, SK6812-RGBW, UCS7604, TM181x, NeoPixel-compatibles, etc.). Their ChipsetTiming differs in exact T1/T2/T3 values; the wave8 expansion handles those differences at runtime via buildWave8ByteExpansionLUT(). The legacy library's hard-coded patterns are a degenerate case of what wave8 already emits dynamically.
So: name the bus by the peripheral block (LPUART), drive it from the generic wave8 encoder (already proven on parlio, i2s, spi, uart on ESP32), and let canHandle() accept anything whose wave8 expansion respects the leading-high/trailing-low/8-mid-pulses topology.
This is consistent with the existing convention:
Bus::RMT,Bus::PARLIO,Bus::I2S,Bus::UART(ESP32 UART-over-wave8 — same architecture as this issue, different SoC),Bus::FLEX_IO,Bus::LCD_CLOCKLESS— all named after the peripheral block, not after a specific chipset.
Current state on master
- A reference implementation exists:
src/platforms/arm/teensy/teensy31_32/ws2812serial_controller.h— wraps PaulStoffregen/WS2812Serial. ~4 Mbaud UART rate; each WS2812 bit encoded as one UART frame via eDMA + inverted TX. - Re-included on T4 via
src/platforms/arm/teensy/teensy4_common/fastled_arm_mxrt1062.h:10. - Exposed only through the legacy template API:
FastLED.addLeds<WS2812SERIAL, DATA_PIN, GRB>(...)atsrc/FastLED.h:1265-1276, gated by#define USE_WS2812SERIAL. - No
Bus::enum value, noIChannelDriversubclass, nobus_traits.h, noinit_channel_driver_mxrt1062.cpp.hppregistration, no AutoResearch wiring. Functionally works for the WS2812 case via the legacy template, but completely off the channels-API rail and locked to one chipset.
Backend strategy
Two viable Phase 1 paths — pick one, document the call:
(A) Wrap the existing PaulStoffregen library as the backend.
- Pro: lowest-risk start; the library already handles LPUART register setup, baud-rate computation, inverted TX, DMA hookup, pin-mux validation, and is field-proven.
- Con: hard-coded to WS2812 byte patterns. We'd ship a
Bus::LPUARTdriver that, at the engine layer, narrowscanHandle()to only WS281x timings. The wave8-generic promise wouldn't be fully delivered until path (B) lands as a follow-up. - Phase 3 wave8-streaming-ISR async work would replace the library entirely.
(B) Direct iMXRT LPUART + eDMA driver using wave8 from day one.
- Pro: chipset-generic from the first commit. No third-party dependency. Lets the engine accept any wave8-compatible chipset whose period fits the LPUART baud-rate range.
- Con: ~400-600 LOC more than (A). Have to re-implement: LPUART register init for inverted TX + chosen baud, eDMA channel allocation + linking, pin-mux table for the {1, 8, 14, 17, 20, 24, 29, 35, 47, 48} LPUART-TX-capable pins on T4.0/4.1, error/underrun handling.
- This is what the Phase 3 wave8 streaming-ISR async pattern wants anyway.
Recommendation: start with (B) — direct + wave8-generic — because the legacy library wrap (A) bakes in a chipset-limit that defeats the point of the generalization, and the Phase 3 async work is going to throw the library away anyway. Doing (A) first is rework.
Key channels-API insight (why this isn't "more #ifdef debt")
The channels API enrols drivers via runtime ChannelManager::addDriver() plus a BusTraits<Bus::X>::registerWithManager() opt-in. No #define USE_WS2812SERIAL-style gate is needed at the engine level — if no TU names Bus::LPUART, the linker strips the entire ChannelEngineLPUART vtable, its bus_traits.h singleton, and (in path A) the WS2812Serial library symbols it pulls in. Tree-shaking takes care of it. The only gate that remains is #if defined(FL_IS_TEENSY_4X) so the host-stub TU doesn't try to compile the LPUART code (same gate FlexIO and ObjectFLED already use).
Implementation plan
Phase 1 — wave8-generic LPUART engine (direct register driver — backend strategy B)
-
src/fl/channels/bus.h:- Add
LPUARTenumerator afterOBJECT_FLED. - Add
case Bus::LPUART: return "LPUART";tobusName(). - Bump the drift-prevention
FL_STATIC_ASSERT(static_cast<fl::u8>(Bus::STUB) == 13, ...)to 14.
- Add
-
src/platforms/arm/teensy/teensy4_common/drivers/lpuart/(new directory):ilpuart_peripheral.h— abstract peripheral interface (initialize,transmit,waitAllDone,isBusy,setBaudRate, ISR-callback registration) so the engine is testable on the host stub via a mock peripheral, mirroring the parlio/i2s pattern.lpuart_peripheral_real.{h,cpp.hpp}— iMXRT register-level implementation. Inverted TX (LPUARTx_CTRL: TXINV=1), 8-N-1 framing, eDMA hookup via DMAMUX source for LPUARTx TX. Pin-mux table for {1, 8, 14, 17, 20, 24, 29, 35, 47, 48}.lpuart_peripheral_mock.{h,cpp.hpp}— host-stub mock with deferred-ISR pump (follows theparlio_peripheral_mockshape; reuse the shared ISR-mock fixture once it exists per the wave8 coverage discussion).wave8_encoder_lpuart.{h,cpp.hpp}— adapter that consumesWave8ByteLUT output and packs it into the 8 programmable UART data bits per frame. Start/stop framing handled by the LPUART hardware (inverted), so only the middle 8 pulses are written. This is the layer that earns the "generic wave8 over LPUART" promise.channel_engine_lpuart.{h,cpp.hpp}—IChannelDriversubclass.getName()returns"LPUART".Capabilities(/*clockless=*/true, /*spi=*/false). Sync for Phase 1 —show()blocks viamPeripheral->waitAllDone().bus_traits.h—BusTraits<Bus::LPUART>specialization mirroringobjectfled/bus_traits.h.BusSupports<Bus::LPUART, ClocklessChipset> : fl::true_type._build.cpp.hpp— include everything.
-
src/platforms/arm/teensy/teensy4_common/init_channel_driver_mxrt1062.cpp.hpp— addaddLPUARTIfPossible(manager)registering at priority 3 (between BIT_BANG at 0 and OBJECT_FLED at 5; lower than ObjectFLED because single-strip-per-LPUART + pin-restricted is a narrower fit than ObjectFLED's any-pin parallel fan-out). -
src/platforms/arm/teensy/channel_drivers_teensy.impl.hpp— appendBus::LPUARTto theenableDrivers<...>()parameter pack inside theFL_IS_TEENSY_4Xarm.
canHandle() filter — generic over wave8-compatible chipsets
Not a single hard-coded WS2812 window. Instead, accept any clockless chipset whose:
- Bit period maps cleanly to the LPUART's achievable baud-rate range (~50 kbaud to ~7.5 Mbaud on iMXRT, so bit periods roughly 1067 ns to 160 µs), AND
- Wave8 expansion at the chipset's
T1/T2/T3produces a pattern withpulse[0] == HIGHandpulse[7] == LOW(the inverted-LPUART start/stop framing requirement).
bool ChannelEngineLPUART::canHandle(const ChannelDataPtr& data) const FL_NOEXCEPT {
if (!data || !data->isClockless()) return false;
const ChipsetTiming& t = data->getTiming();
if (t.total_period_ns() < kLPUARTMinBitPeriodNs ||
t.total_period_ns() > kLPUARTMaxBitPeriodNs) return false;
// wave8 topology check: leading-high + trailing-low + 8 mid-pulses
Wave8Bit zero = wave8_convert_byte_to_wave8byte_for_value(0, ...);
Wave8Bit one = wave8_convert_byte_to_wave8byte_for_value(1, ...);
if ((zero.data & 0x80) == 0 || (one.data & 0x80) == 0) return false; // first pulse must be HIGH
if ((zero.data & 0x01) != 0 || (one.data & 0x01) != 0) return false; // last pulse must be LOW
// Pin must be in the iMXRT LPUART-TX set
return mPeripheral->canHandlePin(static_cast<u8>(data->getPin()));
}This makes the driver accept WS281x-family chipsets without hard-coding which ones — new chipsets land for free as long as their wave8 expansion fits the topology.
Phase 2 — AutoResearch wiring
-
examples/AutoResearch/AutoResearchRemote.cpp:943-944— addelse if (n == "LPUART") opts.mBus = fl::Bus::LPUART;. -
ci/autoresearch/args.py— add--lpuartflag andlpuart: boolfield onArgs. -
ci/autoresearch/phases.py— append"LPUART"to the--allset and the per-flag mapping. PinpinTx=1(T4 default TX is already 1, which is also LPUART6 TX) when driver==LPUARTso it routes correctly — analogous to theFLEX_IO pinTx=6override that landed in fix(autoresearch): exercise both ObjectFLED and FlexIO on Teensy 4.x #3005. -
ci/tests/test_autoresearch_phases.py— update--alldriver-set assertion + addlpuart=Falseto_make_args. - Hardware verification reuses the existing FlexIO RX loopback fixture from [meta] Bootstrap AutoResearch driver development for Teensy 4.0 — FlexIO RX + first LED driver verification #2764 Phase 3 (the
flexioObjectFledTestRPC handler atAutoResearchRemote.cpp:1517— just swapopts.mBus = fl::Bus::LPUARTto point the same fixture at the new driver).
Phase 3 (follow-up issue / BIG TODO) — wave8 streaming-ISR async driver
The Phase 1 engine ships sync (show() blocks via mPeripheral->waitAllDone()). The real prize:
Convert the LPUART engine to the wave8 streaming-ISR async pattern — wave8-encode the next chunk into a ping-pong ring buffer, kick LPUART-eDMA from
show(), return immediately, refill the ring buffer in the eDMA half/done ISR, and surfaceDriverState::DRAININGfrompoll()until the last byte clears the LPUART shift register.Reference patterns:
src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp— wave8 + ISR ring buffer (the "PHASE 1: ASYNC MODE" sections).src/platforms/esp/32/drivers/i2s/channel_driver_i2s.{h,cpp.hpp}— wave8 streaming via I2S half/done ISRs.- feat: add ISR-backed channel poll wakeups #2992 — ISR-backed channel
poll()wakeups; the samechannel_poll_signalplumbing applies.- fix(parlio): mock waitAllDone() pumps deferred ISR callbacks to mirror real-DMA semantics (#2992 follow-up) #3010 — the parlio mock's
settleEngineState()pump pattern, which the futurelpuart_peripheral_mockshould mirror from day one to avoid the same regression class.Frees the CPU during the ~30 ms it currently spends spinning in
waitAllDone()for a 1000-LED strip, brings LPUART to async parity with ObjectFLED/FlexIO, and (combined with a runtime LPUART-instance pool) lets a single sketch run up to 8 LPUART strips fully in parallel via 8 eDMA channels without blocking.Out of scope for the Phase 1 PR — file as a separate issue once Phase 1 lands.
Acceptance criteria (Phase 1)
-
bash compile teensy40 --examples AutoResearchsucceeds with the new engine compiled in. -
bash autoresearch teensy40 --lpuart(Phase 2 hardware run) drives one strip via LPUART-eDMA on pin 1 and captures byte-for-byte via the existing FlexIO RX loopback fixture ([meta] Bootstrap AutoResearch driver development for Teensy 4.0 — FlexIO RX + first LED driver verification #2764 Phase 3 infra reused). -
bash autoresearch teensy40 --allexercises FLEX_IO, OBJECT_FLED, and LPUART in sequence. - Host stub build still passes — the engine TU is gated by
FL_IS_TEENSY_4Xso the stub doesn't try to include LPUART register headers. Host-side coverage runs throughlpuart_peripheral_mock(mirroringparlio_peripheral_mock). -
canHandle()accepts at least: WS2812, WS2812B, WS2812B-V5, SK6812, SK6812-RGBW (verified via host-sidetests/platforms/arm/teensy/teensy4_common/drivers/lpuart/channel_engine_lpuart.cppparameterized over the chipset timing table). -
canHandle()rejects: APA102, SK9822 (clocked SPI chipsets), and any clockless chipset whose wave8 expansion violates the leading-HIGH/trailing-LOW topology. - Legacy
FastLED.addLeds<WS2812SERIAL, DATA_PIN, GRB>(...)template path remains functional (no regressions for existing sketches; no removal of the#define USE_WS2812SERIALgate on the legacy path). -
ChannelManagerdriver dump on boot lists all four Teensy 4.x clockless options:BIT_BANG (pri 0), LPUART (pri 3), OBJECT_FLED (pri 5), FLEX_IO (pri 8).
Related
- [meta] Bootstrap AutoResearch driver development for Teensy 4.0 — FlexIO RX + first LED driver verification #2764 — Bootstrap AutoResearch driver development for Teensy 4.0 (this is Phase 6-adjacent: third TX driver verified against the existing FlexIO RX loopback fixture).
- feat: add ISR-backed channel poll wakeups #2992 — ISR-backed channel
poll()wakeups (the plumbing the Phase 3 async conversion will sit on). - fix(autoresearch): exercise both ObjectFLED and FlexIO on Teensy 4.x #3005 —
fix(autoresearch): exercise both ObjectFLED and FlexIO on Teensy 4.x(the--lpuartflag in Phase 2 of this issue follows the same pattern). - fix(parlio): mock waitAllDone() pumps deferred ISR callbacks to mirror real-DMA semantics (#2992 follow-up) #3010 —
fix(parlio): mock waitAllDone() pumps deferred ISR callbacks(thesettleEngineState()pattern the futurelpuart_peripheral_mockshould adopt from day one). src/platforms/arm/teensy/teensy31_32/ws2812serial_controller.h— the legacy WS2812-specific implementation we're generalizing past.- ESP32
Bus::UARTdriver — the precedent for "wave8 over UART" on a different SoC. The TeensyBus::LPUARTdriver in this issue is its iMXRT counterpart and should follow the same architectural shape.
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Jun 14, 2026
Closing as scope-too-large for a single
/clud-prPR — the issue body itself declares a Phase 1 / Phase 2 / Phase 3 decomposition (with Phase 3 explicitly called out as "Out of scope for the Phase 1 PR — file as a separate issue once Phase 1 lands"), which is exactly the right shape but doesn't fit one drive-by PR.Phase 1 alone is concrete and substantial:
src/platforms/arm/teensy/teensy4_common/drivers/ws2812serial/:channel_engine_ws2812serial.h—IChannelDriversubclass declaration.channel_engine_ws2812serial.cpp.hpp— implementation transplanting the existingCWS2812SerialControllershow-loop into the channels API.bus_traits.h—BusTraits<Bus::WS2812_SERIAL>specialization._build.cpp.hpp— engine + bus_traits inclusion.src/fl/channels/bus.h—WS2812_SERIALenumerator +busName()case + drift-preventionFL_STATIC_ASSERTbump.src/platforms/arm/teensy/teensy4_common/init_channel_driver_mxrt1062.cpp.hpp—addWS2812SerialIfPossible(manager)registration at priority 3.src/platforms/arm/teensy/channel_drivers_teensy.impl.hpp—Bus::WS2812_SERIALappended toenableDrivers<...>()parameter pack.canHandle()filter narrowed to {1200, 1300} ns bit period and the T4 LPUART TX pin set.That's ~500 lines of new platform driver code across 6 files. Acceptance verification for Phase 1 alone calls for
bash compile teensy40 --examples AutoResearch(compile-only) — Phase 2 (bash autoresearch teensy40 --ws2812-serial) needs a connected Teensy 4 board with the FlexIO RX loopback fixture wired up. Phase 3 is the wave8 streaming-ISR async conversion, which the issue body already says should be split into its own follow-up.Suggested decomposition if you want individual tracking:
canHandle()filter. Verification:bash compile teensy40 --examples AutoResearchsucceeds; legacyFastLED.addLeds<WS2812SERIAL, ...>template path remains functional.--ws2812-serialflag,phases.py--allset update,pinTx=1override,ci/tests/test_autoresearch_phases.pyupdate). Verification:bash autoresearch teensy40 --ws2812-serialbyte-for-byte loopback via FlexIO RX.If you want me to spin up dedicated tracking issues for each phase, please let me know. The plan is already detailed enough in this issue body that Phase 1 could be picked up as soon as someone has a focused session + Teensy 4 hardware on hand.
zackees commentedon Jun 14, 2026
Reopening — closing for scope wasn't a real resolution. The work still needs to happen.
[-]feat(teensy4/channels): port WS2812Serial to channels API as Bus::WS2812_SERIAL (third orthogonal peripheral; sync-first, wave8 streaming-ISR async as follow-up)[/-][+]feat(teensy4/channels): add Bus::LPUART — generic wave8-over-LPUART driver (third orthogonal peripheral; sync-first, streaming-ISR async as follow-up)[/+]zackees commentedon Jun 14, 2026
Superseded by #3023.