embassy-stm32

Crates

git

Versions

stm32l083rz

Flavors

📣 We want to hear from you! Fill the Rust Embedded 2024 micro-survey.

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

source§

impl Peripheral for embassy_stm32::exti::AnyChannel

source§

impl Peripheral for AnyPin

source§

impl Peripheral for ADC1

source§

impl Peripheral for AES

source§

type P = AES

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

source§

impl Peripheral for I2C3

source§

impl Peripheral for IWDG

source§

impl Peripheral for LCD

source§

type P = LCD

source§

impl Peripheral for LPTIM1

source§

impl Peripheral for LPUART1

source§

impl Peripheral for MCO

source§

type P = MCO

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

source§

impl Peripheral for SPI2

source§

impl Peripheral for SYSCFG

source§

impl Peripheral for TIM2

source§

impl Peripheral for TIM3

source§

impl Peripheral for TIM6

source§

impl Peripheral for TIM7

source§

impl Peripheral for TIM21

source§

impl Peripheral for TIM22

source§

impl Peripheral for TSC

source§

type P = TSC

source§

impl Peripheral for UID

source§

type P = UID

source§

impl Peripheral for USART1

source§

impl Peripheral for USART2

source§

impl Peripheral for USART4

source§

impl Peripheral for USART5

source§

impl Peripheral for USB

source§

type P = USB

source§

impl Peripheral for USBRAM

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