gpio.h

[Stub] support.

Library Documentation

General purpose I/0 (GPIO) and Alternate Function I/O (AFIO) prototypes, defines, and inlined access functions.

Defines
GPIOA_BASE

GPIO port A register map base pointer.

GPIOB_BASE

GPIO port B register map base pointer.

GPIOC_BASE

GPIO port C register map base pointer.

GPIOD_BASE

GPIO port D register map base pointer.

GPIO_CR_CNF_INPUT_ANALOG

GPIO_CR_CNF_INPUT_FLOATING

GPIO_CR_CNF_INPUT_PU_PD

GPIO_CR_CNF_OUTPUT_PP

GPIO_CR_CNF_OUTPUT_OD

GPIO_CR_CNF_AF_OUTPUT_PP

GPIO_CR_CNF_AF_OUTPUT_OD

GPIO_CR_MODE_INPUT

GPIO_CR_MODE_OUTPUT_10MHZ

GPIO_CR_MODE_OUTPUT_2MHZ

GPIO_CR_MODE_OUTPUT_50MHZ

AFIO_BASE

AFIO register map base pointer.

AFIO_EVCR_EVOE

AFIO_EVCR_PORT_PA

AFIO_EVCR_PORT_PB

AFIO_EVCR_PORT_PC

AFIO_EVCR_PORT_PD

AFIO_EVCR_PORT_PE

AFIO_EVCR_PIN_0

AFIO_EVCR_PIN_1

AFIO_EVCR_PIN_2

AFIO_EVCR_PIN_3

AFIO_EVCR_PIN_4

AFIO_EVCR_PIN_5

AFIO_EVCR_PIN_6

AFIO_EVCR_PIN_7

AFIO_EVCR_PIN_8

AFIO_EVCR_PIN_9

AFIO_EVCR_PIN_10

AFIO_EVCR_PIN_11

AFIO_EVCR_PIN_12

AFIO_EVCR_PIN_13

AFIO_EVCR_PIN_14

AFIO_EVCR_PIN_15

AFIO_MAPR_SWJ_CFG

AFIO_MAPR_SWJ_CFG_FULL_SWJ

AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_NJRST

AFIO_MAPR_SWJ_CFG_NO_JTAG_SW

AFIO_MAPR_SWJ_CFG_NO_JTAG_NO_SW

AFIO_MAPR_ADC2_ETRGREG_REMAP

AFIO_MAPR_ADC2_ETRGINJ_REMAP

AFIO_MAPR_ADC1_ETRGREG_REMAP

AFIO_MAPR_ADC1_ETRGINJ_REMAP

AFIO_MAPR_TIM5CH4_IREMAP

AFIO_MAPR_PD01_REMAP

AFIO_MAPR_CAN_REMAP

AFIO_MAPR_TIM4_REMAP

AFIO_MAPR_TIM3_REMAP

AFIO_MAPR_TIM2_REMAP

AFIO_MAPR_TIM1_REMAP

AFIO_MAPR_USART3_REMAP

AFIO_MAPR_USART2_REMAP

AFIO_MAPR_USART1_REMAP

AFIO_MAPR_I2C1_REMAP

AFIO_MAPR_SPI1_REMAP

AFIO_MAPR2_FSMC_NADV

AFIO_MAPR2_TIM14_REMAP

AFIO_MAPR2_TIM13_REMAP

AFIO_MAPR2_TIM11_REMAP

AFIO_MAPR2_TIM10_REMAP

AFIO_MAPR2_TIM9_REMAP

AFIO_REMAP_USE_MAPR2

Enums
afio_exti_port enum

External interrupt line port selector.

Used to determine which GPIO port to map an external interrupt line onto.

Values:

  • AFIO_EXTI_PA -

    Use PAx pin.

  • AFIO_EXTI_PB -

    Use PBx pin.

  • AFIO_EXTI_PC -

    Use PCx pin.

  • AFIO_EXTI_PD -

    Use PDx pin.

gpio_pin_mode enum

GPIO Pin modes.

These only allow for 50MHZ max output speeds; if you want slower, use direct register access.

Values:

  • GPIO_OUTPUT_PP = (GPIO_CR_CNF_OUTPUT_PP |                       GPIO_CR_MODE_OUTPUT_50MHZ) -

    Output push-pull.

  • GPIO_OUTPUT_OD = (GPIO_CR_CNF_OUTPUT_OD |                       GPIO_CR_MODE_OUTPUT_50MHZ) -

    Output open-drain.

  • GPIO_AF_OUTPUT_PP = (GPIO_CR_CNF_AF_OUTPUT_PP |                          GPIO_CR_MODE_OUTPUT_50MHZ) -

    Alternate function output push-pull.

  • GPIO_AF_OUTPUT_OD = (GPIO_CR_CNF_AF_OUTPUT_OD |                          GPIO_CR_MODE_OUTPUT_50MHZ) -

    Alternate function output open drain.

  • GPIO_INPUT_ANALOG = (GPIO_CR_CNF_INPUT_ANALOG |                          GPIO_CR_MODE_INPUT) -

    Analog input.

  • GPIO_INPUT_FLOATING = (GPIO_CR_CNF_INPUT_FLOATING |                            GPIO_CR_MODE_INPUT) -

    Input floating.

  • GPIO_INPUT_PD = (GPIO_CR_CNF_INPUT_PU_PD |                      GPIO_CR_MODE_INPUT) -

    Input pull-down.

  • GPIO_INPUT_PU -

    Input pull-up.

afio_exti_num enum

External interrupt line numbers.

Values:

  • AFIO_EXTI_0 -

    External interrupt line 0.

  • AFIO_EXTI_1 -

    External interrupt line 1.

  • AFIO_EXTI_2 -

    External interrupt line 2.

  • AFIO_EXTI_3 -

    External interrupt line 3.

  • AFIO_EXTI_4 -

    External interrupt line 4.

  • AFIO_EXTI_5 -

    External interrupt line 5.

  • AFIO_EXTI_6 -

    External interrupt line 6.

  • AFIO_EXTI_7 -

    External interrupt line 7.

  • AFIO_EXTI_8 -

    External interrupt line 8.

  • AFIO_EXTI_9 -

    External interrupt line 9.

  • AFIO_EXTI_10 -

    External interrupt line 10.

  • AFIO_EXTI_11 -

    External interrupt line 11.

  • AFIO_EXTI_12 -

    External interrupt line 12.

  • AFIO_EXTI_13 -

    External interrupt line 13.

  • AFIO_EXTI_14 -

    External interrupt line 14.

  • AFIO_EXTI_15 -

    External interrupt line 15.

AFIORemapPeripheral enum

Values:

  • AFIO_REMAP_ADC2_ETRGREG = AFIO_MAPR_ADC2_ETRGREG_REMAP -
  • AFIO_REMAP_ADC2_ETRGINJ = AFIO_MAPR_ADC2_ETRGINJ_REMAP -
  • AFIO_REMAP_ADC1_ETRGREG = AFIO_MAPR_ADC1_ETRGREG_REMAP -
  • AFIO_REMAP_ADC1_ETRGINJ = AFIO_MAPR_ADC1_ETRGINJ_REMAP -
  • AFIO_REMAP_TIM5CH4_I = AFIO_MAPR_TIM5CH4_IREMAP -
  • AFIO_REMAP_PD01 = AFIO_MAPR_PD01_REMAP -
  • AFIO_REMAP_CAN = AFIO_MAPR_CAN_REMAP -
  • AFIO_REMAP_TIM4 = AFIO_MAPR_TIM4_REMAP -
  • AFIO_REMAP_TIM3 = AFIO_MAPR_TIM3_REMAP -
  • AFIO_REMAP_TIM2 = AFIO_MAPR_TIM2_REMAP -
  • AFIO_REMAP_TIM1 = AFIO_MAPR_TIM1_REMAP -
  • AFIO_REMAP_USART3 = AFIO_MAPR_USART3_REMAP -
  • AFIO_REMAP_USART2 = AFIO_MAPR_USART2_REMAP -
  • AFIO_REMAP_USART1 = AFIO_MAPR_USART1_REMAP -
  • AFIO_REMAP_I2C1 = AFIO_MAPR_I2C1_REMAP -
  • AFIO_REMAP_SPI1 = AFIO_MAPR_SPI1_REMAP -
  • AFIO_REMAP_FSMC_NADV = AFIO_MAPR2_FSMC_NADV | AFIO_REMAP_USE_MAPR2 -
  • AFIO_REMAP_TIM14 = AFIO_MAPR2_TIM14_REMAP | AFIO_REMAP_USE_MAPR2 -
  • AFIO_REMAP_TIM13 = AFIO_MAPR2_TIM13_REMAP | AFIO_REMAP_USE_MAPR2 -
  • AFIO_REMAP_TIM11 = AFIO_MAPR2_TIM11_REMAP | AFIO_REMAP_USE_MAPR2 -
  • AFIO_REMAP_TIM10 = AFIO_MAPR2_TIM10_REMAP | AFIO_REMAP_USE_MAPR2 -
  • AFIO_REMAP_TIM9 = AFIO_MAPR2_TIM9_REMAP | AFIO_REMAP_USE_MAPR2 -
afio_debug_cfg enum

Debug port configuration.

Used to configure the behavior of JTAG and Serial Wire (SW) debug ports and their associated GPIO pins.

Values:

  • AFIO_DEBUG_FULL_SWJ = AFIO_MAPR_SWJ_CFG_FULL_SWJ -

    Full Serial Wire and JTAG debug.

  • AFIO_DEBUG_FULL_SWJ_NO_NJRST = AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_NJRST -

    Full Serial Wire and JTAG, but no NJTRST.

  • AFIO_DEBUG_SW_ONLY = AFIO_MAPR_SWJ_CFG_NO_JTAG_SW -

    Serial Wire debug only (JTAG-DP disabled, SW-DP enabled).

  • AFIO_DEBUG_NONE = AFIO_MAPR_SWJ_CFG_NO_JTAG_NO_SW -

    No debug; all JTAG and SW pins are free for use as GPIOs.

Functions
void gpio_init(gpio_dev * dev)

Initialize a GPIO device.

Enables the clock for and resets the given device.

Parameters:
  • dev -

    GPIO device to initialize.

void gpio_init_all(void )

Initialize and reset all available GPIO devices.

void gpio_set_mode(gpio_dev * dev, uint8 pin, gpio_pin_mode mode)

Set the mode of a GPIO pin.

Parameters:
  • dev -

    GPIO device.

  • pin -

    Pin on the device whose mode to set, 0–15.

  • mode -

    General purpose or alternate function mode to set the pin to.

See:

gpio_pin_mode

afio_exti_port gpio_exti_port(gpio_dev * dev)

Get a GPIO port’s corresponding afio_exti_port.

Parameters:
  • dev -

    GPIO device whose afio_exti_port to return.

void gpio_write_bit(gpio_dev * dev, uint8 pin, uint8 val)

Set or reset a GPIO pin.

Pin must have previously been configured to output mode.

Parameters:
  • dev -

    GPIO device whose pin to set.

  • pin -

    Pin on to set or reset

  • val -

    If true, set the pin. If false, reset the pin.

uint32 gpio_read_bit(gpio_dev * dev, uint8 pin)

Determine whether or not a GPIO pin is set.

Pin must have previously been configured to input mode.

Parameters:
  • dev -

    GPIO device whose pin to test.

  • pin -

    Pin on dev to test.

Return:

True if the pin is set, false otherwise.

void gpio_toggle_bit(gpio_dev * dev, uint8 pin)

Toggle a pin configured as output push-pull.

Parameters:
  • dev -

    GPIO device.

  • pin -

    Pin on dev to toggle.

void afio_remap(AFIORemapPeripheral p)

Remap an alternate function peripheral to a different pin mapping.

Parameters:
  • peripheral -

    to remap

void afio_init(void )

Initialize the AFIO clock, and reset the AFIO registers.

void afio_exti_select(afio_exti_num exti, afio_exti_port gpio_port)

Select a source input for an external interrupt.

Parameters:
  • exti -

    External interrupt. One of: AFIO_EXTI_0, AFIO_EXTI_1, ..., AFIO_EXTI_15.

  • gpio_port -

    Port which contains pin to use as source input. One of: AFIO_EXTI_PA, AFIO_EXTI_PB, AFIO_EXTI_PC, AFIO_EXTI_PD, and, on high density devices, AFIO_EXTI_PE, AFIO_EXTI_PF, AFIO_EXTI_PG.

See:

exti_port

void afio_cfg_debug_ports(afio_debug_cfg config)

Enable or disable the JTAG and SW debug ports.

Parameters:
  • config -

    Desired debug port configuration

See:

afio_debug_cfg

Variables
gpio_dev gpioa

GPIO initialization routine.

gpio_dev *const GPIOA

gpio_dev gpiob

gpio_dev *const GPIOB

gpio_dev gpioc

gpio_dev *const GPIOC

gpio_dev gpiod

gpio_dev *const GPIOD

class gpio_reg_map

GPIO register map type.

Public Members
__io uint32 CRL

Port configuration register low.

__io uint32 CRH

Port configuration register high.

__io uint32 IDR

Port input data register.

__io uint32 ODR

Port output data register.

__io uint32 BSRR

Port bit set/reset register.

__io uint32 BRR

Port bit reset register.

__io uint32 LCKR

Port configuration lock register.

class gpio_dev

GPIO device type.

Public Members
gpio_reg_map * regs

Register map.

rcc_clk_id clk_id

RCC clock information.

afio_exti_port exti_port

AFIO external interrupt port value.

class afio_reg_map

AFIO register map.

Public Members
__io uint32 EVCR

Event control register.

__io uint32 MAPR

AF remap and debug I/O configuration register.

__io uint32 EXTICR1

External interrupt configuration register 1.

__io uint32 EXTICR2

External interrupt configuration register 2.

__io uint32 EXTICR3

External interrupt configuration register 3.

__io uint32 EXTICR4

External interrupt configuration register 4.

__io uint32 MAPR2

AF remap and debug I/O configuration register 2.