embassy-nrf

Crates

git

Versions

nrf9120-s

Flavors

embassy_nrf

Trait 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 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_18

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 PDM

source§

type P = PDM

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_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 PWM0

source§

impl Peripheral for PWM1

source§

impl Peripheral for PWM2

source§

impl Peripheral for PWM3

source§

impl Peripheral for RTC0

source§

impl Peripheral for RTC1

source§

impl Peripheral for SAADC

source§

impl Peripheral for SERIAL0

source§

impl Peripheral for SERIAL1

source§

impl Peripheral for SERIAL2

source§

impl Peripheral for SERIAL3

source§

impl Peripheral for TIMER0

source§

impl Peripheral for TIMER1

source§

impl Peripheral for TIMER2

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 Peripheral for AnyInput

source§

impl Peripheral for VddInput

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