Loading...
Searching...
No Matches
GPIO Pin

Driver for initialising and interacting with individual GPIO pins. More...

Data Structures

struct  GPIO_Config
 Struct definition for GPIO configuration. More...
 
struct  GPIOpin_t
 Struct definition for a GPIO pin. More...
 

Enumerations

enum  GPIO_Pin {
  GPIO_PIN0 , GPIO_PIN1 , GPIO_PIN2 , GPIO_PIN3 ,
  GPIO_PIN4 , GPIO_PIN5 , GPIO_PIN6 , GPIO_PIN7 ,
  GPIO_PIN8 , GPIO_PIN9 , GPIO_PIN10 , GPIO_PIN11 ,
  GPIO_PIN12 , GPIO_PIN13 , GPIO_PIN14 , GPIO_PIN15
}
 GPIO pin enum. More...
 
enum  GPIO_AF {
  GPIO_AF0 , GPIO_AF1 , GPIO_AF2 , GPIO_AF3 ,
  GPIO_AF4 , GPIO_AF5 , GPIO_AF6 , GPIO_AF7 ,
  GPIO_AF8 , GPIO_AF9 , GPIO_AF10 , GPIO_AF11 ,
  GPIO_AF12 , GPIO_AF13 , GPIO_AF14 , GPIO_AF15
}
 GPIO alternate function enum. More...
 
enum  GPIO_Mode { GPIO_MODE_INPUT , GPIO_MODE_OUTPUT , GPIO_MODE_AF , GPIO_MODE_ANALOG }
 GPIO mode enum. More...
 
enum  GPIO_Type { GPIO_TYPE_PUSHPULL , GPIO_TYPE_OPENDRAIN }
 GPIO type enum. More...
 
enum  GPIO_Speed { GPIO_SPEED_LOW , GPIO_SPEED_MEDIUM , GPIO_SPEED_HIGH , GPIO_SPEED_VERYHIGH }
 GPIO speed enum. More...
 
enum  GPIO_PUPD { GPIO_PUPD_NONE , GPIO_PUPD_PULLUP , GPIO_PUPD_PULLDOWN }
 GPIO pull-up/pull-down enum. More...
 

Functions

GPIOpin_t GPIOpin_init (GPIO_TypeDef *, GPIO_Pin, GPIO_Config *)
 Initialiser for a GPIO peripheral pin interface.
 
void GPIOpin_set (GPIOpin_t *)
 Set the selected GPIO pin.
 
void GPIOpin_reset (GPIOpin_t *)
 Clear the selected GPIO pin.
 
void GPIOpin_toggle (GPIOpin_t *)
 Toggle the selected GPIO pin.
 
void GPIOpin_updateConfig (GPIOpin_t *, GPIO_Config *)
 Update GPIO pin configuration.
 

Detailed Description

Driver for initialising and interacting with individual GPIO pins.


Data Structure Documentation

◆ GPIO_Config

struct GPIO_Config

Struct definition for GPIO configuration.

Describes the configuration parameters of a GPIO pin/port.

If GPIOpin_init is passed a null pointer configuration, these parameters will contain their default values.

Definition at line 138 of file gpiopin.h.

Data Fields
GPIO_Mode mode Pin I/O direction | (default GPIO_MODE_OUTPUT)
GPIO_Type type Pin output type | (default GPIO_TYPE_PUSHPULL)
GPIO_Speed speed Pin output speed | (default GPIO_SPEED_HIGH)
GPIO_PUPD pupd Pin pull-up/pull-down | (default GPIO_PUPD_NONE)
GPIO_AF afr Pin alternate function | (default GPIO_AF0)

◆ GPIOpin_t

struct GPIOpin_t

Struct definition for a GPIO pin.

Provides the interface for peripheral drivers and application code to configure and interact with an individual GPIO pin.

Definition at line 151 of file gpiopin.h.

Data Fields
GPIO_TypeDef * port GPIO port in which the pin is located.
GPIO_Pin pin Actual location of the pin within GPIO port.
GPIO_Config config Configuration parameters for the pin.
void(*)(struct GPIOpin *) set
See also
GPIOpin_set
void(*)(struct GPIOpin *) reset
See also
GPIOpin_reset
void(*)(struct GPIOpin *) toggle
See also
GPIOpin_toggle
void(*)(struct GPIOpin *, GPIO_Config *) updateConfig
See also
GPIOpin_updateConfig

Enumeration Type Documentation

◆ GPIO_Pin

enum GPIO_Pin

GPIO pin enum.

Describes the position of the pin within its GPIO port.

Enumerator
GPIO_PIN0 

Pin 0.

GPIO_PIN1 

Pin 1.

GPIO_PIN2 

Pin 2.

GPIO_PIN3 

Pin 3.

GPIO_PIN4 

Pin 4.

GPIO_PIN5 

Pin 5.

GPIO_PIN6 

Pin 6.

GPIO_PIN7 

Pin 7.

GPIO_PIN8 

Pin 8.

GPIO_PIN9 

Pin 9.

GPIO_PIN10 

Pin 10.

GPIO_PIN11 

Pin 11.

GPIO_PIN12 

Pin 12.

GPIO_PIN13 

Pin 13.

GPIO_PIN14 

Pin 14.

GPIO_PIN15 

Pin 15.

Definition at line 49 of file gpiopin.h.

◆ GPIO_AF

enum GPIO_AF

GPIO alternate function enum.

Describes the alternate function mapping of the pin.

Enumerator
GPIO_AF0 

System.

GPIO_AF1 

TIM1/TIM2.

GPIO_AF2 

TIM3..5.

GPIO_AF3 

TIM8..11.

GPIO_AF4 

I2C1..3.

GPIO_AF5 

SPI1/2/3/4/5/6.

GPIO_AF6 

SPI2/3/SAI1.

GPIO_AF7 

USART1..3.

GPIO_AF8 

USART4..8.

GPIO_AF9 

CAN1/CAN2, LTDC, TIM12..14.

GPIO_AF10 

OTG_FS, OTG_HS.

GPIO_AF11 

ETH.

GPIO_AF12 

FMC, SDIO, OTG_HS.

GPIO_AF13 

DCMI.

GPIO_AF14 

LTDC.

GPIO_AF15 

EVENTOUT.

Definition at line 72 of file gpiopin.h.

◆ GPIO_Mode

enum GPIO_Mode

GPIO mode enum.

Describes the I/O direction mode of the pin.

Enumerator
GPIO_MODE_INPUT 

Input mode (reset state)

GPIO_MODE_OUTPUT 

General purpose output mode.

GPIO_MODE_AF 

Alternate function mode.

GPIO_MODE_ANALOG 

Analog mode.

Definition at line 95 of file gpiopin.h.

◆ GPIO_Type

enum GPIO_Type

GPIO type enum.

Describes the output type of the pin.

Enumerator
GPIO_TYPE_PUSHPULL 

Push pull (reset state)

GPIO_TYPE_OPENDRAIN 

Open drain.

Definition at line 106 of file gpiopin.h.

◆ GPIO_Speed

enum GPIO_Speed

GPIO speed enum.

Describes the output speed of the pin.

Enumerator
GPIO_SPEED_LOW 

Low speed output | (default for all not specified)

GPIO_SPEED_MEDIUM 

Medium speed output |.

GPIO_SPEED_HIGH 

High speed output |.

GPIO_SPEED_VERYHIGH 

Very high speed output | (default for PA13, PB3)

Definition at line 115 of file gpiopin.h.

◆ GPIO_PUPD

enum GPIO_PUPD

GPIO pull-up/pull-down enum.

Describes if internal pull-up/pull-down is used by the pin.

Enumerator
GPIO_PUPD_NONE 

No pull-up, pull-down | (default for all not specified)

GPIO_PUPD_PULLUP 

Pull-up | (default for PA15, PA13, PB4)

GPIO_PUPD_PULLDOWN 

Pull-down | (default for PB14)

Definition at line 126 of file gpiopin.h.

Function Documentation

◆ GPIOpin_init()

GPIOpin_t GPIOpin_init ( GPIO_TypeDef * port,
GPIO_Pin pin,
GPIO_Config * config )

Initialiser for a GPIO peripheral pin interface.

Parameters
portPointer to the GPIO_TypeDef struct representing the pin's port.
pinEnum quantified value of the pin's position in its port.
configPointer to GPIO_Config struct for initial configuration. This may be passed as NULL to initialise a default configuration.
Returns
Initialised GPIOpin_t struct.

Definition at line 28 of file gpiopin.c.

◆ GPIOpin_set()

void GPIOpin_set ( GPIOpin_t * gpio)

Set the selected GPIO pin.

Uses a logic OR to set the pin's current value in the data register.

Parameters
gpioPointer to GPIOpin_t struct.
Returns
NULL.

Definition at line 98 of file gpiopin.c.

◆ GPIOpin_reset()

void GPIOpin_reset ( GPIOpin_t * gpio)

Clear the selected GPIO pin.

Uses a logic AND to clear the pin's current value in the data register.

Parameters
gpioPointer to GPIOpin_t struct.
Returns
NULL.

Definition at line 112 of file gpiopin.c.

◆ GPIOpin_toggle()

void GPIOpin_toggle ( GPIOpin_t * gpio)

Toggle the selected GPIO pin.

Uses a logic XOR to invert the pin's current value in the data register.

Parameters
gpioPointer to GPIOpin_t struct.
Returns
NULL.

Definition at line 126 of file gpiopin.c.

◆ GPIOpin_updateConfig()

void GPIOpin_updateConfig ( GPIOpin_t * gpio,
GPIO_Config * config )

Update GPIO pin configuration.

Uses the provided configuration to update the GPIO registers and resets the associated port in the RCC. As with initialisation, passing NULL will set the default config.

Parameters
gpioPointer to GPIOpin_t struct.
Returns
NULL.

Definition at line 142 of file gpiopin.c.