pub struct Peri<'a, T>where
T: PeripheralType,{ /* private fields */ }
Expand description
An exclusive reference to a peripheral.
This is functionally the same as a &'a mut T
. There’s a few advantages in having
a dedicated struct instead:
- Memory efficiency: Peripheral singletons are typically either zero-sized (for concrete
peripherals like
PA9
orSPI4
) or very small (for exampleAnyPin
, which is 1 byte). However&mut T
is always 4 bytes for 32-bit targets, even if T is zero-sized. Peripheral stores a copy ofT
instead, so it’s the same size. - Code size efficiency. If the user uses the same driver with both
SPI4
and&mut SPI4
, the driver code would be monomorphized two times. With Peri, the driver is generic over a lifetime only.SPI4
becomesPeri<'static, SPI4>
, and&mut SPI4
becomesPeri<'a, SPI4>
. Lifetimes don’t cause monomorphization.
Implementations§
Source§impl<'a, T> Peri<'a, T>where
T: PeripheralType,
impl<'a, T> Peri<'a, T>where
T: PeripheralType,
Sourcepub unsafe fn clone_unchecked(&self) -> Peri<'a, T>
pub unsafe fn clone_unchecked(&self) -> Peri<'a, T>
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 reborrow()
instead. It returns a
Peri
that borrows self
, which allows the borrow checker
to enforce this at compile time.
Sourcepub fn reborrow(&mut self) -> Peri<'_, T>
pub fn reborrow(&mut self) -> Peri<'_, T>
Reborrow into a “child” Peri.
self
will stay borrowed until the child Peripheral is dropped.
Sourcepub fn into<U>(self) -> Peri<'a, U>where
T: Into<U>,
U: PeripheralType,
pub fn into<U>(self) -> Peri<'a, U>where
T: Into<U>,
U: PeripheralType,
Map the inner peripheral using Into
.
This converts from Peri<'a, T>
to Peri<'a, U>
, using an
Into
impl to convert from T
to U
.
For example, this can be useful to.into() GPIO pins: converting from Peri<’a, PB11>to
Peri<’a, AnyPin>`.
Trait Implementations§
Source§impl<'a, T> Deref for Peri<'a, T>where
T: PeripheralType,
impl<'a, T> Deref for Peri<'a, T>where
T: PeripheralType,
Source§impl Input for Peri<'_, P0_13>
impl Input for Peri<'_, P0_13>
Source§fn degrade_saadc<'a>(self) -> AnyInput<'a>where
Self: 'a,
fn degrade_saadc<'a>(self) -> AnyInput<'a>where
Self: 'a,
AnyInput
. Read moreSource§impl Input for Peri<'_, P0_14>
impl Input for Peri<'_, P0_14>
Source§fn degrade_saadc<'a>(self) -> AnyInput<'a>where
Self: 'a,
fn degrade_saadc<'a>(self) -> AnyInput<'a>where
Self: 'a,
AnyInput
. Read moreSource§impl Input for Peri<'_, P0_15>
impl Input for Peri<'_, P0_15>
Source§fn degrade_saadc<'a>(self) -> AnyInput<'a>where
Self: 'a,
fn degrade_saadc<'a>(self) -> AnyInput<'a>where
Self: 'a,
AnyInput
. Read moreSource§impl Input for Peri<'_, P0_16>
impl Input for Peri<'_, P0_16>
Source§fn degrade_saadc<'a>(self) -> AnyInput<'a>where
Self: 'a,
fn degrade_saadc<'a>(self) -> AnyInput<'a>where
Self: 'a,
AnyInput
. Read moreSource§impl Input for Peri<'_, P0_17>
impl Input for Peri<'_, P0_17>
Source§fn degrade_saadc<'a>(self) -> AnyInput<'a>where
Self: 'a,
fn degrade_saadc<'a>(self) -> AnyInput<'a>where
Self: 'a,
AnyInput
. Read moreSource§impl Input for Peri<'_, P0_18>
impl Input for Peri<'_, P0_18>
Source§fn degrade_saadc<'a>(self) -> AnyInput<'a>where
Self: 'a,
fn degrade_saadc<'a>(self) -> AnyInput<'a>where
Self: 'a,
AnyInput
. Read more