Module dynpin

Source
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 and DynPinMode
DynPinId
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
DynPinMode
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