libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
Collaboration diagram for GPIO Registers:

Macros

#define GPIO_ADATA   MMIO32(GPIO_BASE + 0x0)
 Data register. More...
 
#define GPIO_ADIR   MMIO32(GPIO_BASE + 0x4)
 Direction register. More...
 
#define GPIO_INTEN_A   MMIO32(GPIO_BASE + 0x30)
 Interrupt enable register. More...
 
#define GPIO_INTMASK_A   MMIO32(GPIO_BASE + 0x34)
 Interrupt mask register. More...
 
#define GPIO_INTLEVEL_A   MMIO32(GPIO_BASE + 0x38)
 Interrupt trigger mode register. More...
 
#define GPIO_INTPOLARITY_A   MMIO32(GPIO_BASE + 0x3c)
 Interrupt polarity register. More...
 
#define GPIO_INTSTAT_A   MMIO32(GPIO_BASE + 0x40)
 Interrupt status after masking. More...
 
#define GPIO_RAWINTSTAT_A   MMIO32(GPIO_BASE + 0x44)
 Interrupt status before masking. More...
 
#define GPIO_INTEOI_A   MMIO32(GPIO_BASE + 0x48)
 Interrupt clear register. More...
 
#define GPIO_AEXT   MMIO32(GPIO_BASE + 0x4c)
 External register (wat) More...
 

Functions

void gpio_set (uint16_t gpios)
 Set a Group of Pins. More...
 
void gpio_clear (uint16_t gpios)
 Clear a Group of Pins. More...
 
uint16_t gpio_get (uint16_t gpios)
 Read a Group of Pins. More...
 
void gpio_toggle (uint16_t gpios)
 Toggle a Group of Pins. More...
 
void gpio_input (uint16_t gpios)
 Set the direction of a Group of Pins to Input. More...
 
void gpio_output (uint16_t gpios)
 Set the direction of a Group of Pins to Output. More...
 
void gpio_int_enable (uint16_t gpios, bool en)
 Sets the pins as external interrupts, rather than normal GPIO. More...
 
void gpio_int_mask (uint16_t gpios, enum gpio_int_masked masked)
 Sets bits in the interrupt mask. More...
 
void gpio_int_type (uint16_t gpios, enum gpio_trig_type type)
 Sets whether the pins are edge triggered or level triggered. More...
 
void gpio_int_pol (uint16_t gpios, enum gpio_pol pol)
 Sets the interrupt trigger polarity. More...
 
uint16_t gpio_int_status (void)
 Gets the masked interrupt status. More...
 
uint16_t gpio_int_raw_status (void)
 Gets the raw unmasked interrupt status. More...
 
void gpio_int_clear (uint16_t gpios)
 Clear the specified pin interrupts. More...
 

Detailed Description

Macro Definition Documentation

◆ GPIO_ADATA

#define GPIO_ADATA   MMIO32(GPIO_BASE + 0x0)

Data register.

Definition at line 90 of file gpio.h.

◆ GPIO_ADIR

#define GPIO_ADIR   MMIO32(GPIO_BASE + 0x4)

Direction register.

Definition at line 92 of file gpio.h.

◆ GPIO_AEXT

#define GPIO_AEXT   MMIO32(GPIO_BASE + 0x4c)

External register (wat)

Definition at line 108 of file gpio.h.

◆ GPIO_INTEN_A

#define GPIO_INTEN_A   MMIO32(GPIO_BASE + 0x30)

Interrupt enable register.

Definition at line 94 of file gpio.h.

◆ GPIO_INTEOI_A

#define GPIO_INTEOI_A   MMIO32(GPIO_BASE + 0x48)

Interrupt clear register.

Definition at line 106 of file gpio.h.

◆ GPIO_INTLEVEL_A

#define GPIO_INTLEVEL_A   MMIO32(GPIO_BASE + 0x38)

Interrupt trigger mode register.

Definition at line 98 of file gpio.h.

◆ GPIO_INTMASK_A

#define GPIO_INTMASK_A   MMIO32(GPIO_BASE + 0x34)

Interrupt mask register.

Definition at line 96 of file gpio.h.

◆ GPIO_INTPOLARITY_A

#define GPIO_INTPOLARITY_A   MMIO32(GPIO_BASE + 0x3c)

Interrupt polarity register.

Definition at line 100 of file gpio.h.

◆ GPIO_INTSTAT_A

#define GPIO_INTSTAT_A   MMIO32(GPIO_BASE + 0x40)

Interrupt status after masking.

Definition at line 102 of file gpio.h.

◆ GPIO_RAWINTSTAT_A

#define GPIO_RAWINTSTAT_A   MMIO32(GPIO_BASE + 0x44)

Interrupt status before masking.

Definition at line 104 of file gpio.h.

Function Documentation

◆ gpio_clear()

void gpio_clear ( uint16_t  gpios)

Clear a Group of Pins.

Set one or more pins of GPIO to 0. Please note that this chip doesn't support atomic pin setting.

Parameters
[in]gpiosPin identifiers GPIO Pin Identifiers If multiple pins are to be changed, use bitwise OR '|' to separate them.

Definition at line 57 of file gpio.c.

References GPIO_ADATA.

◆ gpio_get()

uint16_t gpio_get ( uint16_t  gpios)

Read a Group of Pins.

Parameters
[in]gpiosPin identifiers GPIO Pin Identifiers If multiple pins are to be read, use bitwise OR '|' to separate them.
Returns
The pin values as a bitfield. The bit position of the pin value returned corresponds to the pin number.

Definition at line 71 of file gpio.c.

References GPIO_AEXT.

◆ gpio_input()

void gpio_input ( uint16_t  gpios)

Set the direction of a Group of Pins to Input.

Set the direction of one or more pins of GPIO to input.

Parameters
[in]gpiosPin identifiers GPIO Pin Identifiers If multiple pins are to be changed, use bitwise OR '|' to separate them.

Definition at line 100 of file gpio.c.

References GPIO_ADIR.

◆ gpio_int_clear()

void gpio_int_clear ( uint16_t  gpios)

Clear the specified pin interrupts.

Clears the specified pin interrupts. Edge-triggered interrupts must be cleared by software.

Parameters
[in]gpiosPin identifiers GPIO Pin Identifiers If multiple pins are to be changed, use bitwise OR '|' to separate them.

Definition at line 249 of file gpio.c.

References GPIO_INTEOI_A.

◆ gpio_int_enable()

void gpio_int_enable ( uint16_t  gpios,
bool  en 
)

Sets the pins as external interrupts, rather than normal GPIO.

Enable interrupts on the selected pins. If you want to quickly switch on and off interrupts, use gpio_int_mask() after calling this.

Parameters
[in]gpiosPin identifiers GPIO Pin Identifiers If multiple pins are to be changed, use bitwise OR '|' to separate them.
[in]enTrue to enable, false to disable.

Definition at line 132 of file gpio.c.

References GPIO_INTEN_A.

◆ gpio_int_mask()

void gpio_int_mask ( uint16_t  gpios,
enum gpio_int_masked  masked 
)

Sets bits in the interrupt mask.

When interrupts are masked, it prevents them from being received, which is a quicker way to turn on and off GPIO interrupts (after calling gpio_int_en()).

Parameters
[in]gpiosPin identifiers GPIO Pin Identifiers If multiple pins are to be changed, use bitwise OR '|' to separate them.
[in]maskedPin mask selection GPIO Interrupt Mask Whether to mask or unmask pins.

Definition at line 155 of file gpio.c.

References GPIO_INTMASK_A.

◆ gpio_int_pol()

void gpio_int_pol ( uint16_t  gpios,
enum gpio_pol  pol 
)

Sets the interrupt trigger polarity.

Sets whether the interrupt is triggered by a high or low level/edge.

Parameters
[in]gpiosPin identifiers GPIO Pin Identifiers If multiple pins are to be changed, use bitwise OR '|' to separate them.
[in]polPolarity GPIO Polarity High or low level/edge

Definition at line 200 of file gpio.c.

References GPIO_INTPOLARITY_A.

◆ gpio_int_raw_status()

uint16_t gpio_int_raw_status ( void  )

Gets the raw unmasked interrupt status.

Returns the raw unmasked interrupt status.

Returns
The unmasked pin interrupt status as a bitfield. The bit position of the pin value returned corresponds to the pin number.

Definition at line 233 of file gpio.c.

References GPIO_RAWINTSTAT_A.

◆ gpio_int_status()

uint16_t gpio_int_status ( void  )

Gets the masked interrupt status.

Returns the pin interrupt status masked with the mask set in gpio_int_mask().

Returns
The masked pin interrupt status as a bitfield. The bit position of the pin value returned corresponds to the pin number.

Definition at line 219 of file gpio.c.

References GPIO_INTSTAT_A.

◆ gpio_int_type()

void gpio_int_type ( uint16_t  gpios,
enum gpio_trig_type  type 
)

Sets whether the pins are edge triggered or level triggered.

Sets whether the pins are edge triggered or level triggered. Edge-triggered interrupt bits must be cleared by software.

Parameters
[in]gpiosPin identifiers GPIO Pin Identifiers If multiple pins are to be changed, use bitwise OR '|' to separate them.
[in]typeTrigger Type GPIO Interrupt Trigger Type Level or edge triggered

Definition at line 178 of file gpio.c.

References GPIO_INTLEVEL_A.

◆ gpio_output()

void gpio_output ( uint16_t  gpios)

Set the direction of a Group of Pins to Output.

Set the direction of one or more pins of GPIO to output.

Parameters
[in]gpiosPin identifiers GPIO Pin Identifiers If multiple pins are to be changed, use bitwise OR '|' to separate them.

Definition at line 114 of file gpio.c.

References GPIO_ADIR.

◆ gpio_set()

void gpio_set ( uint16_t  gpios)

Set a Group of Pins.

Set one or more pins of GPIO to 1. Please note that this chip doesn't support atomic pin setting.

Parameters
[in]gpiosPin identifiers GPIO Pin Identifiers If multiple pins are to be changed, use bitwise OR '|' to separate them.

Definition at line 42 of file gpio.c.

References GPIO_ADATA.

◆ gpio_toggle()

void gpio_toggle ( uint16_t  gpios)

Toggle a Group of Pins.

Toggle one or more pins of GPIO. The non-toggled pins are not affected.

Parameters
[in]gpiosPin identifiers GPIO Pin Identifiers If multiple pins are to be changed, use bitwise OR '|' to separate them.

Definition at line 85 of file gpio.c.

References GPIO_ADATA.