Skip to content

feat(lpuart): finish Teensy 4 LPUART engine + encoder + bus_traits + canHandle() host test (split from #3122 B1 / refs #3023) #3157

Closed

Description

@zackees

Why this issue exists

Split from the now-closed rundown meta #3122 row B1. The LPUART driver work tracked under meta #3023 has its real hardware-side driver (lpuart_peripheral_real) explicitly deferred — but the remaining off-bench pieces (engine + encoder + bus_traits + registration + host test) aren't tracked as a single focused PR-able unit anywhere. This issue fixes that.

Scope

Land the host-testable LPUART engine layer for Teensy 4 (iMXRT1062), against the mock peripheral that already shipped in #3032. The real iMXRT register driver stays hardware-deferred under #3023 — this issue is the layer that sits on top of whichever peripheral implementation runs.

Files

All under src/platforms/arm/teensy/teensy4_common/drivers/lpuart/ unless otherwise noted:

  • wave8_encoder_lpuart.{h,cpp.hpp} — packs a Wave8Byte into the 8 programmable UART data bits per frame (start/stop framing handled by the inverted hardware). Mirror the existing wave8_encoder_uart.{h,cpp.hpp} pattern from the ESP32 side.
  • channel_engine_lpuart.{h,cpp.hpp} — IChannelDriver subclass. Sync show() for this issue's phase 1; async path follows under [meta] Teensy 4 channels-API driver coverage + verification fixtures (supersedes #2764, #3006) #3023 §D.
  • bus_traits.h — BusTraits<Bus::LPUART> mirroring the objectfled / flex_io patterns (Driver typedef, instancePtr(), instance(), registerWithManager() at priority 3) plus BusSupports<Bus::LPUART, ClocklessChipset> : fl::true_type.
  • _build.cpp.hpp — engine-side unity-build aggregator that pulls in the new TUs above. The mock-side _build.cpp.hpp already exists (feat(lpuart): scaffold Teensy 4 LPUART peripheral interface + host mock (refs #3023) #3032).
  • src/platforms/arm/teensy/teensy4_common/init_channel_driver_mxrt1062.cpp.hpp — register the driver at priority 3 (between BIT_BANG=0 and OBJECT_FLED=5; LPUART is single-strip + pin-restricted so lower than ObjectFLED's any-pin parallel fan-out).
  • src/platforms/arm/teensy/channel_drivers_teensy.impl.hpp — append Bus::LPUART to the enableDrivers<...>() pack in the FL_IS_TEENSY_4X arm.
  • tests/platforms/arm/teensy/teensy4_common/drivers/lpuart/channel_engine_lpuart.cpp — parameterized host test for canHandle() against the mock peripheral. Asserts:
    • Accepts: WS2812, WS2812B, WS2812B-V5, SK6812, SK6812-RGBW.
    • Rejects: APA102, SK9822 (clocked SPI), plus any chipset whose wave8 expansion violates the leading-HIGH/trailing-LOW topology.

canHandle() — wave8-generic, not chipset-specific

Same shape as the LPUART proposal in #3023 §A:

bool ChannelEngineLPUART::canHandle(const ChannelDataPtr& data) const FL_NOEXCEPT {
    if (!data || !data->isClockless()) return false;
    const ChipsetTiming& t = data->getTiming();
    // (1) Bit period must fit the LPUART baud-rate range
    if (t.total_period_ns() < kLPUARTMinBitPeriodNs ||
        t.total_period_ns() > kLPUARTMaxBitPeriodNs) return false;
    // (2) Wave8 expansion must have leading HIGH and trailing LOW
    auto lut = buildWave8ByteExpansionLUT(buildWave8ExpansionLUT(t));
    if ((lut.lut[0x00].symbols[0].data & 0x80) == 0) return false;
    if ((lut.lut[0xFF].symbols[7].data & 0x01) != 0) return false;
    return mPeripheral->canHandlePin(static_cast<u8>(data->getPin()));
}

Acceptance

  • bash compile teensy40 --examples AutoResearch succeeds with the new engine wired in.
  • Host stub build still passes (engine TU gated by FL_IS_TEENSY_4X).
  • The new canHandle() parameterized test passes against the mock.
  • ChannelManager boot dump lists all four T4.x clockless options: BIT_BANG (pri 0), LPUART (pri 3), OBJECT_FLED (pri 5), FLEX_IO (pri 8).
  • Legacy FastLED.addLeds<WS2812SERIAL, DATA_PIN, GRB>(...) template path remains functional (no regressions; no removal of the #define USE_WS2812SERIAL gate on the legacy path).

Out of scope

Why this is a focused issue rather than rundown-row work

The original rundown meta #3122 B1 mis-scoped this as a single rundown-row commitment. Six files of C++ + a parameterized host test + integration with the existing channels registry + careful coexistence with the legacy WS2812SERIAL controller path is a 3-4 hour focused PR with real review surface, not a "go" / "skip" item. Pulling it into its own issue is the right scoping. See the closeout comment on #3122 for the full rundown context.

Cross-references

Activity

  1. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    Positioning clarification — LPUART is the clockless-only, memory-efficient backend

    Per the discussion that prompted this issue's filing, locking in the LPUART positioning explicitly so future readers don't go down the wrong path:

    What LPUART IS for on Teensy 4:

    • The simple, memory-efficient clockless driver. ~2 KB wave8 LUT per chipset binding + a thin engine layer. No dynamic state, no per-frame allocation.
    • Mixed-chipset independent strips — each LPUART instance can drive a different WS281x-family chipset (WS2812B, SK6812, UCS7604, TM181x) concurrently.
    • The third orthogonal hardware path next to FlexIO and ObjectFLED. Lets a sketch run a 4th strip while FlexIO is mid-transfer and ObjectFLED is mid-DMA.

    What LPUART is NOT for, and why it's structurally impossible:

    LPUART cannot drive SPI/clocked chipsets (APA102, SK9822) — not as a missing feature but as a hardware-level non-starter:

    1. Baud generators are phase-independent. Each LPUART instance free-runs off its own clock divider with no phase-lock mechanism. Inter-instance phase offsets up to ~300 ns at 3.33 Mbaud. APA102's SPI setup-time spec is ~5 ns. Can't fake a synchronized SPI clock by using one LPUART for clock + seven for data.
    2. UART framing forces start/stop bits every 8 data bits. For clockless this is a feature (maps to leading-HIGH/trailing-LOW topology). For SPI this corrupts the bitstream every 8 bits. There's no "raw shifter" mode on iMXRT1062 LPUART.

    These constraints belong in this issue's canHandle() predicate design (predicate #2 — the wave8 topology check — is exactly the static enforcement of constraint #2 above).

    SPI support on Teensy 4 will land via FlexIO and ObjectFLED extensions, not via LPUART. Those are tracked as separate focused issues (linked below).

    Cross-references for the next person picking this up:

  2. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    Companion SPI issues now filed:

    This completes the Teensy 4 channels-API SPI landscape:

  3. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    Cross-reference: #3186 — declarative DriverCapabilities + central resolver. LPUART here will publish 8 PinGroup entries, one per LPUART instance, each with a single TX pin in data_pins and max_concurrent=1. Resolver-side pin rejection becomes NoPin (pin not in the union of LPUART instance TX pins) rather than runtime drop.

  4. zackees commented on Jun 18, 2026

    @zackees
    MemberAuthor

    Closing per the 2026-06-18 session closeout — see #3023 for the meta context.

    What's covered:

    What's deferred to a bench session:

    • lpuart_peripheral_real.{h,cpp.hpp} iMXRT register driver - explicitly hardware-deferred per the original issue scope.
    • channel_engine_lpuart.{h,cpp.hpp} + wave8_encoder_lpuart.{h,cpp.hpp} + bus_traits.h + host test - the full off-bench engine layer ships as a follow-up PR once the iMXRT register driver is on the desk for end-to-end verification.

    Reopen when picking the bench work back up.

  5. moved this from Triage to Done in FastLED Trackeron Jun 18, 2026
  6. zackees commented on Jun 18, 2026

    @zackees
    MemberAuthor

    Reopening — the 2026-06-18 closure was premature. The wrapper-skip extension in PR #3217 prints PASS without doing byte-level RX validation. See #3066 acknowledgement for the full context. Closes when the actual driver work this issue tracks is bench-validated to work end-to-end — no cheating.

  7. moved this from Done to Triage in FastLED Trackeron Jun 18, 2026
  8. zackees commented on Jun 27, 2026

    @zackees
    MemberAuthor

    Closed by PR #3421 () -- all Phase 1 acceptance criteria met:

    • ✓ wave8_encoder_lpuart equivalent: src/platforms/arm/teensy/teensy4_common/drivers/lpuart/lpuart_encoder.h (pure-function wave8 encoder, host-testable)
    • ✓ channel_engine_lpuart.{h,cpp.hpp}: IChannelDriver subclass with sync show()
    • ✓ bus_traits.h: BusTraits<Bus::LPUART> + BusTraits<Bus::UART> (cross-platform alias) + BusSupports<Bus::LPUART, ClocklessChipset>
    • ✓ Engine _build.cpp.hpp aggregator
    • ✓ Registration in channel_drivers_teensy.impl.hpp via enableDrivers<fl::Bus::UART>
    • ✓ Host test: tests/platforms/arm/teensy/teensy4_common/drivers/lpuart/lpuart_encoder.cpp + ilpuart_peripheral.cpp
    • ✓ canHandle(): wave8-generic via period range check + pin validation
    • ✓ Hardware-verified on Teensy 4.0 (LPUART4, pin 8 → wire → pin 22, 5/5 success rate post-framework-fix in 6a46bb2, byte corruption 0.3-2.0% noise floor)
    • ✓ T4.1 pin coverage (35/47/53) audited and added in commit 7d79576

    Async streaming-ISR follow-up tracked separately under #3182.

  9. moved this from Triage to Done in FastLED Trackeron Jun 27, 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