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

A value-level pin, parameterized by DynPinId and DynPinMode
Value-level struct representing pin IDs

Enums

Value-level enum for alternate peripheral function configurations
Value-level enum for disabled configurations
Value-level enum for pin groups
Value-level enum for input configurations
Value-level enum for interrupt configurations
Value-level enum for output configurations
Value-level enum representing pin modes
GPIO error type

Constants

Value-level variant of DynPinMode for alternate peripheral function B
Value-level variant of DynPinMode for alternate peripheral function C
Value-level variant of DynPinMode for alternate peripheral function D
Value-level variant of DynPinMode for alternate peripheral function E
Value-level variant of DynPinMode for alternate peripheral function F
Value-level variant of DynPinMode for alternate peripheral function G
Value-level variant of DynPinMode for alternate peripheral function H
Value-level variant of DynPinMode for floating disabled mode
Value-level variant of DynPinMode for floating input mode
Value-level variant of DynPinMode for floating interrupt mode
Value-level variant of DynPinMode for pull-down disabled mode
Value-level variant of DynPinMode for pull-down input mode
Value-level variant of DynPinMode for pull-down interrupt mode
Value-level variant of DynPinMode for pull-up disabled mode
Value-level variant of DynPinMode for pull-up input mode
Value-level variant of DynPinMode for pull-up interrupt mode
Value-level variant of DynPinMode for push-pull output mode
Value-level variant of DynPinMode for readable push-pull output mode