Skip to content

Introduce l/channels/rx with RxChannel as the public RX API #2397

Closed

Description

@zackees

Summary

After more design work, the right public shape for RX appears to be:

  • keep the existing fl::Channel TX/output-oriented
  • add a sibling RX API under src/fl/channels/rx/**
  • make the public RX object fl::RxChannel
  • keep RxDevice as the internal backend layer / compatibility shim

This is different from folding RX into the current Channel class, and different from leaving RX as only a backend-oriented RxDevice factory.

The key constraint is that every device needs a channel-shaped public handle, because that is what enables AutoResearch and validation flows to reason in terms of persistent, addressable channels.

Why this shape

Today the codebase has a mismatch:

  • TX is channel-managed and channel-addressable:
    • src/fl/channels/channel.h
    • src/fl/channels/data.h
    • src/fl/channels/driver.h
    • src/fl/channels/manager.h
  • RX is backend/device-oriented:
    • src/fl/rx_device.h
    • src/platforms/esp/32/drivers/rmt_rx/rmt_rx_channel.h
    • src/platforms/esp/32/drivers/gpio_isr_rx/gpio_isr_rx.h

And AutoResearch already treats RX conceptually as a channel:

  • examples/AutoResearch/AutoResearch.ino
  • examples/AutoResearch/AutoResearchTest.h
  • examples/AutoResearch/AutoResearchTest.cpp
  • src/fl/channels/detail/validation/rx_test.h

But the public API still exposes RX mostly as a backend/device abstraction.

That creates the wrong center of gravity.

Recommendation

Introduce a sibling RX subsystem:

  • src/fl/channels/rx/types.h
  • src/fl/channels/rx/config.h
  • src/fl/channels/rx/channel.h
  • src/fl/channels/rx/manager.h (lightweight, optional but likely useful)

Public type:

  • fl::RxChannel

Internal/backend types remain:

  • RxDevice
  • RmtRxChannel
  • GpioIsrRx
  • FlexPwmRxChannel
  • NativeRxDevice

Proposed public API

Types

namespace fl {

enum class RxBackend : u8 {
    PLATFORM_DEFAULT,
    RMT,
    ISR,
    FLEXPWM
};

struct RxChannelConfig {
    fl::string name;
    int pin = -1;
    RxBackend backend = RxBackend::PLATFORM_DEFAULT;
    fl::string affinity;  // optional exact backend name override

    size_t edge_capacity = 4096;
    fl::optional<u32> hz = 40000000;
    u32 signal_range_min_ns = 100;
    u32 signal_range_max_ns = 100000;
    u32 skip_signals = 0;
    bool start_low = true;
    bool io_loop_back = false;
    bool use_dma = false;
};

}

Channel object

namespace fl {

class RxChannel {
public:
    static fl::shared_ptr<RxChannel> create(const RxChannelConfig&);

    int id() const;
    const fl::string& name() const;
    int getPin() const;
    fl::string getEngineName() const;

    bool begin(const RxChannelConfig&) FL_NOEXCEPT;
    bool finished() const FL_NOEXCEPT;
    RxWaitResult wait(u32 timeout_ms) FL_NOEXCEPT;

    fl::result<u32, DecodeError> decode(const ChipsetTiming4Phase&, fl::span<u8>) FL_NOEXCEPT;
    size_t getRawEdgeTimes(fl::span<EdgeTime> out, size_t offset = 0) FL_NOEXCEPT;
    bool injectEdges(fl::span<const EdgeTime>) FL_NOEXCEPT;
};

}

FastLED entrypoint

auto rx = FastLED.addRx(rx_config);

This mirrors FastLED.add(...) on the TX side and gives AutoResearch a first-class RX channel object.

Important non-goals

Not this

  • do not make RX inherit the existing TX Channel
  • do not force RX into IChannelDriver::enqueue()/show()/poll()
  • do not keep RxDevice as the long-term primary public abstraction

Why not

The current TX Channel is tightly coupled to CPixelLEDController and TX submission semantics. RX has a different lifecycle:

  • begin()
  • wait()
  • decode()
  • getRawEdgeTimes()

So RX should be a sibling channel type, not a subclass of the TX channel.

AutoResearch impact

This shape is specifically intended to make AutoResearch cleaner.

AutoResearch should be able to think in:

  • TX side: Channel
  • RX side: RxChannel
  • orchestration: fl::validation

That means updating AutoResearchConfig from shared_ptr<RxDevice> to shared_ptr<RxChannel> and moving the canonical capture logic out of example-local helpers into src/fl/channels/validation/*.

Migration path

  1. Add fl/channels/rx/*.
  2. Implement RxChannel as a wrapper over existing RxDevice backends.
  3. Add FastLED.addRx(...).
  4. Migrate AutoResearch and validation code to RxChannel.
  5. Keep fl/rx_device.h as a compatibility shim for a while.

Possible transition pattern:

  • RxDevice::create<T>() forwards internally to RxChannel::create(...)
  • existing platform code stays mostly in place initially

Optional lightweight manager

A lightweight fl/channels/rx/manager.h may still be useful for:

  • lookup by id / name / pin
  • registration / discovery for AutoResearch
  • keeping RX channel-addressable

This should be much lighter than ChannelManager and should not copy TX driver semantics blindly.

Tradeoffs

Pros

  • satisfies the requirement that every device has a channel
  • keeps RX addressable by id / name / pin
  • preserves existing TX Channel semantics
  • gives RX a clean public home next to the channels subsystem
  • keeps backend/resource refactors possible under the API later

Cons

  • fl/channels/** becomes explicitly broader than TX-only, which needs docs clarity
  • RxChannel is channel-like but not API-identical to Channel
  • some validation-specific decode policy will still live in validation helpers, not in generic backend code

Related

Bottom line

The cleanest next step is:

Add fl/channels/rx with RxChannel as a first-class public API, and demote RxDevice to backend/compatibility status.

Activity

  1. added
    area: core
    on Apr 24, 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

    area: core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions