Skip to content

feat(teensy4/channels): add Bus::LPUART — generic wave8-over-LPUART driver (third orthogonal peripheral; sync-first, streaming-ISR async as follow-up) #3006

Closed as not planned

Description

@zackees

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 (0x88 for a "0" bit, 0xEE for 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>(...) at src/FastLED.h:1265-1276, gated by #define USE_WS2812SERIAL.
  • No Bus:: enum value, no IChannelDriver subclass, no bus_traits.h, no init_channel_driver_mxrt1062.cpp.hpp registration, 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::LPUART driver that, at the engine layer, narrows canHandle() 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 LPUART enumerator after OBJECT_FLED.
    • Add case Bus::LPUART: return "LPUART"; to busName().
    • Bump the drift-prevention FL_STATIC_ASSERT(static_cast<fl::u8>(Bus::STUB) == 13, ...) to 14.
  • 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 the parlio_peripheral_mock shape; reuse the shared ISR-mock fixture once it exists per the wave8 coverage discussion).
    • wave8_encoder_lpuart.{h,cpp.hpp} — adapter that consumes Wave8Byte LUT 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} — IChannelDriver subclass. getName() returns "LPUART". Capabilities(/*clockless=*/true, /*spi=*/false). Sync for Phase 1 — show() blocks via mPeripheral->waitAllDone().
    • bus_traits.h — BusTraits<Bus::LPUART> specialization mirroring objectfled/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 — add addLPUARTIfPossible(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 — append Bus::LPUART to the enableDrivers<...>() parameter pack inside the FL_IS_TEENSY_4X arm.

canHandle() filter — generic over wave8-compatible chipsets

Not a single hard-coded WS2812 window. Instead, accept any clockless chipset whose:

  1. 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
  2. Wave8 expansion at the chipset's T1/T2/T3 produces a pattern with pulse[0] == HIGH and pulse[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 — add else if (n == "LPUART") opts.mBus = fl::Bus::LPUART;.
  • ci/autoresearch/args.py — add --lpuart flag and lpuart: bool field on Args.
  • ci/autoresearch/phases.py — append "LPUART" to the --all set and the per-flag mapping. Pin pinTx=1 (T4 default TX is already 1, which is also LPUART6 TX) when driver==LPUART so it routes correctly — analogous to the FLEX_IO pinTx=6 override that landed in fix(autoresearch): exercise both ObjectFLED and FlexIO on Teensy 4.x #3005.
  • ci/tests/test_autoresearch_phases.py — update --all driver-set assertion + add lpuart=False to _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 flexioObjectFledTest RPC handler at AutoResearchRemote.cpp:1517 — just swap opts.mBus = fl::Bus::LPUART to 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 surface DriverState::DRAINING from poll() until the last byte clears the LPUART shift register.

Reference patterns:

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 AutoResearch succeeds 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 --all exercises FLEX_IO, OBJECT_FLED, and LPUART in sequence.
  • Host stub build still passes — the engine TU is gated by FL_IS_TEENSY_4X so the stub doesn't try to include LPUART register headers. Host-side coverage runs through lpuart_peripheral_mock (mirroring parlio_peripheral_mock).
  • canHandle() accepts at least: WS2812, WS2812B, WS2812B-V5, SK6812, SK6812-RGBW (verified via host-side tests/platforms/arm/teensy/teensy4_common/drivers/lpuart/channel_engine_lpuart.cpp parameterized 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_WS2812SERIAL gate on the legacy path).
  • ChannelManager driver 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

🤖 Generated with Claude Code

Activity

  1. zackees commented on Jun 14, 2026

    @zackees
    MemberAuthor

    Closing as scope-too-large for a single /clud-pr PR — 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:

    • New driver directory under src/platforms/arm/teensy/teensy4_common/drivers/ws2812serial/:
      • channel_engine_ws2812serial.h — IChannelDriver subclass declaration.
      • channel_engine_ws2812serial.cpp.hpp — implementation transplanting the existing CWS2812SerialController show-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_SERIAL enumerator + busName() case + drift-prevention FL_STATIC_ASSERT bump.
    • 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_SERIAL appended to enableDrivers<...>() 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:

    1. Phase 1 PR — sync engine + channels-API registration + canHandle() filter. Verification: bash compile teensy40 --examples AutoResearch succeeds; legacy FastLED.addLeds<WS2812SERIAL, ...> template path remains functional.
    2. Phase 2 PR — AutoResearch wiring (--ws2812-serial flag, phases.py --all set update, pinTx=1 override, ci/tests/test_autoresearch_phases.py update). Verification: bash autoresearch teensy40 --ws2812-serial byte-for-byte loopback via FlexIO RX.
    3. Phase 3 PR — wave8 streaming-ISR async conversion (already explicitly BIG TODO in the body — file as a fresh issue when Phase 1 lands).

    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.

  2. moved this from Triage to Done in FastLED Trackeron Jun 14, 2026
  3. zackees commented on Jun 14, 2026

    @zackees
    MemberAuthor

    Reopening — closing for scope wasn't a real resolution. The work still needs to happen.

  4. moved this from Done to Triage in FastLED Trackeron Jun 14, 2026
  5. changed the title [-]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)[/+] on Jun 14, 2026
  6. zackees commented on Jun 14, 2026

    @zackees
    MemberAuthor

    Superseded by #3023.

  7. moved this from Triage to Done in FastLED Trackeron Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions