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

GPIO Driver for STM32F4 Devices. More...

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  GPIOInitConfig_t
 Configuration entry for GPIO initilization. More...
 

Macros

#define GPIO_INIT_INPUT(gpio_bank, pin_num, input_pull_sel)
 Create GPIO Init struct to intilize a GPIO pin for input.
 
#define GPIO_INIT_OUTPUT(gpio_bank, pin_num, ospeed_sel)
 Create GPIO Init struct to intilize a GPIO pin for output.
 
#define GPIO_INIT_OUTPUT_OPEN_DRAIN(gpio_bank, pin_num, ospeed_sel)
 
#define GPIO_INIT_ANALOG(gpio_bank, pin_num)
 Create GPIO Init struct to intilize a GPIO pin for analog.
 
#define GPIO_INIT_AF(gpio_bank, pin_num, alt_func_num, ospeed_sel, otype_sel, input_pull_sel)
 Create GPIO Init struct to intilize a GPIO pin for alternate function.
 
#define GPIO_INIT_SDIO_CLK   GPIO_INIT_AF(GPIOC, 12, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)
 
#define GPIO_INIT_SDIO_CMD   GPIO_INIT_AF(GPIOD, 2, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)
 
#define GPIO_INIT_SDIO_DT0   GPIO_INIT_AF(GPIOC, 8, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)
 
#define GPIO_INIT_SDIO_DT1   GPIO_INIT_AF(GPIOC, 9, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)
 
#define GPIO_INIT_SDIO_DT2   GPIO_INIT_AF(GPIOC, 10, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)
 
#define GPIO_INIT_SDIO_DT3   GPIO_INIT_AF(GPIOC, 11, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)
 
#define GPIO_INIT_MCO1_PA8   GPIO_INIT_AF(GPIOA, 8, 0, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN)
 

Enumerations

enum  GPIOPinType_t { GPIO_TYPE_INPUT = 0b00 , GPIO_TYPE_OUTPUT = 0b01 , GPIO_TYPE_AF = 0b10 , GPIO_TYPE_ANALOG = 0b11 }
 Configuration type for GPIO Pin. More...
 
enum  GPIOOutputSpeed_t { GPIO_OUTPUT_LOW_SPEED = 0b00 , GPIO_OUTPUT_MED_SPEED = 0b01 , GPIO_OUTPUT_HIGH_SPEED = 0b10 , GPIO_OUTPUT_ULTRA_SPEED = 0b11 }
 Slew rate control for output pins. More...
 
enum  GPIOOutputPull_t { GPIO_OUTPUT_PUSH_PULL = 0b0 , GPIO_OUTPUT_OPEN_DRAIN = 0b1 }
 Output drive mode selection. More...
 
enum  GPIOInputPull_t { GPIO_INPUT_OPEN_DRAIN = 0b00 , GPIO_INPUT_PULL_UP = 0b01 , GPIO_INPUT_PULL_DOWN = 0b10 }
 Enable internal pullup/down resistors. More...
 

Functions

bool PHAL_initGPIO (GPIOInitConfig_t config[], uint8_t config_len)
 Initilize the GPIO perpheral given a list of configuration fields for all of the GPIO pins. Will also enable the GPIO RCC clock.
 
static bool PHAL_GPIO_read (GPIO_TypeDef *bank, uint8_t pin)
 Read the state of the input register for the specific GPIO pin.
 
static void PHAL_GPIO_write (GPIO_TypeDef *bank, uint8_t pin, bool value)
 Write a logic value to an output pin.
 
static void PHAL_GPIO_toggle (GPIO_TypeDef *bank, uint8_t pin)
 

Detailed Description

GPIO Driver for STM32F4 Devices.

Author
Adam Busch (busch.nosp@m.8@pu.nosp@m.rdue..nosp@m.edu)
Version
0.1
Date
2021-09-20

Macro Definition Documentation

◆ GPIO_INIT_AF

#define 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_num = alt_func_num, \
.ospeed = ospeed_sel, \
.otype = otype_sel, \
.pull = input_pull_sel } \
}
@ GPIO_TYPE_AF
Definition gpio.h:24

Create GPIO Init struct to intilize a GPIO pin for alternate function.

Parameters
gpio_bankGPIO_TypeDef* reference to the GPIO bank for the pin
pin_numPin number from GPIO bank to configure
alt_func_numAlternate function selection
ospeed_selPin output speed selection
otype_selPin output type selection
input_pull_selInput pullup/pulldown/high-z selection

◆ GPIO_INIT_ANALOG

#define GPIO_INIT_ANALOG ( gpio_bank,
pin_num )
Value:
{ \
.bank = gpio_bank, \
.pin = pin_num, \
@ GPIO_TYPE_ANALOG
Definition gpio.h:25

Create GPIO Init struct to intilize a GPIO pin for analog.

Parameters
gpio_bankGPIO_TypeDef* reference to the GPIO bank for the pin
pin_numPin number from GPIO bank to configure

◆ GPIO_INIT_INPUT

#define GPIO_INIT_INPUT ( gpio_bank,
pin_num,
input_pull_sel )
Value:
{ \
.bank = gpio_bank, .pin = pin_num, .type = GPIO_TYPE_INPUT, .config = {.pull = input_pull_sel } \
}
@ GPIO_TYPE_INPUT
Definition gpio.h:22

Create GPIO Init struct to intilize a GPIO pin for input.

Parameters
gpio_bankGPIO_TypeDef* reference to the GPIO bank for the pin
pin_numPin number from GPIO bank to configure
input_pull_selInput pullup/pulldown/high-z selection

◆ GPIO_INIT_MCO1_PA8

#define GPIO_INIT_MCO1_PA8   GPIO_INIT_AF(GPIOA, 8, 0, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN)

◆ GPIO_INIT_OUTPUT

#define GPIO_INIT_OUTPUT ( gpio_bank,
pin_num,
ospeed_sel )
Value:
{ \
.bank = gpio_bank, .pin = pin_num, .type = GPIO_TYPE_OUTPUT, .config = {.ospeed = ospeed_sel, \
.otype = GPIO_OUTPUT_PUSH_PULL } \
}
@ GPIO_OUTPUT_PUSH_PULL
Definition gpio.h:42
@ GPIO_TYPE_OUTPUT
Definition gpio.h:23

Create GPIO Init struct to intilize a GPIO pin for output.

Parameters
gpio_bankGPIO_TypeDef* reference to the GPIO bank for the pin
pin_numPin number from GPIO bank to configure
ospeed_selPin output speed selection

◆ GPIO_INIT_OUTPUT_OPEN_DRAIN

#define GPIO_INIT_OUTPUT_OPEN_DRAIN ( gpio_bank,
pin_num,
ospeed_sel )
Value:
{ \
.bank = gpio_bank, .pin = pin_num, .type = GPIO_TYPE_OUTPUT, .config = {.ospeed = ospeed_sel, \
}
@ GPIO_OUTPUT_OPEN_DRAIN
Definition gpio.h:43

◆ GPIO_INIT_SDIO_CLK

#define GPIO_INIT_SDIO_CLK   GPIO_INIT_AF(GPIOC, 12, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)

◆ GPIO_INIT_SDIO_CMD

#define GPIO_INIT_SDIO_CMD   GPIO_INIT_AF(GPIOD, 2, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)

◆ GPIO_INIT_SDIO_DT0

#define GPIO_INIT_SDIO_DT0   GPIO_INIT_AF(GPIOC, 8, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)

◆ GPIO_INIT_SDIO_DT1

#define GPIO_INIT_SDIO_DT1   GPIO_INIT_AF(GPIOC, 9, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)

◆ GPIO_INIT_SDIO_DT2

#define GPIO_INIT_SDIO_DT2   GPIO_INIT_AF(GPIOC, 10, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)

◆ GPIO_INIT_SDIO_DT3

#define GPIO_INIT_SDIO_DT3   GPIO_INIT_AF(GPIOC, 11, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)

Enumeration Type Documentation

◆ GPIOInputPull_t

Enable internal pullup/down resistors.

Enumerator
GPIO_INPUT_OPEN_DRAIN 
GPIO_INPUT_PULL_UP 
GPIO_INPUT_PULL_DOWN 

◆ GPIOOutputPull_t

Output drive mode selection.

Enumerator
GPIO_OUTPUT_PUSH_PULL 
GPIO_OUTPUT_OPEN_DRAIN 

◆ GPIOOutputSpeed_t

Slew rate control for output pins.

Enumerator
GPIO_OUTPUT_LOW_SPEED 
GPIO_OUTPUT_MED_SPEED 
GPIO_OUTPUT_HIGH_SPEED 
GPIO_OUTPUT_ULTRA_SPEED 

◆ GPIOPinType_t

Configuration type for GPIO Pin.

Enumerator
GPIO_TYPE_INPUT 
GPIO_TYPE_OUTPUT 
GPIO_TYPE_AF 
GPIO_TYPE_ANALOG 

Function Documentation

◆ PHAL_GPIO_read()

static bool PHAL_GPIO_read ( GPIO_TypeDef * bank,
uint8_t pin )
inlinestatic

Read the state of the input register for the specific GPIO pin.

Parameters
bankGPIO Bank of the pin
pinGPIO pin number
Returns
true GPIO Input true
false GPIO Input false
Here is the caller graph for this function:

◆ PHAL_GPIO_toggle()

static void PHAL_GPIO_toggle ( GPIO_TypeDef * bank,
uint8_t pin )
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PHAL_GPIO_write()

static void PHAL_GPIO_write ( GPIO_TypeDef * bank,
uint8_t pin,
bool value )
inlinestatic

Write a logic value to an output pin.

Parameters
bankGPIO Bank of the pin
pinGPIO pin number
valueLogical value to write
Here is the caller graph for this function:

◆ PHAL_initGPIO()

bool PHAL_initGPIO ( GPIOInitConfig_t config[],
uint8_t config_len )

Initilize the GPIO perpheral given a list of configuration fields for all of the GPIO pins. Will also enable the GPIO RCC clock.

Parameters
configA list of GPIOs to config
config_lenNumber of GPIOs in the config list
Returns
true All GPIOs were a valid configuration format
false Some of the GPIOs had an invalid configuration format
Here is the caller graph for this function: