Embassy
embassy-nrf

Crates

git

Versions

nrf9160-s

Flavors

Trait embassy_nrf::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

§

type P = AnyPin

source§

impl Peripheral for AnyChannel

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

§

type P = NVMC

source§

impl Peripheral for P0_00

§

type P = P0_00

source§

impl Peripheral for P0_01

§

type P = P0_01

source§

impl Peripheral for P0_02

§

type P = P0_02

source§

impl Peripheral for P0_03

§

type P = P0_03

source§

impl Peripheral for P0_04

§

type P = P0_04

source§

impl Peripheral for P0_05

§

type P = P0_05

source§

impl Peripheral for P0_06

§

type P = P0_06

source§

impl Peripheral for P0_07

§

type P = P0_07

source§

impl Peripheral for P0_08

§

type P = P0_08

source§

impl Peripheral for P0_09

§

type P = P0_09

source§

impl Peripheral for P0_10

§

type P = P0_10

source§

impl Peripheral for P0_11

§

type P = P0_11

source§

impl Peripheral for P0_12

§

type P = P0_12

source§

impl Peripheral for P0_13

§

type P = P0_13

source§

impl Peripheral for P0_14

§

type P = P0_14

source§

impl Peripheral for P0_15

§

type P = P0_15

source§

impl Peripheral for P0_16

§

type P = P0_16

source§

impl Peripheral for P0_17

§

type P = P0_17

source§

impl Peripheral for P0_18

§

type P = P0_18

source§

impl Peripheral for P0_19

§

type P = P0_19

source§

impl Peripheral for P0_20

§

type P = P0_20

source§

impl Peripheral for P0_21

§

type P = P0_21

source§

impl Peripheral for P0_22

§

type P = P0_22

source§

impl Peripheral for P0_23

§

type P = P0_23

source§

impl Peripheral for P0_24

§

type P = P0_24

source§

impl Peripheral for P0_25

§

type P = P0_25

source§

impl Peripheral for P0_26

§

type P = P0_26

source§

impl Peripheral for P0_27

§

type P = P0_27

source§

impl Peripheral for P0_28

§

type P = P0_28

source§

impl Peripheral for P0_29

§

type P = P0_29

source§

impl Peripheral for P0_30

§

type P = P0_30

source§

impl Peripheral for P0_31

§

type P = P0_31

source§

impl Peripheral for PDM

§

type P = PDM

source§

impl Peripheral for PPI_CH0

§

type P = PPI_CH0

source§

impl Peripheral for PPI_CH1

§

type P = PPI_CH1

source§

impl Peripheral for PPI_CH2

§

type P = PPI_CH2

source§

impl Peripheral for PPI_CH3

§

type P = PPI_CH3

source§

impl Peripheral for PPI_CH4

§

type P = PPI_CH4

source§

impl Peripheral for PPI_CH5

§

type P = PPI_CH5

source§

impl Peripheral for PPI_CH6

§

type P = PPI_CH6

source§

impl Peripheral for PPI_CH7

§

type P = PPI_CH7

source§

impl Peripheral for PPI_CH8

§

type P = PPI_CH8

source§

impl Peripheral for PPI_CH9

§

type P = PPI_CH9

source§

impl Peripheral for PPI_CH10

§

type P = PPI_CH10

source§

impl Peripheral for PPI_CH11

§

type P = PPI_CH11

source§

impl Peripheral for PPI_CH12

§

type P = PPI_CH12

source§

impl Peripheral for PPI_CH13

§

type P = PPI_CH13

source§

impl Peripheral for PPI_CH14

§

type P = PPI_CH14

source§

impl Peripheral for PPI_CH15

§

type P = 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

§

type P = PWM0

source§

impl Peripheral for PWM1

§

type P = PWM1

source§

impl Peripheral for PWM2

§

type P = PWM2

source§

impl Peripheral for PWM3

§

type P = PWM3

source§

impl Peripheral for RTC0

§

type P = RTC0

source§

impl Peripheral for RTC1

§

type P = RTC1

source§

impl Peripheral for SAADC

§

type P = SAADC

source§

impl Peripheral for SERIAL0

§

type P = SERIAL0

source§

impl Peripheral for SERIAL1

§

type P = SERIAL1

source§

impl Peripheral for SERIAL2

§

type P = SERIAL2

source§

impl Peripheral for SERIAL3

§

type P = SERIAL3

source§

impl Peripheral for TIMER0

§

type P = TIMER0

source§

impl Peripheral for TIMER1

§

type P = TIMER1

source§

impl Peripheral for TIMER2

§

type P = TIMER2

source§

impl Peripheral for WDT

§

type P = WDT

source§

impl Peripheral for AnyConfigurableChannel

source§

impl Peripheral for AnyGroup

§

type P = AnyGroup

source§

impl Peripheral for AnyStaticChannel

source§

impl Peripheral for AnyInput

§

type P = AnyInput

source§

impl Peripheral for VddInput

§

type P = VddInput

source§

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

§

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