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/rp2350"
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.
SYS_HZ
Constant · Source
clk_sys, the processor and peripheral clock, after take().
pub const SYS_HZ: u32 = 150_000_000
PIN_COUNT
Constant · Source
User GPIOs 0 to 29, all the RP2350A (QFN-60) has, and the only ones a program for either package can rely on. pin_count() is the chip’s own.
pub const PIN_COUNT: u32 = 30
MAX_PIN_COUNT
Constant · Source
User GPIOs 0 to 47, all the RP2350B (QFN-80) has.
pub const MAX_PIN_COUNT: u32 = 48
PIO_BLOCKS
Constant · Source
PIO blocks 0 to 2.
pub const PIO_BLOCKS: u32 = 3
RETAIN_SRAM0
Constant · Source
The SRAM domains
Power.power_downcan keep powered, so their contents survive: SRAM0 is SRAM0 to SRAM3, the lower 256 KiB from 0x2000_0000, which holds the program’s statics,.noinitones included, unless they pass 256 KiB; SRAM1 is SRAM4 to SRAM9, the rest, with the stack at its top (6.2.1).
pub const RETAIN_SRAM0: u32 = rp_power.DOMAIN_SRAM0
RETAIN_SRAM1
Constant · Source
pub const RETAIN_SRAM1: u32 = rp_power.DOMAIN_SRAM1
RETAIN_NOTHING
Constant · Source
pub const RETAIN_NOTHING: u32 = 0
SCRATCH_WORDS
Constant · Source
The power manager’s scratch registers for the program, which keep their values through power-down and every reset but a loss of power:
Power.scratch(0)toscratch(SCRATCH_WORDS - 1).
pub const SCRATCH_WORDS: u32 = rp_power.SCRATCH_WORDS
ALARM_COUNT
Constant · Source
Alarms 0 to 3, raising TIMER0_IRQ_0 + n.
pub const ALARM_COUNT: u32 = 4
TIMER0_IRQ_0
Constant · Source
Interrupt numbers (3.2), for std/embedded/cortex_m’s enable, pend, and set_priority. Each is also the vector name of its
@interrupthandler.
pub const TIMER0_IRQ_0: u32 = 0
TIMER0_IRQ_1
Constant · Source
pub const TIMER0_IRQ_1: u32 = 1
TIMER0_IRQ_2
Constant · Source
pub const TIMER0_IRQ_2: u32 = 2
TIMER0_IRQ_3
Constant · Source
pub const TIMER0_IRQ_3: u32 = 3
TIMER1_IRQ_0
Constant · Source
pub const TIMER1_IRQ_0: u32 = 4
TIMER1_IRQ_1
Constant · Source
pub const TIMER1_IRQ_1: u32 = 5
TIMER1_IRQ_2
Constant · Source
pub const TIMER1_IRQ_2: u32 = 6
TIMER1_IRQ_3
Constant · Source
pub const TIMER1_IRQ_3: u32 = 7
PWM_IRQ_WRAP_0
Constant · Source
pub const PWM_IRQ_WRAP_0: u32 = 8
PWM_IRQ_WRAP_1
Constant · Source
pub const PWM_IRQ_WRAP_1: u32 = 9
DMA_IRQ_0
Constant · Source
pub const DMA_IRQ_0: u32 = 10
DMA_IRQ_1
Constant · Source
pub const DMA_IRQ_1: u32 = 11
DMA_IRQ_2
Constant · Source
pub const DMA_IRQ_2: u32 = 12
DMA_IRQ_3
Constant · Source
pub const DMA_IRQ_3: u32 = 13
USBCTRL_IRQ
Constant · Source
pub const USBCTRL_IRQ: u32 = 14
PIO0_IRQ_0
Constant · Source
pub const PIO0_IRQ_0: u32 = 15
PIO0_IRQ_1
Constant · Source
pub const PIO0_IRQ_1: u32 = 16
PIO1_IRQ_0
Constant · Source
pub const PIO1_IRQ_0: u32 = 17
PIO1_IRQ_1
Constant · Source
pub const PIO1_IRQ_1: u32 = 18
PIO2_IRQ_0
Constant · Source
pub const PIO2_IRQ_0: u32 = 19
PIO2_IRQ_1
Constant · Source
pub const PIO2_IRQ_1: u32 = 20
IO_IRQ_BANK0
Constant · Source
pub const IO_IRQ_BANK0: u32 = 21
IO_IRQ_BANK0_NS
Constant · Source
pub const IO_IRQ_BANK0_NS: u32 = 22
IO_IRQ_QSPI
Constant · Source
pub const IO_IRQ_QSPI: u32 = 23
IO_IRQ_QSPI_NS
Constant · Source
pub const IO_IRQ_QSPI_NS: u32 = 24
SIO_IRQ_FIFO
Constant · Source
pub const SIO_IRQ_FIFO: u32 = 25
SIO_IRQ_BELL
Constant · Source
pub const SIO_IRQ_BELL: u32 = 26
SIO_IRQ_FIFO_NS
Constant · Source
pub const SIO_IRQ_FIFO_NS: u32 = 27
SIO_IRQ_BELL_NS
Constant · Source
pub const SIO_IRQ_BELL_NS: u32 = 28
SIO_IRQ_MTIMECMP
Constant · Source
pub const SIO_IRQ_MTIMECMP: u32 = 29
CLOCKS_IRQ
Constant · Source
pub const CLOCKS_IRQ: u32 = 30
SPI0_IRQ
Constant · Source
pub const SPI0_IRQ: u32 = 31
SPI1_IRQ
Constant · Source
pub const SPI1_IRQ: u32 = 32
UART0_IRQ
Constant · Source
pub const UART0_IRQ: u32 = 33
UART1_IRQ
Constant · Source
pub const UART1_IRQ: u32 = 34
ADC_IRQ_FIFO
Constant · Source
pub const ADC_IRQ_FIFO: u32 = 35
I2C0_IRQ
Constant · Source
pub const I2C0_IRQ: u32 = 36
I2C1_IRQ
Constant · Source
pub const I2C1_IRQ: u32 = 37
OTP_IRQ
Constant · Source
pub const OTP_IRQ: u32 = 38
TRNG_IRQ
Constant · Source
pub const TRNG_IRQ: u32 = 39
PROC0_IRQ_CTI
Constant · Source
pub const PROC0_IRQ_CTI: u32 = 40
PROC1_IRQ_CTI
Constant · Source
pub const PROC1_IRQ_CTI: u32 = 41
PLL_SYS_IRQ
Constant · Source
pub const PLL_SYS_IRQ: u32 = 42
PLL_USB_IRQ
Constant · Source
pub const PLL_USB_IRQ: u32 = 43
POWMAN_IRQ_POW
Constant · Source
pub const POWMAN_IRQ_POW: u32 = 44
POWMAN_IRQ_TIMER
Constant · Source
pub const POWMAN_IRQ_TIMER: u32 = 45
CLOCK_ADC
Constant · Source
Clock gates for
Power(8.1.3.5), as std/embedded/power.Clocks: bit n of WAKE_EN0 and SLEEP_EN0 is bit n, bit n of WAKE_EN1 and SLEEP_EN1 bit 32 + n. Each peripheral’s constant holds every clock it uses, its clk_sys register clock and, where it has one, its own clock.
pub const CLOCK_ADC: power.Clocks = (1 << 2) | (1 << 3)
CLOCK_BUSCTRL
Constant · Source
pub const CLOCK_BUSCTRL: power.Clocks = 1 << 5
CLOCK_DMA
Constant · Source
pub const CLOCK_DMA: power.Clocks = 1 << 7
CLOCK_HSTX
Constant · Source
pub const CLOCK_HSTX: power.Clocks = (1 << 9) | (1 << 10)
CLOCK_I2C0
Constant · Source
pub const CLOCK_I2C0: power.Clocks = 1 << 11
CLOCK_I2C1
Constant · Source
pub const CLOCK_I2C1: power.Clocks = 1 << 12
CLOCK_GPIO
Constant · Source
GPIO control and pads: their interrupts need these to wake a deep sleep.
pub const CLOCK_GPIO: power.Clocks = (1 << 13) | (1 << 17)
CLOCK_JTAG
Constant · Source
pub const CLOCK_JTAG: power.Clocks = 1 << 14
CLOCK_PIO0
Constant · Source
pub const CLOCK_PIO0: power.Clocks = 1 << 18
CLOCK_PIO1
Constant · Source
pub const CLOCK_PIO1: power.Clocks = 1 << 19
CLOCK_PIO2
Constant · Source
pub const CLOCK_PIO2: power.Clocks = 1 << 20
CLOCK_PLL_USB
Constant · Source
PLL_USB’s registers; PLL_USB runs while the ADC or USB serial port does.
pub const CLOCK_PLL_USB: power.Clocks = 1 << 22
CLOCK_PWM
Constant · Source
pub const CLOCK_PWM: power.Clocks = 1 << 25
CLOCK_SHA256
Constant · Source
pub const CLOCK_SHA256: power.Clocks = 1 << 30
CLOCK_SPI0
Constant · Source
pub const CLOCK_SPI0: power.Clocks = (1 << 32) | (1 << 33)
CLOCK_SPI1
Constant · Source
pub const CLOCK_SPI1: power.Clocks = (1 << 34) | (1 << 35)
CLOCK_MEMORY
Constant · Source
The SRAM banks and the bus fabric, for DMA during a deep sleep.
pub const CLOCK_MEMORY: power.Clocks = (1 << 6) | (0x3FF << 36)
CLOCK_SYSCFG
Constant · Source
pub const CLOCK_SYSCFG: power.Clocks = 1 << 46
CLOCK_SYSINFO
Constant · Source
pub const CLOCK_SYSINFO: power.Clocks = 1 << 47
CLOCK_TBMAN
Constant · Source
pub const CLOCK_TBMAN: power.Clocks = 1 << 48
CLOCK_TIMER
Constant · Source
TIMER0 and the tick generators that count its microseconds.
pub const CLOCK_TIMER: power.Clocks = (1 << 49) | (1 << 50) | (1 << 51)
CLOCK_TIMER1
Constant · Source
pub const CLOCK_TIMER1: power.Clocks = 1 << 52
CLOCK_TRNG
Constant · Source
pub const CLOCK_TRNG: power.Clocks = 1 << 53
CLOCK_UART0
Constant · Source
pub const CLOCK_UART0: power.Clocks = (1 << 54) | (1 << 55)
CLOCK_UART1
Constant · Source
pub const CLOCK_UART1: power.Clocks = (1 << 56) | (1 << 57)
CLOCK_USB
Constant · Source
pub const CLOCK_USB: power.Clocks = (1 << 58) | (1 << 59)
CLOCK_WATCHDOG
Constant · Source
pub const CLOCK_WATCHDOG: power.Clocks = 1 << 60
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_TIMER
ESSENTIAL_CLOCKS
Constant · Source
Clocks the program cannot run without, which Power.disable_clocks refuses: the clock, reset, power-on, and power manager controls, access control, the glitch detector, the bus fabric, the boot ROM and its RAM, OTP, SRAM, flash (XIP), the cores’ SIO, GPIO, and the oscillators and PLL_SYS, which
dormantrestarts.
pub const ESSENTIAL_CLOCKS: power.Clocks = (1 << 0) | (1 << 1) | (1 << 4) | (1 << 6) | (1 << 8) | CLOCK_GPIO | (1 << 15) | (1 << 16) | (1 << 21) | (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27) | (1 << 28) | (1 << 29) | (1 << 31) | (0x3FF << 36) | (1 << 61) | (1 << 62)
ALL_CLOCKS
Constant · Source
Every gate.
pub const ALL_CLOCKS: power.Clocks = 0x7FFF_FFFF_FFFF_FFFF
LEVEL_LOW
Constant · Source
Pin events for
Pin.listen,ignore,events, andclear_events: the pin’s level is low or high, or it fell or rose. Levels last as long as the level does; edges stay latched until cleared.
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
reboot_to_bootloader
Function · Source
Restart into the boot ROM’s USB bootloader, as if BOOTSEL were held at power-up: the board reappears as the RP2350 drive and accepts new firmware, for example from
dodo run. Pinactivity_led, if below pin_count(), lights while the drive is accessed, except on chip revision A2, whose boot ROM mishandles it on the Arm cores (erratum in the Pico SDK’s rom_reset_usb_boot). Does not return.
pub fn reboot_to_bootloader(activity_led: u32)
report_panic
Function · Source
Write a failed check’s message to every serial port claimed from
pins.uartand not yet released, as the default panic hook does before it halts:dodo: arithmetic overflow check failed at main.dodo:12:5. Call it from a panic hook of your own that, for example, restarts into the bootloader: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.reboot_to_bootloader(25) }
SAFETY:
checkandfilemust 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.
pin_count
Function · Source
The user GPIOs of this chip’s package: PIN_COUNT (30) for the RP2350A (QFN-60), MAX_PIN_COUNT (48) for the RP2350B (QFN-80), from the OTP’s NUM_GPIOS row, or SYSINFO’s PACKAGE_SEL if the row holds neither.
Pinshands out GPIO 0 to pin_count() - 1.
pub fn pin_count() -> u32
Config
Struct · Source
What the circuit board decides. Board packages pass theirs to
take.
pub struct Config {
// The crystal on XIN/XOUT, in hertz: 1 to 15 MHz, a whole number of
// megahertz (for the 1 MHz ticks) that divides 1.5 GHz (for the PLL).
// 12 MHz, as on the Raspberry Pi Pico 2, is the usual choice.
pub crystal_hz: u32
}
Peripherals
Struct · Source
The chip’s peripherals, handed out once by
take.
pub struct Peripherals {
pub pins: Pins
pub timer: Timer
// The always-on timer as a real-time clock: the time of day, counted in
// milliseconds, which survives resets.
pub rtc: Rtc
// The watchdog, stopped; rp_watchdog documents it.
pub watchdog: rp_watchdog.Watchdog
pub usb: Usb
// The DMA controller's channels; rp_dma documents them.
pub dma: rp_dma.Dma
// The random number generator, the TRNG: about 20 KB a second, fit
// for cryptographic keys; rp_rng documents it.
pub rng: rp_rng.Trng
// Core 1, which runs a task once started, and the FIFOs, spinlocks, and
// doorbells the two cores share; see std/embedded/chip/rp_multicore.
pub core1: rp_multicore.Core1
pub fifos: rp_multicore.Fifos
pub spinlocks: rp_multicore.Spinlocks
pub doorbells: rp_multicore.Doorbells
// The program flash, for storing data above the program; see
// std/embedded/chip/rp_flash.
pub flash: rp_flash.Flash
// Sleep modes, clock gating, the dormant state, power-down, and the
// system clock's rate; see Power.
pub power: Power
}
take
Function · Source
Configure clocks, take GPIO, the timer, DMA, and the TRNG out of reset, and return the peripherals. A second call returns Error.Busy, so no two owners exist; an unusable crystal frequency returns Error.InvalidInput, and a crystal, PLL, or TRNG that does not start returns Error.Timeout.
pub fn take(config: Config) -> Peripherals!hal.Error
Pins
Struct · Source
The user GPIOs, 0 to pin_count() - 1 (29 on the RP2350A, 47 on the RP2350B), and the I2C, SPI, and UART controllers that use them. Each pin and each controller can be taken once, and given back. GPIO 30 to 47 carry the same functions in the same pattern as GPIO 0 to 29 (9.4), so the pin rules below continue up to GPIO 47 on the RP2350B.
pub struct Pins {
// Private implementation fields omitted.
}
Pins.pin_count
Function · Source
The GPIOs this chip’s package has: PIN_COUNT on the RP2350A, MAX_PIN_COUNT on the RP2350B. Claims of higher pins are InvalidInput.
pub fn pin_count(&self) -> u32
Pins.output
Function · Source
Claim pin
numberas a push-pull output, initially low.
pub fn output(&mut self, number: u32) -> Pin!hal.Error
Pins.input
Function · Source
Claim pin
numberas an input.
pub fn input(&mut self, number: u32) -> Pin!hal.Error
Pins.release
Function · Source
Give back a pin from
outputorinput. 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
sdaandsclas an I2C bus with an SCL frequency offrequency_hz, at most hal.I2C_FAST_PLUS_HZ. Even pins carry SDA and odd pins SCL. GPIO 0 and 1, 4 and 5, and so on in steps of four belong to I2C0; GPIO 2 and 3, 6 and 7, and so on to I2C1. InvalidInput if the two pins cannot form a bus or the frequency is out of range, Busy if a pin or the controller is taken. The pads’ own pull-ups (about 50 kOhm) 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 designware_i2c driver documents the bus’s errors.
pub fn i2c(&mut self, sda: u32, scl: u32, frequency_hz: u32) -> designware_i2c.Bus!hal.Error
Pins.spi
Function · Source
Claim pins as an SPI bus in
mode, clocked at the fastest rate up tofrequency_hz(at most SYS_HZ / 2, 75 MHz):clock(SCK),tx(data out to the devices, MOSI), andrx(data in from them, MISO), or none when they only listen. GPIO n carries RX when n % 4 is 0, the clock when it is 2, and TX when it is 3. GPIO 0 to 7, 16 to 23, and 32 to 39 belong to SPI0, GPIO 8 to 15, 24 to 31, and 40 to 47 to SPI1. Give each device an output pin as its chip select, through hal.SpiDevice. Errors as fori2c.
pub fn spi(&mut self, clock: u32, tx: u32, rx: Option<u32>, mode: hal.SpiMode, frequency_hz: u32) -> pl022.Bus!hal.Error
Pins.uart
Function · Source
Claim pin
txas a serial port’s transmit line (to the other end’s RX), andrxas its receive line, or none to only send. Frames are 8N1 at the rate closest tobaud, from 144 baud up to SYS_HZ / 16 (9.4 Mbaud); 115_200 is the usual choice for a terminal. GPIO n carries TX when n % 4 is 0 or 2 and RX when it is 1 or 3 (the second of each through the RP2350’s UART_AUX function, on the pins that otherwise carry CTS and RTS): UART0 has TX on 0, 2, 12, 14, 16, 18, and 28 and RX on 1, 3, 13, 15, 17, 19, and 29, UART1 TX on 4, 6, 8, 10, 20, 22, 24, and 26 and RX on 5, 7, 9, 11, 21, 23, 25, and 27; on the RP2350B also UART0 TX on 30, 32, 34, 44, 46 and RX on 31, 33, 35, 45, 47, UART1 TX on 36, 38, 40, 42 and RX on 37, 39, 41, 43. The port implements the std/io Reader and Writer protocols, so std/fmt prints to it; until it is released, a panic writes its failure message to it before the chip halts. InvalidInput if the pins cannot form a port or the baud rate is out of range, Busy if a pin or the controller is taken. The pl011 driver documents the port.
pub fn uart(&mut self, tx: u32, rx: Option<u32>, baud: u32) -> pl011.Port!hal.Error
Pins.uart_flow
Function · Source
uartwith hardware flow control, turned on:ctsis an input, low while the other end may receive, andrtsan output, low while this port may. GPIO n carries CTS when n % 4 is 2 and RTS when it is 3, in the TX and RX pins’ group of four: UART0 has CTS on 2, 14, 18 (and 30, 34, 46) and RTS on 3, 15, 19 (31, 35, 47), UART1 CTS on 6, 10, 22, 26 (38, 42) and RTS on 7, 11, 23, 27 (39, 43). Errors as foruart.
pub fn uart_flow(&mut self, tx: u32, rx: u32, cts: u32, rts: u32, baud: u32) -> pl011.Port!hal.Error
Pins.spi_with_select
Function · Source
spiwith the controller’s own chip select on pinselectas well, for devices in the TI and Microwire frame formats (see pl022.FrameFormat), which need its timing. GPIO n carries it when n % 4 is 1, in the bus’s block of eight: SPI0 on 1, 5, 17, 21 (33, 37), SPI1 on 9, 13, 25, 29 (41, 45). Errors as forspi.
pub fn spi_with_select(&mut self, clock: u32, tx: u32, rx: Option<u32>, select: u32, mode: hal.SpiMode, frequency_hz: u32) -> pl022.Bus!hal.Error
Pins.spi_target
Function · Source
Claim pins as an SPI target (slave) in
mode, for another master to clock, at up to SYS_HZ / 12 (12.5 MHz), and select:rxreceives what it sends,txanswers, and the pins are numbered as forspiandspi_with_select. The pl022 driver documents the target.
pub fn spi_target(&mut self, clock: u32, tx: u32, rx: Option<u32>, select: u32, mode: hal.SpiMode) -> pl022.TargetBus!hal.Error
Pins.i2c_target
Function · Source
Claim pins
sdaandscl, numbered as fori2c, as an I2C target (slave) answering another master ataddress, a 10-bit address withten_bit.frequency_hzis the master’s SCL frequency, which sets the input filter. InvalidInput for an address the I2C specification reserves (7-bit 0x00 to 0x07 and 0x78 to 0x7F), otherwise errors as fori2c. The designware_i2c driver documents the target.
pub fn i2c_target(&mut self, sda: u32, scl: u32, address: u16, ten_bit: bool, frequency_hz: u32) -> designware_i2c.TargetBus!hal.Error
Pins.pwm
Function · Source
Claim pin
pinas a PWM output at the frequency closest tofrequency_hz, from 9 Hz up to SYS_HZ / 2, low until a duty is set. GPIO n is output A (n even) or B (n odd) of PWM slice (n / 2) % 8: GPIO n and n + 16 carry the same output, and the two outputs of a slice share its frequency. On the RP2350B GPIO 32 to 47 are outputs of slices 8 to 11, 8 + ((n - 32) / 2) % 4, so GPIO n and n + 8 share one. The output implements hal.PwmOutput, with max_duty() steps up to 65535; rp_pwm documents it. InvalidInput for a GPIO the chip lacks or a frequency out of range, Busy if the pin or its output is taken, or if the slice’s other output runs at another frequency.
pub fn pwm(&mut self, pin: u32, frequency_hz: u32) -> rp_pwm.Pwm!hal.Error
Pins.pwm_divided
Function · Source
pwmwith the slice’s divider of clk_sys, in sixteenths from 16 (1) to 4095 (255 15/16), and its TOP, up to 65534, given instead: the output’s frequency is SYS_HZ * 16 / divider / (top + 1), and its duty runs from 0 to top + 1. Errors as forpwm.
pub fn pwm_divided(&mut self, pin: u32, divider: u32, top: u32) -> rp_pwm.Pwm!hal.Error
Pins.pwm_input
Function · Source
Claim pin
pin, an odd GPIO, as a PWM input that measures the frequency and duty cycle of the signal on it: GPIO n is input B of its PWM slice (as forpwm), whose counter counts its rising edges and its high time in windows ofwindow_us, up to 111 ms, two per measurement. Its pull-down holds an unconnected pin low. The input implements hal.PwmInput; rp_pwm.Capture documents the measurement and its precision. InvalidInput for an even pin, a GPIO the chip lacks, or a window of 0 or too long, Busy if the pin is taken or either output of its slice is in use.
pub fn pwm_input(&mut self, pin: u32, window_us: u32) -> rp_pwm.PwmCapture!hal.Error
Pins.analog
Function · Source
Claim pin
pin, GPIO 26 to 29 (ADC inputs 0 to 3), as an analog input, with its digital input and pulls turned off. It implements hal.AnalogInput: 12-bit polled reads, 0 to 4095 for 0 V to the ADC’s reference, ADC_AVDD; rp_adc documents it. InvalidInput for another pin, Busy if the pin is taken, Timeout if the ADC does not start.
pub fn analog(&mut self, pin: u32) -> rp_adc.Analog!hal.Error
Pins.temperature
Function · Source
Claim the on-chip temperature sensor, ADC input 4, an analog input like those of
analog: rp_adc.millicelsius(value, 3300) converts a reading. Busy if it is claimed already.
pub fn temperature(&mut self) -> rp_adc.Analog!hal.Error
Pins.sampler
Function · Source
Claim the ADC as a sampler that converts
inputs, a set such as rp_adc.GPIO26 | rp_adc.TEMPERATURE, one after the other atrate_hzconversions a second in all (733 to 500 000), into its FIFO, for polled, interrupt-driven, or DMA reads; rp_adc.Sampler documents it. Its pins are claimed as analog inputs. InvalidInput for an empty set or a rate out of range, Busy if a pin is taken or an analog input or the temperature sensor is claimed, as they share the converter; Timeout if the ADC does not start.
pub fn sampler(&mut self, inputs: rp_adc.Inputs, rate_hz: u32) -> rp_adc.AdcSampler!hal.Error
Pins.pio
Function · Source
Claim PIO block
number, 0 to 2, with its four state machines stopped, for programs from rp_pio.assemble; rp_pio documents it. Its state machines run at up to SYS_HZ instructions a second and drive the pins given to it withpio_pins. InvalidInput for another number, Busy if the block is claimed.
pub fn pio(&mut self, number: u32) -> rp_pio.Pio!hal.Error
Pins.pio_pins
Function · Source
Connect the
countpins from GPIOfirstto PIO blockpio, for its state machines to drive through their pin mappings and read. They also read pins claimed in other ways: claim a pin they only read as an input, for example, to share it. A block reaches GPIO 0 to 31, or 16 to 47 oncepio.set_gpio_base(16)moves its window, which pins above GPIO 31 on the RP2350B need. InvalidInput for a GPIO the chip lacks, pins outside the block’s window, or a count of 0, Busy if a pin is taken.
pub fn pio_pins(&mut self, pio: &rp_pio.Pio, first: u32, count: u32) -> void!hal.Error
Pins.edge_capture
Function · Source
Claim pin
pinfor PIO blockpioand capture its edges (rp_capture.RISING, FALLING, or BOTH) with one of the block’s state machines: a hal.InputCapture whose edge times the state machine latches, in ticks oftick_hz, up to SYS_HZ / 4. rp_capture documents it. Errors as for pio_pins, and InvalidInput for a rate rp_capture.divider refuses; Busy without a free state machine or 14 free instruction slots.
pub fn edge_capture(&mut self, pio: &mut rp_pio.Pio, pin: u32, edges: u32, tick_hz: u32) -> rp_capture.EdgeCapture!hal.Error
Pins.release_edge_capture
Function · Source
Give back a capture from
edge_captureto the block it came from.
pub fn release_edge_capture(&mut self, capture: rp_capture.EdgeCapture, pio: &mut rp_pio.Pio)
Pins.release_pio
Function · Source
Give back a PIO block, once its state machines have been given back to it with
pio.release_state_machine: its pins are disconnected and the block is held in reset, which forgets its programs.
pub fn release_pio(&mut self, pio: rp_pio.Pio)
Pins.release_pwm
Function · Source
Give back a PWM output. Its pin stops driving and is disconnected.
pub fn release_pwm(&mut self, output: rp_pwm.Pwm)
Pins.pwm_timer
Function · Source
Claim PWM slice
slice, 0 to 11, as a periodic timer and counter counting attick_hz: clk_sys divided by a whole number of sixteenths from 1 to 255 15/16, such as 150 MHz, 10 MHz, 1 MHz, or 600 kHz. It is a hal.PeriodicTimer whose periods, up to 65536 ticks, end when the slice’s counter wraps, raising PWM_IRQ_WRAP_0 while it listens, and a hal.TickCounter; rp_pwm.SliceTimer documents it. It drives no pins but takes both outputs of its slice; slices 8 to 11 serve no pins here, so they cost none. InvalidInput for another slice or rate, Busy if the slice is in use.
pub fn pwm_timer(&mut self, slice: u32, tick_hz: u32) -> rp_pwm.PwmTimer!hal.Error
Pins.release_pwm_timer
Function · Source
Give back a timer from
pwm_timer.
pub fn release_pwm_timer(&mut self, timer: rp_pwm.PwmTimer)
Pins.release_pwm_input
Function · Source
Give back a PWM input. Its slice stops and its pin is disconnected.
pub fn release_pwm_input(&mut self, input: rp_pwm.PwmCapture)
Pins.release_analog
Function · Source
Give back an analog input or the temperature sensor; the ADC and its clock stop once no input is left.
pub fn release_analog(&mut self, input: rp_adc.Analog)
Pins.release_sampler
Function · Source
Give back the ADC’s sampler: it stops, its pins are disconnected, and the ADC and its clock stop.
pub fn release_sampler(&mut self, sampler: rp_adc.AdcSampler)
Pins.release_i2c
Function · Source
Give back an I2C bus. Its controller is held in reset and its pins are disconnected but still pulled up, so the bus stays idle. A device that holds SDA low after an interrupted transfer, which makes the bus Timeout, can then be freed by claiming SCL as an output and clocking it by hand before claiming the bus again.
pub fn release_i2c(&mut self, bus: designware_i2c.Bus)
Pins.release_spi
Function · Source
Give back an SPI bus: its controller is held in reset and its pins are disconnected.
pub fn release_spi(&mut self, bus: pl022.Bus)
Pins.release_uart
Function · Source
Give back a serial port, once everything written to it is out: its controller is held in reset and its pins are disconnected but still pulled up, so the line stays idle.
pub fn release_uart(&mut self, port: pl011.Port)
Pins.release_i2c_target
Function · Source
Give back an I2C target, as for
release_i2c.
pub fn release_i2c_target(&mut self, target: designware_i2c.TargetBus)
Pins.release_spi_target
Function · Source
Give back an SPI target, as for
release_spi.
pub fn release_spi_target(&mut self, target: pl022.TargetBus)
Usb
Struct · Source
The USB controller, as a USB serial port for the host the board is plugged into. rp_usb documents the port.
pub struct Usb {
// Private implementation fields omitted.
}
Usb.serial
Function · Source
Start the controller as a USB serial port (CDC-ACM) named “RP2350”, with rp_usb’s default identity, and return it. The host enumerates it within about a second; what is written before a terminal opens it is kept, up to rp_usb.TX_CAPACITY bytes. The port is served from the USBCTRL_IRQ interrupt, so it keeps working while the program busy-waits; a program’s own USBCTRL_IRQ handler replaces that. Until it is released, a panic is reported on it, and a host that sets 1200 baud, as
dodo rundoes, restarts the board into its bootloader. Busy if a port is open or clk_sys runs at 48 MHz or less (Power.set_system_hz), Timeout if PLL_USB or the controller does not start.
pub fn serial(&mut self) -> rp_usb.Serial!hal.Error
Usb.serial_with
Function · Source
serial, with theidentitythe host sees, and the pin the USB bootloader lights while its drive is accessed after the host restarts the board into it, or a pin the chip lacks, such as MAX_PIN_COUNT, for none. Board packages pass the default identity with the board’s name, and the board’s LED.
pub fn serial_with(&mut self, identity: rp_usb.Identity, activity_led: u32) -> rp_usb.Serial!hal.Error
Usb.release_serial
Function · Source
Give back the port: the board disconnects from the host, output not yet sent is dropped, and the controller and its clock stop.
pub fn release_serial(&mut self, serial: rp_usb.Serial)
Pin
Struct · Source
One GPIO driven by the single-cycle I/O block. 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
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.listen
Function · Source
Raise IO_IRQ_BANK0 on the calling core on
events, any of LEVEL_LOW, LEVEL_HIGH, FALLING_EDGE, and RISING_EDGE, after forgetting edges seen so far. Enable the interrupt in that core’s NVIC too:cortex_m.enable(pin.irq()). Every pin shares the one interrupt; its handler tells them apart withevents. Each core has its own enables, and both cores share the vector table, so the one@interrupt(IO_IRQ_BANK0)handler runs on whichever core listens: calllistenandcortex_m.enablefrom code running on core 1 to handle a pin there.
pub fn listen(&mut self, events: u32)
Pin.ignore
Function · Source
Stop raising the calling core’s interrupt on
events.
pub fn ignore(&mut self, events: u32)
Pin.events
Function · Source
The events the calling core listens to that are raising its interrupt now.
pub fn events(&self) -> u32
Pin.listen_on
Function · Source
listenfor corecore, 0 or 1, from either core. Another number traps.
pub fn listen_on(&mut self, core: u32, events: u32)
Pin.ignore_on
Function · Source
ignorefor corecore, 0 or 1.
pub fn ignore_on(&mut self, core: u32, events: u32)
Pin.events_on
Function · Source
eventsfor corecore, 0 or 1.
pub fn events_on(&self, core: u32) -> u32
Pin.clear_events
Function · Source
Forget the edges among
events, acknowledging them; a handler or task must, or the interrupt stays raised. Levels cannot be cleared.
pub fn clear_events(&mut self, events: u32)
Pin.irq
Function · Source
The interrupt pin events raise, IO_IRQ_BANK0, for cortex_m.enable.
pub fn irq(&self) -> u32
Rtc
Struct · Source
The always-on timer of the power manager as a real-time clock: a millisecond counter with an alarm. Implements the std/embedded/hal Rtc and RtcAlarm protocols, so
hal.rtc_now(&mut b.rtc)reads it as a date and time. It sits in the always-on power domain: once set, it keeps counting through the resets that leave that domain running, such as the watchdog’s and the restart afterPower.power_down, so a later take() finds it still set; it stops when the chip loses power. It ticks from the crystal, the most precise source, until told otherwise; the low-power oscillator, an external 32 kHz clock, or an external 1 kHz tick keep it counting while the crystal is stopped too, and Power moves a crystal tick to the low-power oscillator by itself for a timed dormant state or a power-down (12.10.5). The alarm raises POWMAN_IRQ_TIMER whilelistening, and its handler callsclear_alarm.
pub struct Rtc: hal.Rtc + hal.RtcAlarm {
// Private implementation fields omitted.
}
Rtc.tick_source
Function · Source
Where the tick comes from: rp_rtc.TICK_CRYSTAL, TICK_LPOSC, TICK_CLOCK_INPUT, or TICK_INPUT.
pub fn tick_source(&mut self) -> u32
Rtc.use_crystal
Function · Source
Tick from the crystal, as take() sets up. Busy while a GPIO time reference is in use:
release_clock_inputreturns to the crystal.
pub fn use_crystal(&mut self) -> void!hal.Error
Rtc.use_low_power_oscillator
Function · Source
Tick from the low-power oscillator, at the frequency this chip’s OTP records from manufacturing, or else at its nominal 32.768 kHz. It keeps counting while the chip is dormant or powered down, less precisely than the crystal: the oscillator drifts by several percent with temperature and voltage. Busy while a GPIO time reference is in use.
pub fn use_low_power_oscillator(&mut self) -> void!hal.Error
Rtc.use_low_power_oscillator_at
Function · Source
use_low_power_oscillator, with a frequency ofhzmeasured by the program. InvalidInput outside rp_rtc.LPOSC_MIN_HZ to LPOSC_MAX_HZ.
pub fn use_low_power_oscillator_at(&mut self, hz: u32) -> void!hal.Error
Rtc.use_clock_input
Function · Source
Tick from an external clock of
clock_hzon GPIOpin, 12, 14, 20, or 22, typically a 32.768 kHz oscillator: it replaces the low-power oscillator, so it also clocks the power manager while the switched core is off, and keeps the time precise in every power state. The pin is claimed as an input untilrelease_clock_input. InvalidInput for another pin or a clock outside rp_rtc.LPOSC_MIN_HZ to LPOSC_MAX_HZ, Busy if the pin is taken or a reference is in use.
pub fn use_clock_input(&mut self, pins: &mut Pins, pin: u32, clock_hz: u32) -> void!hal.Error
Rtc.use_tick_input
Function · Source
Tick from an external 1 kHz tick on GPIO
pin, 12, 14, 20, or 22, counted on its falling edges, which keeps counting in every power state. The pin is claimed as an input untilrelease_clock_input; the switch may advance the time by up to a millisecond. InvalidInput for another pin, Busy if the pin is taken or a reference is in use.
pub fn use_tick_input(&mut self, pins: &mut Pins, pin: u32) -> void!hal.Error
Rtc.release_clock_input
Function · Source
Tick from the crystal again and give back the pin of
use_clock_inputoruse_tick_input, or of a reference that take() found still in use after a reset and claimed again; nothing happens without one.
pub fn release_clock_input(&mut self, pins: &mut Pins) -> void!hal.Error
Rtc.is_set
Function · Source
pub fn is_set(&mut self) -> bool!hal.Error
Rtc.now_ms
Function · Source
pub fn now_ms(&mut self) -> u64!hal.Error
Rtc.set_ms
Function · Source
pub fn set_ms(&mut self, time_ms: u64) -> void!hal.Error
Rtc.resolution_ms
Function · Source
1: the timer counts milliseconds.
pub fn resolution_ms(&self) -> u32
Rtc.set_alarm_ms
Function · Source
pub fn set_alarm_ms(&mut self, time_ms: u64) -> void!hal.Error
Rtc.alarm_fired
Function · Source
pub fn alarm_fired(&mut self) -> bool!hal.Error
Rtc.clear_alarm
Function · Source
pub fn clear_alarm(&mut self) -> void!hal.Error
Rtc.irq
Function · Source
The alarm’s interrupt: its number for cortex_m.enable, and its vector name, POWMAN_IRQ_TIMER, for
@interrupt.
pub fn irq(&self) -> u32
Rtc.listen
Function · Source
Raise POWMAN_IRQ_TIMER when the alarm fires. Enable it in the NVIC too:
cortex_m.enable(rtc.irq()).
pub fn listen(&mut self)
Rtc.ignore
Function · Source
Stop raising the interrupt; alarm_fired still reports.
pub fn ignore(&mut self)
Rtc.is_listening
Function · Source
pub fn is_listening(&mut self) -> bool
Timer
Struct · Source
The free-running 64-bit microsecond counter of TIMER0. Implements the std/embedded/hal delay and counter protocols.
pub struct Timer {
// Private implementation fields omitted.
}
Timer.alarm
Function · Source
Claim alarm 0 to 3, to run code at a set time from its interrupt. 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.timer1
Function · Source
Start TIMER1, the chip’s second timer, counting from 0 at
tick_hz: clk_sys’s rate,Power.system_hz()(SYS_HZ, 150 MHz, unlessset_system_hzchanged it), to count clk_sys cycles, or the crystal divided by a whole number from 1 to 511, such as 12 MHz, 1 MHz, or 100 kHz with a 12 MHz crystal, from TIMER1’s own tick generator. While it counts clk_sys,set_system_hzis Busy. InvalidInput for another rate, Busy while it is out.
pub fn timer1(&mut self, tick_hz: u32) -> Timer1!hal.Error
Timer.release_timer1
Function · Source
Give TIMER1 back: it stops, held in reset, and its tick generator stops. Every alarm claimed from it must have been given back.
pub fn release_timer1(&mut self, timer1: Timer1)
Timer.now_us
Function · Source
Microseconds since take().
pub fn now_us(&self) -> u64
Timer.tick_hz
Function · Source
The counter as a hal.TickCounter: ticks of 1 MHz, as now_us.
pub fn tick_hz(&self) -> u32
Timer.now_ticks
Function · Source
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 timer’s four alarms, claimed with
Timer.alarm(n). An alarm fires once when the microsecond counter reaches the time it was given; withlistenit raises interrupt TIMER0_IRQ_0 + n, whose handler callsclearand may schedule the next time. Move it into astatic mut Option<Alarm>for the handler to use. Implements the std/embedded/hal alarm and counter protocols, with times up to 2^31 - 1 us (35 minutes) ahead, and, counting microseconds as ticks of 1 MHz, the compare channel and periodic timer protocols:start(period)fires it every period, without drift, and the interrupt handler callspoll_periodsinstead ofclear. rp_timer.Alarm documents the modes.
pub struct Alarm: hal.Alarm + hal.Compare + hal.PeriodicTimer {
// Private implementation fields omitted.
}
Alarm.number
Function · Source
0 to 3.
pub fn number(&self) -> u32
Alarm.irq
Function · Source
The interrupt the alarm raises: its number for cortex_m.enable, and its vector name, TIMER0_IRQ_0 + n, for
@interrupt.
pub fn irq(&self) -> u32
Alarm.now
Function · Source
The low 32 bits of the microsecond counter, which alarm times use.
pub fn now(&self) -> u32
Alarm.schedule_at
Function · Source
Fire when the counter’s low 32 bits equal
time, replacing any earlier time and periodic mode. A time that has just passed fires only after the counter wraps, 71.6 minutes later.
pub fn schedule_at(&mut self, time: u32)
Alarm.schedule_in
Function · Source
Fire
microsecondsfrom now; at least 1, and below 2^31 so the time is still ahead when the write lands.
pub fn schedule_in(&mut self, microseconds: u32)
Alarm.schedule_at_us
Function · Source
Fire when now_us() reaches
time_us, replacing any earlier time and periodic mode, and clearing an earlier firing; the std/embedded/hal alarm protocol. A time already reached fires at once, raising the interrupt if the alarm listens. InvalidInput for a time more than 2^31 - 1 us ahead.
pub fn schedule_at_us(&mut self, time_us: u64) -> void!hal.Error
Alarm.cancel
Function · Source
Disarm, and end periodic mode: 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. Enable the interrupt in the NVIC too:
cortex_m.enable(alarm.irq()).
pub fn listen(&mut self)
Alarm.ignore
Function · Source
Stop raising the interrupt;
firedstill reports.
pub fn ignore(&mut self)
Alarm.is_listening
Function · Source
pub fn is_listening(&self) -> bool
Alarm.now_us
Function · Source
Microseconds since take(), from the whole 64-bit counter, as Timer.now_us reads it.
pub fn now_us(&self) -> u64
Alarm.tick_hz
Function · Source
The compare channel and periodic timer protocols count ticks of 1 MHz: microseconds.
pub fn tick_hz(&self) -> u32
Alarm.now_ticks
Function · Source
pub fn now_ticks(&self) -> u64
Alarm.schedule_at_ticks
Function · Source
As schedule_at_us; hal.Compare.
pub fn schedule_at_ticks(&mut self, ticks: u64) -> void!hal.Error
Alarm.start
Function · Source
Fire every
period_usmicroseconds, the first time one period from now, each a whole number of periods after the start; hal.PeriodicTimer. InvalidInput for 0 or more than 2^31 - 1 us (35 minutes).
pub fn start(&mut self, period_us: u64) -> void!hal.Error
Alarm.poll_periods
Function · Source
How many periods ended since
startor the last call, 0 while none has. Clears the firing and arms the alarm for the next period, so the interrupt handler calls it instead ofclear.
pub fn poll_periods(&mut self) -> u32
Alarm.is_periodic
Function · Source
Whether
startruns it, untilcancelor a schedule.
pub fn is_periodic(&self) -> bool
Alarm.period_us
Function · Source
The period
startset, in microseconds.
pub fn period_us(&self) -> u64
Alarm.sleep_until
Function · Source
Sleep (
wfi) until an interrupt is pending or the counter reachesdeadline, 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@interrupthandler; other interrupts’ handlers run after the return, or once the caller’s own critical section ends. Times more than 35 minutes ahead wake early. Leaves the alarm disarmed and not listening.
pub fn sleep_until(&mut self, deadline: Option<u64>)
Timer1
Struct · Source
TIMER1, the chip’s second timer, from
Timer.timer1: a 64-bit counter at the rate it was started at, with four alarms of its own, whichalarmhands out. At 150 MHz it counts for 3900 years before wrapping, so it times short events to a clk_sys cycle (6.7 ns); at a divided crystal rate it reaches further with each alarm. Implements the std/embedded/hal tick counter protocol and, through now_us, the counter protocol.
pub struct Timer1: hal.TickCounter + hal.Counter {
// Private implementation fields omitted.
}
Timer1.tick_hz
Function · Source
pub fn tick_hz(&self) -> u32
Timer1.now_ticks
Function · Source
Ticks since
Timer.timer1started it.
pub fn now_ticks(&self) -> u64
Timer1.now_us
Function · Source
Microseconds since
Timer.timer1started it, rounded down.
pub fn now_us(&self) -> u64
Timer1.alarm
Function · Source
Claim alarm 0 to 3 of TIMER1, raising TIMER1_IRQ_0 + n. Busy if it is claimed already; InvalidInput for another number.
pub fn alarm(&mut self, number: u32) -> Timer1Alarm!hal.Error
Timer1.release_alarm
Function · Source
Disarm an alarm, stop its interrupt, and take it back.
pub fn release_alarm(&mut self, alarm: Timer1Alarm)
Timer1Alarm
Struct · Source
One of TIMER1’s four alarms, claimed with
Timer1.alarm(n), counting TIMER1’s ticks: a compare channel that fires once at a tick count, and a periodic timer whose periods are whole ticks and do not drift (see rp_timer.Alarm). Withlistenit raises interrupt TIMER1_IRQ_0 + n, whose handler callsclear, orpoll_periodsin periodic mode. Targets reach up to 2^31 - 1 ticks ahead: 14.3 s at 150 MHz, 2147 s at 1 MHz. Implements the std/embedded/hal compare channel and periodic timer protocols, and through microsecond conversions the alarm and counter protocols too.
pub struct Timer1Alarm: hal.Compare + hal.PeriodicTimer + hal.Alarm {
// Private implementation fields omitted.
}
Timer1Alarm.number
Function · Source
0 to 3.
pub fn number(&self) -> u32
Timer1Alarm.irq
Function · Source
The interrupt the alarm raises: its number for cortex_m.enable, and its vector name, TIMER1_IRQ_0 + n, for
@interrupt.
pub fn irq(&self) -> u32
Timer1Alarm.tick_hz
Function · Source
pub fn tick_hz(&self) -> u32
Timer1Alarm.now
Function · Source
The low 32 bits of TIMER1’s count, which raw targets use.
pub fn now(&self) -> u32
Timer1Alarm.schedule_at
Function · Source
Fire when TIMER1’s low 32 bits equal
time, as Alarm.schedule_at.
pub fn schedule_at(&mut self, time: u32)
Timer1Alarm.schedule_in
Function · Source
Fire
ticksfrom now; at least 1 and below 2^31.
pub fn schedule_in(&mut self, ticks: u32)
Timer1Alarm.now_ticks
Function · Source
pub fn now_ticks(&self) -> u64
Timer1Alarm.schedule_at_ticks
Function · Source
Fire when now_ticks() reaches
ticks, as rp_timer.Alarm does; InvalidInput more than 2^31 - 1 ticks ahead.
pub fn schedule_at_ticks(&mut self, ticks: u64) -> void!hal.Error
Timer1Alarm.cancel
Function · Source
pub fn cancel(&mut self)
Timer1Alarm.is_armed
Function · Source
pub fn is_armed(&self) -> bool
Timer1Alarm.fired
Function · Source
pub fn fired(&self) -> bool
Timer1Alarm.clear
Function · Source
pub fn clear(&mut self)
Timer1Alarm.listen
Function · Source
Raise the interrupt when it fires. Enable the interrupt in the NVIC too:
cortex_m.enable(alarm.irq()).
pub fn listen(&mut self)
Timer1Alarm.ignore
Function · Source
pub fn ignore(&mut self)
Timer1Alarm.is_listening
Function · Source
pub fn is_listening(&self) -> bool
Timer1Alarm.start
Function · Source
Fire every
period_ticksticks without drift; InvalidInput for 0 or more than 2^31 - 1.
pub fn start(&mut self, period_ticks: u64) -> void!hal.Error
Timer1Alarm.poll_periods
Function · Source
pub fn poll_periods(&mut self) -> u32
Timer1Alarm.is_periodic
Function · Source
pub fn is_periodic(&self) -> bool
Timer1Alarm.period_ticks
Function · Source
pub fn period_ticks(&self) -> u64
Timer1Alarm.now_us
Function · Source
Microseconds since TIMER1 started, rounded down.
pub fn now_us(&self) -> u64
Timer1Alarm.schedule_at_us
Function · Source
Fire once now_us() reaches
time_us: at the first tick at or after it. InvalidInput for a time more than 2^31 - 1 ticks ahead.
pub fn schedule_at_us(&mut self, time_us: u64) -> void!hal.Error
Power
Struct · Source
Low power, as
Peripherals.power; implements std/embedded/power’s protocol, whose package comment describes the modes.On the RP2350, a deep sleep stops the clocks outside the sleep set only while both cores deep-sleep; a core 1 that was never started does. Every clock starts in the sleep set, so a deep sleep stops nothing more than a light one until
set_sleep_clockssays otherwise. The clock constants above name the gates. Claiming a peripheral starts its clocks, sodisable_unused_clocksis safe at any time. It also stops HSTX, TIMER1, and SHA-256, which this package does not drive, while they are held in reset; the timer (CLOCK_TIMER), DMA (CLOCK_DMA), and the TRNG (CLOCK_TRNG), which take() starts forPeripherals.rng, are not claimed through Pins, so it leaves them to the program.
dormantruns clk_sys from the crystal, stops PLL_SYS and the ring oscillator, and stops the crystal until a pin event, then starts them again. Both cores stop. The microsecond timer pauses meanwhile, sonow_usdoes not count the time spent dormant. It returns Busy while the USB serial port or an ADC input runs, since their 48 MHz clock would stop. Wait until serial ports have sent their last bytes first, as clk_peri slows down to the crystal’s rate during the switch.A timeout in the power.Wake uses the always-on timer’s alarm (6.5.3), which needs the timer set (Busy otherwise) and a tick that runs while the crystal is stopped: a tick from the crystal moves to the low-power oscillator meanwhile, and clk_ref runs from that oscillator, so the power manager stays clocked. The chip wakes up to a millisecond after the timeout, counted at the oscillator’s precision. An alarm set through the Rtc is put back afterwards.
power_downgoes further: it switches off the switched-core power domain, with the processors and every peripheral, and the SRAM it is not told to keep, until a pin event or a timeout powers the chip up again (6.2). The chip then restarts through reset; after take(),woke_from_power_downandpower_down_wakesay why, the SRAM domains kept still hold their contents,.noinitstatics included, and thescratchregisters keep a few words in any case.
set_system_hzruns clk_sys, and with it clk_peri, slower to save power: from the crystal divided by a whole number, with PLL_SYS stopped, or from PLL_SYS at a lower rate. The timers, the watchdog, and the always-on timer keep their rates, as they count clk_ref or their own ticks, and the ADC and USB keep their 48 MHz clock; flash reads slow down with clk_sys.
pub struct Power: power.Power {
// Private implementation fields omitted.
}
Power.system_hz
Function · Source
clk_sys in hertz now: SYS_HZ until
set_system_hz.
pub fn system_hz(&self) -> u32
Power.crystal_hz
Function · Source
The crystal’s frequency, the fastest rate
set_system_hzreaches with PLL_SYS stopped.
pub fn crystal_hz(&self) -> u32
Power.set_system_hz
Function · Source
Run clk_sys at exactly
hz: the crystal divided by a whole number up to 256, with PLL_SYS stopped, which saves the most, or else PLL_SYS at a rate it reaches exactly, or SYS_HZ, take()’s rate, again. Peripherals claimed later compute their dividers from the new rate, and a SysTick reload the program set counts it too. InvalidInput for 0, above SYS_HZ, or a rate neither reaches, Busy while a UART, SPI, I2C, PWM, PIO, or HSTX block runs or TIMER1 counts clk_sys (release them and claim them again afterwards) or while the USB serial port runs andhzis 48 MHz or less, Timeout if PLL_SYS does not lock, leaving clk_sys at the crystal’s rate.
pub fn set_system_hz(&mut self, hz: u32) -> void!hal.Error
Power.woke_from_power_down
Function · Source
Whether this start is the restart after
power_down.
pub fn woke_from_power_down(&self) -> bool
Power.power_down_wake
Function · Source
What powered the chip up after
power_down, as adormantresult: the pins whose events did, bit n for pin n, and power.BY_TIME for the timeout. 0 after any other reset.
pub fn power_down_wake(&self) -> u64
Power.retained
Function · Source
The SRAM domains that stayed powered during the
power_downbefore this start, RETAIN_SRAM0 and RETAIN_SRAM1, whose contents survived; RETAIN_NOTHING after any other reset.
pub fn retained(&self) -> u32
Power.scratch
Function · Source
Scratch register
index, below SCRATCH_WORDS: 0 after power-up, and whatset_scratchleft there through power-down and every reset since. Traps for another index.
pub fn scratch(&self, index: u32) -> u32
Power.set_scratch
Function · Source
pub fn set_scratch(&mut self, index: u32, value: u32)
Power.power_down
Function · Source
Switch off the switched core and the XIP cache, and every SRAM domain not in
retain(RETAIN_SRAM0, RETAIN_SRAM1, or RETAIN_NOTHING), until one ofwake’s pin events or its timeout powers the chip up; it then restarts through reset into the program, andwoke_from_power_downsays so. Up to four pin events (one per pin and event kind) can wake it, each a level or an edge; claim their pins as inputs first, with the pulls they need: the pads keep their state while the core is off. A timeout uses the always-on timer’s alarm, replacing one set through the Rtc, and moves a crystal tick to the low-power oscillator; take() moves it back. Both cores must wait for this: a core 1 that runs a task must be stopped first. Returns only on failure: InvalidInput for an emptywake, a pin from pin_count() up, more than four events, or anotherretain; Busy if the always-on timer has no time for a timeout or a power-up request cancels the power-down, Timeout if the power manager does not take the request.
pub fn power_down(&mut self, wake: &power.Wake, retain: u32) -> void!hal.Error
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
pub fn dormant(&mut self, wake: &power.Wake) -> u64!hal.Error