API referencestd/embedded

std/embedded/chip/esp32c6

Public declarations, types, methods, and source contracts for std/embedded/chip/esp32c6.

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/chip/esp32c6"

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
cpu core/cpu esp32c6.dodo
esp_adc std/embedded/chip/esp_adc esp32c6.dodo
esp_capture std/embedded/chip/esp_capture esp32c6.dodo
esp_flash std/embedded/chip/esp_flash esp32c6.dodo
esp_i2c std/embedded/peripheral/esp_i2c esp32c6.dodo
esp_i2s std/embedded/chip/esp_i2s esp32c6.dodo
esp_lp_shared std/embedded/chip/esp_lp_shared esp32c6.dodo
esp_power std/embedded/chip/esp_power esp32c6.dodo
esp_rmt std/embedded/peripheral/esp_rmt esp32c6.dodo
esp_rng std/embedded/chip/esp_rng esp32c6.dodo
esp_rtc std/embedded/chip/esp_rtc esp32c6.dodo
esp_spi std/embedded/peripheral/esp_spi esp32c6.dodo
esp_twai std/embedded/peripheral/esp_twai esp32c6.dodo
esp_uart std/embedded/peripheral/esp_uart esp32c6.dodo
esp_uhci std/embedded/peripheral/esp_uhci esp32c6.dodo
esp_usb_serial std/embedded/peripheral/esp_usb_serial esp32c6.dodo
esp_watchdog std/embedded/chip/esp_watchdog esp32c6.dodo
executor std/embedded/executor esp32c6.dodo
hal std/embedded/hal esp32c6.dodo
io std/io esp32c6.dodo
mmio core/mmio esp32c6.dodo
power std/embedded/power esp32c6.dodo
ptr core/ptr esp32c6.dodo
serial std/embedded/hal/serial esp32c6.dodo

CPU_HZ

Constant · Source

The CPU clock after take().

pub const CPU_HZ: u32 = 160_000_000

XTAL_HZ

Constant · Source

The crystal, which the ESP32-C6 requires to be 40 MHz.

pub const XTAL_HZ: u32 = 40_000_000

PLL_F80M_HZ

Constant · Source

The PLL output peripherals use.

pub const PLL_F80M_HZ: u32 = 80_000_000

PIN_COUNT

Constant · Source

GPIO 0 to 23: the pins that are not wired to the flash.

pub const PIN_COUNT: u32 = 24

USB_PINS

Constant · Source

GPIO 12 and 13, the USB serial port’s D- and D+.

pub const USB_PINS: u32 = (1u32 << 12) | (1u32 << 13)

WIFI_MAC

Constant · Source

Interrupt sources, numbered as in the interrupt matrix. Each is also the vector name of its handler, @interrupt(UART0); enable routes it to the CPU.

pub const WIFI_MAC: u32 = 0

WIFI_MAC_NMI

Constant · Source

pub const WIFI_MAC_NMI: u32 = 1

WIFI_PWR

Constant · Source

pub const WIFI_PWR: u32 = 2

WIFI_BB

Constant · Source

pub const WIFI_BB: u32 = 3

BT_MAC

Constant · Source

pub const BT_MAC: u32 = 4

BT_BB

Constant · Source

pub const BT_BB: u32 = 5

BT_BB_NMI

Constant · Source

pub const BT_BB_NMI: u32 = 6

LP_TIMER

Constant · Source

pub const LP_TIMER: u32 = 7

COEX

Constant · Source

pub const COEX: u32 = 8

BLE_TIMER

Constant · Source

pub const BLE_TIMER: u32 = 9

BLE_SEC

Constant · Source

pub const BLE_SEC: u32 = 10

I2C_MASTER

Constant · Source

pub const I2C_MASTER: u32 = 11

ZB_MAC

Constant · Source

pub const ZB_MAC: u32 = 12

PMU

Constant · Source

pub const PMU: u32 = 13

EFUSE

Constant · Source

pub const EFUSE: u32 = 14

LP_RTC_TIMER

Constant · Source

pub const LP_RTC_TIMER: u32 = 15

LP_UART

Constant · Source

pub const LP_UART: u32 = 16

LP_I2C

Constant · Source

pub const LP_I2C: u32 = 17

LP_WDT

Constant · Source

pub const LP_WDT: u32 = 18

LP_PERI_TIMEOUT

Constant · Source

pub const LP_PERI_TIMEOUT: u32 = 19

LP_APM_M0

Constant · Source

pub const LP_APM_M0: u32 = 20

LP_APM_M1

Constant · Source

pub const LP_APM_M1: u32 = 21

FROM_CPU_INTR0

Constant · Source

pub const FROM_CPU_INTR0: u32 = 22

FROM_CPU_INTR1

Constant · Source

pub const FROM_CPU_INTR1: u32 = 23

FROM_CPU_INTR2

Constant · Source

pub const FROM_CPU_INTR2: u32 = 24

FROM_CPU_INTR3

Constant · Source

pub const FROM_CPU_INTR3: u32 = 25

ASSIST_DEBUG

Constant · Source

pub const ASSIST_DEBUG: u32 = 26

TRACE

Constant · Source

pub const TRACE: u32 = 27

CACHE

Constant · Source

pub const CACHE: u32 = 28

CPU_PERI_TIMEOUT

Constant · Source

pub const CPU_PERI_TIMEOUT: u32 = 29

GPIO

Constant · Source

pub const GPIO: u32 = 30

GPIO_NMI

Constant · Source

pub const GPIO_NMI: u32 = 31

PAU

Constant · Source

pub const PAU: u32 = 32

HP_PERI_TIMEOUT

Constant · Source

pub const HP_PERI_TIMEOUT: u32 = 33

MODEM_PERI_TIMEOUT

Constant · Source

pub const MODEM_PERI_TIMEOUT: u32 = 34

HP_APM_M0

Constant · Source

pub const HP_APM_M0: u32 = 35

HP_APM_M1

Constant · Source

pub const HP_APM_M1: u32 = 36

HP_APM_M2

Constant · Source

pub const HP_APM_M2: u32 = 37

HP_APM_M3

Constant · Source

pub const HP_APM_M3: u32 = 38

LP_APM0

Constant · Source

pub const LP_APM0: u32 = 39

MSPI

Constant · Source

pub const MSPI: u32 = 40

I2S0

Constant · Source

pub const I2S0: u32 = 41

UHCI0

Constant · Source

pub const UHCI0: u32 = 42

UART0

Constant · Source

pub const UART0: u32 = 43

UART1

Constant · Source

pub const UART1: u32 = 44

LEDC

Constant · Source

pub const LEDC: u32 = 45

TWAI0

Constant · Source

pub const TWAI0: u32 = 46

TWAI1

Constant · Source

pub const TWAI1: u32 = 47

USB_DEVICE

Constant · Source

pub const USB_DEVICE: u32 = 48

RMT

Constant · Source

pub const RMT: u32 = 49

I2C_EXT0

Constant · Source

pub const I2C_EXT0: u32 = 50

TG0_T0_LEVEL

Constant · Source

pub const TG0_T0_LEVEL: u32 = 51

TG0_T1_LEVEL

Constant · Source

pub const TG0_T1_LEVEL: u32 = 52

TG0_WDT_LEVEL

Constant · Source

pub const TG0_WDT_LEVEL: u32 = 53

TG1_T0_LEVEL

Constant · Source

pub const TG1_T0_LEVEL: u32 = 54

TG1_T1_LEVEL

Constant · Source

pub const TG1_T1_LEVEL: u32 = 55

TG1_WDT_LEVEL

Constant · Source

pub const TG1_WDT_LEVEL: u32 = 56

SYSTIMER_TARGET0

Constant · Source

pub const SYSTIMER_TARGET0: u32 = 57

SYSTIMER_TARGET1

Constant · Source

pub const SYSTIMER_TARGET1: u32 = 58

SYSTIMER_TARGET2

Constant · Source

pub const SYSTIMER_TARGET2: u32 = 59

APB_SARADC

Constant · Source

pub const APB_SARADC: u32 = 60

MCPWM0

Constant · Source

pub const MCPWM0: u32 = 61

PCNT

Constant · Source

pub const PCNT: u32 = 62

PARL_IO

Constant · Source

pub const PARL_IO: u32 = 63

SLC0

Constant · Source

pub const SLC0: u32 = 64

SLC1

Constant · Source

pub const SLC1: u32 = 65

DMA_IN_CH0

Constant · Source

pub const DMA_IN_CH0: u32 = 66

DMA_IN_CH1

Constant · Source

pub const DMA_IN_CH1: u32 = 67

DMA_IN_CH2

Constant · Source

pub const DMA_IN_CH2: u32 = 68

DMA_OUT_CH0

Constant · Source

pub const DMA_OUT_CH0: u32 = 69

DMA_OUT_CH1

Constant · Source

pub const DMA_OUT_CH1: u32 = 70

DMA_OUT_CH2

Constant · Source

pub const DMA_OUT_CH2: u32 = 71

SPI2

Constant · Source

pub const SPI2: u32 = 72

AES

Constant · Source

pub const AES: u32 = 73

SHA

Constant · Source

pub const SHA: u32 = 74

RSA

Constant · Source

pub const RSA: u32 = 75

ECC

Constant · Source

pub const ECC: u32 = 76

SOURCE_COUNT

Constant · Source

Sources 0 to 76.

pub const SOURCE_COUNT: u32 = 77

LEVEL_LOW

Constant · Source

Pin events for Pin.listen, ignore, events, and clear_events, as in the Raspberry Pi chip packages: the pin’s level is low or high, or it fell or rose. A pin watches one kind at a time: both edges, one edge, or one level.

pub const LEVEL_LOW: u32 = 1 << 0

LEVEL_HIGH

Constant · Source

pub const LEVEL_HIGH: u32 = 1 << 1

FALLING_EDGE

Constant · Source

pub const FALLING_EDGE: u32 = 1 << 2

RISING_EDGE

Constant · Source

pub const RISING_EDGE: u32 = 1 << 3

ALARM_COUNT

Constant · Source

pub const ALARM_COUNT: u32 = 3

enable

Function · Source

Route interrupt source source to the CPU, so its handler runs whenever the peripheral raises it and interrupts are not masked. Sources are level-triggered: the handler must clear its peripheral’s condition.

pub fn enable(source: u32)

disable

Function · Source

Stop routing source to the CPU. A raised source then stays pending in its peripheral until enabled again.

pub fn disable(source: u32)

is_enabled

Function · Source

pub fn is_enabled(source: u32) -> bool

is_pending

Function · Source

Whether the peripheral raises source now, enabled or not.

pub fn is_pending(source: u32) -> bool

pend

Function · Source

Raise software interrupt FROM_CPU_INTR0 + number, 0 to 3, until unpend: a handler that runs work later, outside a critical section.

pub fn pend(number: u32)

unpend

Function · Source

Lower software interrupt FROM_CPU_INTR0 + number; its handler must.

pub fn unpend(number: u32)

reboot_to_bootloader

Function · Source

Restart into the boot ROM’s serial download mode, as if the BOOT button were held at reset: the chip waits on its USB serial port and UART0 for a flasher such as dodo run. dodo run resets the chip into that mode by itself through the USB serial port, so this is for boards flashed through a USB serial adapter without the reset circuit. Does not return.

pub fn reboot_to_bootloader()

restart

Function · Source

Restart the chip into the firmware. Does not return.

pub fn restart()

Peripherals

Struct · Source

The chip’s peripherals, handed out once by take.

pub struct Peripherals {
    pub pins: Pins
    pub timer: Timer
    pub usb: Usb
    // The DMA controller's channels.
    pub dma: Dma
    // The random number generator, with the SAR ADC's noise source while
    // no analog input is claimed; esp_rng documents it.
    pub rng: esp_rng.Rng
    // Timer group 0's watchdog, stopped; esp_watchdog documents it.
    pub watchdog: esp_watchdog.Watchdog
    // The LP timer as a real-time clock: the time of day, counted in
    // milliseconds, which survives resets; esp_rtc documents it.
    pub rtc: esp_rtc.Rtc
    // The program flash, for storing data above the program; see
    // std/embedded/chip/esp_flash.
    pub flash: esp_flash.Flash
    // Sleep modes, clock gating, the dormant state, and hibernation; see
    // Power.
    pub power: Power
    // The low-power core and the program the firmware embeds for it; see
    // LpCore.
    pub lp_core: LpCore
}

take

Function · Source

Configure clocks and return the peripherals. A second call returns Error.Busy, so no two owners exist; Timeout if the RTC slow clock does not run.

pub fn take() -> Peripherals!hal.Error

Pins

Struct · Source

The pins and the controllers that use them. Each pin and each controller can be taken once, and given back.

pub struct Pins {
    // Private implementation fields omitted.
}

Pins.output

Function · Source

Claim pin number as a push-pull output, initially low.

pub fn output(&mut self, number: u32) -> Pin!hal.Error

Pins.input

Function · Source

Claim pin number as an input, with neither pull-up nor pull-down.

pub fn input(&mut self, number: u32) -> Pin!hal.Error

Pins.release

Function · Source

Give back a pin from output or input. It stops driving and is disconnected until claimed again, for example as part of a bus.

pub fn release(&mut self, pin: Pin)

Pins.i2c

Function · Source

Claim pins sda and scl as an I2C bus with an SCL frequency of frequency_hz, 1 kHz to hal.I2C_FAST_PLUS_HZ, on the chip’s one I2C controller. Any two pins carry the bus. InvalidInput for a pin that cannot be claimed, the same pin twice, or a frequency out of range; Busy if a pin or the controller is taken. The lines are open-drain with the pads’ pull-ups (about 45 kOhm), which keep an idle bus high but are too weak for fast mode: most sensor boards add 4.7 kOhm pull-ups, and a bare bus needs them. The esp_i2c driver documents the bus’s errors.

pub fn i2c(&mut self, sda: u32, scl: u32, frequency_hz: u32) -> I2c!hal.Error

Pins.release_i2c

Function · Source

Give back an I2C bus: the controller stops, and its pins are disconnected but still pulled up, so the bus stays idle.

pub fn release_i2c(&mut self, bus: I2c)

Pins.i2c_target

Function · Source

Claim pins sda and scl as an I2C target (slave) answering another master at address, a 10-bit address with ten_bit, on the chip’s one I2C controller, which is then not a master. frequency_hz is the master’s SCL frequency, 1 kHz to hal.I2C_FAST_PLUS_HZ, which sets the SDA hold and sample times. Any two pins carry the bus, open drain with the pads’ pull-ups, as for i2c. InvalidInput for an address the I2C specification reserves (7-bit 0x00 to 0x07 and 0x78 to 0x7F, 10-bit above 0x3FF), otherwise errors as for i2c. The esp_i2c driver documents the target: it stretches SCL while its receive FIFO is full or a read waits for respond.

pub fn i2c_target(&mut self, sda: u32, scl: u32, address: u16, ten_bit: bool, frequency_hz: u32) -> I2cTarget!hal.Error

Pins.release_i2c_target

Function · Source

Give back an I2C target from i2c_target, as for release_i2c.

pub fn release_i2c_target(&mut self, target: I2cTarget)

Pins.spi

Function · Source

Claim pins as an SPI bus in mode, clocked at the fastest rate up to frequency_hz (at most PLL_F80M_HZ, 80 MHz; at least 78.2 kHz): clock (SCK), tx (MOSI, data from the chip), and rx (MISO, data to the chip), or none for devices that only listen, such as many displays. Any pins carry the bus. InvalidInput for a pin that cannot be claimed, the same pin twice, or a frequency out of range; Busy if a pin or the controller is taken. Chip selects are output pins; see hal.SpiDevice.

pub fn spi(&mut self, clock: u32, tx: u32, rx: Option<u32>, mode: hal.SpiMode, frequency_hz: u32) -> Spi!hal.Error

Pins.spi_with_select

Function · Source

spi, with the controller’s own chip select output, CS0 (FSPICS0), on pin select as well: it goes low before each transfer’s first clock edge and rises after its last (the controller’s CS setup and hold phases), and stays low across the 64-byte runs of a longer transfer, polled, by DMA, or blocking, so a device sees one selection per transfer; a cancelled transfer raises it too. Any pin carries it. Use it for one device on the bus; several devices share a bus through hal.SpiDevice and output pins. Errors as for spi, and InvalidInput if select is another of the bus’s pins.

pub fn spi_with_select(&mut self, clock: u32, tx: u32, rx: Option<u32>, select: u32, mode: hal.SpiMode, frequency_hz: u32) -> Spi!hal.Error

Pins.release_spi

Function · Source

Give back an SPI bus from spi or spi_with_select: the controller stops and its pins are disconnected.

pub fn release_spi(&mut self, bus: Spi)

Pins.spi_target

Function · Source

Claim pins as an SPI target (slave) in mode on the chip’s one SPI controller, GP-SPI2, for another master to clock and select: clock and select are inputs, rx receives what the master sends (MOSI), or none, and tx answers it (MISO), driven at all times. The select input is pulled up, so an unconnected one leaves the target deselected. Any pins carry it. InvalidInput for a pin that cannot be claimed or the same pin twice; Busy if a pin or the controller is taken. The esp_spi driver documents the target: it exchanges transactions of up to 64 bytes, each from the select’s falling to its rising edge.

pub fn spi_target(&mut self, clock: u32, tx: u32, rx: Option<u32>, select: u32, mode: hal.SpiMode) -> SpiTarget!hal.Error

Pins.release_spi_target

Function · Source

Give back an SPI target from spi_target, as for release_spi.

pub fn release_spi_target(&mut self, target: SpiTarget)

Pins.uart

Function · Source

Claim a serial port on pins tx and rx, or none to only send, at baud, 300 to 5_000_000 bit/s, 8N1. Any pins carry the port; UART0 serves the first port and UART1 the second. InvalidInput for a pin that cannot be claimed, the same pin twice, or a baud rate out of range; Busy if a pin or both controllers are taken. The pins are pulled up, so a receiver with nothing connected, and the pins once released, idle high. Panics are reported on the port until it is released.

pub fn uart(&mut self, tx: u32, rx: Option<u32>, baud: u32) -> Uart!hal.Error

Pins.uart_flow

Function · Source

A serial port with hardware flow control: cts, an input the other end holds low while it can take data, and rts, an output the port holds low while its receive FIFO has room. Errors as for uart.

pub fn uart_flow(&mut self, tx: u32, rx: u32, cts: u32, rts: u32, baud: u32) -> Uart!hal.Error

Pins.release_uart

Function · Source

Give back a serial port once everything written is out: the controller stops, and its pins stay pulled up, so the line idles high.

pub fn release_uart(&mut self, port: Uart)

Pins.pwm

Function · Source

Claim a PWM output on pin at frequency_hz, 5 Hz to 40 MHz, with the finest duty steps the frequency allows: 16384 steps up to 4882 Hz, halving as the frequency doubles. The LED PWM controller has six channels and four timers; outputs at the same frequency share a timer. InvalidInput for a pin that cannot be claimed or a frequency out of range; Busy if the pin, all six channels, or all four timers are taken.

pub fn pwm(&mut self, pin: u32, frequency_hz: u32) -> Pwm!hal.Error

Pins.release_pwm

Function · Source

Give back a PWM output: its pin goes low and is disconnected.

pub fn release_pwm(&mut self, output: Pwm)

Pins.analog

Function · Source

Claim pin, GPIO 0 to 6, as an input of the ADC: 12 bits with the converter’s largest attenuation, calibrated from the chip’s eFuse so that 0 is ground and 4095 is 3.3 V, and hal.read_millivolts(&mut input, 3300) gives millivolts. The converter reaches about 3.25 V. The pin’s digital input and pulls are turned off, so they do not disturb the voltage; the input draws some current while it samples, so a source above about 10 kOhm reads low. InvalidInput for another pin, Busy if the pin is taken.

pub fn analog(&mut self, pin: u32) -> Analog!hal.Error

Pins.temperature

Function · Source

Claim the chip’s temperature sensor as an analog input: 8-bit readings that millicelsius converts. Busy if claimed.

pub fn temperature(&mut self) -> Analog!hal.Error

Pins.release_analog

Function · Source

Give back an analog input; the converter stops with the last one.

pub fn release_analog(&mut self, input: Analog)

Pins.analog_stream

Function · Source

Convert analog inputs continuously by DMA: channels, up to esp_adc.MAX_CHANNELS entries of a pin (GPIO 0 to 6) and its attenuation, converted in turn, rate_hz conversions a second in all (esp_adc.MIN_RATE_HZ to MAX_RATE_HZ), streamed through dma into a ring in buffer; see AnalogStream. The pins are set up as for analog. The stream has the converter to itself: Busy while an analog input or the temperature sensor is claimed, and they are Busy until the stream is given back with release_analog_stream; Busy too if a pin is taken or the channel runs a copy. InvalidInput for no channels or too many, another pin or the same pin twice, a rate out of range, or a buffer outside SRAM or too short for a sample in each of its eight parts.

pub fn analog_stream(&mut self, channels: &[esp_adc.Channel], rate_hz: u32, dma: &mut DmaChannel, buffer: &mut[u8]) -> AnalogStream!hal.Error from(dma, buffer)

Pins.release_analog_stream

Function · Source

Give back a stream: it stops, its pins return to GPIO inputs, and the converter’s controller is reset, ready for analog and for the random number generator’s noise source.

pub fn release_analog_stream(&mut self, stream: AnalogStream)

Pins.ws2812

Function · Source

Claim pin to drive WS2812 addressable LEDs (also sold as NeoPixels, SK6812, and others with the same protocol), such as the RGB LED of Espressif’s development boards, through an RMT transmit channel with one block of memory, as rmt_tx claims it. write refills the channel’s memory while it sends, so a chain may have any length. InvalidInput for a pin that cannot be claimed; Busy if the pin or both transmit channels are taken.

pub fn ws2812(&mut self, pin: u32) -> Ws2812!hal.Error

Pins.release_ws2812

Function · Source

Give back the LED driver: its channel stops and its pin is disconnected.

pub fn release_ws2812(&mut self, leds: Ws2812)

Pins.rmt_tx

Function · Source

Claim pin as the output of an RMT transmit channel set up from config: channel 0, or 1, whichever is free with config.memory_blocks blocks of memory after it; see std/embedded/peripheral/esp_rmt. The channel counts ticks of the PLL’s 80 MHz output (PLL_F80M_HZ) divided down to config.resolution_hz, and the pin drives the idle level from now on. Any pin carries it. InvalidInput for a pin that cannot be claimed or settings out of range (esp_rmt.check_tx); Busy if the pin is taken or no transmit channel has that much memory free.

pub fn rmt_tx(&mut self, pin: u32, config: &esp_rmt.TxConfig) -> RmtTx!hal.Error

Pins.release_rmt_tx

Function · Source

Give back an RMT transmit channel: its transmission stops and its pin is disconnected.

pub fn release_rmt_tx(&mut self, tx: RmtTx)

Pins.rmt_rx

Function · Source

Claim pin as the input of an RMT receive channel set up from config: receive channel 0 (the RMT’s channel 2), or 1, whichever is free with config.memory_blocks blocks of memory after it; see std/embedded/peripheral/esp_rmt. The channel counts ticks of the PLL’s 80 MHz output divided down to config.resolution_hz. Any pin carries it, with its pulls off (set_pull sets them). The pin of an RMT transmit channel, a WS2812 driver’s included, may be given too: the receiver then reads what the transmitter sends, through the pad, for self-tests. InvalidInput for a pin that cannot be claimed or settings out of range (esp_rmt.check_rx); Busy if the pin is taken otherwise or no receive channel has that much memory free.

pub fn rmt_rx(&mut self, pin: u32, config: &esp_rmt.RxConfig) -> RmtRx!hal.Error

Pins.release_rmt_rx

Function · Source

Give back an RMT receive channel: its reception stops and its pin, unless a transmitter’s, is disconnected with its pulls off.

pub fn release_rmt_rx(&mut self, rx: RmtRx)

Pins.can

Function · Source

Claim a CAN controller on pins tx and rx: TWAI0 for the first, TWAI1 for the second, configured from config and filters; see std/embedded/peripheral/esp_twai for the bit timing (from the 40 MHz crystal), the modes, and how filters map onto the hardware filter. Any pins carry the bus; wire them to a CAN transceiver’s TXD and RXD. TX drives push-pull, idling recessive (high), and RX has its pull-up, so it reads a recessive bus with nothing connected. tx may equal rx: the pad is then open-drain with its pull-up and the controller both drives and reads it, which loops a controller to itself for self-tests and joins controllers wired together without transceivers. InvalidInput for a pin that cannot be claimed, a bit rate the controller cannot reach, or filters it does not take; Busy if a pin or both controllers are taken.

pub fn can(&mut self, tx: u32, rx: u32, config: &esp_twai.Config, filters: &[hal.CanFilter]) -> Can!hal.Error

Pins.release_can

Function · Source

Give back a CAN controller: it enters reset mode and stops, and its pins are disconnected, still pulled up.

pub fn release_can(&mut self, can: Can)

Pins.i2s_output

Function · Source

Claim an I2S output on I2S0’s transmitter: data on data, the bit clock on bclk, and word select on ws, streaming through a DMA channel claimed from dma; see std/embedded/chip/esp_i2s for the framing, clock accuracy, and queue. It plays silence until samples are queued, and whenever the queue runs dry. InvalidInput for a pin that cannot be claimed, the same pin twice, or settings out of range (esp_i2s.check); Busy if a pin, the transmitter, or every DMA channel is taken.

pub fn i2s_output(&mut self, data: u32, bclk: u32, ws: u32, dma: &mut Dma, config: &esp_i2s.Config) -> I2sOutput!hal.Error

Pins.release_i2s_output

Function · Source

Give back an I2S output: the transmitter and its DMA channel stop, the channel goes back to dma, and the pins are disconnected. An input sharing the output’s clocks stops receiving; release it first.

pub fn release_i2s_output(&mut self, output: I2sOutput, dma: &mut Dma)

Pins.i2s_input

Function · Source

Claim an I2S input on I2S0’s receiver: data on data, streaming through a DMA channel claimed from dma. With the running output’s bclk and ws pins it shares the output’s clocks (the same sample rate and slot width are then required) and claims only data; with other pins it is a master of its own, making BCLK and WS on them. Errors as for i2s_output; InvalidInput also for the output’s clock pins with another rate or slot width.

pub fn i2s_input(&mut self, data: u32, bclk: u32, ws: u32, dma: &mut Dma, config: &esp_i2s.Config) -> I2sInput!hal.Error

Pins.release_i2s_input

Function · Source

Give back an I2S input: the receiver and its DMA channel stop, the channel goes back to dma, and the pins it claimed are disconnected.

pub fn release_i2s_input(&mut self, input: I2sInput, dma: &mut Dma)

Pins.pwm_input

Function · Source

Claim pin as a PWM input that measures the frequency and duty cycle of the signal on it in windows of window_us, 1 us to 25 s: the MCPWM capture unit timestamps its edges to 6.25 ns and a PCNT unit counts its rising edges, from 1 Hz (or slower, with a longer window) to about 10 MHz; std/embedded/chip/esp_capture documents the measurement and its precision. The pad never drives and has its pull-down on, so an unconnected pin reads as a steady low line; an open-collector signal, such as a fan’s tachometer, needs a pull-up of 10 kOhm or less to 3.3 V. One PWM input at a time. InvalidInput for a pin that cannot be claimed or a window out of range; Busy if the pin or the capture unit is taken.

pub fn pwm_input(&mut self, pin: u32, window_us: u32) -> esp_capture.PwmCapture!hal.Error

Pins.release_pwm_input

Function · Source

Give back a PWM input from pwm_input: the capture unit and the counter stop, and the pin is disconnected.

pub fn release_pwm_input(&mut self, input: esp_capture.PwmCapture)

Pin

Struct · Source

One GPIO. Implements the std/embedded/hal output and input pin protocols.

pub struct Pin {
    // Private implementation fields omitted.
}

Pin.number

Function · Source

The GPIO number.

pub fn number(&self) -> u32

Pin.set_high

Function · Source

pub fn set_high(&mut self)

Pin.set_low

Function · Source

pub fn set_low(&mut self)

Pin.toggle

Function · Source

pub fn toggle(&mut self)

Pin.is_high

Function · Source

The level on the pin, as an input reads it, also while it drives.

pub fn is_high(&self) -> bool

Pin.set_as_output

Function · Source

Drive the pin at its output level, for a line that changes direction such as a half-duplex data line. Pins claimed as inputs start released.

pub fn set_as_output(&mut self)

Pin.set_as_input

Function · Source

Release the pin so another device can drive it; is_high reads it.

pub fn set_as_input(&mut self)

Pin.set_pull

Function · Source

Turn the pad’s pull-up (about 45 kOhm) and pull-down on or off.

pub fn set_pull(&mut self, up: bool, down: bool)

Pin.set_open_drain

Function · Source

Drive only low, and let the pin float when high, for a line other devices also pull low, such as a bit-banged I2C line.

pub fn set_open_drain(&mut self, on: bool)

Pin.listen

Function · Source

Raise interrupt source GPIO on events, after forgetting events seen so far. A pin watches one kind: RISING_EDGE | FALLING_EDGE, one edge, or one level; listening to more keeps the edges, or the high level over the low one. Route the source too: esp32c6.enable(pin.irq()). Every pin shares the one source; its handler tells them apart with events.

pub fn listen(&mut self, events: u32)

Pin.ignore

Function · Source

Stop raising the interrupt on events; the pin stops watching once none of its kind are left.

pub fn ignore(&mut self, events: u32)

Pin.events

Function · Source

The listened-to events that are raising the interrupt now: the events the pin watches once one happened, until clear_events.

pub fn events(&self) -> u32

Pin.clear_events

Function · Source

Forget the events seen, acknowledging them; a handler or task must, or the interrupt stays raised. A level being watched comes back at once while it lasts.

pub fn clear_events(&mut self, events: u32)

Pin.irq

Function · Source

The interrupt source pin events raise, GPIO, for esp32c6.enable.

pub fn irq(&self) -> u32

Timer

Struct · Source

The system timer, counting microseconds since power-up. Implements the std/embedded/hal delay protocol.

pub struct Timer {
    // Private implementation fields omitted.
}

Timer.alarm

Function · Source

Claim alarm 0 to 2, to run code at a set time from its interrupt or to run the executor. Busy if it is claimed already; InvalidInput for another number.

pub fn alarm(&mut self, number: u32) -> Alarm!hal.Error

Timer.release_alarm

Function · Source

Disarm an alarm, stop its interrupt, and take it back.

pub fn release_alarm(&mut self, alarm: Alarm)

Timer.now_us

Function · Source

Microseconds since power-up.

pub fn now_us(&self) -> u64

Timer.now_ticks

Function · Source

The 16 MHz count the microseconds come from, for finer timing.

pub fn now_ticks(&self) -> u64

Timer.delay_us

Function · Source

pub fn delay_us(&mut self, microseconds: u32)

Timer.delay_ms

Function · Source

pub fn delay_ms(&mut self, milliseconds: u32)

Alarm

Struct · Source

One of the system timer’s three comparators, claimed with Timer.alarm(n). An alarm fires once when the count reaches the time it was given; with listen it raises interrupt source SYSTIMER_TARGET0 + n, whose handler calls clear and may schedule the next time. Move it into a static mut Option<Alarm> for the handler to use.

pub struct Alarm {
    // Private implementation fields omitted.
}

Alarm.number

Function · Source

0 to 2.

pub fn number(&self) -> u32

Alarm.irq

Function · Source

The interrupt source the alarm raises: its number for esp32c6.enable, and its vector name, SYSTIMER_TARGET0 + n, for @interrupt.

pub fn irq(&self) -> u32

Alarm.schedule_at

Function · Source

Fire when the timer reaches time_us, a now_us time, replacing any earlier time. A time that has passed fires at once.

pub fn schedule_at(&mut self, time_us: u64)

Alarm.schedule_in

Function · Source

Fire microseconds from now.

pub fn schedule_in(&mut self, microseconds: u32)

Alarm.cancel

Function · Source

Disarm: a scheduled time no longer fires.

pub fn cancel(&mut self)

Alarm.is_armed

Function · Source

True from scheduling until it fires or is cancelled.

pub fn is_armed(&self) -> bool

Alarm.fired

Function · Source

True once it has fired, until clear.

pub fn fired(&self) -> bool

Alarm.clear

Function · Source

Acknowledge that it fired. An interrupt handler has to, or the interrupt stays raised and the handler runs again at once.

pub fn clear(&mut self)

Alarm.listen

Function · Source

Raise the interrupt when it fires. Route the source too: esp32c6.enable(alarm.irq()).

pub fn listen(&mut self)

Alarm.ignore

Function · Source

Stop raising the interrupt; fired still reports.

pub fn ignore(&mut self)

Alarm.is_listening

Function · Source

pub fn is_listening(&self) -> bool

Alarm.now_us

Function · Source

Microseconds since power-up, as Timer.now_us reads them.

pub fn now_us(&self) -> u64

Alarm.sleep_until

Function · Source

Sleep (wfi) until an interrupt is pending or the timer reaches deadline, a now_us time; none waits for an interrupt only. With now_us this is the std/embedded/executor clock, so an alarm runs an executor: executor.run(&mut tasks, &mut alarm). The alarm’s interrupt ends the sleep while interrupts are masked and is cleared before they are unmasked, so it needs no @interrupt handler; other interrupts’ handlers run after the return, or once the caller’s own critical section ends. Leaves the alarm disarmed and not listening.

pub fn sleep_until(&mut self, deadline: Option<u64>)

Usb

Struct · Source

The USB serial port on the chip’s USB pins, as Peripherals.usb.

pub struct Usb {
    // Private implementation fields omitted.
}

Usb.serial

Function · Source

The USB serial port, for printing and reading over the USB cable; esp_usb_serial documents it. The port is the chip’s own, which the boot ROM also uses, so it is there whether or not the program opens it, and dodo run reaches the chip through it regardless. Busy if a port is open.

pub fn serial(&mut self) -> UsbSerial!hal.Error

Usb.release_serial

Function · Source

Give back the port.

pub fn release_serial(&mut self, serial: UsbSerial)

UsbSerial

Struct · Source

The USB serial port, as Usb.serial hands it out. Implements the std/io Reader and Writer protocols, so std/fmt prints to it, and serial.Port and serial.PollPort.

pub struct UsbSerial: serial.Port + serial.PollPort {
    // Private implementation fields omitted.
}

UsbSerial.write

Function · Source

pub fn write(&mut self, bytes: &[u8]) -> usize!io.Error

UsbSerial.poll_write

Function · Source

pub fn poll_write(&mut self, bytes: &[u8]) -> io.Poll!io.Error

UsbSerial.flush

Function · Source

pub fn flush(&mut self) -> void!io.Error

UsbSerial.poll_flush

Function · Source

pub fn poll_flush(&mut self) -> bool!io.Error

UsbSerial.read

Function · Source

pub fn read(&mut self, buffer: &mut[u8]) -> usize!io.Error

UsbSerial.poll_read

Function · Source

pub fn poll_read(&mut self, buffer: &mut[u8]) -> io.Poll!io.Error

UsbSerial.set_crlf

Function · Source

pub fn set_crlf(&mut self, on: bool)

UsbSerial.is_connected

Function · Source

Whether a program on the host has the port open (DTR on).

pub fn is_connected(&mut self) -> bool

UsbSerial.listen

Function · Source

Raise interrupt source USB_DEVICE for these esp_usb_serial sources.

pub fn listen(&mut self, sources: u32)

UsbSerial.ignore

Function · Source

pub fn ignore(&mut self, sources: u32)

UsbSerial.pending_interrupts

Function · Source

pub fn pending_interrupts(&mut self) -> u32

UsbSerial.clear_interrupts

Function · Source

pub fn clear_interrupts(&mut self, sources: u32)

UsbSerial.irq

Function · Source

The interrupt source the port raises, USB_DEVICE.

pub fn irq(&self) -> u32

report_panic

Function · Source

Write a failed check’s message to every serial port claimed from pins.uart and not yet released, and to the USB serial port while one is open, as the default panic hook does before it halts:

dodo: arithmetic overflow check failed at /home/me/blink/main.dodo:12:5

Call it from a panic hook of your own that, for example, restarts:

extern “C” fn dodo_board_panic(check: *const u8, file: *const u8, line: u32, column: u32) { unsafe { chip.report_panic(check, file, line, column) } chip.restart() }

Only the first call reports. Processor exceptions arrive as processor exception check failed at mcause:mepc:CAUSE:ADDRESS. SAFETY: check and file must be the hook’s NUL-terminated strings, and the caller must halt or reset afterwards, as this takes over the ports.

pub unsafe fn report_panic(check: *const u8, file: *const u8, line: u32, column: u32)

Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.

I2c

Struct · Source

An I2C bus, as Pins.i2c hands it out. Implements the std/embedded/hal I2C bus protocol and its polling form; esp_i2c documents the methods.

pub struct I2c: hal.I2c + hal.I2cPoll {
    // Private implementation fields omitted.
}

I2c.write

Function · Source

pub fn write(&mut self, address: u8, bytes: &[u8]) -> void!hal.Error

I2c.read

Function · Source

pub fn read(&mut self, address: u8, buffer: &mut[u8]) -> void!hal.Error

I2c.write_read

Function · Source

pub fn write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut[u8]) -> void!hal.Error

I2c.write_ten_bit

Function · Source

pub fn write_ten_bit(&mut self, address: u16, bytes: &[u8]) -> void!hal.Error

I2c.read_ten_bit

Function · Source

pub fn read_ten_bit(&mut self, address: u16, buffer: &mut[u8]) -> void!hal.Error

I2c.write_read_ten_bit

Function · Source

pub fn write_read_ten_bit(&mut self, address: u16, bytes: &[u8], buffer: &mut[u8]) -> void!hal.Error

I2c.probe

Function · Source

pub fn probe(&mut self, address: u8) -> bool!hal.Error

I2c.poll_write

Function · Source

The polled transactions, which never wait; see esp_i2c.

pub fn poll_write(&mut self, address: u8, bytes: &[u8]) -> bool!hal.Error

I2c.poll_read

Function · Source

pub fn poll_read(&mut self, address: u8, buffer: &mut[u8]) -> bool!hal.Error

I2c.poll_write_read

Function · Source

pub fn poll_write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut[u8]) -> bool!hal.Error

I2c.poll_write_ten_bit

Function · Source

pub fn poll_write_ten_bit(&mut self, address: u16, bytes: &[u8]) -> bool!hal.Error

I2c.poll_read_ten_bit

Function · Source

pub fn poll_read_ten_bit(&mut self, address: u16, buffer: &mut[u8]) -> bool!hal.Error

I2c.poll_write_read_ten_bit

Function · Source

pub fn poll_write_read_ten_bit(&mut self, address: u16, bytes: &[u8], buffer: &mut[u8]) -> bool!hal.Error

I2c.cancel

Function · Source

pub fn cancel(&mut self)

I2c.is_busy

Function · Source

True while a polled transaction runs.

pub fn is_busy(&self) -> bool

I2c.frequency_hz

Function · Source

pub fn frequency_hz(&self) -> u32

I2c.irq

Function · Source

The interrupt source of the controller, I2C_EXT0.

pub fn irq(&self) -> u32

Spi

Struct · Source

An SPI bus, as Pins.spi and Pins.spi_with_select hand it out. Implements the std/embedded/hal SPI bus protocol and its polling form; esp_spi documents the methods. dma runs transfers by DMA.

pub struct Spi: hal.Spi + hal.SpiPoll {
    // Private implementation fields omitted.
}

Spi.transfer

Function · Source

pub fn transfer(&mut self, bytes: &mut[u8]) -> void!hal.Error

Spi.write

Function · Source

pub fn write(&mut self, bytes: &[u8]) -> void!hal.Error

Spi.poll_transfer

Function · Source

The polled transfers, which never wait; see esp_spi.

pub fn poll_transfer(&mut self, bytes: &mut[u8]) -> bool!hal.Error

Spi.poll_write

Function · Source

pub fn poll_write(&mut self, bytes: &[u8]) -> bool!hal.Error

Spi.cancel

Function · Source

pub fn cancel(&mut self)

Spi.is_busy

Function · Source

True while a polled transfer runs.

pub fn is_busy(&self) -> bool

Spi.dma

Function · Source

Move bytes between buffer and the bus by DMA until the returned SpiDmaBus is dropped: channel, which serves both directions, feeds the controller from the buffer and stores what it receives back into it, while the processor does other work; see SpiDmaBus. InvalidInput for an empty buffer or one outside SRAM, such as a constant; Busy if the channel runs a copy or the bus a polled transfer.

pub fn dma(&mut self, channel: &mut DmaChannel, buffer: &mut[u8]) -> SpiDmaBus!hal.Error from(self, channel, buffer)

Spi.frequency_hz

Function · Source

pub fn frequency_hz(&self) -> u32

Spi.set_frequency

Function · Source

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

Spi.set_mode

Function · Source

pub fn set_mode(&mut self, mode: hal.SpiMode)

Spi.set_loopback

Function · Source

Read MISO from the bus’s own MOSI pin through the GPIO matrix, so transfers read back what they send. Meant for self-tests.

pub fn set_loopback(&mut self, on: bool)

Spi.irq

Function · Source

The interrupt source of the controller, SPI2.

pub fn irq(&self) -> u32

Uart

Struct · Source

A serial port, as Pins.uart hands it out. Implements the std/io Reader and Writer protocols and serial.Port and serial.PollPort; esp_uart documents the methods.

pub struct Uart: serial.Port + serial.PollPort {
    // Private implementation fields omitted.
}

Uart.write

Function · Source

pub fn write(&mut self, bytes: &[u8]) -> usize!io.Error

Uart.poll_write

Function · Source

pub fn poll_write(&mut self, bytes: &[u8]) -> io.Poll!io.Error

Uart.flush

Function · Source

pub fn flush(&mut self) -> void!io.Error

Uart.poll_flush

Function · Source

pub fn poll_flush(&mut self) -> bool!io.Error

Uart.read

Function · Source

pub fn read(&mut self, buffer: &mut[u8]) -> usize!io.Error

Uart.poll_read

Function · Source

pub fn poll_read(&mut self, buffer: &mut[u8]) -> io.Poll!io.Error

Uart.baud

Function · Source

pub fn baud(&self) -> u32

Uart.set_baud

Function · Source

Change the baud rate, 300 to 5_000_000 bit/s, once everything written is out. InvalidInput or Timeout leaves it unchanged.

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

Uart.set_format

Function · Source

pub fn set_format(&mut self, data_bits: u32, parity: esp_uart.Parity, stop_bits: u32) -> void!hal.Error

Uart.set_crlf

Function · Source

pub fn set_crlf(&mut self, on: bool)

Uart.set_loopback

Function · Source

pub fn set_loopback(&mut self, on: bool) -> void!hal.Error

Uart.set_break

Function · Source

pub fn set_break(&mut self, on: bool) -> void!hal.Error

Uart.set_poll_limit

Function · Source

pub fn set_poll_limit(&mut self, polls: u32)

Uart.set_read_poll_limit

Function · Source

pub fn set_read_poll_limit(&mut self, polls: u32)

Uart.listen

Function · Source

pub fn listen(&mut self, sources: u32)

Uart.ignore

Function · Source

pub fn ignore(&mut self, sources: u32)

Uart.pending_interrupts

Function · Source

pub fn pending_interrupts(&mut self) -> u32

Uart.clear_interrupts

Function · Source

pub fn clear_interrupts(&mut self, sources: u32)

Uart.number

Function · Source

0 for UART0, 1 for UART1.

pub fn number(&self) -> u32

Uart.irq

Function · Source

The interrupt source of the controller, UART0 or UART1.

pub fn irq(&self) -> u32

Uart.dma

Function · Source

Receive into ring by DMA, through UHCI0 and channel rx, until the returned UartDma is dropped; see UartDma. InvalidInput for a ring shorter than esp_uhci.MIN_RING or outside SRAM; Busy if the channel runs a copy or the other port receives by DMA.

pub fn dma(&mut self, rx: &mut DmaChannel, ring: &mut[u8]) -> UartDma!hal.Error from(self, rx, ring)

Pwm

Struct · Source

A PWM output, as Pins.pwm hands it out. Implements the std/embedded/hal PWM output protocol.

pub struct Pwm: hal.PwmOutput {
    // Private implementation fields omitted.
}

Pwm.max_duty

Function · Source

The duty that holds the output high: 2 to the timer’s resolution.

pub fn max_duty(&self) -> u16

Pwm.set_duty

Function · Source

Take duty, 0 to max_duty(), from the next period on. InvalidInput above max_duty().

pub fn set_duty(&mut self, duty: u16) -> void!hal.Error

Pwm.duty

Function · Source

The duty in effect, as the controller reports it.

pub fn duty(&self) -> u16

Pwm.frequency_hz

Function · Source

The output’s frequency, the closest the timer makes to the request.

pub fn frequency_hz(&self) -> u32

Pwm.channel

Function · Source

The LEDC channel, 0 to 5.

pub fn channel(&self) -> u32

Pwm.pin

Function · Source

pub fn pin(&self) -> u32

Analog

Struct · Source

An analog input, as Pins.analog or Pins.temperature hands it out. Implements the std/embedded/hal analog input protocol. The inputs share the converter, so each read converts inside a critical section, about 50 us; inputs held by an interrupt handler and by the main program then never mix up their conversions.

pub struct Analog: hal.AnalogInput {
    // Private implementation fields omitted.
}

Analog.max_value

Function · Source

4095 for an ADC input, 255 for the temperature sensor.

pub fn max_value(&self) -> u16

Analog.read

Function · Source

Convert once. Timeout if the converter does not finish.

pub fn read(&mut self) -> u16!hal.Error

Analog.channel

Function · Source

The GPIO, or TEMPERATURE_CHANNEL for the temperature sensor.

pub fn channel(&self) -> u32

millicelsius

Function · Source

The temperature in thousandths of a degree Celsius that a reading of the temperature sensor shows: 0.4386 C per step from 7.36 C, as Espressif’s drivers convert it. The sensor is accurate to a few degrees.

pub fn millicelsius(value: u16) -> i32

AnalogStream

Struct · Source

Analog inputs converted continuously by DMA, as Pins.analog_stream hands them out (esp_adc documents the details). The timer starts a conversion rate_hz() times a second, taking the channels in turn, and the channel stores the results in a ring in the buffer: its first word-aligned byte on, in eight parts of the same size, 4 bytes per sample. Samples become readable a part at a time.

A sample is a word: esp_adc.sample_millivolts(sample) is the voltage, calibrated from eFuse for the channel’s attenuation, esp_adc.sample_channel(sample) the GPIO, and esp_adc.sample_raw the 12-bit reading. When the ring is full the channel stops; once the program has read what it held, poll_read reports Overrun once, and the stream starts again from the first channel. Dropping the stream stops it; give it back with Pins.release_analog_stream to free its pins and the converter.

pub struct AnalogStream {
    // Private implementation fields omitted.
}

AnalogStream.poll_read

Function · Source

The samples converted since the last call, oldest first, as many as fit samples, without waiting; returns how many. Overrun once after the ring filled up and conversions were lost.

pub fn poll_read(&mut self, samples: &mut[u32]) -> usize!hal.Error

AnalogStream.read

Function · Source

Wait until samples is full. Overrun as for poll_read, with the samples read before it dropped.

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

AnalogStream.available

Function · Source

The samples converted and readable now.

pub fn available(&mut self) -> usize

AnalogStream.capacity

Function · Source

The samples the ring holds when full, and per part.

pub fn capacity(&self) -> usize

AnalogStream.part_samples

Function · Source

pub fn part_samples(&self) -> usize

AnalogStream.rate_hz

Function · Source

The conversions a second, in all channels, that the timer gives.

pub fn rate_hz(&self) -> u32

AnalogStream.channels

Function · Source

The entries in the pattern.

pub fn channels(&self) -> u32

AnalogStream.dma_channel

Function · Source

The DMA channel the stream runs on.

pub fn dma_channel(&self) -> u32

AnalogStream.stop

Function · Source

Stop converting; nothing more arrives. Dropping the stream does this too.

pub fn stop(&mut self)

RmtTx

Struct · Source

An RMT transmit channel and its pin, as Pins.rmt_tx hands it out; see std/embedded/peripheral/esp_rmt for the codes and the operations.

pub struct RmtTx {
    // Private implementation fields omitted.
}

RmtTx.transmit

Function · Source

Send codes and wait until the last has gone out.

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

RmtTx.poll_transmit

Function · Source

Start sending codes, then keep the channel’s memory filled; true once sent.

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

RmtTx.send

Function · Source

transmit and poll_transmit for codes computed while they go out.

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

RmtTx.poll_send

Function · Source

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

RmtTx.start_loop

Function · Source

Send codes count times back to back, or until stop for 0.

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

RmtTx.poll_loop

Function · Source

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

RmtTx.stop

Function · Source

Stop at once; the pin returns to the idle level.

pub fn stop(&mut self)

RmtTx.is_busy

Function · Source

pub fn is_busy(&self) -> bool

RmtTx.listen

Function · Source

The channel’s part of the RMT interrupt, irq(); see esp_rmt.

pub fn listen(&mut self)

RmtTx.ignore

Function · Source

pub fn ignore(&mut self)

RmtTx.is_pending

Function · Source

pub fn is_pending(&mut self) -> bool

RmtTx.irq

Function · Source

pub fn irq(&self) -> u32

RmtTx.resolution_hz

Function · Source

The tick the channel counts, the closest to the configuration’s.

pub fn resolution_hz(&self) -> u32

RmtTx.carrier_hz

Function · Source

The carrier’s frequency, 0 for none.

pub fn carrier_hz(&self) -> u32

RmtTx.channel

Function · Source

The transmit channel, 0 or 1.

pub fn channel(&self) -> u32

RmtTx.memory_codes

Function · Source

pub fn memory_codes(&self) -> usize

RmtTx.pin

Function · Source

pub fn pin(&self) -> u32

RmtRx

Struct · Source

An RMT receive channel and its pin, as Pins.rmt_rx hands it out; see std/embedded/peripheral/esp_rmt for the codes and the operations.

pub struct RmtRx {
    // Private implementation fields omitted.
}

RmtRx.receive

Function · Source

Receive a frame into buffer within timeout_us; the number of codes.

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

RmtRx.poll_receive

Function · Source

Start receiving a frame into buffer, then keep the channel’s memory emptied; true once the frame has ended.

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

RmtRx.received

Function · Source

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

pub fn received(&self) -> usize

RmtRx.stop

Function · Source

pub fn stop(&mut self)

RmtRx.is_busy

Function · Source

pub fn is_busy(&self) -> bool

RmtRx.listen

Function · Source

The channel’s part of the RMT interrupt, irq(); see esp_rmt.

pub fn listen(&mut self)

RmtRx.ignore

Function · Source

pub fn ignore(&mut self)

RmtRx.is_pending

Function · Source

pub fn is_pending(&mut self) -> bool

RmtRx.irq

Function · Source

pub fn irq(&self) -> u32

RmtRx.set_pull

Function · Source

Turn the pin’s pull-up or pull-down on, as for an infrared receiver with an open-collector output; a transmitter’s pin keeps its own.

pub fn set_pull(&mut self, up: bool, down: bool)

RmtRx.resolution_hz

Function · Source

pub fn resolution_hz(&self) -> u32

RmtRx.channel

Function · Source

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

pub fn channel(&self) -> u32

RmtRx.memory_codes

Function · Source

pub fn memory_codes(&self) -> usize

RmtRx.pin

Function · Source

pub fn pin(&self) -> u32

Ws2812

Struct · Source

WS2812 LEDs on one pin, as Pins.ws2812 hands them out.

pub struct Ws2812 {
    // Private implementation fields omitted.
}

Ws2812.write

Function · Source

Show colors, one 0xRRGGBB value per LED along the chain, and wait until they are sent: 30 us per LED and 300 us that latch them, with interrupts masked. For the write the channel also takes the RMT memory blocks after its own that nothing has claimed, so that up to 7 LEDs (one block for each 2) fit in memory at once. Longer chains are refilled while they go out, 12 codes every 15 us, which needs an optimized build (-O1 and up); too slow a refill reports Overrun. Timeout if the transmission does not end; Bus if the channel reports an error.

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

Ws2812.pin

Function · Source

pub fn pin(&self) -> u32

DMA_CHANNELS

Constant · Source

pub const DMA_CHANNELS: u32 = 3

DMA_MAX_BYTES

Constant · Source

The most bytes one transfer moves.

pub const DMA_MAX_BYTES: usize = DESCRIPTORS * DESCRIPTOR_BYTES

Dma

Struct · Source

The DMA controller’s three channels, handed out once each, as Peripherals.dma.

pub struct Dma {
    // Private implementation fields omitted.
}

Dma.channel

Function · Source

Claim a free channel. Busy if all three are taken.

pub fn channel(&mut self) -> DmaChannel!hal.Error

Dma.claim

Function · Source

Claim channel number, 0 to 2. Busy if taken, InvalidInput for another number.

pub fn claim(&mut self, number: u32) -> DmaChannel!hal.Error

Dma.is_claimed

Function · Source

pub fn is_claimed(&self, number: u32) -> bool

Dma.release

Function · Source

Stop a channel’s transfer and take it back.

pub fn release(&mut self, channel: DmaChannel)

DmaChannel

Struct · Source

One DMA channel, as Dma.channel hands it out. Implements hal.DmaChannel for copies between buffers in SRAM: the ESP32-C6’s DMA serves peripherals through their own DMA interfaces, not through register addresses, so transfers paced by a peripheral are InvalidInput. Chip drivers that use a peripheral’s DMA interface take a channel instead, as Spi.dma does.

pub struct DmaChannel: hal.DmaChannel {
    // Private implementation fields omitted.
}

DmaChannel.number

Function · Source

pub fn number(&self) -> u32

DmaChannel.irq

Function · Source

The interrupt source a finished transfer raises with listen, DMA_IN_CH0 + n.

pub fn irq(&self) -> u32

DmaChannel.start

Function · Source

Start copying transfer.count elements from source to destination, both incrementing and both in SRAM; the controller cannot read flash. InvalidInput for a paced or wrapping transfer, one that does not increment both addresses, an empty one, more than DMA_MAX_BYTES, or a buffer outside SRAM, such as a constant; Busy while one runs. SAFETY: as hal.DmaChannel.start requires.

pub unsafe fn start(&mut self, transfer: hal.DmaTransfer) -> void!hal.Error

Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.

DmaChannel.is_busy

Function · Source

True while a transfer is running.

pub fn is_busy(&mut self) -> bool

DmaChannel.remaining

Function · Source

The elements the running transfer has yet to write: 0 once it is done. The controller reports progress per descriptor, 4092 bytes.

pub fn remaining(&mut self) -> u32

DmaChannel.max_count

Function · Source

The largest count a transfer of bytes may have, DMA_MAX_BYTES; one of halfwords or words moves the same number of bytes.

pub fn max_count(&mut self) -> u32

DmaChannel.abort

Function · Source

Stop the running transfer, if any.

pub fn abort(&mut self)

DmaChannel.take_error

Function · Source

Bus if a transfer since the last call met a descriptor error.

pub fn take_error(&mut self) -> void!hal.Error

DmaChannel.set_signal

Function · Source

Raise signal whenever a transfer on this channel finishes, from the runtime’s DMA interrupt handler, so a task waits for it. Routes the channel’s interrupt.

pub fn set_signal(&mut self, signal: &executor.Signal)

DmaChannel.clear_signal

Function · Source

Stop raising the signal and the channel’s interrupt.

pub fn clear_signal(&mut self)

DmaChannel.listen

Function · Source

With listen, a finished transfer raises DMA_IN_CH0 + n.

pub fn listen(&mut self)

DmaChannel.ignore

Function · Source

pub fn ignore(&mut self)

DmaChannel.finished

Function · Source

True once a transfer has finished, until clear.

pub fn finished(&mut self) -> bool

DmaChannel.clear

Function · Source

pub fn clear(&mut self)

DmaChannel.copy

Function · Source

Copy source into destination, which must have the same length, and wait until it is done. InvalidInput for different lengths, more than DMA_MAX_BYTES, or a buffer outside SRAM; Bus on a descriptor error.

pub fn copy(&mut self, destination: &mut[u8], source: &[u8]) -> void!hal.Error

I2cTarget

Struct · Source

An I2C target (slave), as Pins.i2c_target hands it out. Implements hal.I2cTarget; esp_i2c documents the methods.

pub struct I2cTarget: hal.I2cTarget {
    // Private implementation fields omitted.
}

I2cTarget.poll

Function · Source

What the master did since the last poll, without waiting.

pub fn poll(&mut self, buffer: &mut[u8]) -> hal.I2cTargetEvent!hal.Error

I2cTarget.respond

Function · Source

Answer a Read with bytes, up to 32; returns how many.

pub fn respond(&mut self, bytes: &[u8]) -> usize!hal.Error

I2cTarget.set_address

Function · Source

Answer at another address from the next transaction on.

pub fn set_address(&mut self, address: u16, ten_bit: bool) -> void!hal.Error

I2cTarget.irq

Function · Source

The interrupt source of the controller, I2C_EXT0.

pub fn irq(&self) -> u32

SpiTarget

Struct · Source

An SPI target (slave), as Pins.spi_target hands it out. Implements hal.SpiTarget; esp_spi documents the methods.

pub struct SpiTarget: hal.SpiTarget {
    // Private implementation fields omitted.
}

SpiTarget.queue

Function · Source

Queue bytes for the master’s next transactions, up to 64, without waiting; returns how many.

pub fn queue(&mut self, bytes: &[u8]) -> usize!hal.Error

SpiTarget.read

Function · Source

What the master sent in finished transactions, without waiting.

pub fn read(&mut self, buffer: &mut[u8]) -> usize!hal.Error

SpiTarget.unsent

Function · Source

The bytes queued and not yet sent.

pub fn unsent(&self) -> usize

SpiTarget.irq

Function · Source

The interrupt source of the controller, SPI2.

pub fn irq(&self) -> u32

SpiDmaBus

Struct · Source

An SPI bus master that moves bytes between a buffer it holds and the bus by DMA, from Spi.dma(channel, buffer). A transfer of up to DMA_MAX_BYTES (32_736) runs as one run of the controller, without gaps between bytes and with a hardware chip select low throughout, while the program does other work:

dma := spi.dma(&mut channel, &mut buffer)! fill dma.buffer()!, then: dma.start_transfer(count)! … other work, or return Pending from a task … if dma.poll_finish()! { … read dma.buffer()! … }

The bus holds the controller, the channel, and the buffer until it is dropped, and lends the buffer out only between transfers, so the program never touches memory the channel is moving. The channel’s signal (DmaChannel.set_signal) is raised once a start_transfer’s last byte is in memory; a start_write raises none, as it receives nothing. Dropping the bus aborts a running transfer; the device then saw only part of it. Implements hal.SpiDma.

pub struct SpiDmaBus: hal.SpiDma {
    // Private implementation fields omitted.
}

SpiDmaBus.buffer

Function · Source

The buffer, to fill before a transfer or read after one. Busy from start_transfer or start_write until it is finished.

pub fn buffer(&mut self) -> &mut[u8]!hal.Error from(self)

SpiDmaBus.capacity

Function · Source

The buffer’s length, the most a transfer moves.

pub fn capacity(&self) -> usize

SpiDmaBus.start_transfer

Function · Source

Start sending buffer[..count] and replacing each byte with the one received at the same time, and return at once. InvalidInput for 0, more than the buffer holds, or more than DMA_MAX_BYTES; Busy until the last transfer is finished.

pub fn start_transfer(&mut self, count: usize) -> void!hal.Error

SpiDmaBus.start_write

Function · Source

Start sending buffer[..count] and discard what arrives, as for start_transfer; the buffer stays as it is.

pub fn start_write(&mut self, count: usize) -> void!hal.Error

SpiDmaBus.is_busy

Function · Source

True while a transfer runs: until the last byte has been sent and, for start_transfer, the last byte received is in memory.

pub fn is_busy(&mut self) -> bool

SpiDmaBus.finish

Function · Source

Wait until the running transfer is done, if one is, and end it, so the buffer is free again. Overrun if the channel delivered data too slowly for the clock, so bytes were lost, which only very fast clocks with other DMA traffic cause; Bus if the channel hit a descriptor error. Either way the transfer is over.

pub fn finish(&mut self) -> void!hal.Error

SpiDmaBus.poll_finish

Function · Source

Without waiting: true once no transfer runs, ending a transfer that is done, false while one runs. Errors as for finish.

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

SpiDmaBus.abort

Function · Source

Stop a running transfer; the device saw only part of it.

pub fn abort(&mut self)

SpiDmaBus.transfer

Function · Source

start_transfer, then finish.

pub fn transfer(&mut self, count: usize) -> void!hal.Error

SpiDmaBus.write

Function · Source

start_write, then finish.

pub fn write(&mut self, count: usize) -> void!hal.Error

UartDma

Struct · Source

A serial port that receives into a ring buffer by DMA, from Uart.dma(rx, ring). It implements the std/io Reader and Writer protocols, serial.Port, and serial.PollPort like Uart; esp_uhci documents the details:

  • Input waits in the ring, not just the 128-byte FIFO, so the program reads at its own pace. The ring is the part of ring from its first word-aligned byte, cut into 32 parts of the same size, a multiple of 4 bytes; ring_size() tells. Received bytes become readable when their part closes: when it is full, or 30 bit times after the last byte of a message (2.6 ms at 115200 baud). Each message takes at least one part, so the ring holds at most 32 messages.
  • When the ring is full, the channel stops instead of overwriting it, and bytes that arrive beyond the 128-byte FIFO are lost; a read returns what the ring held and then reports esp_uart.OVERRUN.
  • Bytes with framing or parity errors, and breaks, are dropped, and a read reports them after the bytes it returns.

Writes go through the transmit FIFO as on Uart: UHCI0’s transmit side does not work on this chip (see esp_uhci). Dropping the session stops the channel and hands the port back; input still in the ring is lost.

pub struct UartDma: serial.Port + serial.PollPort {
    // Private implementation fields omitted.
}

UartDma.write

Function · Source

pub fn write(&mut self, bytes: &[u8]) -> usize!io.Error

UartDma.poll_write

Function · Source

pub fn poll_write(&mut self, bytes: &[u8]) -> io.Poll!io.Error

UartDma.flush

Function · Source

pub fn flush(&mut self) -> void!io.Error

UartDma.poll_flush

Function · Source

pub fn poll_flush(&mut self) -> bool!io.Error

UartDma.read

Function · Source

pub fn read(&mut self, buffer: &mut[u8]) -> usize!io.Error

UartDma.poll_read

Function · Source

pub fn poll_read(&mut self, buffer: &mut[u8]) -> io.Poll!io.Error

UartDma.ring_size

Function · Source

The ring’s size in bytes.

pub fn ring_size(&self) -> usize

UartDma.available

Function · Source

The bytes received and readable now.

pub fn available(&mut self) -> usize

UartDma.set_crlf

Function · Source

pub fn set_crlf(&mut self, on: bool)

UartDma.set_poll_limit

Function · Source

pub fn set_poll_limit(&mut self, polls: u32)

UartDma.set_read_poll_limit

Function · Source

pub fn set_read_poll_limit(&mut self, polls: u32)

UartDma.listen

Function · Source

pub fn listen(&mut self, sources: u32)

UartDma.ignore

Function · Source

pub fn ignore(&mut self, sources: u32)

UartDma.pending_interrupts

Function · Source

pub fn pending_interrupts(&mut self) -> u32

UartDma.clear_interrupts

Function · Source

pub fn clear_interrupts(&mut self, sources: u32)

UartDma.number

Function · Source

0 for UART0, 1 for UART1.

pub fn number(&self) -> u32

UartDma.irq

Function · Source

The interrupt source of the controller, UART0 or UART1.

pub fn irq(&self) -> u32

Can

Struct · Source

A CAN controller, as Pins.can hands it out: TWAI0 or TWAI1. Implements the std/embedded/hal CAN protocol; esp_twai documents the methods.

pub struct Can: hal.Can {
    // Private implementation fields omitted.
}

Can.poll_send

Function · Source

pub fn poll_send(&mut self, frame: &hal.CanFrame) -> bool!hal.Error

Can.poll_receive

Function · Source

pub fn poll_receive(&mut self, frame: &mut hal.CanFrame) -> bool!hal.Error

Can.error_state

Function · Source

pub fn error_state(&mut self) -> hal.CanErrorState!hal.Error

Can.set_mode

Function · Source

Switch modes, keeping the bit timing and filters; frames waiting in either direction are dropped.

pub fn set_mode(&mut self, mode: esp_twai.Mode)

Can.tec

Function · Source

The transmit and receive error counters.

pub fn tec(&mut self) -> u32

Can.rec

Function · Source

pub fn rec(&mut self) -> u32

Can.status

Function · Source

The status register, for the bits error_state does not report.

pub fn status(&mut self) -> u32

Can.waiting

Function · Source

The frames waiting in the receive FIFO, with lost frames’ places.

pub fn waiting(&mut self) -> u32

Can.is_pending

Function · Source

Whether a frame waits in the transmit buffer.

pub fn is_pending(&mut self) -> bool

Can.error_code

Function · Source

The last bus error captured (ERR_CODE_CAP).

pub fn error_code(&mut self) -> u32

Can.abort_pending

Function · Source

Cancel the frame waiting to be sent.

pub fn abort_pending(&mut self) -> void!hal.Error

Can.recover

Function · Source

Start bus-off recovery, for Config.automatic_recovery off.

pub fn recover(&mut self)

Can.listen

Function · Source

Raise TWAI0 or TWAI1 (see irq) while any of sources (esp_twai.RECEIVE, …) is pending, and read and clear them.

pub fn listen(&mut self, sources: u32)

Can.take_interrupts

Function · Source

pub fn take_interrupts(&mut self) -> u32

Can.number

Function · Source

The controller: 0 for TWAI0, 1 for TWAI1.

pub fn number(&self) -> u32

Can.irq

Function · Source

The interrupt source, TWAI0 + number.

pub fn irq(&self) -> u32

Can.tx_pin

Function · Source

pub fn tx_pin(&self) -> u32

Can.rx_pin

Function · Source

pub fn rx_pin(&self) -> u32

I2sOutput

Struct · Source

An I2S output, as Pins.i2s_output hands it out. Implements the std/embedded/hal I2S output protocol; esp_i2s documents the methods.

pub struct I2sOutput: hal.I2sOutput {
    // Private implementation fields omitted.
}

I2sOutput.sample_rate

Function · Source

pub fn sample_rate(&self) -> u32

I2sOutput.channels

Function · Source

pub fn channels(&self) -> u32

I2sOutput.poll_write

Function · Source

pub fn poll_write(&mut self, samples: &[i32]) -> usize!hal.Error

I2sOutput.bits

Function · Source

pub fn bits(&self) -> u32

I2sOutput.slot_bits

Function · Source

pub fn slot_bits(&self) -> u32

I2sOutput.timing

Function · Source

The clock dividers and the sample rate they give.

pub fn timing(&self) -> esp_i2s.Timing

I2sOutput.queued

Function · Source

The frames queued and not yet playing.

pub fn queued(&self) -> u32

I2sOutput.frames_played

Function · Source

The frames played since the output started, silence included, a descriptor at a time.

pub fn frames_played(&self) -> u64

I2sOutput.frames_per_descriptor

Function · Source

pub fn frames_per_descriptor(&self) -> u32

I2sOutput.dma_channel

Function · Source

The DMA channel the output streams through.

pub fn dma_channel(&self) -> u32

I2sOutput.data_pin

Function · Source

pub fn data_pin(&self) -> u32

I2sOutput.bclk_pin

Function · Source

pub fn bclk_pin(&self) -> u32

I2sOutput.ws_pin

Function · Source

pub fn ws_pin(&self) -> u32

I2sInput

Struct · Source

An I2S input, as Pins.i2s_input hands it out. Implements the std/embedded/hal I2S input protocol; esp_i2s documents the methods.

pub struct I2sInput: hal.I2sInput {
    // Private implementation fields omitted.
}

I2sInput.sample_rate

Function · Source

pub fn sample_rate(&self) -> u32

I2sInput.channels

Function · Source

pub fn channels(&self) -> u32

I2sInput.poll_read

Function · Source

pub fn poll_read(&mut self, samples: &mut[i32]) -> usize!hal.Error

I2sInput.bits

Function · Source

pub fn bits(&self) -> u32

I2sInput.slot_bits

Function · Source

pub fn slot_bits(&self) -> u32

I2sInput.timing

Function · Source

pub fn timing(&self) -> esp_i2s.Timing

I2sInput.is_shared

Function · Source

Whether the input runs on the output’s clocks.

pub fn is_shared(&self) -> bool

I2sInput.available

Function · Source

The frames received and not yet read.

pub fn available(&mut self) -> u32

I2sInput.frames_received

Function · Source

The frames received since the input started, a descriptor at a time.

pub fn frames_received(&mut self) -> u64

I2sInput.frames_per_descriptor

Function · Source

pub fn frames_per_descriptor(&self) -> u32

I2sInput.dma_channel

Function · Source

pub fn dma_channel(&self) -> u32

I2sInput.data_pin

Function · Source

pub fn data_pin(&self) -> u32

I2sInput.bclk_pin

Function · Source

pub fn bclk_pin(&self) -> u32

I2sInput.ws_pin

Function · Source

pub fn ws_pin(&self) -> u32

CLOCK_UART0

Constant · Source

Clock gates for Power, as std/embedded/power.Clocks: one bit per enable in the system clock controller (PCR), numbered in register order (see std/embedded/chip/esp_power). Each peripheral’s constant holds every clock it uses: its bus (APB) clock and, where it has them, its function clocks.

pub const CLOCK_UART0: power.Clocks = (1 << 0) | (1 << 1)

CLOCK_UART1

Constant · Source

pub const CLOCK_UART1: power.Clocks = (1 << 2) | (1 << 3)

CLOCK_MSPI

Constant · Source

The flash and PSRAM controller, which the program runs from.

pub const CLOCK_MSPI: power.Clocks = 1 << 4

CLOCK_I2C0

Constant · Source

pub const CLOCK_I2C0: power.Clocks = (1 << 5) | (1 << 6)

CLOCK_UHCI

Constant · Source

pub const CLOCK_UHCI: power.Clocks = 1 << 7

CLOCK_RMT

Constant · Source

pub const CLOCK_RMT: power.Clocks = (1 << 8) | (1 << 9)

CLOCK_LEDC

Constant · Source

pub const CLOCK_LEDC: power.Clocks = (1 << 10) | (1 << 11)

CLOCK_TIMG0

Constant · Source

Timer groups 0 and 1: registers, timer, and watchdog clocks.

pub const CLOCK_TIMG0: power.Clocks = (1 << 12) | (1 << 13) | (1 << 14)

CLOCK_TIMG1

Constant · Source

pub const CLOCK_TIMG1: power.Clocks = (1 << 15) | (1 << 16) | (1 << 17)

CLOCK_SYSTIMER

Constant · Source

The system timer behind Timer and its alarms.

pub const CLOCK_SYSTIMER: power.Clocks = (1 << 18) | (1 << 19)

CLOCK_TWAI0

Constant · Source

pub const CLOCK_TWAI0: power.Clocks = (1 << 20) | (1 << 21)

CLOCK_TWAI1

Constant · Source

pub const CLOCK_TWAI1: power.Clocks = (1 << 22) | (1 << 23)

CLOCK_I2S

Constant · Source

I2S: registers, transmitter, and receiver.

pub const CLOCK_I2S: power.Clocks = (1 << 24) | (1 << 25) | (1 << 26)

CLOCK_SARADC

Constant · Source

The ADC’s controller, whose registers the temperature sensor also uses.

pub const CLOCK_SARADC: power.Clocks = (1 << 27) | (1 << 28)

CLOCK_TSENS

Constant · Source

pub const CLOCK_TSENS: power.Clocks = 1 << 29

CLOCK_USB_DEVICE

Constant · Source

The USB serial port’s controller.

pub const CLOCK_USB_DEVICE: power.Clocks = 1 << 30

CLOCK_INTMTX

Constant · Source

The interrupt matrix.

pub const CLOCK_INTMTX: power.Clocks = 1 << 31

CLOCK_PCNT

Constant · Source

pub const CLOCK_PCNT: power.Clocks = 1 << 32

CLOCK_ETM

Constant · Source

pub const CLOCK_ETM: power.Clocks = 1 << 33

CLOCK_MCPWM

Constant · Source

pub const CLOCK_MCPWM: power.Clocks = (1 << 34) | (1 << 35)

CLOCK_PARLIO

Constant · Source

The parallel IO controller: registers, receiver, and transmitter.

pub const CLOCK_PARLIO: power.Clocks = (1 << 36) | (1 << 37) | (1 << 38)

CLOCK_SDIO_SLAVE

Constant · Source

pub const CLOCK_SDIO_SLAVE: power.Clocks = 1 << 39

CLOCK_PVT

Constant · Source

The process, voltage, and temperature monitors.

pub const CLOCK_PVT: power.Clocks = 1 << 40

CLOCK_GDMA

Constant · Source

pub const CLOCK_GDMA: power.Clocks = 1 << 41

CLOCK_SPI2

Constant · Source

pub const CLOCK_SPI2: power.Clocks = (1 << 42) | (1 << 43)

CLOCK_AES

Constant · Source

The cryptographic accelerators.

pub const CLOCK_AES: power.Clocks = 1 << 44

CLOCK_SHA

Constant · Source

pub const CLOCK_SHA: power.Clocks = 1 << 45

CLOCK_RSA

Constant · Source

pub const CLOCK_RSA: power.Clocks = 1 << 46

CLOCK_ECC

Constant · Source

pub const CLOCK_ECC: power.Clocks = 1 << 47

CLOCK_DS

Constant · Source

pub const CLOCK_DS: power.Clocks = 1 << 48

CLOCK_HMAC

Constant · Source

pub const CLOCK_HMAC: power.Clocks = 1 << 49

CLOCK_IOMUX

Constant · Source

The IO MUX and GPIO matrix: registers and their function clock. GPIO interrupts need them to wake a deep sleep.

pub const CLOCK_IOMUX: power.Clocks = (1 << 50) | (1 << 51)

CLOCK_MEM_MONITOR

Constant · Source

pub const CLOCK_MEM_MONITOR: power.Clocks = 1 << 52

CLOCK_TRACE

Constant · Source

pub const CLOCK_TRACE: power.Clocks = 1 << 53

CLOCK_ASSIST_DEBUG

Constant · Source

pub const CLOCK_ASSIST_DEBUG: power.Clocks = 1 << 54

CLOCK_CACHE

Constant · Source

pub const CLOCK_CACHE: power.Clocks = 1 << 55

CLOCK_MODEM_APB

Constant · Source

The radio’s register bus, which the ADC’s calibration also goes through.

pub const CLOCK_MODEM_APB: power.Clocks = 1 << 56

ALARM_CLOCKS

Constant · Source

What the timer and its alarms need: keep them in the sleep set to wake from a deep sleep on an alarm, as an executor on an alarm does.

pub const ALARM_CLOCKS: power.Clocks = CLOCK_SYSTIMER

ESSENTIAL_CLOCKS

Constant · Source

Clocks the program cannot run without, which Power.disable_clocks refuses and a deep sleep never stops: the flash controller and cache the program runs from, the interrupt matrix, the IO MUX and GPIO matrix, the USB serial port, which dodo run and the boot ROM reach the chip through, and the radio’s register bus.

pub const ESSENTIAL_CLOCKS: power.Clocks = CLOCK_MSPI | CLOCK_INTMTX | CLOCK_IOMUX | CLOCK_USB_DEVICE | CLOCK_CACHE | CLOCK_MODEM_APB

ALL_CLOCKS

Constant · Source

Every gate.

pub const ALL_CLOCKS: power.Clocks = (1 << 57) - 1

Power

Struct · Source

Low power, as Peripherals.power; implements std/embedded/power’s protocol, whose package comment describes the modes.

Sleep. Every wait (wfi) stops the CPU’s clock until an interrupt is pending (PCR CPU_WAITI_CONF), so a light sleep saves power and still wakes within a few microseconds.

Deep sleep. The ESP32-C6 has no per-peripheral sleep enables and its core no deep-sleep state, and the PMU’s own sleep, which does gate clocks per peripheral, ends only on pins, the low-power timer, and UARTs, not on the system timer’s alarms or other interrupts. So in Mode.DeepSleep every wait, through dodo_wait_for_interrupt, closes the PCR gates of the running clocks outside the sleep set before its wfi and opens them again once an interrupt is pending, with interrupts masked in between. A peripheral whose clock keeps running, such as the system timer for an alarm (ALARM_CLOCKS), or any GPIO, wakes the core; the essential clocks never stop. Every clock starts in the sleep set, so a deep sleep stops nothing more than a light one until set_sleep_clocks says otherwise.

Clock gating. The constants above name the gates; ESSENTIAL_CLOCKS are refused. Claiming a peripheral starts its clocks, so disable_unused_clocks is safe at any time; it stops the peripherals listed in MANAGED_CLOCKS that nothing has claimed, including those the package has no driver for. A timer alarm’s claim keeps CLOCK_SYSTIMER running; without one it can be stopped, and Timer.now_us, delays, and alarms then wait for it until it starts again. The PCR keeps its gates through the resets of dodo run: the package’s own claims start every clock they need, but a program that drives a peripheral directly should call enable_clocks first.

Dormant. dormant asks the PMU for a light sleep: the CPU stalls with its state, SRAM, and every register kept, every HP clock stops, and the crystal, the PLL, and the fast RC oscillator power down, until a pin event. The pins are watched through the GPIO wakeup, which sees levels only: each pin wakes the chip when it leaves its current level, and dormant sleeps again until one of the events in the Wake has happened (an edge takes two sleeps when the pin starts at the edge’s end level). GPIO 0 to 23 apart from the USB pins can wake it. The system timer pauses meanwhile, so now_us does not count the time spent dormant; the low-power timer keeps counting its 136 kHz RC oscillator. The USB connection does not survive the stopped PLL: the host sees the device stop answering and gives up on it. So dormant returns Busy while the USB serial port is open and a host has it open; release the port first. After a sleep it detaches the USB device for 100 ms (D+ released) so the host enumerates it again: a program on the host has to open the port anew. Serial ports must have sent their last bytes, and peripherals’ clocks from the PLL stop too. Wakes take about 2 ms (the crystal restarts) plus the 100 ms detach.

The PMU’s registers are in the always-on domain, which the resets of dodo run keep, so what one program leaves there, the next finds. dormant restores every PMU, LP clock, and LP timer register it changes, and take() puts the PMU’s HP_ACTIVE state, the analog bus’s power (RF_PWC), and the radio domain’s clock gating where ESP-IDF’s start-up code puts them (see esp_power.init_active_state), so whatever ran before, the ADC and a dormant state work.

pub struct Power: power.Power {
    // Private implementation fields omitted.
}

Power.mode

Function · Source

pub fn mode(&self) -> power.Mode

Power.set_mode

Function · Source

pub fn set_mode(&mut self, mode: power.Mode)

Power.sleep

Function · Source

pub fn sleep(&mut self)

Power.enabled_clocks

Function · Source

pub fn enabled_clocks(&self) -> power.Clocks

Power.enable_clocks

Function · Source

pub fn enable_clocks(&mut self, clocks: power.Clocks)

Power.disable_clocks

Function · Source

pub fn disable_clocks(&mut self, clocks: power.Clocks) -> void!hal.Error

Power.disable_unused_clocks

Function · Source

pub fn disable_unused_clocks(&mut self) -> power.Clocks

Power.sleep_clocks

Function · Source

pub fn sleep_clocks(&self) -> power.Clocks

Power.set_sleep_clocks

Function · Source

pub fn set_sleep_clocks(&mut self, clocks: power.Clocks)

Power.dormant

Function · Source

A timeout in wake (power.Wake.after_ms) ends the dormant state on the low-power timer as set_dormant_timeout_us does, the shorter of the two applying; when it is the one that ran out, the result is power.BY_TIME.

pub fn dormant(&mut self, wake: &power.Wake) -> u64!hal.Error

Power.set_dormant_timeout_us

Function · Source

Also end a dormant state after microseconds of the low-power timer, 0 (the default) for no limit: dormant then returns the pins that woke the chip, none if the time ran out first. The timer counts the RC_SLOW oscillator, whose rate the first timed dormant state measures against the system timer for 10 ms; the time is then accurate to about 1 %. It uses the timer’s target 0 (LP_TIMER TAR0), the only one the PMU wakes on, and puts back what another user, such as an RTC alarm, had there; an alarm that falls due during the dormant state does not end it.

pub fn set_dormant_timeout_us(&mut self, microseconds: u64)

Power.lp_ticks

Function · Source

The low-power timer’s count of its RC_SLOW oscillator, which keeps running in a dormant state, and its measured rate in counts per 10 ms, measured once.

pub fn lp_ticks(&self) -> u64

Power.lp_rate

Function · Source

pub fn lp_rate(&mut self) -> u64

Power.hibernate

Function · Source

Hibernate: power the whole chip down but its LP system until one of wake’s sources, which then boots the firmware again from the start, as a reset does. Returns only if it cannot: InvalidInput for a Hibernation without sources, with a pin above GPIO 7, or that waits for an LP core that is not running; Timeout if the PMU never powers the chip down. See the package comment of Hibernation.

pub fn hibernate(&mut self, wake: &Hibernation) -> hal.Error

Power.woke_from_hibernation

Function · Source

True if this boot follows a hibernation.

pub fn woke_from_hibernation(&self) -> bool

Power.wake_cause

Function · Source

The sources that ended the hibernation this boot follows, WAKE_PINS, WAKE_TIMER, and WAKE_LP_CORE; 0 after any other reset.

pub fn wake_cause(&self) -> u32

Power.wake_pins

Function · Source

The pins whose level ended that hibernation, bit n for GPIO n.

pub fn wake_pins(&self) -> u32

WAKE_PINS

Constant · Source

Wakeup sources of a hibernation, for Power.wake_cause: a pin’s level, the LP timer, and the LP core.

pub const WAKE_PINS: u32 = esp_power.WAKE_EXT1

WAKE_TIMER

Constant · Source

pub const WAKE_TIMER: u32 = esp_power.WAKE_LP_TIMER

WAKE_LP_CORE

Constant · Source

pub const WAKE_LP_CORE: u32 = esp_power.WAKE_LP_CORE

HIBERNATE_PINS

Constant · Source

The pins that can end a hibernation, GPIO 0 to 7: the LP IO pads.

pub const HIBERNATE_PINS: u32 = 0xFF

Hibernation

Struct · Source

What ends a hibernation, for Power.hibernate:

wake := esp32c6.Hibernation.new() wake.wake_after_us(60_000_000) wake.wake_on_pin(4, power.LEVEL_LOW) error := b.power.hibernate(&wake) // returns only on failure

Hibernation is the ESP32-C6’s deep sleep, the deepest state there is: the CPU, SRAM, every HP peripheral, the flash, and the crystal power down, and only the LP system keeps running, the LP timer, LP SRAM, the LP IO pads, and the LP core if it was started. The chip then draws a few microamps. One of the sources boots the firmware again from the reset handler; Power.wake_cause() and wake_pins() tell what woke it. SRAM does not survive, but statics placed with @section(".lp_noinit") live in LP SRAM and keep their values through hibernation and every reset but a power cycle (they start out random, so mark them valid yourself). The pins are GPIO 0 to 7, each ending the hibernation at a level: claim each as an input with the pull it needs first; its pulls carry over to the LP IO pad, which keeps them while the chip sleeps. A source that holds already ends the hibernation at once. The USB serial port goes away while the chip hibernates and comes back with the new boot. The timer uses the LP timer’s target 0, like the RTC’s alarm.

pub struct Hibernation {
    // Private implementation fields omitted.
}

Hibernation.new

Function · Source

No sources yet.

pub fn new() -> Hibernation

Hibernation.wake_after_us

Function · Source

Wake after microseconds of the LP timer, whose RC oscillator the first hibernation or timed dormant state measures for 10 ms: accurate to about 1 %. 0 removes the timer.

pub fn wake_after_us(&mut self, microseconds: u64)

Hibernation.wake_on_pin

Function · Source

Wake while GPIO pin, 0 to 7, is at level, power.LEVEL_HIGH or power.LEVEL_LOW. Anything else makes hibernate return InvalidInput.

pub fn wake_on_pin(&mut self, pin: u32, level: u32)

Hibernation.wake_on_lp_core

Function · Source

Wake when the LP core asks, with esp32c6_lp.wake_hp(); the LP core must be running (LpCore.start).

pub fn wake_on_lp_core(&mut self)

LpCore

Struct · Source

The ESP32-C6’s low-power core, as Peripherals.lp_core: loads the program the firmware embeds and starts, stops, and talks to it.

The program is a Dodo program built for chip = "esp32c6_lp" with std/embedded/chip/esp32c6_lp; name its entry file in the firmware’s target, and the compiler builds it and embeds its image:

[targets.app] entry = “main.dodo” board = “esp32c6_devkitc” lp-core = “lp/main.dodo”

start() runs its main once; start_every_us(period) runs it now and then again each period, timed by the LP timer, which keeps going while the main core hibernates. The two programs share SHARED_WORDS words of LP SRAM, shared and set_shared on both sides, and the LP program wakes the main core with esp32c6_lp.wake_hp(): it ends a hibernation that waits for it (Hibernation.wake_on_lp_core) or, while the main core runs, raises the request take_wake_request reports. A panic on the LP core stops it and leaves its message for panic_message.

The LP core keeps running through hibernation, as it should, so a boot that follows one finds it as it was: the firmware need not start it again. Every other reset stops it at take(), so a program flashed later never meets an earlier one’s LP core.

pub struct LpCore {
    // Private implementation fields omitted.
}

LpCore.has_program

Function · Source

Whether the firmware embeds an LP program (lp-core).

pub fn has_program(&self) -> bool

LpCore.program_size

Function · Source

The embedded program’s size in bytes, at most 12 KiB.

pub fn program_size(&self) -> usize

LpCore.load

Function · Source

Stop the LP core, copy the program into its LP SRAM, zero the rest of that, and clear the shared words. Unsupported if the firmware embeds no program. start loads too, the first time; load first to set shared words the program reads at its start.

pub fn load(&mut self) -> void!hal.Error

LpCore.start

Function · Source

Run the program’s main once, loading it first if it is not. A program that has halted runs again from the start. Unsupported without a program.

pub fn start(&mut self) -> void!hal.Error

LpCore.start_every_us

Function · Source

Run the program now, and then again every period_us microseconds of the LP timer from the end of one run to the start of the next, until stop. The timer’s RC oscillator is measured for 10 ms the first time, so periods are accurate to about 1 %. InvalidInput for a period of 0.

pub fn start_every_us(&mut self, period_us: u64) -> void!hal.Error

LpCore.stop

Function · Source

Stop the LP core: a run in progress ends at once, and it does not wake again until the next start.

pub fn stop(&mut self)

LpCore.is_running

Function · Source

True from a start until stop or a panic.

pub fn is_running(&self) -> bool

LpCore.runs

Function · Source

How many runs of main have started since the program was loaded.

pub fn runs(&self) -> u32

LpCore.shared

Function · Source

Shared word index, below SHARED_WORDS, as either program last wrote it. Traps past the end.

pub fn shared(&self, index: u32) -> u32

LpCore.set_shared

Function · Source

pub fn set_shared(&mut self, index: u32, value: u32)

LpCore.take_wake_request

Function · Source

True once if the LP program asked to wake the main core (esp32c6_lp.wake_hp()) while it ran, since the last call.

pub fn take_wake_request(&mut self) -> bool

LpCore.panicked

Function · Source

True if the LP program panicked since it was loaded.

pub fn panicked(&self) -> bool

LpCore.panic_message

Function · Source

Write the LP program’s panic into out as CHECK check failed at FILE:LINE:COLUMN, as much as fits, and return the length; 0 if it has not panicked.

pub fn panic_message(&self, out: &mut[u8]) -> usize

SHARED_WORDS

Constant · Source

How many shared words the programs have.

pub const SHARED_WORDS: u32 = esp_lp_shared.USER_WORDS

Search every guide, reference page, and API declaration.