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 NoDma

§

type P = NoDma

source§

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

source§

impl Peripheral for ADC_COMMON

source§

impl Peripheral for BDMA

§

type P = BDMA

source§

impl Peripheral for BDMA_CH0

§

type P = BDMA_CH0

source§

impl Peripheral for BDMA_CH1

§

type P = BDMA_CH1

source§

impl Peripheral for BDMA_CH2

§

type P = BDMA_CH2

source§

impl Peripheral for BDMA_CH3

§

type P = BDMA_CH3

source§

impl Peripheral for BDMA_CH4

§

type P = BDMA_CH4

source§

impl Peripheral for BDMA_CH5

§

type P = BDMA_CH5

source§

impl Peripheral for BDMA_CH6

§

type P = BDMA_CH6

source§

impl Peripheral for BDMA_CH7

§

type P = BDMA_CH7

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 DBGMCU

§

type P = DBGMCU

source§

impl Peripheral for DCMI

§

type P = DCMI

source§

impl Peripheral for DMA1

§

type P = DMA1

source§

impl Peripheral for DMA1_CH0

§

type P = DMA1_CH0

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 DMA2

§

type P = DMA2

source§

impl Peripheral for DMA2D

§

type P = DMA2D

source§

impl Peripheral for DMA2_CH0

§

type P = DMA2_CH0

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 DMAMUX1

§

type P = DMAMUX1

source§

impl Peripheral for DMAMUX2

§

type P = DMAMUX2

source§

impl Peripheral for ETH

§

type P = ETH

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 FDCANRAM

§

type P = FDCANRAM

source§

impl Peripheral for FLASH

§

type P = FLASH

source§

impl Peripheral for FMC

§

type P = FMC

source§

impl Peripheral for HRTIM

§

type P = HRTIM

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 IWDG1

§

type P = IWDG1

source§

impl Peripheral for IWDG2

§

type P = IWDG2

source§

impl Peripheral for JPEG

§

type P = JPEG

source§

impl Peripheral for LPUART1

§

type P = LPUART1

source§

impl Peripheral for MCO1

§

type P = MCO1

source§

impl Peripheral for MCO2

§

type P = MCO2

source§

impl Peripheral for MDIOS

§

type P = MDIOS

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 PH0

§

type P = PH0

source§

impl Peripheral for PH1

§

type P = PH1

source§

impl Peripheral for PH2

§

type P = PH2

source§

impl Peripheral for PH3

§

type P = PH3

source§

impl Peripheral for PH4

§

type P = PH4

source§

impl Peripheral for PH5

§

type P = PH5

source§

impl Peripheral for PH6

§

type P = PH6

source§

impl Peripheral for PH7

§

type P = PH7

source§

impl Peripheral for PH8

§

type P = PH8

source§

impl Peripheral for PH9

§

type P = PH9

source§

impl Peripheral for PH10

§

type P = PH10

source§

impl Peripheral for PH11

§

type P = PH11

source§

impl Peripheral for PH12

§

type P = PH12

source§

impl Peripheral for PH13

§

type P = PH13

source§

impl Peripheral for PH14

§

type P = PH14

source§

impl Peripheral for PH15

§

type P = PH15

source§

impl Peripheral for PI0

§

type P = PI0

source§

impl Peripheral for PI1

§

type P = PI1

source§

impl Peripheral for PI2

§

type P = PI2

source§

impl Peripheral for PI3

§

type P = PI3

source§

impl Peripheral for PI4

§

type P = PI4

source§

impl Peripheral for PI5

§

type P = PI5

source§

impl Peripheral for PI6

§

type P = PI6

source§

impl Peripheral for PI7

§

type P = PI7

source§

impl Peripheral for PI8

§

type P = PI8

source§

impl Peripheral for PI9

§

type P = PI9

source§

impl Peripheral for PI10

§

type P = PI10

source§

impl Peripheral for PI11

§

type P = PI11

source§

impl Peripheral for PI12

§

type P = PI12

source§

impl Peripheral for PI13

§

type P = PI13

source§

impl Peripheral for PI14

§

type P = PI14

source§

impl Peripheral for PI15

§

type P = PI15

source§

impl Peripheral for PJ0

§

type P = PJ0

source§

impl Peripheral for PJ1

§

type P = PJ1

source§

impl Peripheral for PJ2

§

type P = PJ2

source§

impl Peripheral for PJ3

§

type P = PJ3

source§

impl Peripheral for PJ4

§

type P = PJ4

source§

impl Peripheral for PJ5

§

type P = PJ5

source§

impl Peripheral for PJ6

§

type P = PJ6

source§

impl Peripheral for PJ7

§

type P = PJ7

source§

impl Peripheral for PJ8

§

type P = PJ8

source§

impl Peripheral for PJ9

§

type P = PJ9

source§

impl Peripheral for PJ10

§

type P = PJ10

source§

impl Peripheral for PJ11

§

type P = PJ11

source§

impl Peripheral for PJ12

§

type P = PJ12

source§

impl Peripheral for PJ13

§

type P = PJ13

source§

impl Peripheral for PJ14

§

type P = PJ14

source§

impl Peripheral for PJ15

§

type P = PJ15

source§

impl Peripheral for PK0

§

type P = PK0

source§

impl Peripheral for PK1

§

type P = PK1

source§

impl Peripheral for PK2

§

type P = PK2

source§

impl Peripheral for PK3

§

type P = PK3

source§

impl Peripheral for PK4

§

type P = PK4

source§

impl Peripheral for PK5

§

type P = PK5

source§

impl Peripheral for PK6

§

type P = PK6

source§

impl Peripheral for PK7

§

type P = PK7

source§

impl Peripheral for PK8

§

type P = PK8

source§

impl Peripheral for PK9

§

type P = PK9

source§

impl Peripheral for PK10

§

type P = PK10

source§

impl Peripheral for PK11

§

type P = PK11

source§

impl Peripheral for PK12

§

type P = PK12

source§

impl Peripheral for PK13

§

type P = PK13

source§

impl Peripheral for PK14

§

type P = PK14

source§

impl Peripheral for PK15

§

type P = PK15

source§

impl Peripheral for PWR

§

type P = PWR

source§

impl Peripheral for QUADSPI

§

type P = QUADSPI

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 SAI2

§

type P = SAI2

source§

impl Peripheral for SAI3

§

type P = SAI3

source§

impl Peripheral for SAI4

§

type P = SAI4

source§

impl Peripheral for SDMMC1

§

type P = SDMMC1

source§

impl Peripheral for SDMMC2

§

type P = SDMMC2

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 SPI5

§

type P = SPI5

source§

impl Peripheral for SPI6

§

type P = SPI6

source§

impl Peripheral for SYSCFG

§

type P = SYSCFG

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 TIM12

§

type P = TIM12

source§

impl Peripheral for TIM13

§

type P = TIM13

source§

impl Peripheral for TIM14

§

type P = TIM14

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 UART4

§

type P = UART4

source§

impl Peripheral for UART5

§

type P = UART5

source§

impl Peripheral for UART7

§

type P = UART7

source§

impl Peripheral for UART8

§

type P = UART8

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 USART6

§

type P = USART6

source§

impl Peripheral for USB_OTG_FS

source§

impl Peripheral for USB_OTG_HS

source§

impl Peripheral for WWDG1

§

type P = WWDG1

source§

impl Peripheral for WWDG2

§

type P = WWDG2

source§

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

§

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