Expand description

Remote Control Peripheral (RMT)

Summary

The ESP32 variants include a remote control peripheral (RMT) that is designed to handle infrared remote control signals. For that purpose, it can convert bitstreams of data (from the RAM) into pulse codes and even modulate those codes into a carrier wave.

It can also convert received pulse codes (again, with carrier wave support) into data bits.

A secondary use case for this peripheral is to drive RGB(W) LEDs that bear an internal IC and use a pulse code protocol.

Channels

The RMT peripheral has the following channels available on individual chips:

  • The ESP32 has 8 channels, each of them can be either receiver or transmitter
  • The ESP32-C3 has 4 channels, Channel0 and Channel1 hardcoded for transmitting signals and Channel2 and Channel3 hardcoded for receiving signals.
  • The ESP32-S2 has 4 channels, each of them can be either receiver or transmitter.
  • The ESP32-S3 has 8 channels, Channel0-Channel3 hardcdoded for transmitting signals and Channel4-Channel7 hardcoded for receiving signals.

Implementation State

  • FIFO mode is not supported (there appear to be some issues with FIFO mode in some variants and for consistency all variants therefore we use NON-FIFO mode everywhere)
  • Non-blocking mode is currently not supported!
  • Input channels are currently not supported!

Example (for ESP32-C3)

let mut peripherals = peripherals::Peripherals::take();

// Configure RMT peripheral globally
let pulse = PulseControl::new(
    peripherals.RMT,
    &mut peripherals.SYSTEM,
    ClockSource::APB,
    0, // Integer part of the RMT-wide clock divider
    0, // Numerator part of the RMT-wide clock divider
    0, // Denominator part of the RMT-wide clock divider
)
.unwrap();

// Get reference to channel
let mut rmt_channel0 = pulse.channel0;

// Set up channel
rmt_channel0
    .set_idle_output_level(false)
    .set_carrier_modulation(false)
    .set_channel_divider(1)
    .set_idle_output(true);

// Assign GPIO pin where pulses should be sent to
let mut rmt_channel0 = rmt_channel0.assign_pin(io.pins.gpio8);

// Create pulse sequence
let mut seq = [PulseCode {
    level1: true,
    length1: 10u32.nanos(),
    level2: false,
    length2: 90u32.nanos(),
}; 288];

// Send sequence
rmt_channel0
    .send_pulse_sequence(RepeatMode::SingleShot, &seq)
    .unwrap();

Macros

Structs

Enums

  • Specify the clock source for the RMT peripheral
  • Specifies the mode with which pulses are sent out in transmitter channels
  • Errors that can occur when the peripheral is configured
  • Errors that can occur during a transmission attempt

Traits