embassy-nrf

Crates

git

Versions

nrf9160-s

Flavors

๐Ÿ“ฃ We want to hear from you! Fill the Rust Embedded 2024 micro-survey.

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

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ยง

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ยง

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