STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
Loading...
Searching...
No Matches
gpio.h File Reference

GPIO driver: pin configuration and digital I/O. More...

#include "driver_status.h"
#include "gpio_reg.h"
#include <stdint.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.

Data Structures

struct  GpioResetValues_t
 Power-on values of the GPIO registers that are not zero on every port. More...

Macros

#define GPIO_AF_MAX   (15U)
 Highest alternate-function number (AF0-AF15).

Typedefs

typedef enum GpioPin_e GpioPin_e
 Pin number within a port.
typedef enum GpioPinState_e GpioPinState_e
 Logic level of a pin.
typedef struct GpioResetValues_t GpioResetValues_t
 Power-on values of the GPIO registers that are not zero on every port.

Enumerations

enum  GpioPin_e {
  GPIO_PIN_0 = 0 , GPIO_PIN_1 = 1 , GPIO_PIN_2 = 2 , GPIO_PIN_3 = 3 ,
  GPIO_PIN_4 = 4 , GPIO_PIN_5 = 5 , GPIO_PIN_6 = 6 , GPIO_PIN_7 = 7 ,
  GPIO_PIN_8 = 8 , GPIO_PIN_9 = 9 , GPIO_PIN_10 = 10 , GPIO_PIN_11 = 11 ,
  GPIO_PIN_12 = 12 , GPIO_PIN_13 = 13 , GPIO_PIN_14 = 14 , GPIO_PIN_15 = 15
}
 Pin number within a port. More...
enum  GpioPinState_e { GPIO_PIN_RESET = 0 , GPIO_PIN_SET = 1 }
 Logic level of a pin. More...

Functions

GpioResetValues_t gpioPortResetValues (const GpioRegisters_t *port)
 Look up a port's power-on MODER, OSPEEDR and PUPDR values.
DRIVER_MUST_CHECK DriverStatus_e gpioInit (GpioRegisters_t *port, GpioPin_e pin, uint32_t mode, uint32_t otype, uint32_t ospeed, uint32_t pupd)
 Configure a pin's mode, output type, speed and pull.
void gpioDeinit (GpioRegisters_t *port, GpioPin_e pin)
 Return a pin to its power-on configuration.
void gpioDeinitToReset (GpioRegisters_t *port, GpioPin_e pin, GpioResetValues_t reset)
 gpioDeinit() with the reset values supplied by the caller.
DRIVER_MUST_CHECK DriverStatus_e gpioSetAlternateFunction (GpioRegisters_t *port, GpioPin_e pin, uint32_t af)
 Select a pin's alternate function in AFRL/AFRH.
void gpioWritePin (GpioRegisters_t *port, GpioPin_e pin, GpioPinState_e level)
 Drive a pin high or low with one atomic BSRR write.
GpioPinState_e gpioReadPin (const GpioRegisters_t *port, GpioPin_e pin)
 Read a pin's input level from IDR.
void gpioTogglePin (GpioRegisters_t *port, GpioPin_e pin)
 Invert a pin's output level.

Detailed Description

GPIO driver: pin configuration and digital I/O.

Typical use, an output on PA5 (the NUCLEO's LD2):

@ DRIVER_STATUS_OK
Succeeded.
void gpioWritePin(GpioRegisters_t *port, GpioPin_e pin, GpioPinState_e level)
Drive a pin high or low with one atomic BSRR write.
Definition gpio.c:140
DRIVER_MUST_CHECK DriverStatus_e gpioInit(GpioRegisters_t *port, GpioPin_e pin, uint32_t mode, uint32_t otype, uint32_t ospeed, uint32_t pupd)
Configure a pin's mode, output type, speed and pull.
Definition gpio.c:30
@ GPIO_PIN_5
Pin 5.
Definition gpio.h:45
@ GPIO_PIN_SET
High.
Definition gpio.h:62
#define GPIO_OSPEED_LOW
Low speed.
Definition gpio_reg.h:74
#define GPIOA
Port A.
Definition gpio_reg.h:48
#define GPIO_MODE_OUTPUT
General-purpose output.
Definition gpio_reg.h:61
#define GPIO_PUPD_NONE
No pull.
Definition gpio_reg.h:82
#define GPIO_OTYPE_PP
Push-pull.
Definition gpio_reg.h:68
DRIVER_MUST_CHECK DriverStatus_e rccGpioClockEnable(RccRegisters_t *rcc, const GpioRegisters_t *port)
Enable a GPIO port's clock.
Definition rcc.c:69
#define RCC
The RCC instance.
Definition rcc_reg.h:61

For an alternate function, call gpioSetAlternateFunction() before gpioInit() so the function is selected before MODER switches the pin.

Definition in file gpio.h.