Expand description
§Type-erased, value-level module for GPIO pins
Although the type-level API is generally preferred, it is not suitable in all cases. Because each pin is represented by a distinct type, it is not possible to store multiple pins in a homogeneous data structure. The value-level API solves this problem by erasing the type information and tracking the pin at run-time.
Value-level pins are represented by the DynPin
type. DynPin
has two
fields, id
and mode
with types DynPinId
and DynPinMode
respectively. The implementation of these types closely mirrors the
type-level API.
Instances of DynPin
cannot be created directly. Rather, they must be
created from their type-level equivalents using From
/Into
.
// Move a pin out of the Pins struct and convert to a DynPin
let pa27: DynPin = pins.pa27.into();
Conversions between pin modes use a value-level version of the type-level API.
// Use one of the literal function names
pa27.into_floating_input();
// Use a method and a DynPinMode variant
pa27.into_mode(DYN_FLOATING_INPUT);
Because the pin state cannot be tracked at compile-time, many DynPin
operations become fallible. Run-time checks are inserted to ensure that
users don’t try to, for example, set the output level of an input pin.
Users may try to convert value-level pins back to their type-level
equivalents. However, this option is fallible, because the compiler cannot
guarantee the pin has the correct ID or is in the correct mode at
compile-time. Use TryFrom
/TryInto
for this conversion.
// Convert to a `DynPin`
let pa27: DynPin = pins.pa27.into();
// Change pin mode
pa27.into_floating_input();
// Convert back to a `Pin`
let pa27: Pin<PA27, FloatingInput> = pa27.try_into().unwrap();
§Embedded HAL traits
This module implements all of the embedded HAL GPIO traits for DynPin
.
However, whereas the type-level API uses
Error = core::convert::Infallible
, the value-level API can return a real
error. If the DynPin
is not in the correct DynPinMode
for the
operation, the trait functions will return
InvalidPinType
.
Structs§
- DynPin
- A value-level pin, parameterized by
DynPinId
andDynPinMode
- DynPin
Id - Value-level
struct
representing pin IDs
Enums§
- DynAlternate
- Value-level
enum
for alternate peripheral function configurations - DynDisabled
- Value-level
enum
for disabled configurations - DynGroup
- Value-level
enum
for pin groups - DynInput
- Value-level
enum
for input configurations - DynInterrupt
- Value-level
enum
for interrupt configurations - DynOutput
- Value-level
enum
for output configurations - DynPin
Mode - Value-level
enum
representing pin modes - Error
- GPIO error type
Constants§
- DYN_
ALTERNATE_ B - Value-level variant of
DynPinMode
for alternate peripheral function B - DYN_
ALTERNATE_ C - Value-level variant of
DynPinMode
for alternate peripheral function C - DYN_
ALTERNATE_ D - Value-level variant of
DynPinMode
for alternate peripheral function D - DYN_
ALTERNATE_ E - Value-level variant of
DynPinMode
for alternate peripheral function E - DYN_
ALTERNATE_ F - Value-level variant of
DynPinMode
for alternate peripheral function F - DYN_
ALTERNATE_ G - Value-level variant of
DynPinMode
for alternate peripheral function G - DYN_
ALTERNATE_ H - Value-level variant of
DynPinMode
for alternate peripheral function H - DYN_
ALTERNATE_ I - Value-level variant of
DynPinMode
for alternate peripheral function I - DYN_
ALTERNATE_ J - Value-level variant of
DynPinMode
for alternate peripheral function J - DYN_
ALTERNATE_ K - Value-level variant of
DynPinMode
for alternate peripheral function K - DYN_
ALTERNATE_ L - Value-level variant of
DynPinMode
for alternate peripheral function L - DYN_
ALTERNATE_ M - Value-level variant of
DynPinMode
for alternate peripheral function M - DYN_
ALTERNATE_ N - Value-level variant of
DynPinMode
for alternate peripheral function N - DYN_
FLOATING_ DISABLED - Value-level variant of
DynPinMode
for floating disabled mode - DYN_
FLOATING_ INPUT - Value-level variant of
DynPinMode
for floating input mode - DYN_
FLOATING_ INTERRUPT - Value-level variant of
DynPinMode
for floating interrupt mode - DYN_
PULL_ DOWN_ DISABLED - Value-level variant of
DynPinMode
for pull-down disabled mode - DYN_
PULL_ DOWN_ INPUT - Value-level variant of
DynPinMode
for pull-down input mode - DYN_
PULL_ DOWN_ INTERRUPT - Value-level variant of
DynPinMode
for pull-down interrupt mode - DYN_
PULL_ UP_ DISABLED - Value-level variant of
DynPinMode
for pull-up disabled mode - DYN_
PULL_ UP_ INPUT - Value-level variant of
DynPinMode
for pull-up input mode - DYN_
PULL_ UP_ INTERRUPT - Value-level variant of
DynPinMode
for pull-up interrupt mode - DYN_
PUSH_ PULL_ OUTPUT - Value-level variant of
DynPinMode
for push-pull output mode - DYN_
READABLE_ OUTPUT - Value-level variant of
DynPinMode
for readable push-pull output mode