Module gpio

Source
Expand description

General Purpose Input / Output

The GPIO pins are organised into groups of 16 pins which can be accessed through the gpioa, gpiob… modules. To get access to the pins, you first need to convert them into a HAL designed struct from the pac struct using the split function.

// Acquire the GPIOC peripheral
// NOTE: `dp` is the device peripherals from the `PAC` crate
let mut gpioa = dp.GPIOA.split();

This gives you a struct containing all the pins px0..px15. By default pins are in floating input mode. You can change their modes. For example, to set pa5 high, you would call

let output = gpioa.pa5.into_push_pull_output();
output.set_high();

§Modes

Each GPIO pin can be set to various modes:

  • Alternate: Pin mode required when the pin is driven by other peripherals
  • Analog: Analog input to be used with ADC.
  • Dynamic: Pin mode is selected at runtime. See changing configurations for more details
  • Input
    • PullUp: Input connected to high with a weak pull up resistor. Will be high when nothing is connected
    • PullDown: Input connected to high with a weak pull up resistor. Will be low when nothing is connected
    • Floating: Input not pulled to high or low. Will be undefined when nothing is connected
  • Output
    • PushPull: Output which either drives the pin high or low
    • OpenDrain: Output which leaves the gate floating, or pulls it do ground in drain mode. Can be used as an input in the open configuration

§Changing modes

The simplest way to change the pin mode is to use the into_<mode> functions. These return a new struct with the correct mode that you can use the input or output functions on.

If you need a more temporary mode change, and can not use the into_<mode> functions for ownership reasons, you can use the closure based with_<mode> functions to temporarily change the pin type, do some output or input, and then have it change back once done.

§Dynamic Mode Change

The above mode change methods guarantee that you can only call input functions when the pin is in input mode, and output when in output modes, but can lead to some issues. Therefore, there is also a mode where the state is kept track of at runtime, allowing you to change the mode often, and without problems with ownership, or references, at the cost of some performance and the risk of runtime errors.

To make a pin dynamic, use the into_dynamic function, and then use the make_<mode> functions to change the mode

Re-exports§

pub use gpioa::PA0;
pub use gpioa::PA1;
pub use gpioa::PA2;
pub use gpioa::PA3;
pub use gpioa::PA4;
pub use gpioa::PA5;
pub use gpioa::PA6;
pub use gpioa::PA7;
pub use gpioa::PA8;
pub use gpioa::PA9;
pub use gpioa::PA10;
pub use gpioa::PA11;
pub use gpioa::PA12;
pub use gpioa::PA13;
pub use gpioa::PA14;
pub use gpioa::PA15;
pub use gpiob::PB0;
pub use gpiob::PB1;
pub use gpiob::PB2;
pub use gpiob::PB3;
pub use gpiob::PB4;
pub use gpiob::PB5;
pub use gpiob::PB6;
pub use gpiob::PB7;
pub use gpiob::PB8;
pub use gpiob::PB9;
pub use gpiob::PB10;
pub use gpiob::PB11;
pub use gpiob::PB12;
pub use gpiob::PB13;
pub use gpiob::PB14;
pub use gpiob::PB15;
pub use gpioc::PC0;
pub use gpioc::PC1;
pub use gpioc::PC2;
pub use gpioc::PC3;
pub use gpioc::PC4;
pub use gpioc::PC5;
pub use gpioc::PC6;
pub use gpioc::PC7;
pub use gpioc::PC8;
pub use gpioc::PC9;
pub use gpioc::PC10;
pub use gpioc::PC11;
pub use gpioc::PC12;
pub use gpioc::PC13;
pub use gpioc::PC14;
pub use gpioc::PC15;
pub use gpiod::PD0;
pub use gpiod::PD1;
pub use gpiod::PD2;
pub use gpiod::PD3;
pub use gpiod::PD4;
pub use gpiod::PD5;
pub use gpiod::PD6;
pub use gpiod::PD7;
pub use gpiod::PD8;
pub use gpiod::PD9;
pub use gpiod::PD10;
pub use gpiod::PD11;
pub use gpiod::PD12;
pub use gpiod::PD13;
pub use gpiod::PD14;
pub use gpiod::PD15;
pub use gpioe::PE0;
pub use gpioe::PE1;
pub use gpioe::PE2;
pub use gpioe::PE3;
pub use gpioe::PE4;
pub use gpioe::PE5;
pub use gpioe::PE6;
pub use gpioe::PE7;
pub use gpioe::PE8;
pub use gpioe::PE9;
pub use gpioe::PE10;
pub use gpioe::PE11;
pub use gpioe::PE12;
pub use gpioe::PE13;
pub use gpioe::PE14;
pub use gpioe::PE15;
pub use gpiof::PF0;
pub use gpiof::PF1;
pub use gpiof::PF2;
pub use gpiof::PF3;
pub use gpiof::PF4;
pub use gpiof::PF5;
pub use gpiof::PF6;
pub use gpiof::PF7;
pub use gpiof::PF8;
pub use gpiof::PF9;
pub use gpiof::PF10;
pub use gpiof::PF11;
pub use gpiof::PF12;
pub use gpiof::PF13;
pub use gpiof::PF14;
pub use gpiof::PF15;
pub use gpiog::PG0;
pub use gpiog::PG1;
pub use gpiog::PG2;
pub use gpiog::PG3;
pub use gpiog::PG4;
pub use gpiog::PG5;
pub use gpiog::PG6;
pub use gpiog::PG7;
pub use gpiog::PG8;
pub use gpiog::PG9;
pub use gpiog::PG10;
pub use gpiog::PG11;
pub use gpiog::PG12;
pub use gpiog::PG13;
pub use gpiog::PG14;
pub use gpiog::PG15;
pub use gpioh::PH0;
pub use gpioh::PH1;
pub use gpioh::PH2;
pub use gpioh::PH3;
pub use gpioh::PH4;
pub use gpioh::PH5;
pub use gpioh::PH6;
pub use gpioh::PH7;
pub use gpioh::PH8;
pub use gpioh::PH9;
pub use gpioh::PH10;
pub use gpioh::PH11;
pub use gpioh::PH12;
pub use gpioh::PH13;
pub use gpioh::PH14;
pub use gpioh::PH15;
pub use gpioi::PI0;
pub use gpioi::PI1;
pub use gpioi::PI2;
pub use gpioi::PI3;
pub use gpioi::PI4;
pub use gpioi::PI5;
pub use gpioi::PI6;
pub use gpioi::PI7;
pub use gpioi::PI8;
pub use gpioi::PI9;
pub use gpioi::PI10;
pub use gpioi::PI11;
pub use gpioi::PI12;
pub use gpioi::PI13;
pub use gpioi::PI14;
pub use gpioi::PI15;
pub use gpioj::PJ0;
pub use gpioj::PJ1;
pub use gpioj::PJ2;
pub use gpioj::PJ3;
pub use gpioj::PJ4;
pub use gpioj::PJ5;
pub use gpioj::PJ6;
pub use gpioj::PJ7;
pub use gpioj::PJ8;
pub use gpioj::PJ9;
pub use gpioj::PJ10;
pub use gpioj::PJ11;
pub use gpioj::PJ12;
pub use gpioj::PJ13;
pub use gpioj::PJ14;
pub use gpioj::PJ15;
pub use gpiok::PK0;
pub use gpiok::PK1;
pub use gpiok::PK2;
pub use gpiok::PK3;
pub use gpiok::PK4;
pub use gpiok::PK5;
pub use gpiok::PK6;
pub use gpiok::PK7;

Modules§

gpioa
GPIO
gpiob
GPIO
gpioc
GPIO
gpiod
GPIO
gpioe
GPIO
gpiof
GPIO
gpiog
GPIO
gpioh
GPIO
gpioi
GPIO
gpioj
GPIO
gpiok
GPIO

Structs§

Alternate
Some alternate mode (type state)
Analog
Analog mode (type state)
DynamicPin
Pin type with dynamic mode
ErasedPin
Fully erased pin
Floating
Floating input (type state)
Input
Input mode (type state)
NoPin
A filler pin type
OpenDrain
Open drain input or output (type state)
Output
Output mode (type state)
PartiallyErasedPin
Partially erased pin
Pin
Generic pin type
PullDown
Pulled down input (type state)
PullUp
Pulled up input (type state)
PushPull
Push pull output (type state)

Enums§

Dynamic
Tracks the current pin state for dynamic pins
Edge
PinState
Digital output pin state
Speed
GPIO Pin speed selection

Traits§

ExtiPin
External Interrupt Pin
GpioExt
Extension trait to split a GPIO peripheral in independent pins and registers
PinExt

Type Aliases§

Debugger
EPin
PEPin