Class Channel

extends Object
An RMT channel.
The channel must be configured after construction.
The channel can be configured for either RX or TX.
Deprecated. Use In and Out instead.

Class summary


constructor pin/any --memory-block-count/int= --channel-id/int=
Constructs a channel using the given num using the given pin.
constructor --input/bool pin/any --memory-block-count/int= --channel-id/int= --clk-div/int= --flags/int= --idle-threshold/int= --enable-filter/bool= --filter-ticks-threshold/int= --buffer-size/int=
Variant of constructor pin.
constructor --output/bool pin/any --memory-block-count/int= --channel-id/int= --clk-div/int= --flags/int= --enable-carrier/bool= --carrier-frequency-hz/int= --carrier-level/int= --carrier-duty-percent/int= --idle-level/int=
Variant of constructor pin.

Constructors

constructor pin/any --memory-block-count/int=1 --channel-id/int=null
Constructs a channel using the given num using the given pin.
Note: only the ESP32 and the ESP32S2 support configuring the channel direction at a later time. For all other platforms, this constructor will give a TX channel, unless the channel-id is provided.
The memory-block-count determines how many memory blocks are assigned to this channel. See the Advanced section for more information.
The channel-id should generally be left as default. If provided, it selects the channel with that physical id. On a standard ESP32, there are 8 channels which can be selected by providing a channel id in the range [0,7]. See the advanced section for when this can be useful.
This constructor does not configure the channel for input or output yet. Call configure (either --input or --output) to do so.
Deprecated. Use the --input or --output constructor instead.
Advanced
The memory-block-count determines how many memory blocks are assigned to this channel. Memory blocks are of size 256 bytes or 128 signals. They are in continuous memory and there are only a limited number of them.
Generally, output channels don't need extra blocks as interrupts will copy data into the buffer when necessary. However, input channels can only receive as many signals (in one sequence) as there is space in the memory blocks.
If a channel requests more than one memory block, then the following internal channel id is marked as used as well.
Users might run into fragmentation issues as well: there might still be more than 1 free memory block, but if they are not next to each other, then a channel can't use them at the same time. The given channel-id parameter may be used to force the constructor to use a certain channel. Internally, channels always use their own memory block, plus the required additional memory blocks. The additional memory blocks come from the channels with the next-higher ids.
Example
Say a program starts by allocating two channels, A and then B.
It then releases channel A. If the program now wants to allocate a channel with 7 memory blocks, it would fail, as there are only 6 continuous memory blocks available.
The developer could force channel A to use channel id 1, and channel B to use id 0. This way releasing channel A would free the second memory block (at location 1) and thus allow the creation of a channel with 7 memory blocks.

constructor --input/bool pin/any --memory-block-count/int=1 --channel-id/int=null --clk-div/int=DEFAULT-IN-CLK-DIV --flags/int=DEFAULT-IN-FLAGS --idle-threshold/int=DEFAULT-IN-IDLE-THRESHOLD --enable-filter/bool=DEFAULT-IN-ENABLE-FILTER --filter-ticks-threshold/int=DEFAULT-IN-FILTER-TICKS-THRESHOLD --buffer-size/int=null
Variant of constructor pin.
Configures the channel for input. See configure --input for input parameters.

constructor --output/bool pin/any --memory-block-count/int=1 --channel-id/int=null --clk-div/int=DEFAULT-OUT-CLK-DIV --flags/int=DEFAULT-OUT-FLAGS --enable-carrier/bool=DEFAULT-OUT-ENABLE-CARRIER --carrier-frequency-hz/int=DEFAULT-OUT-CARRIER-FREQUENCY --carrier-level/int=DEFAULT-OUT-CARRIER-LEVEL --carrier-duty-percent/int=DEFAULT-OUT-CARRIER-DUTY-PERCENT --idle-level/int=DEFAULT-OUT-IDLE-LEVEL
Variant of constructor pin.
Configures the channel for output. See configure --output for output parameters.

Statics

make-bidirectional --in/Channel --out/Channel --pull-up/bool=false -> none
Deprecated. Create an In channel first, then create an Out channel with the --open-drain flag on the same pin, instead.
Takes the in and out channel that share the same pin and configures them to be bidirectional.
The out channel must be configured as output (see configure --output) and must have been configured before the in channel, which must be configured as input (see configure --input).
Sets the pin to open-drain, as the input channel would otherwise just read the signals of the output channel.
If pull-up is true, then the internal pull-up is enabled.
This function can be used to implement protocols that communicate over one wire, like the 1-wire protocol or the one used for DHTxx sensors.
Any new call to configure requires a new call to this function.

Methods

close -> none
Closes the channel.

configure --input/bool --clk-div/int=DEFAULT-IN-CLK-DIV --flags/int=DEFAULT-IN-FLAGS --idle-threshold/int=DEFAULT-IN-IDLE-THRESHOLD --enable-filter/bool=DEFAULT-IN-ENABLE-FILTER --filter-ticks-threshold/int=DEFAULT-IN-FILTER-TICKS-THRESHOLD --buffer-size/int=null -> none
Configures the channel for input.
Only some chips (for example ESP32 and ESP32S2) support configuring the channel direction at a later time. For all other platforms changing direction will throw.
The clk-div divides the 80MHz clock. The value must be in range [1, 255].
The RMT unit works with ticks. All sent and received signals count ticks.
The flags can be found in the ESP-IDF documentation.
The idle-threshold determines how many ticks the channel must not change before it is considered idle (and thus finishes a signal sequence). The value must be in range [1, 32767] (15 bits).
If enable-filter is set, discards signals that are shorter than filter-ticks-threshold. Contrary to most other parameters, the filter counts the APB ticks and not the divided clock ticks. The value must be in range [0, 255].
The buffer-size determines how many signals can be buffered before the channel is considered full. This buffer is used internally to copy signals from the RMT memory blocks (which have been reserved in the constructor) to user code.
The maximum size of any item in this buffer is less than half of the buffer size. This means that the buffer should be 8 bytes + the maximum expected size (which must be a multiple of 4, as each signal is handled in pairs of 16 bits).
By default it is set to twice the size of the reserved memory blocks (which limit the size of the received signal sequence). However, due to the book-keeping overhead this means that some very long signal sequences can not be received. If necessary, adjust to a bigger size.
If the input is well known and has a limited size it's ok to request a smaller size. In that case request at least twice the expected size + 8.
Another use case, where bigger buffers are necessary, is when the input can receive multiple sequences where the handling of the data might not be fast enough. In that case, too, it is necessary to increase the buffer size.

configure --output/bool --clk-div/int=DEFAULT-OUT-CLK-DIV --flags/int=DEFAULT-OUT-FLAGS --enable-carrier/bool=DEFAULT-OUT-ENABLE-CARRIER --carrier-frequency-hz/int=DEFAULT-OUT-CARRIER-FREQUENCY --carrier-level/int=DEFAULT-OUT-CARRIER-LEVEL --carrier-duty-percent/int=DEFAULT-OUT-CARRIER-DUTY-PERCENT --idle-level/int=DEFAULT-OUT-IDLE-LEVEL -> none
Configures the channel for output.
Only some chips (for example ESP32 and ESP32S2) support configuring the channel direction at a later time. For all other platforms changing direction will throw.
The clk-div divides the 80MHz clock. The value must be in range [1, 255].
The RMT unit works with ticks. All sent and received signals count ticks.
The flags can be found in the ESP-IDF documentation.
When the carrier is enabled (enable-carrier) the output signal is a square wave that is modulated by the pulses. In that case the clock frequency (80MHz) is divided by the carrier-frequency-hz, yielding duty units. These are then divided according to the carrier-duty-percent.
The carrier-level indicates at which level of the RMT pulses the carrier (and thus any output) is enabled. When set to 1 transmits on low output level, and when equal to 0 transmits on high output level.
The idle-level is the level that the channel is set to when it is idle.

idle-threshold= threshold/int -> none

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

read --stop-reading/bool=null -> Signals
Receives signals.
This channel must be configured for receiving (see configure --input).
The result may contain trailing 0-period signals. Those should be ignored.
If the channel hasn't yet started to read, starts reading (start-reading). However, does not flush
If stop-reading is true, stops reading after the next signal is received.
If stop-reading is false, always keeps the channel reading.
If stop-reading is null, stops reading if the channel wasn't reading yet.

start-reading --flush/bool=true -> none
Starts receiving signals for this channel.
This channel must be configured for receiving (see configure --input).
If flush is set (the default) flushes all buffered signals.

stop-reading -> none
Stops receiving.

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.

write signals/Signals -> none
Transmits the given signals.
This channel must be configured for writing (see configure --output).

Fields

pin / any