Skip to content

feat(platform): LPC845 PWM+DMA-to-GPIO clockless driver (Stage 2c of #2836) #2842

Closed

Description

@zackees

Stage 2c follow-up to meta issue #2836 — implement WS2812 output on LPC845 via 3 PWM channels triggering DMA-to-GPIO writes, as proposed in #2831.

Context

Stage 2a (#2837, merged) shipped a bit-banged M0+ C++ clockless driver for LPC845. At 30 MHz CPU clock the cycle budget is comfortable, so the bit-bang driver is the "boring, correct" baseline.

@phatpaul's original proposal in #2831 suggested an optimization: use 3 PWM channels to trigger DMA bursts that write to GPIO output registers, generating WS2812 timing entirely in hardware. This is novel in FastLED — no existing port uses PWM→DMA→GPIO for LED bit timing. Closest analogues are the RP2040 PIO driver and the Teensy 4.x FlexIO driver, both of which coordinate hardware shift/output engines with DMA but use different peripherals.

Benefits over the Stage 2a bit-bang path:

  • CPU free during transmission (can run frame-rate-critical animation logic)
  • Lower jitter, since timing is generated by SCT/PWM hardware not by software
  • Potential to drive multiple parallel WS2812 chains from one DMA stream (if GPIO write mask is configured properly)

Reference for the same pattern on a different NXP chip (Kinetis K64F):

Proposal

Create src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h that:

  1. Configures the SCT (State Configurable Timer) or MRT in PWM mode with 3 channels at the WS2812 T0/T1 timing positions (350 ns rising edge, 800 ns mid, 1250 ns end-of-bit).
  2. Configures DMA channels to fire on PWM channel events, each writing a fixed value (set-or-clear) to the GPIO SET/CLR registers.
  3. Source buffer is the serialized LED data converted into a DMA descriptor stream of GPIO write masks.
  4. Replaces the bit-banged driver for LPC845 when FL_LPC845 && FASTLED_LPC_PWM_DMA=1 is set.

Architectural references already in tree:

  • src/platforms/arm/rp/rpcommon/clockless_rp_pio.h — coordination of hardware timing engine with DMA
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/ — DMA-fed hardware output engine on NXP/Freescale silicon (FlexIO is the i.MX RT cousin of LPC's SCT)
  • NXP UM11029 §16 (SCT), §17 (DMA), and the LPC84x DMA matrix table

Acceptance criteria

  • src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h exists, gated by FL_LPC845 && FASTLED_LPC_PWM_DMA
  • SCT configuration is documented with NXP register references (UM11029)
  • DMA channel/trigger wiring is documented and respects the LPC84x DMA matrix
  • CPU usage during a 60 Hz update of a 144-LED strip is measured and reported (target: <5% CPU)
  • examples/Blink/Blink.ino compiles for LPC845 with the PWM+DMA driver active
  • WS2812 output verified on hardware (scope trace + visible LED output)
  • Optional: demonstrate parallel output across multiple GPIO pins from one DMA stream

Decisions

  • Priority: P3 — Optimization, not a port-completeness blocker. The Stage 2a bit-bang driver covers the basic use case.
  • Build-time opt-in via FASTLED_LPC_PWM_DMA — Bit-bang remains default. This driver consumes DMA channels and SCT events that user code may want for other purposes.
  • Novel pattern in FastLED — Code review should confirm the SCT+DMA design before any merge, not just hardware-validate after the fact. The driver design doc should be reviewed as a separate phase from the implementation.
  • Hardware validation required before merge — Same reasoning as Stage 2b.

Related issues

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