Embassy
embassy-stm32

Crates

git

Versions

stm32l052c6

Flavors

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

source§

impl Peripheral for NoDma

§

type P = NoDma

source§

impl Peripheral for embassy_stm32::exti::AnyChannel

source§

impl Peripheral for AnyPin

§

type P = AnyPin

source§

impl Peripheral for ADC

§

type P = ADC

source§

impl Peripheral for CRC

§

type P = CRC

source§

impl Peripheral for CRS

§

type P = CRS

source§

impl Peripheral for DAC

§

type P = DAC

source§

impl Peripheral for DBGMCU

§

type P = DBGMCU

source§

impl Peripheral for DMA1

§

type P = DMA1

source§

impl Peripheral for DMA1_CH1

§

type P = DMA1_CH1

source§

impl Peripheral for DMA1_CH2

§

type P = DMA1_CH2

source§

impl Peripheral for DMA1_CH3

§

type P = DMA1_CH3

source§

impl Peripheral for DMA1_CH4

§

type P = DMA1_CH4

source§

impl Peripheral for DMA1_CH5

§

type P = DMA1_CH5

source§

impl Peripheral for DMA1_CH6

§

type P = DMA1_CH6

source§

impl Peripheral for DMA1_CH7

§

type P = DMA1_CH7

source§

impl Peripheral for EXTI0

§

type P = EXTI0

source§

impl Peripheral for EXTI1

§

type P = EXTI1

source§

impl Peripheral for EXTI2

§

type P = EXTI2

source§

impl Peripheral for EXTI3

§

type P = EXTI3

source§

impl Peripheral for EXTI4

§

type P = EXTI4

source§

impl Peripheral for EXTI5

§

type P = EXTI5

source§

impl Peripheral for EXTI6

§

type P = EXTI6

source§

impl Peripheral for EXTI7

§

type P = EXTI7

source§

impl Peripheral for EXTI8

§

type P = EXTI8

source§

impl Peripheral for EXTI9

§

type P = EXTI9

source§

impl Peripheral for EXTI10

§

type P = EXTI10

source§

impl Peripheral for EXTI11

§

type P = EXTI11

source§

impl Peripheral for EXTI12

§

type P = EXTI12

source§

impl Peripheral for EXTI13

§

type P = EXTI13

source§

impl Peripheral for EXTI14

§

type P = EXTI14

source§

impl Peripheral for EXTI15

§

type P = EXTI15

source§

impl Peripheral for FLASH

§

type P = FLASH

source§

impl Peripheral for I2C1

§

type P = I2C1

source§

impl Peripheral for I2C2

§

type P = I2C2

source§

impl Peripheral for IWDG

§

type P = IWDG

source§

impl Peripheral for LPTIM1

§

type P = LPTIM1

source§

impl Peripheral for LPUART1

§

type P = LPUART1

source§

impl Peripheral for MCO

§

type P = MCO

source§

impl Peripheral for PA0

§

type P = PA0

source§

impl Peripheral for PA1

§

type P = PA1

source§

impl Peripheral for PA2

§

type P = PA2

source§

impl Peripheral for PA3

§

type P = PA3

source§

impl Peripheral for PA4

§

type P = PA4

source§

impl Peripheral for PA5

§

type P = PA5

source§

impl Peripheral for PA6

§

type P = PA6

source§

impl Peripheral for PA7

§

type P = PA7

source§

impl Peripheral for PA8

§

type P = PA8

source§

impl Peripheral for PA9

§

type P = PA9

source§

impl Peripheral for PA10

§

type P = PA10

source§

impl Peripheral for PA11

§

type P = PA11

source§

impl Peripheral for PA12

§

type P = PA12

source§

impl Peripheral for PA13

§

type P = PA13

source§

impl Peripheral for PA14

§

type P = PA14

source§

impl Peripheral for PA15

§

type P = PA15

source§

impl Peripheral for PB0

§

type P = PB0

source§

impl Peripheral for PB1

§

type P = PB1

source§

impl Peripheral for PB2

§

type P = PB2

source§

impl Peripheral for PB3

§

type P = PB3

source§

impl Peripheral for PB4

§

type P = PB4

source§

impl Peripheral for PB5

§

type P = PB5

source§

impl Peripheral for PB6

§

type P = PB6

source§

impl Peripheral for PB7

§

type P = PB7

source§

impl Peripheral for PB8

§

type P = PB8

source§

impl Peripheral for PB9

§

type P = PB9

source§

impl Peripheral for PB10

§

type P = PB10

source§

impl Peripheral for PB11

§

type P = PB11

source§

impl Peripheral for PB12

§

type P = PB12

source§

impl Peripheral for PB13

§

type P = PB13

source§

impl Peripheral for PB14

§

type P = PB14

source§

impl Peripheral for PB15

§

type P = PB15

source§

impl Peripheral for PC0

§

type P = PC0

source§

impl Peripheral for PC1

§

type P = PC1

source§

impl Peripheral for PC2

§

type P = PC2

source§

impl Peripheral for PC3

§

type P = PC3

source§

impl Peripheral for PC4

§

type P = PC4

source§

impl Peripheral for PC5

§

type P = PC5

source§

impl Peripheral for PC6

§

type P = PC6

source§

impl Peripheral for PC7

§

type P = PC7

source§

impl Peripheral for PC8

§

type P = PC8

source§

impl Peripheral for PC9

§

type P = PC9

source§

impl Peripheral for PC10

§

type P = PC10

source§

impl Peripheral for PC11

§

type P = PC11

source§

impl Peripheral for PC12

§

type P = PC12

source§

impl Peripheral for PC13

§

type P = PC13

source§

impl Peripheral for PC14

§

type P = PC14

source§

impl Peripheral for PC15

§

type P = PC15

source§

impl Peripheral for PD0

§

type P = PD0

source§

impl Peripheral for PD1

§

type P = PD1

source§

impl Peripheral for PD2

§

type P = PD2

source§

impl Peripheral for PD3

§

type P = PD3

source§

impl Peripheral for PD4

§

type P = PD4

source§

impl Peripheral for PD5

§

type P = PD5

source§

impl Peripheral for PD6

§

type P = PD6

source§

impl Peripheral for PD7

§

type P = PD7

source§

impl Peripheral for PD8

§

type P = PD8

source§

impl Peripheral for PD9

§

type P = PD9

source§

impl Peripheral for PD10

§

type P = PD10

source§

impl Peripheral for PD11

§

type P = PD11

source§

impl Peripheral for PD12

§

type P = PD12

source§

impl Peripheral for PD13

§

type P = PD13

source§

impl Peripheral for PD14

§

type P = PD14

source§

impl Peripheral for PD15

§

type P = PD15

source§

impl Peripheral for PH0

§

type P = PH0

source§

impl Peripheral for PH1

§

type P = PH1

source§

impl Peripheral for PH2

§

type P = PH2

source§

impl Peripheral for PH3

§

type P = PH3

source§

impl Peripheral for PH4

§

type P = PH4

source§

impl Peripheral for PH5

§

type P = PH5

source§

impl Peripheral for PH6

§

type P = PH6

source§

impl Peripheral for PH7

§

type P = PH7

source§

impl Peripheral for PH8

§

type P = PH8

source§

impl Peripheral for PH9

§

type P = PH9

source§

impl Peripheral for PH10

§

type P = PH10

source§

impl Peripheral for PH11

§

type P = PH11

source§

impl Peripheral for PH12

§

type P = PH12

source§

impl Peripheral for PH13

§

type P = PH13

source§

impl Peripheral for PH14

§

type P = PH14

source§

impl Peripheral for PH15

§

type P = PH15

source§

impl Peripheral for PWR

§

type P = PWR

source§

impl Peripheral for RCC

§

type P = RCC

source§

impl Peripheral for RNG

§

type P = RNG

source§

impl Peripheral for RTC

§

type P = RTC

source§

impl Peripheral for SPI1

§

type P = SPI1

source§

impl Peripheral for SPI2

§

type P = SPI2

source§

impl Peripheral for SYSCFG

§

type P = SYSCFG

source§

impl Peripheral for TIM2

§

type P = TIM2

source§

impl Peripheral for TIM6

§

type P = TIM6

source§

impl Peripheral for TIM21

§

type P = TIM21

source§

impl Peripheral for TIM22

§

type P = TIM22

source§

impl Peripheral for TSC

§

type P = TSC

source§

impl Peripheral for UID

§

type P = UID

source§

impl Peripheral for USART1

§

type P = USART1

source§

impl Peripheral for USART2

§

type P = USART2

source§

impl Peripheral for USB

§

type P = USB

source§

impl Peripheral for USBRAM

§

type P = USBRAM

source§

impl Peripheral for WWDG

§

type P = WWDG

source§

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

§

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