Embassy
embassy-stm32

Crates

git

Versions

stm32f103t8

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

sourceยง

impl Peripheral for ADC1

ยง

type P = ADC1

sourceยง

impl Peripheral for ADC2

ยง

type P = ADC2

sourceยง

impl Peripheral for AFIO

ยง

type P = AFIO

sourceยง

impl Peripheral for BKP

ยง

type P = BKP

sourceยง

impl Peripheral for CAN

ยง

type P = CAN

sourceยง

impl Peripheral for CRC

ยง

type P = CRC

sourceยง

impl Peripheral for DBGMCU

sourceยง

impl Peripheral for DMA1

ยง

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

ยง

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

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

ยง

type P = FLASH

sourceยง

impl Peripheral for I2C1

ยง

type P = I2C1

sourceยง

impl Peripheral for IWDG

ยง

type P = IWDG

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 PE0

ยง

type P = PE0

sourceยง

impl Peripheral for PE1

ยง

type P = PE1

sourceยง

impl Peripheral for PE2

ยง

type P = PE2

sourceยง

impl Peripheral for PE3

ยง

type P = PE3

sourceยง

impl Peripheral for PE4

ยง

type P = PE4

sourceยง

impl Peripheral for PE5

ยง

type P = PE5

sourceยง

impl Peripheral for PE6

ยง

type P = PE6

sourceยง

impl Peripheral for PE7

ยง

type P = PE7

sourceยง

impl Peripheral for PE8

ยง

type P = PE8

sourceยง

impl Peripheral for PE9

ยง

type P = PE9

sourceยง

impl Peripheral for PE10

ยง

type P = PE10

sourceยง

impl Peripheral for PE11

ยง

type P = PE11

sourceยง

impl Peripheral for PE12

ยง

type P = PE12

sourceยง

impl Peripheral for PE13

ยง

type P = PE13

sourceยง

impl Peripheral for PE14

ยง

type P = PE14

sourceยง

impl Peripheral for PE15

ยง

type P = PE15

sourceยง

impl Peripheral for PWR

ยง

type P = PWR

sourceยง

impl Peripheral for RCC

ยง

type P = RCC

sourceยง

impl Peripheral for RTC

ยง

type P = RTC

sourceยง

impl Peripheral for SPI1

ยง

type P = SPI1

sourceยง

impl Peripheral for TIM1

ยง

type P = TIM1

sourceยง

impl Peripheral for TIM2

ยง

type P = TIM2

sourceยง

impl Peripheral for TIM3

ยง

type P = TIM3

sourceยง

impl Peripheral for TIM4

ยง

type P = TIM4

sourceยง

impl Peripheral for UID

ยง

type P = UID

sourceยง

impl Peripheral for USART1

sourceยง

impl Peripheral for USART2

sourceยง

impl Peripheral for USB

ยง

type P = USB

sourceยง

impl Peripheral for 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