Embassy
embassy-rp

Crates

git

Versions

rp2040

Flavors

Trait embassy_rp::Peripheral

·
pub trait Peripheral: Sized {
    type P;

    // Required method
    unsafe fn clone_unchecked(&self) -> Self::P;

    // Provided method
    fn into_ref<'a>(self) -> PeripheralRef<'a, Self::P>
       where Self: 'a { ... }
}
Expand description

Trait for any type that can be used as a peripheral of type P.

This is used in driver constructors, to allow passing either owned peripherals (e.g. TWISPI0), or borrowed peripherals (e.g. &mut TWISPI0).

For example, if you have a driver with a constructor like this:

impl<'d, T: Instance> Twim<'d, T> {
    pub fn new(
        twim: impl Peripheral<P = T> + 'd,
        irq: impl Peripheral<P = T::Interrupt> + 'd,
        sda: impl Peripheral<P = impl GpioPin> + 'd,
        scl: impl Peripheral<P = impl GpioPin> + 'd,
        config: Config,
    ) -> Self { .. }
}

You may call it with owned peripherals, which yields an instance that can live forever ('static):

let mut twi: Twim<'static, ...> = Twim::new(p.TWISPI0, irq, p.P0_03, p.P0_04, config);

Or you may call it with borrowed peripherals, which yields an instance that can only live for as long as the borrows last:

let mut twi: Twim<'_, ...> = Twim::new(&mut p.TWISPI0, &mut irq, &mut p.P0_03, &mut p.P0_04, config);

Implementation details, for HAL authors

When writing a HAL, the intended way to use this trait is to take impl Peripheral<P = ..> in the HAL’s public API (such as driver constructors), calling .into_ref() to obtain a PeripheralRef, and storing that in the driver struct.

.into_ref() on an owned T yields a PeripheralRef<'static, T>. .into_ref() on an &'a mut T yields a PeripheralRef<'a, T>.

Required Associated Types§

source

type P

Peripheral singleton type

Required Methods§

source

unsafe fn clone_unchecked(&self) -> Self::P

Unsafely clone (duplicate) a peripheral singleton.

Safety

This returns an owned clone of the peripheral. You must manually ensure only one copy of the peripheral is in use at a time. For example, don’t create two SPI drivers on SPI1, because they will “fight” each other.

You should strongly prefer using into_ref() instead. It returns a PeripheralRef, which allows the borrow checker to enforce this at compile time.

Provided Methods§

source

fn into_ref<'a>(self) -> PeripheralRef<'a, Self::P>
where Self: 'a,

Convert a value into a PeripheralRef.

When called on an owned T, yields a PeripheralRef<'static, T>. When called on an &'a mut T, yields a PeripheralRef<'a, T>.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Peripheral for AnyChannel

source§

impl Peripheral for AnyPin

§

type P = AnyPin

source§

impl Peripheral for ADC

§

type P = ADC

source§

impl Peripheral for ADC_TEMP_SENSOR

source§

impl Peripheral for BOOTSEL

§

type P = BOOTSEL

source§

impl Peripheral for CORE1

§

type P = CORE1

source§

impl Peripheral for DMA_CH0

§

type P = DMA_CH0

source§

impl Peripheral for DMA_CH1

§

type P = DMA_CH1

source§

impl Peripheral for DMA_CH2

§

type P = DMA_CH2

source§

impl Peripheral for DMA_CH3

§

type P = DMA_CH3

source§

impl Peripheral for DMA_CH4

§

type P = DMA_CH4

source§

impl Peripheral for DMA_CH5

§

type P = DMA_CH5

source§

impl Peripheral for DMA_CH6

§

type P = DMA_CH6

source§

impl Peripheral for DMA_CH7

§

type P = DMA_CH7

source§

impl Peripheral for DMA_CH8

§

type P = DMA_CH8

source§

impl Peripheral for DMA_CH9

§

type P = DMA_CH9

source§

impl Peripheral for DMA_CH10

§

type P = DMA_CH10

source§

impl Peripheral for DMA_CH11

§

type P = DMA_CH11

source§

impl Peripheral for FLASH

§

type P = FLASH

source§

impl Peripheral for I2C0

§

type P = I2C0

source§

impl Peripheral for I2C1

§

type P = I2C1

source§

impl Peripheral for PIN_0

§

type P = PIN_0

source§

impl Peripheral for PIN_1

§

type P = PIN_1

source§

impl Peripheral for PIN_2

§

type P = PIN_2

source§

impl Peripheral for PIN_3

§

type P = PIN_3

source§

impl Peripheral for PIN_4

§

type P = PIN_4

source§

impl Peripheral for PIN_5

§

type P = PIN_5

source§

impl Peripheral for PIN_6

§

type P = PIN_6

source§

impl Peripheral for PIN_7

§

type P = PIN_7

source§

impl Peripheral for PIN_8

§

type P = PIN_8

source§

impl Peripheral for PIN_9

§

type P = PIN_9

source§

impl Peripheral for PIN_10

§

type P = PIN_10

source§

impl Peripheral for PIN_11

§

type P = PIN_11

source§

impl Peripheral for PIN_12

§

type P = PIN_12

source§

impl Peripheral for PIN_13

§

type P = PIN_13

source§

impl Peripheral for PIN_14

§

type P = PIN_14

source§

impl Peripheral for PIN_15

§

type P = PIN_15

source§

impl Peripheral for PIN_16

§

type P = PIN_16

source§

impl Peripheral for PIN_17

§

type P = PIN_17

source§

impl Peripheral for PIN_18

§

type P = PIN_18

source§

impl Peripheral for PIN_19

§

type P = PIN_19

source§

impl Peripheral for PIN_20

§

type P = PIN_20

source§

impl Peripheral for PIN_21

§

type P = PIN_21

source§

impl Peripheral for PIN_22

§

type P = PIN_22

source§

impl Peripheral for PIN_23

§

type P = PIN_23

source§

impl Peripheral for PIN_24

§

type P = PIN_24

source§

impl Peripheral for PIN_25

§

type P = PIN_25

source§

impl Peripheral for PIN_26

§

type P = PIN_26

source§

impl Peripheral for PIN_27

§

type P = PIN_27

source§

impl Peripheral for PIN_28

§

type P = PIN_28

source§

impl Peripheral for PIN_29

§

type P = PIN_29

source§

impl Peripheral for PIN_QSPI_SCLK

source§

impl Peripheral for PIN_QSPI_SD0

source§

impl Peripheral for PIN_QSPI_SD1

source§

impl Peripheral for PIN_QSPI_SD2

source§

impl Peripheral for PIN_QSPI_SD3

source§

impl Peripheral for PIN_QSPI_SS

source§

impl Peripheral for PIO0

§

type P = PIO0

source§

impl Peripheral for PIO1

§

type P = PIO1

source§

impl Peripheral for PWM_CH0

§

type P = PWM_CH0

source§

impl Peripheral for PWM_CH1

§

type P = PWM_CH1

source§

impl Peripheral for PWM_CH2

§

type P = PWM_CH2

source§

impl Peripheral for PWM_CH3

§

type P = PWM_CH3

source§

impl Peripheral for PWM_CH4

§

type P = PWM_CH4

source§

impl Peripheral for PWM_CH5

§

type P = PWM_CH5

source§

impl Peripheral for PWM_CH6

§

type P = PWM_CH6

source§

impl Peripheral for PWM_CH7

§

type P = PWM_CH7

source§

impl Peripheral for RTC

§

type P = RTC

source§

impl Peripheral for SPI0

§

type P = SPI0

source§

impl Peripheral for SPI1

§

type P = SPI1

source§

impl Peripheral for UART0

§

type P = UART0

source§

impl Peripheral for UART1

§

type P = UART1

source§

impl Peripheral for USB

§

type P = USB

source§

impl Peripheral for WATCHDOG

§

type P = WATCHDOG

source§

impl<'b, T> Peripheral for T
where T: Deref, <T as Deref>::Target: Peripheral,

§

type P = <<T as Deref>::Target as Peripheral>::P