Trait esp_ward::Peripheral

pub trait Peripheral: Sized + Sealed {
    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>.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl<T> Peripheral for &mut T
where T: Peripheral<P = T>,

§

type P = T

§

unsafe fn clone_unchecked(&mut self) -> <&mut T as Peripheral>::P

Implementors§

§

impl Peripheral for ADC1

§

type P = ADC1

§

impl Peripheral for AES

§

type P = AES

§

impl Peripheral for ASSIST_DEBUG

§

type P = ASSIST_DEBUG

§

impl Peripheral for ATOMIC

§

type P = ATOMIC

§

impl Peripheral for BT

§

type P = BT

§

impl Peripheral for DMA

§

type P = DMA

§

impl Peripheral for DS

§

type P = DS

§

impl Peripheral for ECC

§

type P = ECC

§

impl Peripheral for EFUSE

§

type P = EFUSE

§

impl Peripheral for EXTMEM

§

type P = EXTMEM

§

impl Peripheral for GPIO

§

type P = GPIO

§

impl Peripheral for GPIO_SD

§

type P = GPIO_SD

§

impl Peripheral for HINF

§

type P = HINF

§

impl Peripheral for HMAC

§

type P = HMAC

§

impl Peripheral for HP_APM

§

type P = HP_APM

§

impl Peripheral for HP_SYS

§

type P = HP_SYS

§

impl Peripheral for I2C0

§

type P = I2C0

§

impl Peripheral for I2S0

§

type P = I2S0

§

impl Peripheral for IEEE802154

§

type P = IEEE802154

§

impl Peripheral for INTERRUPT_CORE0

§

type P = INTERRUPT_CORE0

§

impl Peripheral for INTPRI

§

type P = INTPRI

§

impl Peripheral for IO_MUX

§

type P = IO_MUX

§

impl Peripheral for LEDC

§

type P = LEDC

§

impl Peripheral for LPWR

§

type P = LPWR

§

impl Peripheral for LP_ANA

§

type P = LP_ANA

§

impl Peripheral for LP_AON

§

type P = LP_AON

§

impl Peripheral for LP_APM

§

type P = LP_APM

§

impl Peripheral for LP_APM0

§

type P = LP_APM0

§

impl Peripheral for LP_CORE

§

type P = LP_CORE

§

impl Peripheral for LP_I2C0

§

type P = LP_I2C0

§

impl Peripheral for LP_I2C_ANA_MST

§

type P = LP_I2C_ANA_MST

§

impl Peripheral for LP_IO

§

type P = LP_IO

§

impl Peripheral for LP_PERI

§

type P = LP_PERI

§

impl Peripheral for LP_TEE

§

type P = LP_TEE

§

impl Peripheral for LP_TIMER

§

type P = LP_TIMER

§

impl Peripheral for LP_UART

§

type P = LP_UART

§

impl Peripheral for LP_WDT

§

type P = LP_WDT

§

impl Peripheral for MCPWM0

§

type P = MCPWM0

§

impl Peripheral for MEM_MONITOR

§

type P = MEM_MONITOR

§

impl Peripheral for OTP_DEBUG

§

type P = OTP_DEBUG

§

impl Peripheral for PARL_IO

§

type P = PARL_IO

§

impl Peripheral for PAU

§

type P = PAU

§

impl Peripheral for PCNT

§

type P = PCNT

§

impl Peripheral for PMU

§

type P = PMU

§

impl Peripheral for RMT

§

type P = RMT

§

impl Peripheral for RNG

§

type P = RNG

§

impl Peripheral for RSA

§

type P = RSA

§

impl Peripheral for SHA

§

type P = SHA

§

impl Peripheral for SLCHOST

§

type P = SLCHOST

§

impl Peripheral for SOC_ETM

§

type P = SOC_ETM

§

impl Peripheral for SPI0

§

type P = SPI0

§

impl Peripheral for SPI1

§

type P = SPI1

§

impl Peripheral for SPI2

§

type P = SPI2

§

impl Peripheral for SYSTEM

§

type P = SYSTEM

§

impl Peripheral for SYSTIMER

§

type P = SYSTIMER

§

impl Peripheral for SystemClockControl

§

type P = SystemClockControl

§

impl Peripheral for TEE

§

type P = TEE

§

impl Peripheral for TIMG0

§

type P = TIMG0

§

impl Peripheral for TIMG1

§

type P = TIMG1

§

impl Peripheral for TRACE0

§

type P = TRACE0

§

impl Peripheral for TWAI0

§

type P = TWAI0

§

impl Peripheral for TWAI1

§

type P = TWAI1

§

impl Peripheral for UART0

§

type P = UART0

§

impl Peripheral for UART1

§

type P = UART1

§

impl Peripheral for UHCI0

§

type P = UHCI0

§

impl Peripheral for USB_DEVICE

§

type P = USB_DEVICE

§

impl Peripheral for WIFI

§

type P = WIFI

§

impl<MODE, TYPE> Peripheral for AnyPin<MODE, TYPE>
where TYPE: PinType,

§

type P = AnyPin<MODE, TYPE>

§

impl<MODE, const GPIONUM: u8> Peripheral for GpioPin<MODE, GPIONUM>
where GpioPin<MODE, GPIONUM>: GpioProperties,

§

type P = GpioPin<MODE, GPIONUM>