Embassy
embassy-stm32

Crates

git

Versions

stm32c011d6

Flavors

Trait embassy_stm32::Peripheral

·
pub trait Peripheral: Sized {
    type P;

    // Required method
    unsafe fn clone_unchecked(&mut 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§

type P

Peripheral singleton type

Required Methods§

unsafe fn clone_unchecked(&mut 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§

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

Implementors§

source§

impl Peripheral for NoDma

§

type P = NoDma

source§

impl Peripheral for AnyChannel

source§

impl Peripheral for AnyPin

§

type P = AnyPin

§

impl Peripheral for ADC1

§

type P = ADC1

§

impl Peripheral for DMA1_CHANNEL1

§

impl Peripheral for DMA1_CHANNEL2_3

§

impl Peripheral for embassy_stm32::interrupt::DMAMUX1

§

type P = DMAMUX1

§

impl Peripheral for EXTI0_1

§

type P = EXTI0_1

§

impl Peripheral for EXTI2_3

§

type P = EXTI2_3

§

impl Peripheral for EXTI4_15

§

type P = EXTI4_15

§

impl Peripheral for embassy_stm32::interrupt::FLASH

§

type P = FLASH

§

impl Peripheral for embassy_stm32::interrupt::I2C1

§

type P = I2C1

§

impl Peripheral for embassy_stm32::interrupt::RCC

§

type P = RCC

§

impl Peripheral for RTC

§

type P = RTC

§

impl Peripheral for embassy_stm32::interrupt::SPI1

§

type P = SPI1

§

impl Peripheral for TIM1_BRK_UP_TRG_COM

§

impl Peripheral for TIM1_CC

§

type P = TIM1_CC

§

impl Peripheral for embassy_stm32::interrupt::TIM3

§

type P = TIM3

§

impl Peripheral for embassy_stm32::interrupt::TIM14

§

type P = TIM14

§

impl Peripheral for embassy_stm32::interrupt::TIM16

§

type P = TIM16

§

impl Peripheral for embassy_stm32::interrupt::TIM17

§

type P = TIM17

§

impl Peripheral for embassy_stm32::interrupt::USART1

§

type P = USART1

§

impl Peripheral for embassy_stm32::interrupt::USART2

§

type P = USART2

§

impl Peripheral for WWDG

§

type P = WWDG

§

impl Peripheral for CRC

§

type P = CRC

§

impl Peripheral for DBGMCU

§

type P = DBGMCU

§

impl Peripheral for DMA1

§

type P = DMA1

§

impl Peripheral for DMA1_CH1

§

type P = DMA1_CH1

§

impl Peripheral for DMA1_CH2

§

type P = DMA1_CH2

§

impl Peripheral for DMA1_CH3

§

type P = DMA1_CH3

§

impl Peripheral for embassy_stm32::peripherals::DMAMUX1

§

type P = DMAMUX1

§

impl Peripheral for EXTI0

§

type P = EXTI0

§

impl Peripheral for EXTI1

§

type P = EXTI1

§

impl Peripheral for EXTI2

§

type P = EXTI2

§

impl Peripheral for EXTI3

§

type P = EXTI3

§

impl Peripheral for EXTI4

§

type P = EXTI4

§

impl Peripheral for EXTI5

§

type P = EXTI5

§

impl Peripheral for EXTI6

§

type P = EXTI6

§

impl Peripheral for EXTI7

§

type P = EXTI7

§

impl Peripheral for EXTI8

§

type P = EXTI8

§

impl Peripheral for EXTI9

§

type P = EXTI9

§

impl Peripheral for EXTI10

§

type P = EXTI10

§

impl Peripheral for EXTI11

§

type P = EXTI11

§

impl Peripheral for EXTI12

§

type P = EXTI12

§

impl Peripheral for EXTI13

§

type P = EXTI13

§

impl Peripheral for EXTI14

§

type P = EXTI14

§

impl Peripheral for EXTI15

§

type P = EXTI15

§

impl Peripheral for embassy_stm32::peripherals::FLASH

§

type P = FLASH

§

impl Peripheral for embassy_stm32::peripherals::I2C1

§

type P = I2C1

§

impl Peripheral for IWDG

§

type P = IWDG

§

impl Peripheral for PA0

§

type P = PA0

§

impl Peripheral for PA1

§

type P = PA1

§

impl Peripheral for PA2

§

type P = PA2

§

impl Peripheral for PA3

§

type P = PA3

§

impl Peripheral for PA4

§

type P = PA4

§

impl Peripheral for PA5

§

type P = PA5

§

impl Peripheral for PA6

§

type P = PA6

§

impl Peripheral for PA7

§

type P = PA7

§

impl Peripheral for PA8

§

type P = PA8

§

impl Peripheral for PA9

§

type P = PA9

§

impl Peripheral for PA10

§

type P = PA10

§

impl Peripheral for PA11

§

type P = PA11

§

impl Peripheral for PA12

§

type P = PA12

§

impl Peripheral for PA13

§

type P = PA13

§

impl Peripheral for PA14

§

type P = PA14

§

impl Peripheral for PA15

§

type P = PA15

§

impl Peripheral for PB0

§

type P = PB0

§

impl Peripheral for PB1

§

type P = PB1

§

impl Peripheral for PB2

§

type P = PB2

§

impl Peripheral for PB3

§

type P = PB3

§

impl Peripheral for PB4

§

type P = PB4

§

impl Peripheral for PB5

§

type P = PB5

§

impl Peripheral for PB6

§

type P = PB6

§

impl Peripheral for PB7

§

type P = PB7

§

impl Peripheral for PB8

§

type P = PB8

§

impl Peripheral for PB9

§

type P = PB9

§

impl Peripheral for PB10

§

type P = PB10

§

impl Peripheral for PB11

§

type P = PB11

§

impl Peripheral for PB12

§

type P = PB12

§

impl Peripheral for PB13

§

type P = PB13

§

impl Peripheral for PB14

§

type P = PB14

§

impl Peripheral for PB15

§

type P = PB15

§

impl Peripheral for PC0

§

type P = PC0

§

impl Peripheral for PC1

§

type P = PC1

§

impl Peripheral for PC2

§

type P = PC2

§

impl Peripheral for PC3

§

type P = PC3

§

impl Peripheral for PC4

§

type P = PC4

§

impl Peripheral for PC5

§

type P = PC5

§

impl Peripheral for PC6

§

type P = PC6

§

impl Peripheral for PC7

§

type P = PC7

§

impl Peripheral for PC8

§

type P = PC8

§

impl Peripheral for PC9

§

type P = PC9

§

impl Peripheral for PC10

§

type P = PC10

§

impl Peripheral for PC11

§

type P = PC11

§

impl Peripheral for PC12

§

type P = PC12

§

impl Peripheral for PC13

§

type P = PC13

§

impl Peripheral for PC14

§

type P = PC14

§

impl Peripheral for PC15

§

type P = PC15

§

impl Peripheral for PF0

§

type P = PF0

§

impl Peripheral for PF1

§

type P = PF1

§

impl Peripheral for PF2

§

type P = PF2

§

impl Peripheral for PF3

§

type P = PF3

§

impl Peripheral for PF4

§

type P = PF4

§

impl Peripheral for PF5

§

type P = PF5

§

impl Peripheral for PF6

§

type P = PF6

§

impl Peripheral for PF7

§

type P = PF7

§

impl Peripheral for PF8

§

type P = PF8

§

impl Peripheral for PF9

§

type P = PF9

§

impl Peripheral for PF10

§

type P = PF10

§

impl Peripheral for PF11

§

type P = PF11

§

impl Peripheral for PF12

§

type P = PF12

§

impl Peripheral for PF13

§

type P = PF13

§

impl Peripheral for PF14

§

type P = PF14

§

impl Peripheral for PF15

§

type P = PF15

§

impl Peripheral for PWR

§

type P = PWR

§

impl Peripheral for embassy_stm32::peripherals::RCC

§

type P = RCC

§

impl Peripheral for embassy_stm32::peripherals::SPI1

§

type P = SPI1

§

impl Peripheral for SYSCFG

§

type P = SYSCFG

§

impl Peripheral for TIM1

§

type P = TIM1

§

impl Peripheral for embassy_stm32::peripherals::TIM3

§

type P = TIM3

§

impl Peripheral for embassy_stm32::peripherals::TIM14

§

type P = TIM14

§

impl Peripheral for embassy_stm32::peripherals::TIM16

§

type P = TIM16

§

impl Peripheral for embassy_stm32::peripherals::TIM17

§

type P = TIM17

§

impl Peripheral for embassy_stm32::peripherals::USART1

§

type P = USART1

§

impl Peripheral for embassy_stm32::peripherals::USART2

§

type P = USART2

§

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

§

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