embassy-stm32

Crates

git

Versions

stm32g030f6

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 ADC1_COMMON

Source§

impl Peripheral for CRC

Source§

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

Source§

impl Peripheral for I2C2

Source§

impl Peripheral for IWDG

Source§

impl Peripheral for MCO1

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 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 PWR

Source§

type P = PWR

Source§

impl Peripheral for RCC

Source§

type P = RCC

Source§

impl Peripheral for RTC

Source§

type P = RTC

Source§

impl Peripheral for SPI1

Source§

impl Peripheral for SPI2

Source§

impl Peripheral for SYSCFG

Source§

impl Peripheral for TAMP

Source§

impl Peripheral for TIM1

Source§

impl Peripheral for TIM3

Source§

impl Peripheral for TIM14

Source§

impl Peripheral for TIM16

Source§

impl Peripheral for TIM17

Source§

impl Peripheral for UID

Source§

type P = UID

Source§

impl Peripheral for USART1

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