PER Firmware
Loading...
Searching...
No Matches
gpio.h File Reference

G4 GPIO public API. More...

#include <stddef.h>
#include <stdint.h>
#include "stm32g474xx.h"
Include dependency graph for gpio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  PHAL_GPIO_InitConfig_t
 Configuration entry for GPIO initialization. More...
 

Macros

#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.
 

Enumerations

enum  PHAL_GPIO_PinType_t { GPIO_TYPE_INPUT , GPIO_TYPE_OUTPUT , GPIO_TYPE_AF , GPIO_TYPE_ANALOG }
 GPIO pin mode. More...
 
enum  PHAL_GPIO_OutputSpeed_t { GPIO_OUTPUT_LOW_SPEED , GPIO_OUTPUT_MED_SPEED , GPIO_OUTPUT_HIGH_SPEED , GPIO_OUTPUT_ULTRA_SPEED }
 Output pin slew rate / maximum toggle frequency. More...
 
enum  PHAL_GPIO_OutputPull_t { GPIO_OUTPUT_PUSH_PULL , GPIO_OUTPUT_OPEN_DRAIN }
 Output pin drive type. More...
 
enum  PHAL_GPIO_InputPull_t { GPIO_INPUT_OPEN_DRAIN , GPIO_INPUT_PULL_UP , GPIO_INPUT_PULL_DOWN }
 Input pin pull-up/pull-down resistor selection. More...
 

Functions

bool PHAL_GPIO_init (PHAL_GPIO_InitConfig_t config[], size_t config_len)
 Initialize a set of GPIO pins from a configuration table.
 
bool PHAL_GPIO_read (const GPIO_TypeDef *bank, uint8_t pin)
 Read the current input state of a pin.
 
void PHAL_GPIO_write (GPIO_TypeDef *bank, uint8_t pin, bool value)
 Drive an output pin high or low.
 
void PHAL_GPIO_toggle (GPIO_TypeDef *bank, uint8_t pin)
 Flip an output pin's current state.
 

Detailed Description

G4 GPIO public API.

Author
Millan Kumar (kumar.nosp@m.798@.nosp@m.purdu.nosp@m.e.ed.nosp@m.u)

Macro Definition Documentation

◆ 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, \
.type = GPIO_TYPE_AF, \
.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_bankGPIO_TypeDef* for the pin's port
pin_numPin number, 0-15
alt_func_numAlternate function selection
ospeed_selOutput speed selection
otype_selOutput drive type selection
input_pull_selPull-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, \
.type = GPIO_TYPE_ANALOG \
}
@ GPIO_TYPE_ANALOG
Definition gpio.h:25

Construct PHAL_GPIO_InitConfig_t for an analog pin.

Parameters
gpio_bankGPIO_TypeDef* for the pin's port
pin_numPin 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, \
.type = GPIO_TYPE_INPUT, \
.config = { \
.input = { \
.pull = input_pull_sel \
} \
} \
}
@ GPIO_TYPE_INPUT
Definition gpio.h:22

Construct PHAL_GPIO_InitConfig_t for an input pin.

Parameters
gpio_bankGPIO_TypeDef* for the pin's port
pin_numPin number, 0-15
input_pull_selPull-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, \
.type = GPIO_TYPE_OUTPUT, \
.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_bankGPIO_TypeDef* for the pin's port
pin_numPin number, 0-15
ospeed_selOutput 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, \
.type = GPIO_TYPE_OUTPUT, \
.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_bankGPIO_TypeDef* for the pin's port
pin_numPin number, 0-15
ospeed_selOutput speed selection

Enumeration Type Documentation

◆ 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 

Function Documentation

◆ PHAL_GPIO_init()

bool PHAL_GPIO_init ( PHAL_GPIO_InitConfig_t config[],
size_t config_len )

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
configArray of pin configurations
config_lenNumber of entries in config
Returns
true if every entry was valid (bank, pin #, type) and configured; false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PHAL_GPIO_read()

bool PHAL_GPIO_read ( const GPIO_TypeDef * bank,
uint8_t pin )

Read the current input state of a pin.

Parameters
bankGPIO port
pinPin number, 0-15
Returns
true if the pin currently reads high
Here is the call graph for this function:

◆ PHAL_GPIO_toggle()

void PHAL_GPIO_toggle ( GPIO_TypeDef * bank,
uint8_t pin )

Flip an output pin's current state.

Parameters
bankGPIO port
pinPin number, 0-15
Here is the call graph for this function:

◆ 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
bankGPIO port
pinPin number, 0-15
valuetrue to drive high, false to drive low
Here is the call graph for this function: