API referencestd/embedded

std/embedded/chip/rp_pins

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

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/rp_pins"

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
designware_i2c std/embedded/peripheral/designware_i2c rp_pins.dodo
hal std/embedded/hal rp_pins.dodo
pl011 std/embedded/peripheral/pl011 rp_pins.dodo
pl022 std/embedded/peripheral/pl022 rp_pins.dodo
ptr core/ptr rp_pins.dodo
rp_adc std/embedded/chip/rp_adc rp_pins.dodo
rp_capture std/embedded/chip/rp_capture rp_pins.dodo
rp_dma std/embedded/chip/rp_dma rp_pins.dodo
rp_pio std/embedded/chip/rp_pio rp_pins.dodo
rp_pwm std/embedded/chip/rp_pwm rp_pins.dodo

PIN_COUNT

Constant · Source

The GPIOs every chip has: GPIO 0 to 29, all of the RP2040 and the RP2350A (QFN-60).

pub const PIN_COUNT: u32 = 30

MAX_PIN_COUNT

Constant · Source

The GPIOs the function tables below reach: GPIO 0 to 47, all of the RP2350B (QFN-80). A Bank refuses those its chip lacks.

pub const MAX_PIN_COUNT: u32 = 48

pin_bit

Function · Source

GPIO number’s bit in a pin mask.

pub fn pin_bit(number: u32) -> u64

I2C0

Constant · Source

The bus controllers, as Bank numbers them for its chip.

pub const I2C0: u32 = 0

I2C1

Constant · Source

pub const I2C1: u32 = 1

SPI0

Constant · Source

pub const SPI0: u32 = 2

SPI1

Constant · Source

pub const SPI1: u32 = 3

UART0

Constant · Source

pub const UART0: u32 = 4

UART1

Constant · Source

pub const UART1: u32 = 5

PWM

Constant · Source

The PWM block and the ADC, which serve several pins each.

pub const PWM: u32 = 6

ADC

Constant · Source

pub const ADC: u32 = 7

PIO0

Constant · Source

The PIO blocks: PIO0 + n is block n, up to PIO1 on the RP2040 and PIO2 on the RP2350.

pub const PIO0: u32 = 8

PIO1

Constant · Source

pub const PIO1: u32 = 9

PIO2

Constant · Source

pub const PIO2: u32 = 10

i2c_controller

Function · Source

The I2C controller, 0 or 1, that pins sda and scl form a bus on. 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, up to GPIO 47. InvalidInput if the two pins cannot form a bus.

pub fn i2c_controller(sda: u32, scl: u32) -> u32!hal.Error

SpiPins

Struct · Source

The pins of an SPI bus, from spi_pins.

pub struct SpiPins {
    // The controller, 0 or 1.
    pub controller: u32
    // The receive pin, if the bus has one.
    pub rx: Option<u32>
    // Every pin of the bus, one bit each.
    pub mask: u64
}

spi_pins

Function · Source

The SPI bus that pins clock, tx, and rx (if any) form. 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. InvalidInput if the pins cannot form a bus.

pub fn spi_pins(clock: u32, tx: u32, rx: Option<u32>) -> SpiPins!hal.Error

spi_select_pin

Function · Source

The chip select pin of SPI controller controller at GPIO select, as a mask: GPIO n carries it when n % 4 is 1, in the same blocks of eight as spi_pins. InvalidInput if the pin cannot.

pub fn spi_select_pin(controller: u32, select: u32) -> u64!hal.Error

UartPins

Struct · Source

The pins of a serial port, from uart_pins.

pub struct UartPins {
    // The controller, 0 or 1.
    pub controller: u32
    // Every pin of the port, one bit each.
    pub mask: u64
    // The pins among them on the RP2350's UART_AUX function.
    pub aux: u64
}

uart_pins

Function · Source

The serial port that pins tx and rx (if any) form. GPIO n carries TX when n % 4 is 0 and RX when it is 1. GPIO 0 to 3, 12 to 19, 28 to 35, and 44 to 47 belong to UART0, GPIO 4 to 11, 20 to 27, and 36 to 43 to UART1. InvalidInput if the pins cannot form a port.

pub fn uart_pins(tx: u32, rx: Option<u32>) -> UartPins!hal.Error

uart_aux_pins

Function · Source

The serial port that pins tx and rx (if any) form on the RP2350, which also carries TX on GPIO n with n % 4 = 2 and RX on n % 4 = 3, the pins of its UART_AUX function; aux marks them. Pins of both kinds may be mixed within a UART. InvalidInput if the pins cannot form a port.

pub fn uart_aux_pins(tx: u32, rx: Option<u32>) -> UartPins!hal.Error

uart_flow_pins

Function · Source

The serial port of uart_pins with hardware flow control: GPIO n carries CTS when n % 4 is 2 and RTS when it is 3, in the same groups of four. InvalidInput if the pins cannot form the port.

pub fn uart_flow_pins(tx: u32, rx: u32, cts: u32, rts: u32) -> UartPins!hal.Error

Bank

Struct · Source

The GPIOs, the bus controllers, and the PWM outputs and ADC inputs of one chip C, each handed out once and taken back by the release methods. C does what differs between the chips, with these methods, controller numbered as I2C0 to PIO2 above:

pin_count(&self) -> u32 the GPIOs the chip has, 0 to pin_count() - 1: PIN_COUNT, or MAX_PIN_COUNT on the RP2350B route(&mut self, pin: u32, function: u32, clear: u32, set: u32) connect the pin to FUNCSEL function, then clear the clear and set the set bits of its pad reset(&mut self, controller: u32) -> void!hal.Error pulse the controller’s reset and wait until it runs (I2C0 to PWM, and the PIO blocks) hold(&mut self, controller: u32) hold the controller in reset (as for reset) base(&self, controller: u32) -> usize the controller’s register block clock_hz(&self) -> u32 the frequency of the clock that feeds the controllers and PWM pwm_slices(&self) -> u32 the PWM block’s slices: 8 on the RP2040, 12 on the RP2350 pwm_irq(&self) -> u32 the PWM wrap interrupt: PWM_IRQ_WRAP on the RP2040, PWM_IRQ_WRAP_0 on the RP2350 timer_base(&self) -> usize the running microsecond timer that times PWM input windows, with TIMERAWH and TIMERAWL at 0x24 and 0x28 start_adc(&mut self) -> void!hal.Error start the ADC’s 48 MHz clock, pulse its reset, and rp_adc.start it stop_adc(&mut self) rp_adc.stop the ADC, hold it in reset, and stop its clock uart_aux(&self) -> bool whether the chip has the UART_AUX function (the RP2350) pio_blocks(&self) -> u32 the number of PIO blocks: 2 on the RP2040, 3 on the RP2350 pio_version(&self) -> u32 their PIO version: 0 on the RP2040, 1 on the RP2350 pio_irq(&self, block: u32) -> u32 the interrupt number of PIO block block’s interrupt line 0; line 1’s follows it

pub struct Bank<C> {
    // Private implementation fields omitted.
}

Bank.new

Function · Source

SAFETY: C’s methods must do what the protocol above says, base must name the controller’s DW_apb_i2c, PL022, or PL011, the PWM block, the ADC, or the PIO block, timer_base a running microsecond timer that nothing changes, and the bank must be the only bank, and the only user of its GPIOs’ control and pad registers, of the controllers, the PWM block, the ADC, and the PIO blocks, and of their resets and clocks.

pub unsafe fn new(chip: C) -> Bank<C>

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

Bank.pin_count

Function · Source

The GPIOs the chip has: 0 to pin_count() - 1.

pub fn pin_count(&self) -> u32

Bank.taken

Function · Source

The pins in use, one bit each.

pub fn taken(&self) -> u64

Bank.gpio

Function · Source

Claim pin number for the single-cycle I/O block. Returns its bit in a pin mask. InvalidInput for a GPIO the chip lacks, Busy if taken.

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

Bank.release_gpio

Function · Source

Give back the GPIO with bit mask, from gpio, which the caller has stopped driving. The pin is disconnected until it is claimed again.

pub fn release_gpio(&mut self, mask: u64)

Bank.i2c

Function · Source

Claim pins sda and scl as an I2C bus with an SCL frequency of frequency_hz; see i2c_controller for the pins. 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’ pull-ups (about 50 kOhm) keep an idle bus high but are too weak for fast mode.

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

Bank.spi

Function · Source

Claim pins as an SPI bus in mode, clocked at the fastest rate up to frequency_hz; see spi_pins for the pins. Errors as for i2c.

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

Bank.i2c_target

Function · Source

Claim pins sda and scl as an I2C target answering at address, a 10-bit address with ten_bit; see designware_i2c.target_address. frequency_hz is the master’s SCL frequency, for the input filter. Errors as for i2c, and InvalidInput for a reserved address.

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

Bank.spi_with_select

Function · Source

spi, with the controller’s own chip select on pin select as well; see spi_select_pin. The TI and Microwire frame formats need it. Errors as for spi.

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

Bank.spi_target

Function · Source

Claim pins as an SPI target in mode, clocked and selected by another master: clock and select are inputs, rx receives what the master sends, and tx answers it; see spi_pins and spi_select_pin. Pulled up, an unconnected select leaves the target deselected. Errors as for spi.

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

Bank.uart

Function · Source

Claim pin tx, and rx if any, as a serial port with 8N1 frames at the baud rate closest to baud; see uart_pins for the pins. 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. Until the port is released, report_panic writes to it.

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

Bank.uart_flow

Function · Source

uart with hardware flow control on pins cts and rts as well, turned on; see uart_flow_pins and pl011’s set_flow_control. Errors as for uart.

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

Bank.pwm

Function · Source

Claim pin pin as a PWM output at the frequency closest to frequency_hz, low until a duty is set; see rp_pwm for the slices and the frequency range. InvalidInput for a GPIO the chip lacks or a frequency out of range, Busy if the pin is taken, if its output is in use on another pin (GPIO n and n + 16 below GPIO 32, and n and n + 8 above, carry the same output), or if the other output of its slice runs at another frequency.

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

Bank.pwm_divided

Function · Source

pwm with the slice’s divider, in sixteenths, and TOP given instead of a frequency; see rp_pwm.divided. Errors as for pwm.

pub fn pwm_divided(&mut self, pin: u32, divider: u32, top: u32) -> rp_pwm.Pwm!hal.Error

Bank.release_pwm

Function · Source

Give back a PWM output from pwm: it stops driving its pin, which is disconnected, and the PWM block is held in reset once no output or input is left.

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

Bank.pwm_input

Function · Source

Claim pin pin, an odd GPIO (output B of rp_pwm.slice_of(pin)), as a PWM input measuring in windows of window_us; see rp_pwm.Capture for the measurement and its range. The input uses the whole slice, so its output A is not available while it runs. The pin’s pad never drives and has its pull-down on and pull-up off, 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, which overrides the pull-down. InvalidInput for an even pin, a GPIO the chip lacks, or a window out of range; Busy if the pin is taken or either output of its slice is in use (GPIO n and n + 16 share a slice, and above GPIO 31 n and n + 8).

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

Bank.release_pwm_input

Function · Source

Give back a PWM input from pwm_input: its slice stops and is free for outputs again, its pin is disconnected, and the PWM block is held in reset once no output or input is left.

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

Bank.pwm_timer

Function · Source

Claim PWM slice slice as a periodic timer and counter at tick_hz, which drives no pins; see rp_pwm.SliceTimer. Slices 0 to 7 serve pins too, so a timer takes both outputs of its slice (GPIO 2n, 2n + 1, 2n + 16, and 2n + 17); the RP2350’s slices 8 to 11 serve none here. InvalidInput for another slice or a rate rp_pwm.timer_divider refuses, Busy if an output or input uses the slice.

pub fn pwm_timer(&mut self, slice: u32, tick_hz: u32) -> rp_pwm.PwmTimer!hal.Error

Bank.release_pwm_timer

Function · Source

Give back a timer from pwm_timer: its slice stops and is free again, and the PWM block is held in reset once nothing uses it.

pub fn release_pwm_timer(&mut self, timer: rp_pwm.PwmTimer)

Bank.analog

Function · Source

Claim pin pin, GPIO 26 to 29, as an ADC input. Its digital input and pulls are turned off, so they do not disturb the voltage. The ADC starts with its first input. InvalidInput for another pin, Busy if the pin is taken, and Timeout if the ADC or its clock does not start.

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

Bank.temperature

Function · Source

Claim the temperature sensor, an ADC input; rp_adc.millicelsius converts its readings. Busy if it is claimed already, Timeout as for analog.

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

Bank.release_analog

Function · Source

Give back an ADC input from analog or temperature. A pin is disconnected; the ADC stops, with its clock, once no input is left.

pub fn release_analog(&mut self, analog: rp_adc.Analog)

Bank.sampler

Function · Source

Claim the ADC as a sampler of inputs, an rp_adc.Inputs set, that converts rate_hz times a second; irq is the chip’s ADC_IRQ_FIFO. Its pins are claimed as by analog. InvalidInput for an empty set, one beyond rp_adc.ALL_INPUTS, or a rate out of range; Busy if a pin is taken or the ADC has inputs or a sampler already; Timeout if the ADC or its clock does not start.

pub fn sampler(&mut self, inputs: u32, rate_hz: u32, irq: u32) -> rp_adc.AdcSampler!hal.Error

Bank.release_sampler

Function · Source

Give back the ADC’s sampler: it stops, its pins are disconnected, and the ADC stops with its clock.

pub fn release_sampler(&mut self, sampler: rp_adc.AdcSampler)

Bank.pio

Function · Source

Claim PIO block number, 0 to pio_blocks() - 1, out of reset with every state machine stopped. InvalidInput for another number, Busy if it is claimed, Timeout if it does not leave reset.

pub fn pio(&mut self, number: u32) -> rp_pio.Pio!hal.Error

Bank.pio_pins

Function · Source

Connect the count pins from GPIO first to PIO block pio, so its state machines drive them, through the pin mappings of their configs, and read them. State machines also read pins claimed in other ways, such as inputs. The pins must lie in the block’s window (rp_pio’s Pio.gpio_base: GPIO 0 to 31, or 16 to 47 after pio.set_gpio_base(16)), together with the pins it has already. InvalidInput for a GPIO the chip lacks, pins outside the 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

Bank.edge_capture

Function · Source

Claim pin pin for PIO block pio and capture its edges (rp_capture.RISING, FALLING, or BOTH) with a free state machine of the block, in ticks of tick_hz; see rp_capture. Errors as for pio_pins and rp_capture.EdgeCapture.new.

pub fn edge_capture(&mut self, pio: &mut rp_pio.Pio, pin: u32, edges: u32, tick_hz: u32) -> rp_capture.EdgeCapture!hal.Error

Bank.release_edge_capture

Function · Source

Give back a capture from edge_capture to pio, the block it came from: its state machine and program, and its pin, which is disconnected.

pub fn release_edge_capture(&mut self, capture: rp_capture.EdgeCapture, pio: &mut rp_pio.Pio)

Bank.release_pio

Function · Source

Give back a PIO block from pio once its state machines have been given back to it: 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)

Bank.release_i2c

Function · Source

Give back an I2C bus from i2c: its pins are disconnected, still pulled up so the bus stays idle, and its controller held in reset. The pins can then be claimed as GPIOs, for example to clock a stuck device free, and the bus claimed again.

pub fn release_i2c(&mut self, bus: designware_i2c.Bus)

Bank.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: designware_i2c.TargetBus)

Bank.release_spi

Function · Source

Give back an SPI bus from spi or spi_with_select, as for release_i2c.

pub fn release_spi(&mut self, bus: pl022.Bus)

Bank.release_spi_target

Function · Source

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

pub fn release_spi_target(&mut self, target: pl022.TargetBus)

Bank.release_uart

Function · Source

Give back a serial port from uart or uart_flow once everything written to it is out, as for release_i2c: its pins stay pulled up, so the line stays idle.

pub fn release_uart(&mut self, port: pl011.Port)

set_panic_console

Function · Source

Report panics on another console as well, through reporter, called as report_panic is, and run after once the default panic hook has reported, instead of halting at once; after should not return. The chip packages register the USB serial port here while it is open. SAFETY: call with interrupts masked; reporter and after must be safe to call from a panic hook, with interrupts masked for good.

pub unsafe fn set_panic_console(reporter: Option<fn(*const u8, *const u8, u32, u32)>, after: Option<fn()>)

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

report_panic

Function · Source

Write a failed check, as the compiler passes it to a firmware panic hook, to every serial port claimed from a Bank and not yet released, and to the panic console of set_panic_console, and wait until it is out:

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

the line a desktop program prints, on a line of its own. Only the first call reports; a failure while reporting must not report again. SAFETY: check and file must be NUL-terminated, and the caller must halt or reset afterwards, as this takes the ports, and the DMA channels, from their owners.

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.

write_failure

Function · Source

Write the report of report_panic to the PL011 with registers R, a value with the register block protocol, as its owner configured it. SAFETY: check and file must be NUL-terminated.

pub unsafe fn write_failure<R: hal.Registers>(registers: &mut R, 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.

Search every guide, reference page, and API declaration.