Embassy
embassy-stm32

Crates

git

Versions

stm32g474mb

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 ADC1

§

type P = ADC1

source§

impl Peripheral for ADC2

§

type P = ADC2

source§

impl Peripheral for ADC3

§

type P = ADC3

source§

impl Peripheral for ADC4

§

type P = ADC4

source§

impl Peripheral for ADC5

§

type P = ADC5

source§

impl Peripheral for ADC_COMMON

source§

impl Peripheral for COMP1

§

type P = COMP1

source§

impl Peripheral for COMP2

§

type P = COMP2

source§

impl Peripheral for COMP3

§

type P = COMP3

source§

impl Peripheral for COMP4

§

type P = COMP4

source§

impl Peripheral for COMP5

§

type P = COMP5

source§

impl Peripheral for COMP6

§

type P = COMP6

source§

impl Peripheral for COMP7

§

type P = COMP7

source§

impl Peripheral for CORDIC

§

type P = CORDIC

source§

impl Peripheral for CRC

§

type P = CRC

source§

impl Peripheral for CRS

§

type P = CRS

source§

impl Peripheral for DAC1

§

type P = DAC1

source§

impl Peripheral for DAC2

§

type P = DAC2

source§

impl Peripheral for DAC3

§

type P = DAC3

source§

impl Peripheral for DAC4

§

type P = DAC4

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 DMA1_CH8

§

type P = DMA1_CH8

source§

impl Peripheral for DMA2

§

type P = DMA2

source§

impl Peripheral for DMA2_CH1

§

type P = DMA2_CH1

source§

impl Peripheral for DMA2_CH2

§

type P = DMA2_CH2

source§

impl Peripheral for DMA2_CH3

§

type P = DMA2_CH3

source§

impl Peripheral for DMA2_CH4

§

type P = DMA2_CH4

source§

impl Peripheral for DMA2_CH5

§

type P = DMA2_CH5

source§

impl Peripheral for DMA2_CH6

§

type P = DMA2_CH6

source§

impl Peripheral for DMA2_CH7

§

type P = DMA2_CH7

source§

impl Peripheral for DMA2_CH8

§

type P = DMA2_CH8

source§

impl Peripheral for DMAMUX1

§

type P = DMAMUX1

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 FDCAN1

§

type P = FDCAN1

source§

impl Peripheral for FDCAN2

§

type P = FDCAN2

source§

impl Peripheral for FDCAN3

§

type P = FDCAN3

source§

impl Peripheral for FDCANRAM1

§

type P = FDCANRAM1

source§

impl Peripheral for FDCANRAM2

§

type P = FDCANRAM2

source§

impl Peripheral for FDCANRAM3

§

type P = FDCANRAM3

source§

impl Peripheral for FLASH

§

type P = FLASH

source§

impl Peripheral for FMAC

§

type P = FMAC

source§

impl Peripheral for HRTIM1

§

type P = HRTIM1

source§

impl Peripheral for I2C1

§

type P = I2C1

source§

impl Peripheral for I2C2

§

type P = I2C2

source§

impl Peripheral for I2C3

§

type P = I2C3

source§

impl Peripheral for I2C4

§

type P = I2C4

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 OPAMP1

§

type P = OPAMP1

source§

impl Peripheral for OPAMP2

§

type P = OPAMP2

source§

impl Peripheral for OPAMP3

§

type P = OPAMP3

source§

impl Peripheral for OPAMP4

§

type P = OPAMP4

source§

impl Peripheral for OPAMP5

§

type P = OPAMP5

source§

impl Peripheral for OPAMP6

§

type P = OPAMP6

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 PF0

§

type P = PF0

source§

impl Peripheral for PF1

§

type P = PF1

source§

impl Peripheral for PF2

§

type P = PF2

source§

impl Peripheral for PF3

§

type P = PF3

source§

impl Peripheral for PF4

§

type P = PF4

source§

impl Peripheral for PF5

§

type P = PF5

source§

impl Peripheral for PF6

§

type P = PF6

source§

impl Peripheral for PF7

§

type P = PF7

source§

impl Peripheral for PF8

§

type P = PF8

source§

impl Peripheral for PF9

§

type P = PF9

source§

impl Peripheral for PF10

§

type P = PF10

source§

impl Peripheral for PF11

§

type P = PF11

source§

impl Peripheral for PF12

§

type P = PF12

source§

impl Peripheral for PF13

§

type P = PF13

source§

impl Peripheral for PF14

§

type P = PF14

source§

impl Peripheral for PF15

§

type P = PF15

source§

impl Peripheral for PG0

§

type P = PG0

source§

impl Peripheral for PG1

§

type P = PG1

source§

impl Peripheral for PG2

§

type P = PG2

source§

impl Peripheral for PG3

§

type P = PG3

source§

impl Peripheral for PG4

§

type P = PG4

source§

impl Peripheral for PG5

§

type P = PG5

source§

impl Peripheral for PG6

§

type P = PG6

source§

impl Peripheral for PG7

§

type P = PG7

source§

impl Peripheral for PG8

§

type P = PG8

source§

impl Peripheral for PG9

§

type P = PG9

source§

impl Peripheral for PG10

§

type P = PG10

source§

impl Peripheral for PG11

§

type P = PG11

source§

impl Peripheral for PG12

§

type P = PG12

source§

impl Peripheral for PG13

§

type P = PG13

source§

impl Peripheral for PG14

§

type P = PG14

source§

impl Peripheral for PG15

§

type P = PG15

source§

impl Peripheral for PWR

§

type P = PWR

source§

impl Peripheral for QUADSPI1

§

type P = QUADSPI1

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 SAI1

§

type P = SAI1

source§

impl Peripheral for SPI1

§

type P = SPI1

source§

impl Peripheral for SPI2

§

type P = SPI2

source§

impl Peripheral for SPI3

§

type P = SPI3

source§

impl Peripheral for SPI4

§

type P = SPI4

source§

impl Peripheral for SYSCFG

§

type P = SYSCFG

source§

impl Peripheral for TAMP

§

type P = TAMP

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 TIM5

§

type P = TIM5

source§

impl Peripheral for TIM6

§

type P = TIM6

source§

impl Peripheral for TIM7

§

type P = TIM7

source§

impl Peripheral for TIM8

§

type P = TIM8

source§

impl Peripheral for TIM15

§

type P = TIM15

source§

impl Peripheral for TIM16

§

type P = TIM16

source§

impl Peripheral for TIM17

§

type P = TIM17

source§

impl Peripheral for TIM20

§

type P = TIM20

source§

impl Peripheral for UART4

§

type P = UART4

source§

impl Peripheral for UART5

§

type P = UART5

source§

impl Peripheral for UCPD1

§

type P = UCPD1

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 USART3

§

type P = USART3

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