embassy-stm32

Crates

git

Versions

stm32l041c4

Flavors

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 embassy_stm32::dma::AnyChannel

Sourceยง

impl Peripheral for NoDma

Sourceยง

impl Peripheral for embassy_stm32::exti::AnyChannel

Sourceยง

impl Peripheral for AnyPin

Sourceยง

impl Peripheral for ADC1

Sourceยง

impl Peripheral for AES

Sourceยง

impl Peripheral for CRC

Sourceยง

impl Peripheral for DBGMCU

Sourceยง

impl Peripheral for DMA1

Sourceยง

impl Peripheral for DMA1_CH1

Sourceยง

impl Peripheral for DMA1_CH2

Sourceยง

impl Peripheral for DMA1_CH3

Sourceยง

impl Peripheral for DMA1_CH4

Sourceยง

impl Peripheral for DMA1_CH5

Sourceยง

impl Peripheral for DMA1_CH6

Sourceยง

impl Peripheral for DMA1_CH7

Sourceยง

impl Peripheral for EXTI0

Sourceยง

impl Peripheral for EXTI1

Sourceยง

impl Peripheral for EXTI2

Sourceยง

impl Peripheral for EXTI3

Sourceยง

impl Peripheral for EXTI4

Sourceยง

impl Peripheral for EXTI5

Sourceยง

impl Peripheral for EXTI6

Sourceยง

impl Peripheral for EXTI7

Sourceยง

impl Peripheral for EXTI8

Sourceยง

impl Peripheral for EXTI9

Sourceยง

impl Peripheral for EXTI10

Sourceยง

impl Peripheral for EXTI11

Sourceยง

impl Peripheral for EXTI12

Sourceยง

impl Peripheral for EXTI13

Sourceยง

impl Peripheral for EXTI14

Sourceยง

impl Peripheral for EXTI15

Sourceยง

impl Peripheral for FLASH

Sourceยง

impl Peripheral for I2C1

Sourceยง

impl Peripheral for IWDG

Sourceยง

impl Peripheral for LPTIM1

Sourceยง

impl Peripheral for LPUART1

Sourceยง

impl Peripheral for MCO

Sourceยง

impl Peripheral for PA0

Sourceยง

impl Peripheral for PA1

Sourceยง

impl Peripheral for PA2

Sourceยง

impl Peripheral for PA3

Sourceยง

impl Peripheral for PA4

Sourceยง

impl Peripheral for PA5

Sourceยง

impl Peripheral for PA6

Sourceยง

impl Peripheral for PA7

Sourceยง

impl Peripheral for PA8

Sourceยง

impl Peripheral for PA9

Sourceยง

impl Peripheral for PA10

Sourceยง

impl Peripheral for PA11

Sourceยง

impl Peripheral for PA12

Sourceยง

impl Peripheral for PA13

Sourceยง

impl Peripheral for PA14

Sourceยง

impl Peripheral for PA15

Sourceยง

impl Peripheral for PB0

Sourceยง

impl Peripheral for PB1

Sourceยง

impl Peripheral for PB2

Sourceยง

impl Peripheral for PB3

Sourceยง

impl Peripheral for PB4

Sourceยง

impl Peripheral for PB5

Sourceยง

impl Peripheral for PB6

Sourceยง

impl Peripheral for PB7

Sourceยง

impl Peripheral for PB8

Sourceยง

impl Peripheral for PB9

Sourceยง

impl Peripheral for PB10

Sourceยง

impl Peripheral for PB11

Sourceยง

impl Peripheral for PB12

Sourceยง

impl Peripheral for PB13

Sourceยง

impl Peripheral for PB14

Sourceยง

impl Peripheral for PB15

Sourceยง

impl Peripheral for PC0

Sourceยง

impl Peripheral for PC13

Sourceยง

impl Peripheral for PC14

Sourceยง

impl Peripheral for PC15

Sourceยง

impl Peripheral for PH0

Sourceยง

impl Peripheral for PH1

Sourceยง

impl Peripheral for PWR

Sourceยง

impl Peripheral for RCC

Sourceยง

impl Peripheral for RTC

Sourceยง

impl Peripheral for SPI1

Sourceยง

impl Peripheral for SYSCFG

Sourceยง

impl Peripheral for TIM2

Sourceยง

impl Peripheral for TIM21

Sourceยง

impl Peripheral for TIM22

Sourceยง

impl Peripheral for UID

Sourceยง

impl Peripheral for USART2

Sourceยง

impl Peripheral for WWDG

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