embassy-nrf

Crates

git

Versions

nrf52820

Flavors

embassy_nrf

Trait Peripheral

Source
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>.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Peripheral for AnyPin

Source§

impl Peripheral for AnyChannel

Source§

impl Peripheral for EGU0

Source§

impl Peripheral for EGU1

Source§

impl Peripheral for EGU2

Source§

impl Peripheral for EGU3

Source§

impl Peripheral for EGU4

Source§

impl Peripheral for EGU5

Source§

impl Peripheral for GPIOTE_CH0

Source§

impl Peripheral for GPIOTE_CH1

Source§

impl Peripheral for GPIOTE_CH2

Source§

impl Peripheral for GPIOTE_CH3

Source§

impl Peripheral for GPIOTE_CH4

Source§

impl Peripheral for GPIOTE_CH5

Source§

impl Peripheral for GPIOTE_CH6

Source§

impl Peripheral for GPIOTE_CH7

Source§

impl Peripheral for NVMC

Source§

impl Peripheral for P0_00

Source§

impl Peripheral for P0_01

Source§

impl Peripheral for P0_02

Source§

impl Peripheral for P0_03

Source§

impl Peripheral for P0_04

Source§

impl Peripheral for P0_05

Source§

impl Peripheral for P0_06

Source§

impl Peripheral for P0_07

Source§

impl Peripheral for P0_08

Source§

impl Peripheral for P0_09

Source§

impl Peripheral for P0_10

Source§

impl Peripheral for P0_11

Source§

impl Peripheral for P0_12

Source§

impl Peripheral for P0_13

Source§

impl Peripheral for P0_14

Source§

impl Peripheral for P0_15

Source§

impl Peripheral for P0_16

Source§

impl Peripheral for P0_17

Source§

impl Peripheral for P0_19

Source§

impl Peripheral for P0_20

Source§

impl Peripheral for P0_21

Source§

impl Peripheral for P0_22

Source§

impl Peripheral for P0_23

Source§

impl Peripheral for P0_24

Source§

impl Peripheral for P0_25

Source§

impl Peripheral for P0_26

Source§

impl Peripheral for P0_27

Source§

impl Peripheral for P0_28

Source§

impl Peripheral for P0_29

Source§

impl Peripheral for P0_30

Source§

impl Peripheral for P0_31

Source§

impl Peripheral for PPI_CH0

Source§

impl Peripheral for PPI_CH1

Source§

impl Peripheral for PPI_CH2

Source§

impl Peripheral for PPI_CH3

Source§

impl Peripheral for PPI_CH4

Source§

impl Peripheral for PPI_CH5

Source§

impl Peripheral for PPI_CH6

Source§

impl Peripheral for PPI_CH7

Source§

impl Peripheral for PPI_CH8

Source§

impl Peripheral for PPI_CH9

Source§

impl Peripheral for PPI_CH10

Source§

impl Peripheral for PPI_CH11

Source§

impl Peripheral for PPI_CH12

Source§

impl Peripheral for PPI_CH13

Source§

impl Peripheral for PPI_CH14

Source§

impl Peripheral for PPI_CH15

Source§

impl Peripheral for PPI_CH16

Source§

impl Peripheral for PPI_CH17

Source§

impl Peripheral for PPI_CH18

Source§

impl Peripheral for PPI_CH19

Source§

impl Peripheral for PPI_CH20

Source§

impl Peripheral for PPI_CH21

Source§

impl Peripheral for PPI_CH22

Source§

impl Peripheral for PPI_CH23

Source§

impl Peripheral for PPI_CH24

Source§

impl Peripheral for PPI_CH25

Source§

impl Peripheral for PPI_CH26

Source§

impl Peripheral for PPI_CH27

Source§

impl Peripheral for PPI_CH28

Source§

impl Peripheral for PPI_CH29

Source§

impl Peripheral for PPI_CH30

Source§

impl Peripheral for PPI_CH31

Source§

impl Peripheral for PPI_GROUP0

Source§

impl Peripheral for PPI_GROUP1

Source§

impl Peripheral for PPI_GROUP2

Source§

impl Peripheral for PPI_GROUP3

Source§

impl Peripheral for PPI_GROUP4

Source§

impl Peripheral for PPI_GROUP5

Source§

impl Peripheral for QDEC

Source§

impl Peripheral for RADIO

Source§

impl Peripheral for RNG

Source§

type P = RNG

Source§

impl Peripheral for RTC0

Source§

impl Peripheral for RTC1

Source§

impl Peripheral for TEMP

Source§

impl Peripheral for TIMER0

Source§

impl Peripheral for TIMER1

Source§

impl Peripheral for TIMER2

Source§

impl Peripheral for TIMER3

Source§

impl Peripheral for TWISPI0

Source§

impl Peripheral for TWISPI1

Source§

impl Peripheral for UARTE0

Source§

impl Peripheral for USBD

Source§

impl Peripheral for WDT

Source§

type P = WDT

Source§

impl Peripheral for AnyConfigurableChannel

Source§

impl Peripheral for AnyGroup

Source§

impl Peripheral for AnyStaticChannel

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