Module stm32f7xx_hal::gpio [−][src]
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
- AlternateOD: Pin mode required when the pin is driven by other peripherals and has open drain
- Analog: Analog input to be used with ADC.
- 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.
Modules
GPIO
GPIO
GPIO
GPIO
GPIO
GPIO
GPIO
GPIO
GPIO
GPIO
GPIO
Structs
Some alternate mode (type state)
Some alternate mode in open drain configuration (type state)
Analog mode (type state)
Fully erased pin
Floating input (type state)
Input mode (type state)
A filler pin type
Open drain input or output (type state)
Output mode (type state)
Partially erased pin
Generic pin type
Pulled down input (type state)
Pulled up input (type state)
Push pull output (type state)
Enums
Constants
Traits
External Interrupt Pin
Extension trait to split a GPIO peripheral in independent pins and registers