Skip to content

Refactor RX devices into a shared signal-device layer; keep Channel API TX-only #2396

Closed

Description

@zackees

Summary

FastLED currently has two parallel hardware abstractions that are starting to overlap conceptually but not architecturally:

  • TX path: Channel -> ChannelData -> IChannelDriver -> ChannelManager
  • RX path: RxDevice -> RmtRxChannel / GpioIsrRx / FlexPwmRxChannel

The overlap is now visible enough that it is worth deciding whether RX should be folded into the Channel API, or whether both TX and RX should instead sit on top of a shared lower-level device/backend layer.

My recommendation is:

Do not move RX directly into the current Channel API.

Instead, keep Channel explicitly TX/output-oriented, and introduce a shared signal-device / peripheral-backend layer below both TX and RX.

Why not put RX directly in the Channel API?

The current Channel API is strongly output-centric by design:

  • Channel owns LED spans, gamma, color order, screen maps, and showLeds() / showPixels() lifecycle.
  • ChannelData is an encoded transmit buffer DTO.
  • IChannelDriver is an enqueue/show/poll state machine for transmission.
  • ChannelManager is a TX router/priority selector for output drivers.

RX does not match those semantics well:

  • RxDevice models begin() / wait() / decode() / getRawEdgeTimes().
  • RX output is captured edges / decoded bytes, not LED frames.
  • RX is used by validation and autoresearch independent of any LED Channel object.
  • RxDeviceType::{RMT, ISR, FLEXPWM} are transport/capture choices, not LED-strip renderers.

Trying to force RX into the current Channel API would either:

  1. overload Channel with non-output meaning, or
  2. distort RX into an unnatural enqueue() / show() / poll() shape.

Evidence in the current tree

Relevant files:

  • src/fl/channels/channel.h
  • src/fl/channels/data.h
  • src/fl/channels/driver.h
  • src/fl/channels/manager.h
  • src/fl/rx_device.h
  • src/fl/rx_device.cpp.hpp
  • src/platforms/esp/32/drivers/rmt_rx/rmt_rx_channel.h
  • src/platforms/esp/32/drivers/gpio_isr_rx/gpio_isr_rx.h
  • src/platforms/shared/rx_device_native.h
  • examples/AutoResearch/AutoResearch*.{ino,h,cpp}

There is already a strong architectural hint that TX and RX share hardware resource concerns even though their APIs are separate:

  • src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp explicitly coordinates TX DMA policy around active RX channels.
  • RmtMemoryManager and related comments already treat TX and RX as consumers of the same underlying RMT resource domain.
  • README.md describes the driver stack as a platform-neutral channel driver plus thin platform peripheral layer, but RX currently lives outside that layering.

So the shared concern is real, but the current Channel abstraction is the wrong level to absorb it.

Proposed refactor option

Option A (recommended): shared backend layer under both TX and RX

Add a new layer for hardware/peripheral ownership and capabilities. Example naming could be one of:

  • fl::signal
  • fl::io
  • fl::peripherals

The important part is the shape, not the exact namespace.

Suggested responsibilities:

  • Backend/resource layer

    • Owns peripheral handles, DMA slots, memory pools, IRQ registration, GPIO binding, loopback capability, etc.
    • Exposes capability flags like tx, rx, clockless, spi, capture_edges, decode_assist, etc.
    • Centralizes cross-cutting resource arbitration such as RMT TX/RX DMA conflicts.
  • TX adapter layer

    • Existing IChannelDriver implementations become TX adapters over the backend/resource layer.
    • ChannelManager remains the TX-facing router.
  • RX adapter layer

    • RxDevice implementations become RX adapters over the same backend/resource layer.
    • Optionally add an RxManager or DeviceRegistry later if runtime selection by capability/name becomes useful.

First migration slice

A practical incremental path:

  1. Do not break public APIs first.
    Keep Channel, IChannelDriver, ChannelManager, and RxDevice public surfaces intact.

  2. Extract shared resource ownership first.
    Start with RMT, because it already has visible TX/RX interaction.
    Create a shared RMT backend/resource object used by both ChannelEngineRMT and RmtRxChannel.

  3. Move arbitration logic down.
    Things like DMA slot ownership, memory block accounting, loopback compatibility, and TX/RX coexistence policy should live below both APIs rather than leaking across them.

  4. Only after that, add a generic device registry if still useful.
    That would allow future APIs like named RX backend selection or affinity, without forcing RX into Channel.

What this buys us

  • Preserves the clean meaning of Channel as an LED output abstraction.
  • Gives RX a first-class architectural home instead of leaving it as a parallel one-off tree.
  • Fixes the real pain point: shared peripheral/resource logic duplicated or leaked across TX/RX implementations.
  • Makes future peripherals easier to model when they support both TX and RX modes.
  • Avoids turning the Channels API into a catch-all abstraction for anything that touches a pin.

Non-goal

This issue is not proposing to delete RxDevice or immediately replace it with Channels API calls.

The goal is to refactor the layering so that:

  • Channel stays TX-facing,
  • RxDevice stays RX-facing,
  • and both share the same lower-level backend/resource model where appropriate.

Related

Concrete deliverable for this issue

A good outcome here would be agreement on the target architecture and a first implementation step such as:

  • extracting shared RMT TX/RX backend/resource management into a common module, or
  • creating a minimal signal / io backend interface used by both ChannelEngineRMT and RmtRxChannel.

Activity

  1. added
    area: core
    on Apr 24, 2026
  2. zackees commented on Apr 24, 2026

    @zackees
    MemberAuthor

    Follow-up design direction is now tracked in #2397.\n\nThe updated conclusion is not to keep RX entirely outside channels, but to introduce a sibling API under l/channels/rx/** with RxChannel as the public type, while keeping the existing TX Channel TX-only and leaving RxDevice as the internal backend / compatibility layer.

  3. zackees commented on May 24, 2026

    @zackees
    MemberAuthor

    Closing as completed — superseded by #2397.

    The architectural decision was made (per the April 24 comment in this thread): "introduce a sibling API under `fl/channels/rx/**` with `RxChannel` as the public type, while keeping the existing TX `Channel` TX-only and leaving `RxDevice` as the internal backend / compatibility layer."

    Follow-up tracker #2397 (Introduce `fl/channels/rx` with `RxChannel` as the public RX API) is CLOSED. The codebase reflects this: src/fl/channels/rx/ exists (channel.cpp.hpp, channel.h, config.h, types.h, _build.cpp.hpp), and the commits that delivered it are merged:

    • b22324b3eb — Add public RxChannel API under fl/channels/rx
    • b42e28c3f0 — Move RX interface under fl/channels
    • c269a6a024 — refactor(fl/channels): relocate id_tracker and RxDevice impl into channels API

    Nothing further to do on this design-discussion issue.

    🤖 Reviewed with Claude Code

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

    area: core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions