Expand description
§Type-level module for GPIO pins
This module provides a type-level API for GPIO pins. It uses the type system
to track the state of pins at compile-time. Representing GPIO pins in this
manner incurs no run-time overhead. Each Pin struct is zero-sized, so
there is no data to copy around. Instead, real code is generated as a side
effect of type transformations, and the resulting assembly is nearly
identical to the equivalent, hand-written C.
To track the state of pins at compile-time, this module uses traits to
represent type classes and types as instances of those type classes. For
example, the trait InputConfig acts as a type-level enum of the
available input configurations, and the types Floating, PullDown and
PullUp are its type-level variants.
Type-level Pins are parameterized by two type-level enums, PinId and
PinMode.
pub struct Pin<I, M>
where
I: PinId,
M: PinMode,
{
// ...
}A PinId identifies a pin by it’s group (A, B, C or D) and pin number. Each
PinId instance is named according to its datasheet identifier, e.g.
PA02.
A PinMode represents the various pin modes. The available PinMode
variants are Disabled, Input, Interrupt, Output and
Alternate, each with its own corresponding configurations.
It is not possible for users to create new instances of a Pin. Singleton
instances of each pin are made available to users through the Pins
struct.
To create the Pins struct, users must supply the PAC
Port peripheral. The Pins struct takes
ownership of the Port and provides the corresponding pins. Each Pin
within the Pins struct can be moved out and used individually.
let mut peripherals = Peripherals::take().unwrap();
let pins = Pins::new(peripherals.Port);Pins can be converted between modes using several different methods.
// Use one of the literal function names
let pa27 = pins.pa27.into_floating_input();
// Use a generic method and one of the `PinMode` variant types
let pa27 = pins.pa27.into_mode::<FloatingInput>();
// Specify the target type and use `From`/`Into`
let pa27: Pin<PA27, FloatingInput> = pins.pa27.into();§Embedded HAL traits
This module implements all of the embedded HAL GPIO traits for each Pin
in the corresponding PinModes, namely: InputPin, OutputPin,
ToggleableOutputPin and StatefulOutputPin.
For example, you can control the logic level of an OutputPin like so
use atsamd_hal::pac::Peripherals;
use atsamd_hal::gpio::Pins;
use crate::ehal_02::digital::v2::OutputPin;
let mut peripherals = Peripherals::take().unwrap();
let mut pins = Pins::new(peripherals.Port);
pins.pa27.set_high();§Type-level features
This module also provides additional, type-level tools to work with GPIO pins.
The OptionalPinId and OptionalPin traits use the OptionalKind
pattern to act as type-level versions of Option for PinId and Pin
respectively. And the AnyPin trait defines an AnyKind type class
for all Pin types.
Structs§
- Alternate
- Type-level variant of
PinModefor alternate peripheral functions - Disabled
- Type-level variant of
PinModefor disabled modes - Input
- Type-level variant of
PinModefor input modes - Interrupt
- Type-level variant of
PinModefor Interrupt modes - Output
- Type-level variant of
PinModefor output modes - Pin
- A type-level GPIO pin, parameterized by
PinIdandPinModetypes - Pins
- Collection of all the individual
Pins
Enums§
- B
- Type-level variant of
AlternateConfigfor alternate peripheral function B - C
- Type-level variant of
AlternateConfigfor alternate peripheral function C - D
- Type-level variant of
AlternateConfigfor alternate peripheral function D - E
- Type-level variant of
AlternateConfigfor alternate peripheral function E - F
- Type-level variant of
AlternateConfigfor alternate peripheral function F - Floating
- Type-level variant of both
DisabledConfigandInputConfig - G
- Type-level variant of
AlternateConfigfor alternate peripheral function G - H
- Type-level variant of
AlternateConfigfor alternate peripheral function H - I
- Type-level variant of
AlternateConfigfor alternate peripheral function I - J
- Type-level variant of
AlternateConfigfor alternate peripheral function J - K
- Type-level variant of
AlternateConfigfor alternate peripheral function K - L
- Type-level variant of
AlternateConfigfor alternate peripheral function L - M
- Type-level variant of
AlternateConfigfor alternate peripheral function M - N
- Type-level variant of
AlternateConfigfor alternate peripheral function N - PA00
- Pin ID representing pin PA00
- PA01
- Pin ID representing pin PA01
- PA02
- Pin ID representing pin PA02
- PA03
- Pin ID representing pin PA03
- PA04
- Pin ID representing pin PA04
- PA05
- Pin ID representing pin PA05
- PA06
- Pin ID representing pin PA06
- PA07
- Pin ID representing pin PA07
- PA08
- Pin ID representing pin PA08
- PA09
- Pin ID representing pin PA09
- PA10
- Pin ID representing pin PA10
- PA11
- Pin ID representing pin PA11
- PA12
- Pin ID representing pin PA12
- PA13
- Pin ID representing pin PA13
- PA14
- Pin ID representing pin PA14
- PA15
- Pin ID representing pin PA15
- PA16
- Pin ID representing pin PA16
- PA17
- Pin ID representing pin PA17
- PA18
- Pin ID representing pin PA18
- PA19
- Pin ID representing pin PA19
- PA20
- Pin ID representing pin PA20
- PA21
- Pin ID representing pin PA21
- PA22
- Pin ID representing pin PA22
- PA23
- Pin ID representing pin PA23
- PA24
- Pin ID representing pin PA24
- PA25
- Pin ID representing pin PA25
- PA27
- Pin ID representing pin PA27
- PA30
- Pin ID representing pin PA30
- PA31
- Pin ID representing pin PA31
- PB00
- Pin ID representing pin PB00
- PB01
- Pin ID representing pin PB01
- PB02
- Pin ID representing pin PB02
- PB03
- Pin ID representing pin PB03
- PB04
- Pin ID representing pin PB04
- PB05
- Pin ID representing pin PB05
- PB06
- Pin ID representing pin PB06
- PB07
- Pin ID representing pin PB07
- PB08
- Pin ID representing pin PB08
- PB09
- Pin ID representing pin PB09
- PB10
- Pin ID representing pin PB10
- PB11
- Pin ID representing pin PB11
- PB12
- Pin ID representing pin PB12
- PB13
- Pin ID representing pin PB13
- PB14
- Pin ID representing pin PB14
- PB15
- Pin ID representing pin PB15
- PB16
- Pin ID representing pin PB16
- PB17
- Pin ID representing pin PB17
- PB22
- Pin ID representing pin PB22
- PB23
- Pin ID representing pin PB23
- PB30
- Pin ID representing pin PB30
- PB31
- Pin ID representing pin PB31
- Pull
Down - Type-level variant of both
DisabledConfigandInputConfig - PullUp
- Type-level variant of both
DisabledConfigandInputConfig - Push
Pull - Type-level variant of
OutputConfigfor a push-pull configuration - Readable
- Type-level variant of
OutputConfigfor a readable push-pull configuration
Traits§
- Alternate
Config - Type-level enum for alternate peripheral function configurations
- AnyPin
- Type class for
Pintypes - Disabled
Config - Type-level enum for disabled configurations
- Input
Config - Type-level enum for input configurations
- Interrupt
Config - Type-level
enumfor Interrupt configurations - Optional
Pin - Type-level equivalent of
Option<PinId> - Optional
PinId - Type-level equivalent of
Option<PinId> - Output
Config - Type-level enum for output configurations
- PinId
- Type-level enum for pin IDs
- PinMode
- Type-level enum representing pin modes
- SomePin
- Type-level equivalent of
Some(PinId) - Some
PinId - Type-level equivalent of
Some(PinId)
Type Aliases§
- AlternateB
- Type-level variant of
PinModefor alternate peripheral functionB - AlternateC
- Type-level variant of
PinModefor alternate peripheral functionC - AlternateD
- Type-level variant of
PinModefor alternate peripheral functionD - AlternateE
- Type-level variant of
PinModefor alternate peripheral functionE - AlternateF
- Type-level variant of
PinModefor alternate peripheral functionF - AlternateG
- Type-level variant of
PinModefor alternate peripheral functionG - AlternateH
- Type-level variant of
PinModefor alternate peripheral functionH - AlternateI
- Type-level variant of
PinModefor alternate peripheral functionI - AlternateJ
- Type-level variant of
PinModefor alternate peripheral functionJ - AlternateK
- Type-level variant of
PinModefor alternate peripheral functionK - AlternateL
- Type-level variant of
PinModefor alternate peripheral functionL - AlternateM
- Type-level variant of
PinModefor alternate peripheral functionM - AlternateN
- Type-level variant of
PinModefor alternate peripheral functionN - Floating
Disabled - Type-level variant of
PinModefor floating disabled mode - Floating
Input - Type-level variant of
PinModefor floating input mode - Floating
Interrupt - Type-level variant of
PinModefor floating Interrupt mode - Pull
Down Disabled - Type-level variant of
PinModefor pull-down disabled mode - Pull
Down Input - Type-level variant of
PinModefor pull-down input mode - Pull
Down Interrupt - Type-level variant of
PinModefor pull-down Interrupt mode - Pull
UpDisabled - Type-level variant of
PinModefor pull-up disabled mode - Pull
UpInput - Type-level variant of
PinModefor pull-up input mode - Pull
UpInterrupt - Type-level variant of
PinModefor pull-up Interrupt mode - Push
Pull Output - Type-level variant of
PinModefor push-pull output mode - Readable
Output - Type-level variant of
PinModefor readable push-pull output mode - Reset
- Type alias for the
PinModeat reset - Specific
Pin - Type alias to recover the specific
Pintype from an implementation ofAnyPin