Module gpio

Source
Expand description

This module provides functionality for General Purpose Input and Output (GPIO) pins, including all GPIOx register functions. It also configures GPIO interrupts using SYSCFG and EXTI registers as appropriate. It allows pin mode configuration, interrupts, and DMA.

The primary API uses a Pin struct, with its methods. There are also standalone functions available to set and read pin state, and clear interrupts, without access to a Pin.

Structs§

Pin
Represents a single GPIO pin. Allows configuration, and reading/setting state.

Enums§

CfgLock
Values for GPIOx_LCKR.
Edge
The pulse edge used to trigger interrupts. Either rising, falling, or either.
OutputSpeed
Values for GPIOx_OSPEEDR. This configures I/O output speed. See the user manual for your MCU for what speeds these are. Note that Fast speed (0b10) is not available on all STM32 families.
OutputType
Values for GPIOx_OTYPER.
PinMode
Values for GPIOx_MODER. Sets pin to input, output, and other functionality.
PinState
Values for GPIOx_IDR and GPIOx_ODR.
Port
GPIO port letter
Pull
Values for GPIOx_PUPDR. Sets if the pin uses the internal pull-up or pull-down
ResetState
Values for GPIOx_BRR.

Functions§

clear_exti_interrupt
Clear an EXTI interrupt, lines 0 - 15. Note that this function currently doesn’t support higher extis, but will work for all GPIO interrupts.
is_high
Check if a pin’s input voltage is high. Reads from the IDR register. Does not require a Pin struct.
is_low
Check if a pin’s input voltage is low. Reads from the IDR register. Does not require a Pin struct.
read_dma
Read a series of words from the IDR register.
set_high
Set a pin’s output voltage to high. Sets the BSRR register. Atomic. Does not require a Pin struct.
set_low
Set a pin’s output voltage to low. Sets the BSRR register. Atomic. Does not require a Pin struct.
set_state
Set a pin state (ie set high or low output voltage level). See also set_high() and set_low(). Sets the BSRR register. Atomic. Does not require a Pin struct.
write_dma
Write a series of words to the BSRR (atomic output) register. Note that these are direct writes to the full, 2-sided register - not a series of low/high values.