embassy-rp

Crates

git

Versions

rp235xb

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

source§

impl Peripheral for ADC

source§

type P = ADC

source§

impl Peripheral for ADC_TEMP_SENSOR

source§

impl Peripheral for BOOTSEL

source§

impl Peripheral for CORE1

source§

impl Peripheral for DMA_CH0

source§

impl Peripheral for DMA_CH1

source§

impl Peripheral for DMA_CH2

source§

impl Peripheral for DMA_CH3

source§

impl Peripheral for DMA_CH4

source§

impl Peripheral for DMA_CH5

source§

impl Peripheral for DMA_CH6

source§

impl Peripheral for DMA_CH7

source§

impl Peripheral for DMA_CH8

source§

impl Peripheral for DMA_CH9

source§

impl Peripheral for DMA_CH10

source§

impl Peripheral for DMA_CH11

source§

impl Peripheral for DMA_CH12

source§

impl Peripheral for DMA_CH13

source§

impl Peripheral for DMA_CH14

source§

impl Peripheral for DMA_CH15

source§

impl Peripheral for FLASH

source§

impl Peripheral for I2C0

source§

impl Peripheral for I2C1

source§

impl Peripheral for PIN_0

source§

impl Peripheral for PIN_1

source§

impl Peripheral for PIN_2

source§

impl Peripheral for PIN_3

source§

impl Peripheral for PIN_4

source§

impl Peripheral for PIN_5

source§

impl Peripheral for PIN_6

source§

impl Peripheral for PIN_7

source§

impl Peripheral for PIN_8

source§

impl Peripheral for PIN_9

source§

impl Peripheral for PIN_10

source§

impl Peripheral for PIN_11

source§

impl Peripheral for PIN_12

source§

impl Peripheral for PIN_13

source§

impl Peripheral for PIN_14

source§

impl Peripheral for PIN_15

source§

impl Peripheral for PIN_16

source§

impl Peripheral for PIN_17

source§

impl Peripheral for PIN_18

source§

impl Peripheral for PIN_19

source§

impl Peripheral for PIN_20

source§

impl Peripheral for PIN_21

source§

impl Peripheral for PIN_22

source§

impl Peripheral for PIN_23

source§

impl Peripheral for PIN_24

source§

impl Peripheral for PIN_25

source§

impl Peripheral for PIN_26

source§

impl Peripheral for PIN_27

source§

impl Peripheral for PIN_28

source§

impl Peripheral for PIN_29

source§

impl Peripheral for PIN_30

source§

impl Peripheral for PIN_31

source§

impl Peripheral for PIN_32

source§

impl Peripheral for PIN_33

source§

impl Peripheral for PIN_34

source§

impl Peripheral for PIN_35

source§

impl Peripheral for PIN_36

source§

impl Peripheral for PIN_37

source§

impl Peripheral for PIN_38

source§

impl Peripheral for PIN_39

source§

impl Peripheral for PIN_40

source§

impl Peripheral for PIN_41

source§

impl Peripheral for PIN_42

source§

impl Peripheral for PIN_43

source§

impl Peripheral for PIN_44

source§

impl Peripheral for PIN_45

source§

impl Peripheral for PIN_46

source§

impl Peripheral for PIN_47

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

source§

impl Peripheral for PIO1

source§

impl Peripheral for PIO2

source§

impl Peripheral for PWM_SLICE0

source§

impl Peripheral for PWM_SLICE1

source§

impl Peripheral for PWM_SLICE2

source§

impl Peripheral for PWM_SLICE3

source§

impl Peripheral for PWM_SLICE4

source§

impl Peripheral for PWM_SLICE5

source§

impl Peripheral for PWM_SLICE6

source§

impl Peripheral for PWM_SLICE7

source§

impl Peripheral for PWM_SLICE8

source§

impl Peripheral for PWM_SLICE9

source§

impl Peripheral for PWM_SLICE10

source§

impl Peripheral for PWM_SLICE11

source§

impl Peripheral for RTC

source§

type P = RTC

source§

impl Peripheral for SPI0

source§

impl Peripheral for SPI1

source§

impl Peripheral for TRNG

source§

impl Peripheral for UART0

source§

impl Peripheral for UART1

source§

impl Peripheral for USB

source§

type P = USB

source§

impl Peripheral for WATCHDOG

source§

impl<'b, T> Peripheral for PeripheralRef<'_, T>
where T: Peripheral,

source§

type P = <T as Peripheral>::P

source§

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

source§

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