G4 GPIO public API.
More...
#include <stddef.h>
#include <stdint.h>
#include "stm32g474xx.h"
Go to the source code of this file.
|
| #define | PHAL_GPIO_INIT_INPUT(gpio_bank, pin_num, input_pull_sel) |
| | Construct PHAL_GPIO_InitConfig_t for an input pin.
|
| |
| #define | PHAL_GPIO_INIT_OUTPUT(gpio_bank, pin_num, ospeed_sel) |
| | Construct PHAL_GPIO_InitConfig_t for an output (push-pull) pin.
|
| |
| #define | PHAL_GPIO_INIT_OUTPUT_OPEN_DRAIN(gpio_bank, pin_num, ospeed_sel) |
| | Construct PHAL_GPIO_InitConfig_t for an output (open-drain) pin.
|
| |
| #define | PHAL_GPIO_INIT_ANALOG(gpio_bank, pin_num) |
| | Construct PHAL_GPIO_InitConfig_t for an analog pin.
|
| |
| #define | PHAL_GPIO_INIT_AF(gpio_bank, pin_num, alt_func_num, ospeed_sel, otype_sel, input_pull_sel) |
| | Construct PHAL_GPIO_InitConfig_t for an alternate function pin.
|
| |
◆ PHAL_GPIO_INIT_AF
| #define PHAL_GPIO_INIT_AF |
( |
| gpio_bank, |
|
|
| pin_num, |
|
|
| alt_func_num, |
|
|
| ospeed_sel, |
|
|
| otype_sel, |
|
|
| input_pull_sel ) |
Value: { \
.bank = gpio_bank, \
.pin = pin_num, \
.config = { \
.af = { \
.af_num = alt_func_num, \
.ospeed = ospeed_sel, \
.otype = otype_sel, \
.pull = input_pull_sel \
} \
} \
}
@ GPIO_TYPE_AF
Definition gpio.h:24
Construct PHAL_GPIO_InitConfig_t for an alternate function pin.
- Parameters
-
| gpio_bank | GPIO_TypeDef* for the pin's port |
| pin_num | Pin number, 0-15 |
| alt_func_num | Alternate function selection |
| ospeed_sel | Output speed selection |
| otype_sel | Output drive type selection |
| input_pull_sel | Pull-up/pull-down/high-z selection |
◆ PHAL_GPIO_INIT_ANALOG
| #define PHAL_GPIO_INIT_ANALOG |
( |
| gpio_bank, |
|
|
| pin_num ) |
Value: { \
.bank = gpio_bank, \
.pin = pin_num, \
}
@ GPIO_TYPE_ANALOG
Definition gpio.h:25
Construct PHAL_GPIO_InitConfig_t for an analog pin.
- Parameters
-
| gpio_bank | GPIO_TypeDef* for the pin's port |
| pin_num | Pin number, 0-15 |
◆ PHAL_GPIO_INIT_INPUT
| #define PHAL_GPIO_INIT_INPUT |
( |
| gpio_bank, |
|
|
| pin_num, |
|
|
| input_pull_sel ) |
Value: { \
.bank = gpio_bank, \
.pin = pin_num, \
.config = { \
.input = { \
.pull = input_pull_sel \
} \
} \
}
@ GPIO_TYPE_INPUT
Definition gpio.h:22
Construct PHAL_GPIO_InitConfig_t for an input pin.
- Parameters
-
| gpio_bank | GPIO_TypeDef* for the pin's port |
| pin_num | Pin number, 0-15 |
| input_pull_sel | Pull-up/pull-down/high-z selection |
◆ PHAL_GPIO_INIT_OUTPUT
| #define PHAL_GPIO_INIT_OUTPUT |
( |
| gpio_bank, |
|
|
| pin_num, |
|
|
| ospeed_sel ) |
Value: { \
.bank = gpio_bank, \
.pin = pin_num, \
.config = { \
.output = { \
.ospeed = ospeed_sel, \
} \
} \
}
@ GPIO_OUTPUT_PUSH_PULL
Definition gpio.h:42
@ GPIO_TYPE_OUTPUT
Definition gpio.h:23
Construct PHAL_GPIO_InitConfig_t for an output (push-pull) pin.
- Parameters
-
| gpio_bank | GPIO_TypeDef* for the pin's port |
| pin_num | Pin number, 0-15 |
| ospeed_sel | Output speed selection |
◆ PHAL_GPIO_INIT_OUTPUT_OPEN_DRAIN
| #define PHAL_GPIO_INIT_OUTPUT_OPEN_DRAIN |
( |
| gpio_bank, |
|
|
| pin_num, |
|
|
| ospeed_sel ) |
Value: { \
.bank = gpio_bank, \
.pin = pin_num, \
.config = { \
.output = { \
.ospeed = ospeed_sel, \
} \
} \
}
@ GPIO_OUTPUT_OPEN_DRAIN
Definition gpio.h:43
Construct PHAL_GPIO_InitConfig_t for an output (open-drain) pin.
- Parameters
-
| gpio_bank | GPIO_TypeDef* for the pin's port |
| pin_num | Pin number, 0-15 |
| ospeed_sel | Output speed selection |
◆ PHAL_GPIO_InputPull_t
Input pin pull-up/pull-down resistor selection.
| Enumerator |
|---|
| GPIO_INPUT_OPEN_DRAIN | No internal pull up/down
|
| GPIO_INPUT_PULL_UP | Weak internal pull-up enabled
|
| GPIO_INPUT_PULL_DOWN | Weak internal pull-down enabled
|
◆ PHAL_GPIO_OutputPull_t
Output pin drive type.
| Enumerator |
|---|
| GPIO_OUTPUT_PUSH_PULL | Drive the output pin high and low
|
| GPIO_OUTPUT_OPEN_DRAIN | Drive the output pin low, high-z otherwise
|
◆ PHAL_GPIO_OutputSpeed_t
Output pin slew rate / maximum toggle frequency.
| Enumerator |
|---|
| GPIO_OUTPUT_LOW_SPEED | Slew rate control, max 8Mhz
|
| GPIO_OUTPUT_MED_SPEED | Slew rate control, max 50Mhz
|
| GPIO_OUTPUT_HIGH_SPEED | Slew rate control, max 100Mhz
|
| GPIO_OUTPUT_ULTRA_SPEED | Slew rate control, max 180Mhz
|
◆ PHAL_GPIO_PinType_t
GPIO pin mode.
Is the key for the config tagged union in PHAL_GPIO_PinType_t
| Enumerator |
|---|
| GPIO_TYPE_INPUT | |
| GPIO_TYPE_OUTPUT | |
| GPIO_TYPE_AF | |
| GPIO_TYPE_ANALOG | |
◆ PHAL_GPIO_init()
Initialize a set of GPIO pins from a configuration table.
Enables each pin's port clock, then configures mode, speed, drive type, pull, and alternate function per entry as applicable to that entry's PHAL_GPIO_PinType_t
Register fields that don't apply to a given type (ex: pull for an output pin) are left untouched.
When encountering an unknown bank, pin outside 0-15, or unrecognized type, stops and returns false. Already configured pins remain configured.
- Parameters
-
| config | Array of pin configurations |
| config_len | Number of entries in config |
- Returns
- true if every entry was valid (bank, pin #, type) and configured; false otherwise
◆ PHAL_GPIO_read()
| bool PHAL_GPIO_read |
( |
const GPIO_TypeDef * | bank, |
|
|
uint8_t | pin ) |
Read the current input state of a pin.
- Parameters
-
| bank | GPIO port |
| pin | Pin number, 0-15 |
- Returns
- true if the pin currently reads high
◆ PHAL_GPIO_toggle()
| void PHAL_GPIO_toggle |
( |
GPIO_TypeDef * | bank, |
|
|
uint8_t | pin ) |
Flip an output pin's current state.
- Parameters
-
| bank | GPIO port |
| pin | Pin number, 0-15 |
◆ PHAL_GPIO_write()
| void PHAL_GPIO_write |
( |
GPIO_TypeDef * | bank, |
|
|
uint8_t | pin, |
|
|
bool | value ) |
Drive an output pin high or low.
Safe to call from an ISR concurrently with other threads/etc touching other pins on the same port
- Parameters
-
| bank | GPIO port |
| pin | Pin number, 0-15 |
| value | true to drive high, false to drive low |