PER Firmware
Loading...
Searching...
No Matches
gpio.h
Go to the documentation of this file.
1
6#ifndef PHAL_G4_GPIO_H
7#define PHAL_G4_GPIO_H
8
9#include <stddef.h>
10#include <stdint.h>
11
12#include "stm32g474xx.h"
13
25
42
51
52
58typedef struct {
59 GPIO_TypeDef *bank;
60 uint8_t pin;
63 union {
64 struct {
66 } input;
68 struct {
71 } output;
73 struct {
74 uint8_t af_num;
78 } af;
80 // GPIO_TYPE_ANALOG needs no additional configuration
83
101bool PHAL_GPIO_init(PHAL_GPIO_InitConfig_t config[], size_t config_len);
102
109bool PHAL_GPIO_read(const GPIO_TypeDef *bank, uint8_t pin);
110
121void PHAL_GPIO_write(GPIO_TypeDef *bank, uint8_t pin, bool value);
122
128void PHAL_GPIO_toggle(GPIO_TypeDef *bank, uint8_t pin);
129
136#define PHAL_GPIO_INIT_INPUT(gpio_bank, pin_num, input_pull_sel) \
137 { \
138 .bank = gpio_bank, \
139 .pin = pin_num, \
140 .type = GPIO_TYPE_INPUT, \
141 .config = { \
142 .input = { \
143 .pull = input_pull_sel \
144 } \
145 } \
146 }
147
154#define PHAL_GPIO_INIT_OUTPUT(gpio_bank, pin_num, ospeed_sel) \
155 { \
156 .bank = gpio_bank, \
157 .pin = pin_num, \
158 .type = GPIO_TYPE_OUTPUT, \
159 .config = { \
160 .output = { \
161 .ospeed = ospeed_sel, \
162 .otype = GPIO_OUTPUT_PUSH_PULL \
163 } \
164 } \
165 }
166
173#define PHAL_GPIO_INIT_OUTPUT_OPEN_DRAIN(gpio_bank, pin_num, ospeed_sel) \
174 { \
175 .bank = gpio_bank, \
176 .pin = pin_num, \
177 .type = GPIO_TYPE_OUTPUT, \
178 .config = { \
179 .output = { \
180 .ospeed = ospeed_sel, \
181 .otype = GPIO_OUTPUT_OPEN_DRAIN \
182 } \
183 } \
184 }
185
191#define PHAL_GPIO_INIT_ANALOG(gpio_bank, pin_num) \
192 { \
193 .bank = gpio_bank, \
194 .pin = pin_num, \
195 .type = GPIO_TYPE_ANALOG \
196 }
197
207#define PHAL_GPIO_INIT_AF(gpio_bank, pin_num, alt_func_num, ospeed_sel, otype_sel, input_pull_sel) \
208 { \
209 .bank = gpio_bank, \
210 .pin = pin_num, \
211 .type = GPIO_TYPE_AF, \
212 .config = { \
213 .af = { \
214 .af_num = alt_func_num, \
215 .ospeed = ospeed_sel, \
216 .otype = otype_sel, \
217 .pull = input_pull_sel \
218 } \
219 } \
220 }
221
222#endif // PHAL_G4_GPIO_H
static ethernet_config_t config
Definition ethernet.c:22
@ GPIO_OUTPUT_OPEN_DRAIN
Definition gpio.h:43
@ GPIO_OUTPUT_PUSH_PULL
Definition gpio.h:42
static void PHAL_GPIO_write(GPIO_TypeDef *bank, uint8_t pin, bool value)
Write a logic value to an output pin.
Definition gpio.h:230
@ GPIO_TYPE_AF
Definition gpio.h:24
@ GPIO_TYPE_INPUT
Definition gpio.h:22
@ GPIO_TYPE_OUTPUT
Definition gpio.h:23
@ GPIO_TYPE_ANALOG
Definition gpio.h:25
static void PHAL_GPIO_toggle(GPIO_TypeDef *bank, uint8_t pin)
Definition gpio.h:234
static bool PHAL_GPIO_read(GPIO_TypeDef *bank, uint8_t pin)
Read the state of the input register for the specific GPIO pin.
Definition gpio.h:219
@ GPIO_INPUT_PULL_UP
Definition gpio.h:51
@ GPIO_INPUT_OPEN_DRAIN
Definition gpio.h:50
@ GPIO_INPUT_PULL_DOWN
Definition gpio.h:52
@ GPIO_OUTPUT_HIGH_SPEED
Definition gpio.h:34
@ GPIO_OUTPUT_MED_SPEED
Definition gpio.h:33
@ GPIO_OUTPUT_LOW_SPEED
Definition gpio.h:32
@ GPIO_OUTPUT_ULTRA_SPEED
Definition gpio.h:35
PHAL_GPIO_OutputSpeed_t
Output pin slew rate / maximum toggle frequency.
Definition gpio.h:29
PHAL_GPIO_PinType_t
GPIO pin mode.
Definition gpio.h:19
PHAL_GPIO_InputPull_t
Input pin pull-up/pull-down resistor selection.
Definition gpio.h:46
PHAL_GPIO_OutputPull_t
Output pin drive type.
Definition gpio.h:38
bool PHAL_GPIO_init(PHAL_GPIO_InitConfig_t config[], size_t config_len)
Initialize a set of GPIO pins from a configuration table.
Definition gpio.c:11
Configuration entry for GPIO initialization.
Definition gpio.h:58
PHAL_GPIO_PinType_t type
Definition gpio.h:61
GPIO_TypeDef * bank
Definition gpio.h:59
PHAL_GPIO_InputPull_t pull
Definition gpio.h:65
PHAL_GPIO_OutputSpeed_t ospeed
Definition gpio.h:69
PHAL_GPIO_OutputPull_t otype
Definition gpio.h:70
uint8_t af_num
Definition gpio.h:74
uint8_t pin
Definition gpio.h:60