embassy-stm32

Crates

git

Versions

stm32l4p5rg

Flavors

embassy_stm32

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 ADC2

Source§

impl Peripheral for ADC12_COMMON

Source§

impl Peripheral for CAN1

Source§

impl Peripheral for CRC

Source§

type P = CRC

Source§

impl Peripheral for CRS

Source§

type P = CRS

Source§

impl Peripheral for DAC1

Source§

impl Peripheral for DBGMCU

Source§

impl Peripheral for DCMI

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 DMA2

Source§

impl Peripheral for DMA2D

Source§

impl Peripheral for DMA2_CH1

Source§

impl Peripheral for DMA2_CH2

Source§

impl Peripheral for DMA2_CH3

Source§

impl Peripheral for DMA2_CH4

Source§

impl Peripheral for DMA2_CH5

Source§

impl Peripheral for DMA2_CH6

Source§

impl Peripheral for DMA2_CH7

Source§

impl Peripheral for DMAMUX1

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 HASH

Source§

impl Peripheral for I2C1

Source§

impl Peripheral for I2C2

Source§

impl Peripheral for I2C3

Source§

impl Peripheral for I2C4

Source§

impl Peripheral for IWDG

Source§

impl Peripheral for LPTIM1

Source§

impl Peripheral for LPTIM2

Source§

impl Peripheral for LPUART1

Source§

impl Peripheral for MCO

Source§

type P = MCO

Source§

impl Peripheral for OCTOSPI1

Source§

impl Peripheral for OCTOSPI2

Source§

impl Peripheral for OCTOSPIM

Source§

impl Peripheral for PA0

Source§

type P = PA0

Source§

impl Peripheral for PA1

Source§

type P = PA1

Source§

impl Peripheral for PA2

Source§

type P = PA2

Source§

impl Peripheral for PA3

Source§

type P = PA3

Source§

impl Peripheral for PA4

Source§

type P = PA4

Source§

impl Peripheral for PA5

Source§

type P = PA5

Source§

impl Peripheral for PA6

Source§

type P = PA6

Source§

impl Peripheral for PA7

Source§

type P = PA7

Source§

impl Peripheral for PA8

Source§

type P = PA8

Source§

impl Peripheral for PA9

Source§

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

type P = PB0

Source§

impl Peripheral for PB1

Source§

type P = PB1

Source§

impl Peripheral for PB2

Source§

type P = PB2

Source§

impl Peripheral for PB3

Source§

type P = PB3

Source§

impl Peripheral for PB4

Source§

type P = PB4

Source§

impl Peripheral for PB5

Source§

type P = PB5

Source§

impl Peripheral for PB6

Source§

type P = PB6

Source§

impl Peripheral for PB7

Source§

type P = PB7

Source§

impl Peripheral for PB8

Source§

type P = PB8

Source§

impl Peripheral for PB9

Source§

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

type P = PC0

Source§

impl Peripheral for PC1

Source§

type P = PC1

Source§

impl Peripheral for PC2

Source§

type P = PC2

Source§

impl Peripheral for PC3

Source§

type P = PC3

Source§

impl Peripheral for PC4

Source§

type P = PC4

Source§

impl Peripheral for PC5

Source§

type P = PC5

Source§

impl Peripheral for PC6

Source§

type P = PC6

Source§

impl Peripheral for PC7

Source§

type P = PC7

Source§

impl Peripheral for PC8

Source§

type P = PC8

Source§

impl Peripheral for PC9

Source§

type P = PC9

Source§

impl Peripheral for PC10

Source§

impl Peripheral for PC11

Source§

impl Peripheral for PC12

Source§

impl Peripheral for PC13

Source§

impl Peripheral for PC14

Source§

impl Peripheral for PC15

Source§

impl Peripheral for PD0

Source§

type P = PD0

Source§

impl Peripheral for PD1

Source§

type P = PD1

Source§

impl Peripheral for PD2

Source§

type P = PD2

Source§

impl Peripheral for PD3

Source§

type P = PD3

Source§

impl Peripheral for PD4

Source§

type P = PD4

Source§

impl Peripheral for PD5

Source§

type P = PD5

Source§

impl Peripheral for PD6

Source§

type P = PD6

Source§

impl Peripheral for PD7

Source§

type P = PD7

Source§

impl Peripheral for PD8

Source§

type P = PD8

Source§

impl Peripheral for PD9

Source§

type P = PD9

Source§

impl Peripheral for PD10

Source§

impl Peripheral for PD11

Source§

impl Peripheral for PD12

Source§

impl Peripheral for PD13

Source§

impl Peripheral for PD14

Source§

impl Peripheral for PD15

Source§

impl Peripheral for PE0

Source§

type P = PE0

Source§

impl Peripheral for PE1

Source§

type P = PE1

Source§

impl Peripheral for PE2

Source§

type P = PE2

Source§

impl Peripheral for PE3

Source§

type P = PE3

Source§

impl Peripheral for PE4

Source§

type P = PE4

Source§

impl Peripheral for PE5

Source§

type P = PE5

Source§

impl Peripheral for PE6

Source§

type P = PE6

Source§

impl Peripheral for PE7

Source§

type P = PE7

Source§

impl Peripheral for PE8

Source§

type P = PE8

Source§

impl Peripheral for PE9

Source§

type P = PE9

Source§

impl Peripheral for PE10

Source§

impl Peripheral for PE11

Source§

impl Peripheral for PE12

Source§

impl Peripheral for PE13

Source§

impl Peripheral for PE14

Source§

impl Peripheral for PE15

Source§

impl Peripheral for PF0

Source§

type P = PF0

Source§

impl Peripheral for PF1

Source§

type P = PF1

Source§

impl Peripheral for PF2

Source§

type P = PF2

Source§

impl Peripheral for PF3

Source§

type P = PF3

Source§

impl Peripheral for PF4

Source§

type P = PF4

Source§

impl Peripheral for PF5

Source§

type P = PF5

Source§

impl Peripheral for PF6

Source§

type P = PF6

Source§

impl Peripheral for PF7

Source§

type P = PF7

Source§

impl Peripheral for PF8

Source§

type P = PF8

Source§

impl Peripheral for PF9

Source§

type P = PF9

Source§

impl Peripheral for PF10

Source§

impl Peripheral for PF11

Source§

impl Peripheral for PF12

Source§

impl Peripheral for PF13

Source§

impl Peripheral for PF14

Source§

impl Peripheral for PF15

Source§

impl Peripheral for PG0

Source§

type P = PG0

Source§

impl Peripheral for PG1

Source§

type P = PG1

Source§

impl Peripheral for PG2

Source§

type P = PG2

Source§

impl Peripheral for PG3

Source§

type P = PG3

Source§

impl Peripheral for PG4

Source§

type P = PG4

Source§

impl Peripheral for PG5

Source§

type P = PG5

Source§

impl Peripheral for PG6

Source§

type P = PG6

Source§

impl Peripheral for PG7

Source§

type P = PG7

Source§

impl Peripheral for PG8

Source§

type P = PG8

Source§

impl Peripheral for PG9

Source§

type P = PG9

Source§

impl Peripheral for PG10

Source§

impl Peripheral for PG11

Source§

impl Peripheral for PG12

Source§

impl Peripheral for PG13

Source§

impl Peripheral for PG14

Source§

impl Peripheral for PG15

Source§

impl Peripheral for PH0

Source§

type P = PH0

Source§

impl Peripheral for PH1

Source§

type P = PH1

Source§

impl Peripheral for PH2

Source§

type P = PH2

Source§

impl Peripheral for PH3

Source§

type P = PH3

Source§

impl Peripheral for PH4

Source§

type P = PH4

Source§

impl Peripheral for PH5

Source§

type P = PH5

Source§

impl Peripheral for PH6

Source§

type P = PH6

Source§

impl Peripheral for PH7

Source§

type P = PH7

Source§

impl Peripheral for PH8

Source§

type P = PH8

Source§

impl Peripheral for PH9

Source§

type P = PH9

Source§

impl Peripheral for PH10

Source§

impl Peripheral for PH11

Source§

impl Peripheral for PH12

Source§

impl Peripheral for PH13

Source§

impl Peripheral for PH14

Source§

impl Peripheral for PH15

Source§

impl Peripheral for PI0

Source§

type P = PI0

Source§

impl Peripheral for PI1

Source§

type P = PI1

Source§

impl Peripheral for PI2

Source§

type P = PI2

Source§

impl Peripheral for PI3

Source§

type P = PI3

Source§

impl Peripheral for PI4

Source§

type P = PI4

Source§

impl Peripheral for PI5

Source§

type P = PI5

Source§

impl Peripheral for PI6

Source§

type P = PI6

Source§

impl Peripheral for PI7

Source§

type P = PI7

Source§

impl Peripheral for PI8

Source§

type P = PI8

Source§

impl Peripheral for PI9

Source§

type P = PI9

Source§

impl Peripheral for PI10

Source§

impl Peripheral for PI11

Source§

impl Peripheral for PI12

Source§

impl Peripheral for PI13

Source§

impl Peripheral for PI14

Source§

impl Peripheral for PI15

Source§

impl Peripheral for PSSI

Source§

impl Peripheral for PWR

Source§

type P = PWR

Source§

impl Peripheral for RCC

Source§

type P = RCC

Source§

impl Peripheral for RNG

Source§

type P = RNG

Source§

impl Peripheral for RTC

Source§

type P = RTC

Source§

impl Peripheral for SAI1

Source§

impl Peripheral for SAI2

Source§

impl Peripheral for SPI1

Source§

impl Peripheral for SPI2

Source§

impl Peripheral for SPI3

Source§

impl Peripheral for SYSCFG

Source§

impl Peripheral for TIM1

Source§

impl Peripheral for TIM2

Source§

impl Peripheral for TIM3

Source§

impl Peripheral for TIM4

Source§

impl Peripheral for TIM5

Source§

impl Peripheral for TIM6

Source§

impl Peripheral for TIM7

Source§

impl Peripheral for TIM8

Source§

impl Peripheral for TIM15

Source§

impl Peripheral for TIM16

Source§

impl Peripheral for TIM17

Source§

impl Peripheral for TSC

Source§

type P = TSC

Source§

impl Peripheral for UART4

Source§

impl Peripheral for UID

Source§

type P = UID

Source§

impl Peripheral for USART1

Source§

impl Peripheral for USART2

Source§

impl Peripheral for USART3

Source§

impl Peripheral for USB_OTG_FS

Source§

impl Peripheral for VREFINTCAL

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