Expand description
Startup allocator for hardware peripherals, DMA channels, and PIO state machines. Hardware bus allocator.
The allocator hands out peripherals (SPI/I2C/UART), PIO state machines and DMA channels to drivers. Constructed bus handles own their resources for the rest of the boot; the allocator is intentionally a startup-time allocator, not a hot-plug pool. The API is designed so that the most common ways to misconfigure hardware are caught at compile time:
- Pin roles can’t be swapped —
clk/mosi/misoandtx/rxare distinguished by trait bounds (ClkPin<I>,MosiPin<I>, …). A pin only implements the role trait for its actual function, so passingmisowhereclkis expected is a type error. - Pins can’t be paired with the wrong peripheral instance — the role traits
are parameterized by the instance (
ClkPin<SPI0>vsClkPin<SPI1>), so an SPI0 pin can’t be used with the SPI1 peripheral. - The backend can’t be confused — there are separate
create_*_hardware,create_*_pioandcreate_*_bitbangmethods. There is noboolflag and no silent HW→bitbang downgrade when a hardware peripheral was specifically requested. - DMA channels are owned by the allocator — callers specify which typed
channel to use, and the allocator tracks availability. A channel already
handed out returns
Err(Exhausted). - PIO state machines are allocated soundly — the
PioManagerkeeps every SM alive, so all 12 SMs are independently available and no(block, sm)combination the allocator returns is unbuild-able.
Async SPI (hardware and PIO) requires DMA. Because embassy-rp models each
DMA channel as a distinct type, the caller specifies the channel types
(TxDma, RxDma) and provides the board’s IRQ binding; the allocator
dispenses the matching Peri tokens from its pool. PIO UART uses FIFO
polling (no DMA), so BusAllocator::create_uart provides a PIO→BitBang fallback without
DMA for baud rates supported by at least one backend.
Structs§
- BusAllocator
- DmaPool
- Set of DMA channels the board hands to the allocator. Fields left as
Noneare not owned by the allocator and can’t be dispensed.
Enums§
- Allocator
Error - Startup-time resource allocation error.
- PioBlock
- RP235x PIO instances
- Sm
- RP235x PIO state machine index within a block.
Traits§
- DmaChannel
- A DMA channel the allocator can hand out. Each RP235x DMA channel is a distinct type; the caller specifies which channel(s) to use, and the allocator tracks availability.
- I2cHw
- A hardware I2C instance the allocator can hand out.
- SpiHw
- A hardware SPI instance the allocator can hand out.
- UartHw
- A hardware UART instance the allocator can hand out.