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

Macros

#define GPIO(port)   (GPIO_BASE + (0x040 * (port)))
 
#define GPIO0   (GPIO_BASE + 0x000)
 
#define GPIO1   (GPIO_BASE + 0x040)
 
#define GPIO2   (GPIO_BASE + 0x080)
 
#define GPIO3   (GPIO_BASE + 0x0C0)
 
#define GPIO4   (GPIO_BASE + 0x100)
 
#define GPIO_OFFSET(gpio)   (0x1 << ((gpio) % 32))
 
#define GPIO_PDOR(gpio_base)   MMIO32((gpio_base) + 0x00)
 
#define GPIO_PSOR(gpio_base)   MMIO32((gpio_base) + 0x04)
 
#define GPIO_PCOR(gpio_base)   MMIO32((gpio_base) + 0x08)
 
#define GPIO_PTOR(gpio_base)   MMIO32((gpio_base) + 0x0C)
 
#define GPIO_PDIR(gpio_base)   MMIO32((gpio_base) + 0x10)
 

Functions

void gpio_set (uint32_t gpio)
 Set GPIO. More...
 
void gpio_clear (uint32_t gpio)
 Set GPIO. More...
 
bool gpio_get (uint32_t gpio)
 Get GPIOs logic state. More...
 
void gpio_toggle (uint32_t gpio)
 Toggles GPIO. More...
 
uint32_t gpio_port_read (uint32_t gpioport)
 Read a whole GPIO Port. More...
 
void gpio_port_write (uint32_t gpioport, uint32_t data)
 Write a whole GPIO Port. More...
 

Detailed Description

Macro Definition Documentation

◆ GPIO

#define GPIO (   port)    (GPIO_BASE + (0x040 * (port)))

Definition at line 48 of file gpio.h.

◆ GPIO0

#define GPIO0   (GPIO_BASE + 0x000)

Definition at line 49 of file gpio.h.

◆ GPIO1

#define GPIO1   (GPIO_BASE + 0x040)

Definition at line 50 of file gpio.h.

◆ GPIO2

#define GPIO2   (GPIO_BASE + 0x080)

Definition at line 51 of file gpio.h.

◆ GPIO3

#define GPIO3   (GPIO_BASE + 0x0C0)

Definition at line 52 of file gpio.h.

◆ GPIO4

#define GPIO4   (GPIO_BASE + 0x100)

Definition at line 53 of file gpio.h.

◆ GPIO_OFFSET

#define GPIO_OFFSET (   gpio)    (0x1 << ((gpio) % 32))

Definition at line 55 of file gpio.h.

◆ GPIO_PCOR

#define GPIO_PCOR (   gpio_base)    MMIO32((gpio_base) + 0x08)

Definition at line 61 of file gpio.h.

◆ GPIO_PDIR

#define GPIO_PDIR (   gpio_base)    MMIO32((gpio_base) + 0x10)

Definition at line 63 of file gpio.h.

◆ GPIO_PDOR

#define GPIO_PDOR (   gpio_base)    MMIO32((gpio_base) + 0x00)

Definition at line 59 of file gpio.h.

◆ GPIO_PSOR

#define GPIO_PSOR (   gpio_base)    MMIO32((gpio_base) + 0x04)

Definition at line 60 of file gpio.h.

◆ GPIO_PTOR

#define GPIO_PTOR (   gpio_base)    MMIO32((gpio_base) + 0x0C)

Definition at line 62 of file gpio.h.

Function Documentation

◆ gpio_clear()

void gpio_clear ( uint32_t  gpio)

Set GPIO.

Clears GPIO by GPIO number according to MUX list

Parameters
[in]gpiounsigned 32 bit. GPIO number

Definition at line 65 of file gpio.c.

References GPIO, GPIO_OFFSET, and GPIO_PCOR.

◆ gpio_get()

bool gpio_get ( uint32_t  gpio)

Get GPIOs logic state.

Get logic level of GPIO given by GPIO number according to MUX list. Reading a GPIO value is possible even if the port is not muxed for GPIO.

Parameters
[in]gpiounsigned 32 bit. GPIO number
Returns
the logic state of the given GPIO.

Definition at line 81 of file gpio.c.

References GPIO, GPIO_OFFSET, and GPIO_PDIR.

◆ gpio_port_read()

uint32_t gpio_port_read ( uint32_t  gpioport)

Read a whole GPIO Port.

Gets all 32 GPIOs of a Port.

Parameters
[in]gpioportunsigned 32 bit. GPIO port GPIO register base addresses
Returns
the logic states of the given GPIO port.

Definition at line 110 of file gpio.c.

References GPIO_PDIR.

◆ gpio_port_write()

void gpio_port_write ( uint32_t  gpioport,
uint32_t  data 
)

Write a whole GPIO Port.

Sets all 32 GPIOs of a Port.

Parameters
[in]gpioportunsigned 32 bit. GPIO port GPIO register base addresses
[in]gpiounsigned 32 bit. 1 for a logic 1 driven at port, 0 for a logic 0 driven at port.

Definition at line 125 of file gpio.c.

References GPIO_PDOR.

◆ gpio_set()

void gpio_set ( uint32_t  gpio)

Set GPIO.

Set GPIO by GPIO number according to MUX list

Parameters
[in]gpiounsigned 32 bit. GPIO number

Definition at line 51 of file gpio.c.

References GPIO, GPIO_OFFSET, and GPIO_PSOR.

◆ gpio_toggle()

void gpio_toggle ( uint32_t  gpio)

Toggles GPIO.

Toggles GPIO by GPIO number according to MUX list

Parameters
[in]gpiounsigned 32 bit. GPIO number

Definition at line 95 of file gpio.c.

References GPIO, GPIO_OFFSET, and GPIO_PTOR.