API referencestd/embedded

std/embedded/peripheral/esp_rmt

Public declarations, types, methods, and source contracts for std/embedded/peripheral/esp_rmt.

On this page

Library guide · API index and notation

This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.

import "std/embedded/peripheral/esp_rmt"

Names used in signatures

Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.

Alias Package Source file
hal std/embedded/hal esp_rmt.dodo

TX_CHANNELS

Constant · Source

Transmit and receive channels, and memory blocks; a block holds 48 codes.

pub const TX_CHANNELS: u32 = 2

RX_CHANNELS

Constant · Source

pub const RX_CHANNELS: u32 = 2

BLOCKS

Constant · Source

pub const BLOCKS: u32 = 4

BLOCK_CODES

Constant · Source

pub const BLOCK_CODES: usize = 48

MAX_TICKS

Constant · Source

The longest duration in a code, in ticks.

pub const MAX_TICKS: u32 = 0x7FFF

END

Constant · Source

A code that ends a pulse train.

pub const END: u32 = 0

MAX_DIVIDER

Constant · Source

The most a channel’s clock divides the source clock by.

pub const MAX_DIVIDER: u32 = 256

MAX_LOOPS

Constant · Source

The most times start_loop repeats its codes.

pub const MAX_LOOPS: u32 = 1023

MAX_FILTER_CYCLES

Constant · Source

The longest pulse the glitch filter removes, in source clock cycles.

pub const MAX_FILTER_CYCLES: u32 = 255

code

Function · Source

The code of a level for ticks0, then a level for ticks1; both 0 to MAX_TICKS, and a 0 ends the pulse train there.

pub fn code(level0: bool, ticks0: u32, level1: bool, ticks1: u32) -> u32

level0

Function · Source

A code’s first level and duration, then its second.

pub fn level0(code: u32) -> bool

ticks0

Function · Source

pub fn ticks0(code: u32) -> u32

level1

Function · Source

pub fn level1(code: u32) -> bool

ticks1

Function · Source

pub fn ticks1(code: u32) -> u32

encode

Function · Source

Write the codes of pulses that alternate between high and low, starting high when first_high, with the durations in ticks of durations, into out, and return how many codes that took. A duration longer than MAX_TICKS becomes several pulses at the same level; an odd number of pulses leaves the last code’s second duration 0, which ends the pulse train. InvalidInput for a duration of 0, Overrun if out is too short.

pub fn encode(first_high: bool, durations: &[u32], out: &mut[u32]) -> usize!hal.Error

divider

Function · Source

The channel divider for ticks at resolution_hz from a source clock at source_hz: the closest of 1 to MAX_DIVIDER. InvalidInput if none is within reach.

pub fn divider(source_hz: u32, resolution_hz: u32) -> u32!hal.Error

carrier_counts

Function · Source

The carrier’s high and low counts, CHCARRIER_DUTY’s CARRIER_HIGH and CARRIER_LOW, for carrier_hz at duty_percent from a clock at clock_hz, or 0 for no carrier (carrier_hz 0). InvalidInput for a duty cycle outside 1 to 99 percent, or a frequency whose counts fall outside 1 to 65535.

pub fn carrier_counts(clock_hz: u32, carrier_hz: u32, duty_percent: u32) -> u32!hal.Error

TxConfig

Struct · Source

A transmit channel’s settings.

pub struct TxConfig {
    // The tick in which codes count, 312.5 kHz to the source clock
    // (80 MHz); the channel gets the closest its divider makes.
    pub resolution_hz: u32
    // The output's level between pulse trains.
    pub idle_high: bool
    // A carrier modulating the output, 0 for none, and its duty cycle,
    // 1 to 99 percent; counted in source clock cycles, so 1.3 kHz to
    // 40 MHz from 80 MHz.
    pub carrier_hz: u32
    pub carrier_duty_percent: u32
    // Modulate the low level instead of the high one.
    pub carrier_on_low: bool
    // Blocks of RMT memory, 1 to 4 less the channel's number: the codes
    // that fit before the transmission must be refilled.
    pub memory_blocks: u32
}

TxConfig.new

Function · Source

Ticks at resolution_hz, idle low, no carrier, one block.

pub fn new(resolution_hz: u32) -> TxConfig

RxConfig

Struct · Source

A receive channel’s settings.

pub struct RxConfig {
    // The tick in which codes count, as for TxConfig.
    pub resolution_hz: u32
    // The ticks, 1 to MAX_TICKS, the input must keep its level for the
    // frame to end.
    pub idle_ticks: u32
    // Pulses shorter than this are ignored; 0 turns the filter off. It
    // counts source clock cycles, up to MAX_FILTER_CYCLES: 3187 ns from
    // 80 MHz.
    pub filter_ns: u32
    // Demodulate a carrier of this frequency, 0 for none, and duty cycle,
    // counted in ticks: the resolution must be several times the carrier
    // frequency.
    pub carrier_hz: u32
    pub carrier_duty_percent: u32
    // The carrier is on the low level instead of the high one.
    pub carrier_on_low: bool
    // Blocks of RMT memory, 1 for receive channel 1, 1 or 2 for channel 0:
    // the codes that arrive before the channel must be emptied.
    pub memory_blocks: u32
}

RxConfig.new

Function · Source

Ticks at resolution_hz, frames ending after idle_ticks, no filter, no carrier, one block.

pub fn new(resolution_hz: u32, idle_ticks: u32) -> RxConfig

check_tx

Function · Source

Check config for transmit channel channel from a source clock at source_hz; InvalidInput for settings out of range.

pub fn check_tx(source_hz: u32, channel: u32, config: &TxConfig) -> void!hal.Error

check_rx

Function · Source

Check config for receive channel channel from a source clock at source_hz; InvalidInput for settings out of range.

pub fn check_rx(source_hz: u32, channel: u32, config: &RxConfig) -> void!hal.Error

Pulses

Interface · Source

Codes a transmitter sends, computed while they go out, for send and poll_send.

pub interface Pulses {
    // How many codes, at least 1.
    fn count(&self) -> usize
    // Write codes `first` to `first + out.len - 1` into `out`.
    fn fill(&self, first: usize, out: &mut[u32])
}

Codes

Struct · Source

Codes in a slice, as Pulses.

pub struct Codes: Pulses {
    // Private implementation fields omitted.
}

Codes.new

Function · Source

pub fn new(codes: &[u32]) -> Codes from(codes)

Codes.count

Function · Source

pub fn count(&self) -> usize

Codes.fill

Function · Source

pub fn fill(&self, first: usize, out: &mut[u32])

Ws2812Pulses

Struct · Source

The pulses of colors for WS2812 addressable LEDs (also sold as NeoPixels, SK6812, and others with the same protocol): 24 codes per LED, green, red, then blue, most significant bit first, then a code that holds the line low long enough to latch the colors.

pub struct Ws2812Pulses: Pulses {
    // Private implementation fields omitted.
}

Ws2812Pulses.new

Function · Source

The pulses of colors, one 0xRRGGBB value per LED along the chain, in ticks at resolution_hz, which must be at least 10 MHz.

pub fn new(colors: &[u32], resolution_hz: u32) -> Ws2812Pulses from(colors)

Ws2812Pulses.count

Function · Source

pub fn count(&self) -> usize

Ws2812Pulses.fill

Function · Source

pub fn fill(&self, first: usize, out: &mut[u32])

Transmitter

Struct · Source

One transmit channel. Its configuration is set when it is created and kept until it is released.

pub struct Transmitter<R: hal.Registers> {
    // Private implementation fields omitted.
}

Transmitter.new

Function · Source

Configure transmit channel channel, 0 or 1, of an RMT whose source clock runs at source_hz, from config; clock gives microseconds for blocking waits. The output goes to its idle level. InvalidInput for settings out of range (check_tx).

pub fn new(registers: R, channel: u32, source_hz: u32, config: &TxConfig, clock: fn() -> u64) -> Transmitter<R>!hal.Error

Transmitter.release

Function · Source

Stop any transmission and give back the registers.

pub fn release(self) -> R

Transmitter.transmit

Function · Source

Send codes and wait until the last has gone out. InvalidInput for no codes; Busy while another transmission runs; Overrun if refilling fell behind; Bus if the channel reports an error; Timeout if the transmission takes longer than its durations add up to, plus 10 ms.

pub fn transmit(&mut self, codes: &[u32]) -> void!hal.Error

Transmitter.poll_transmit

Function · Source

Start sending codes, then, called again with the same codes, keep the channel’s memory filled; true once the last code has gone out. Errors as for transmit, without Timeout; the transmission is over after any error.

pub fn poll_transmit(&mut self, codes: &[u32]) -> bool!hal.Error

Transmitter.send

Function · Source

transmit for codes computed while they go out.

pub fn send<P: Pulses>(&mut self, pulses: &P) -> void!hal.Error

Transmitter.poll_send

Function · Source

poll_transmit for codes computed while they go out.

pub fn poll_send<P: Pulses>(&mut self, pulses: &P) -> bool!hal.Error

Transmitter.start_loop

Function · Source

Send codes, which with their end must fit the channel’s memory, count times, 1 to MAX_LOOPS, or 0 for until stop, back to back. InvalidInput for too many codes or loops; Busy while another transmission runs. poll_loop reports when the loops are done.

pub fn start_loop(&mut self, codes: &[u32], count: u32) -> void!hal.Error

Transmitter.poll_loop

Function · Source

Whether the loops of start_loop are done; never for endless ones. Bus if the channel reports an error, Unsupported without loops.

pub fn poll_loop(&mut self) -> bool!hal.Error

Transmitter.stop

Function · Source

Stop any transmission at once; the output returns to its idle level.

pub fn stop(&mut self)

Transmitter.is_busy

Function · Source

Whether a transmission or loop runs.

pub fn is_busy(&self) -> bool

Transmitter.set_memory_blocks

Function · Source

Use blocks blocks of memory from now on, 1 to 4 less the channel’s number; the blocks after the channel’s own must be free for it. InvalidInput for another number; Busy while a transmission runs.

pub fn set_memory_blocks(&mut self, blocks: u32) -> void!hal.Error

Transmitter.listen

Function · Source

Raise the RMT interrupt when the transmission ends, fails, its loops are done, or a quarter of the memory needs refilling; poll to handle and clear it. ignore stops that.

pub fn listen(&mut self)

Transmitter.ignore

Function · Source

pub fn ignore(&mut self)

Transmitter.is_pending

Function · Source

Whether this channel raises the RMT interrupt now.

pub fn is_pending(&mut self) -> bool

Transmitter.resolution_hz

Function · Source

The tick the channel counts, and the carrier frequency, 0 for none.

pub fn resolution_hz(&self) -> u32

Transmitter.carrier_hz

Function · Source

pub fn carrier_hz(&self) -> u32

Transmitter.channel

Function · Source

The transmit channel, 0 or 1.

pub fn channel(&self) -> u32

Transmitter.memory_codes

Function · Source

The codes the channel’s memory holds.

pub fn memory_codes(&self) -> usize

Receiver

Struct · Source

One receive channel. Its configuration is set when it is created and kept until it is released.

pub struct Receiver<R: hal.Registers> {
    // Private implementation fields omitted.
}

Receiver.new

Function · Source

Configure receive channel channel, 0 or 1 (the RMT’s channels 2 and 3), of an RMT whose source clock runs at source_hz, from config; clock gives microseconds for blocking waits. InvalidInput for settings out of range (check_rx).

pub fn new(registers: R, channel: u32, source_hz: u32, config: &RxConfig, clock: fn() -> u64) -> Receiver<R>!hal.Error

Receiver.release

Function · Source

Stop any reception and give back the registers.

pub fn release(self) -> R

Receiver.receive

Function · Source

Receive one frame into buffer and return its number of codes, the last of which holds a zero duration where the input went idle; a reception poll_receive started into the same buffer goes on. Timeout if no frame has ended within timeout_us; Overrun if the frame does not fit buffer (which then holds its start) or the channel’s memory was emptied too late; Bus if the channel reports an error. The reception is stopped after any error.

pub fn receive(&mut self, buffer: &mut[u32], timeout_us: u64) -> usize!hal.Error

Receiver.poll_receive

Function · Source

Start receiving a frame into buffer, then, called again with the same buffer, keep the channel’s memory emptied; true once the frame has ended, with received codes in buffer. Errors as for receive, without Timeout.

pub fn poll_receive(&mut self, buffer: &mut[u32]) -> bool!hal.Error

Receiver.stop

Function · Source

Stop any reception.

pub fn stop(&mut self)

Receiver.is_busy

Function · Source

Whether a reception runs.

pub fn is_busy(&self) -> bool

Receiver.received

Function · Source

The codes of the last frame, or received so far.

pub fn received(&self) -> usize

Receiver.listen

Function · Source

Raise the RMT interrupt when a frame ends, the channel fails, or a quarter of the memory needs emptying; poll to handle and clear it. ignore stops that.

pub fn listen(&mut self)

Receiver.ignore

Function · Source

pub fn ignore(&mut self)

Receiver.is_pending

Function · Source

Whether this channel raises the RMT interrupt now.

pub fn is_pending(&mut self) -> bool

Receiver.resolution_hz

Function · Source

pub fn resolution_hz(&self) -> u32

Receiver.channel

Function · Source

The receive channel, 0 or 1 (the RMT’s channels 2 and 3).

pub fn channel(&self) -> u32

Receiver.memory_codes

Function · Source

pub fn memory_codes(&self) -> usize

Search every guide, reference page, and API declaration.