Contiki-NG
Files | Data Structures | Macros | Typedefs
GPIO Hardware Abstraction Layer

The GPIO HAL provides a set of common functions that can be used in a platform-independent fashion. More...

Files

file  gpio-hal.c
 Implementation of the platform-independent aspects of the GPIO HAL.
 
file  gpio-hal.h
 Header file for the GPIO HAL.
 

Data Structures

struct  gpio_hal_event_handler_s
 Datatype for GPIO event handlers. More...
 

Macros

#define GPIO_HAL_PORT_PIN_NUMBERING   1
 Specifies whether the HAL should support a port/pin convention. More...
 
#define GPIO_HAL_ARCH_SW_TOGGLE   1
 Specifies whether software-based pin toggle is required. More...
 
#define GPIO_HAL_NULL_PORT   0
 Convenience macro to use this as the port argument of macros. More...
 
#define GPIO_HAL_PIN_COUNT   32
 Specifies the total number of pins on a device. More...
 
#define GPIO_HAL_PIN_UNKNOWN   0xFF
 Unknown GPIO. More...
 

Typedefs

typedef uint8_t gpio_hal_pin_t
 GPIO pin number representation.
 
typedef uint8_t gpio_hal_port_t
 A data structure that represents ports. More...
 
typedef uint32_t gpio_hal_pin_cfg_t
 GPIO pin configuration. More...
 
typedef uint32_t gpio_hal_pin_mask_t
 GPIO pin mask representation. More...
 
typedef struct gpio_hal_event_handler_s gpio_hal_event_handler_t
 Datatype for GPIO event handlers. More...
 

Core GPIO functions

Functions implemented by the HAL itself

void gpio_hal_register_handler (gpio_hal_event_handler_t *handler)
 Register a function to be called whenever a pin triggers an event. More...
 
void gpio_hal_init (void)
 Initialise the GPIO HAL.
 
void gpio_hal_event_handler (gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
 The platform-independent GPIO event handler. More...
 
#define gpio_hal_pin_to_mask(pin)   ((gpio_hal_pin_mask_t)1 << (pin))
 Convert a pin to a pin mask. More...
 

GPIO pin manipulation functions to be provided by the platform code.

All functions have two flavours:

  • gpio_hal_arch_port_foo are used when GPIO_HAL_PORT_PIN_NUMBERING is non-zero and expect a gpio_hal_port_t as one of their arguments
  • gpio_hal_arch_no_port_foo are used when GPIO_HAL_PORT_PIN_NUMBERING is 0 and do not expect a gpio_hal_port_t as one of their arguments

Macros are provided that automatically expand to the desirable prototype depending on the value of GPIO_HAL_PORT_PIN_NUMBERING. In order to achieve code portability, all platform-independent code should use those macros to manipulate GPIOs instead of using the port_ / no_port_ functions directly. A convenience macro GPIO_HAL_NULL_PORT is provided to be used as the port argument of macros when GPIO_HAL_PORT_PIN_NUMBERING is zero.

All the functions below must be provided by the platform's developer. The HAL offers the developer a number of options of how to provide the required functionality.

  • The developer can provide a symbol. For example, the developer can create a .c file and implement a function called gpio_hal_arch_set_port_pin(). In this scenario the developer only needs to provide a symbol for the gpio_hal_arch_port_foo / gpio_hal_arch_no_port_foo that applies.
  • The developer can provide a function-like macro that has the same name as one of the manipulation macros declared here. In this scenario, the declaration here will be removed by the pre-processor. For example, the developer can do something like:
#define gpio_hal_arch_write_pin(port, pin, v) sdk_function(port, pin, v)
  • The developer can provide a static inline implementation. For this to work, the developer can do something like:
#define gpio_hal_arch_set_pin(port, pin) set_pin(port, pin)
static inline void set_pin(gpio_hal_port_t port, gpio_hal_pin_t pin) { ... }

In the latter two cases, the developer will likely provide implementations in a header file. In this scenario, one of the platform's configuration files must define GPIO_HAL_CONF_ARCH_HDR_PATH to the name of this header file. For example:

#define GPIO_HAL_CONF_ARCH_HDR_PATH "dev/gpio-hal-arch.h"
void gpio_hal_arch_init (void)
 Perform architecture specific gpio initaliaztion. More...
 
void gpio_hal_arch_port_interrupt_enable (gpio_hal_port_t port, gpio_hal_pin_t pin)
 Enable interrupts for a gpio pin. More...
 
void gpio_hal_arch_no_port_interrupt_enable (gpio_hal_pin_t pin)
 Enable interrupts for a gpio pin. More...
 
void gpio_hal_arch_port_interrupt_disable (gpio_hal_port_t port, gpio_hal_pin_t pin)
 Disable interrupts for a gpio pin. More...
 
void gpio_hal_arch_no_port_interrupt_disable (gpio_hal_pin_t pin)
 Disable interrupts for a gpio pin. More...
 
void gpio_hal_arch_port_pin_cfg_set (gpio_hal_port_t port, gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
 Configure a gpio pin. More...
 
void gpio_hal_arch_no_port_pin_cfg_set (gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
 Configure a gpio pin. More...
 
gpio_hal_pin_cfg_t gpio_hal_arch_port_pin_cfg_get (gpio_hal_port_t port, gpio_hal_pin_t pin)
 Read the configuration of a GPIO pin. More...
 
gpio_hal_pin_cfg_t gpio_hal_arch_no_port_pin_cfg_get (gpio_hal_pin_t pin)
 Read the configuration of a GPIO pin. More...
 
void gpio_hal_arch_port_pin_set_input (gpio_hal_port_t port, gpio_hal_pin_t pin)
 Configure a pin as GPIO input. More...
 
void gpio_hal_arch_no_port_pin_set_input (gpio_hal_pin_t pin)
 Configure a pin as GPIO input. More...
 
void gpio_hal_arch_port_pin_set_output (gpio_hal_port_t port, gpio_hal_pin_t pin)
 Configure a pin as GPIO output. More...
 
void gpio_hal_arch_no_port_pin_set_output (gpio_hal_pin_t pin)
 Configure a pin as GPIO output. More...
 
void gpio_hal_arch_port_set_pin (gpio_hal_port_t port, gpio_hal_pin_t pin)
 Set a GPIO pin to logical high. More...
 
void gpio_hal_arch_no_port_set_pin (gpio_hal_pin_t pin)
 Set a GPIO pin to logical high. More...
 
void gpio_hal_arch_port_clear_pin (gpio_hal_port_t port, gpio_hal_pin_t pin)
 Clear a GPIO pin (logical low) More...
 
void gpio_hal_arch_no_port_clear_pin (gpio_hal_pin_t pin)
 Clear a GPIO pin (logical low) More...
 
void gpio_hal_arch_port_toggle_pin (gpio_hal_port_t port, gpio_hal_pin_t pin)
 Toggle a GPIO pin. More...
 
void gpio_hal_arch_no_port_toggle_pin (gpio_hal_pin_t pin)
 Toggle a GPIO pin. More...
 
uint8_t gpio_hal_arch_port_read_pin (gpio_hal_port_t port, gpio_hal_pin_t pin)
 Read a GPIO pin. More...
 
uint8_t gpio_hal_arch_no_port_read_pin (gpio_hal_pin_t pin)
 Read a GPIO pin. More...
 
void gpio_hal_arch_port_write_pin (gpio_hal_port_t port, gpio_hal_pin_t pin, uint8_t value)
 Write a GPIO pin. More...
 
void gpio_hal_arch_no_port_write_pin (gpio_hal_pin_t pin, uint8_t value)
 Write a GPIO pin. More...
 
void gpio_hal_arch_port_set_pins (gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
 Set multiple pins to logical high. More...
 
void gpio_hal_arch_no_port_set_pins (gpio_hal_pin_mask_t pins)
 Set multiple pins to logical high. More...
 
void gpio_hal_arch_port_clear_pins (gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
 Clear multiple pins to logical low. More...
 
void gpio_hal_arch_no_port_clear_pins (gpio_hal_pin_mask_t pins)
 Clear multiple pins to logical low. More...
 
void gpio_hal_arch_port_toggle_pins (gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
 Toggle multiple pins. More...
 
void gpio_hal_arch_no_port_toggle_pins (gpio_hal_pin_mask_t pins)
 Toggle multiple pins. More...
 
gpio_hal_pin_mask_t gpio_hal_arch_port_read_pins (gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
 Read multiple pins. More...
 
gpio_hal_pin_mask_t gpio_hal_arch_no_port_read_pins (gpio_hal_pin_mask_t pins)
 Read multiple pins. More...
 
void gpio_hal_arch_port_write_pins (gpio_hal_port_t port, gpio_hal_pin_mask_t pins, gpio_hal_pin_mask_t value)
 Write multiple pins. More...
 
void gpio_hal_arch_no_port_write_pins (gpio_hal_pin_mask_t pins, gpio_hal_pin_mask_t value)
 Write multiple pins. More...
 
#define gpio_hal_arch_interrupt_enable(port, pin)   gpio_hal_arch_port_interrupt_enable(port, pin)
 
#define gpio_hal_arch_interrupt_disable(port, pin)   gpio_hal_arch_port_interrupt_disable(port, pin)
 
#define gpio_hal_arch_pin_cfg_set(port, pin, cfg)   gpio_hal_arch_port_pin_cfg_set(port, pin, cfg)
 
#define gpio_hal_arch_pin_cfg_get(port, pin)   gpio_hal_arch_port_pin_cfg_get(port, pin)
 
#define gpio_hal_arch_pin_set_input(port, pin)   gpio_hal_arch_port_pin_set_input(port, pin)
 
#define gpio_hal_arch_pin_set_output(port, pin)   gpio_hal_arch_port_pin_set_output(port, pin)
 
#define gpio_hal_arch_set_pin(port, pin)   gpio_hal_arch_port_set_pin(port, pin)
 
#define gpio_hal_arch_clear_pin(port, pin)   gpio_hal_arch_port_clear_pin(port, pin)
 
#define gpio_hal_arch_toggle_pin(port, pin)   gpio_hal_arch_port_toggle_pin(port, pin)
 
#define gpio_hal_arch_read_pin(port, pin)   gpio_hal_arch_port_read_pin(port, pin)
 
#define gpio_hal_arch_write_pin(port, pin, value)   gpio_hal_arch_port_write_pin(port, pin, value)
 
#define gpio_hal_arch_set_pins(port, pin)   gpio_hal_arch_port_set_pins(port, pin)
 
#define gpio_hal_arch_clear_pins(port, pin)   gpio_hal_arch_port_clear_pins(port, pin)
 
#define gpio_hal_arch_toggle_pins(port, pin)   gpio_hal_arch_port_toggle_pins(port, pin)
 
#define gpio_hal_arch_read_pins(port, pin)   gpio_hal_arch_port_read_pins(port, pin)
 
#define gpio_hal_arch_write_pins(port, pin, value)   gpio_hal_arch_port_write_pins(port, pin, value)
 

Detailed Description

The GPIO HAL provides a set of common functions that can be used in a platform-independent fashion.

Internally, the GPIO HAL handles edge detection handling and also provides fallback functions for GPIO pin toggling if the hardware does not have a direct method of toggling pins through direct register access.

Macro Definition Documentation

◆ GPIO_HAL_ARCH_SW_TOGGLE

#define GPIO_HAL_ARCH_SW_TOGGLE   1

Specifies whether software-based pin toggle is required.

Some MCUs allow GPIO pin toggling via direct register access. For these MCUs, define GPIO_HAL_CONF_ARCH_SW_TOGGLE to 0 and then implement gpio_hal_arch_toggle_pin() and gpio_hal_arch_toggle_pins()

See also
gpio_hal_arch_toggle_pin()
gpio_hal_arch_toggle_pins()

Definition at line 89 of file gpio-hal.h.

◆ GPIO_HAL_NULL_PORT

#define GPIO_HAL_NULL_PORT   0

Convenience macro to use this as the port argument of macros.

Use this as the port argument of macros when GPIO_HAL_PORT_PIN_NUMBERING is zero

Definition at line 98 of file gpio-hal.h.

◆ GPIO_HAL_PIN_COUNT

#define GPIO_HAL_PIN_COUNT   32

◆ gpio_hal_pin_to_mask

#define gpio_hal_pin_to_mask (   pin)    ((gpio_hal_pin_mask_t)1 << (pin))

Convert a pin to a pin mask.

Parameters
pinThe pin
Returns
The corresponding mask

Definition at line 255 of file gpio-hal.h.

◆ GPIO_HAL_PIN_UNKNOWN

#define GPIO_HAL_PIN_UNKNOWN   0xFF

Unknown GPIO.

A default GPIO value for unknown GPIO

Definition at line 194 of file gpio-hal.h.

Referenced by ext_flash_open().

◆ GPIO_HAL_PORT_PIN_NUMBERING

#define GPIO_HAL_PORT_PIN_NUMBERING   1

Specifies whether the HAL should support a port/pin convention.

Some MCUs specify GPIOs as a port/pin combination, whereas some others only use a pin number. Our GPIO HAL supports both conventions in a portable fashion and this define is used to set the HAL in the desired of the two modes.

The port developer should define GPIO_HAL_CONF_PORT_PIN_NUMBERING as a if the platform uses port/pin numbering, or to 0 if the platform only uses a simple number.

Definition at line 73 of file gpio-hal.h.

Typedef Documentation

◆ gpio_hal_event_handler_t

Datatype for GPIO event handlers.

A GPIO event handler is a function that gets called whenever a pin triggers an event. The same handler can be registered to handle events for more than one pin by setting the respective pin's position but in pin_mask.

If GPIO_HAL_PORT_PIN_NUMBERING is non-zero, a separate handler is required per port.

◆ gpio_hal_pin_cfg_t

typedef uint32_t gpio_hal_pin_cfg_t

GPIO pin configuration.

A logical representation of a pin's configuration. It is an OR combination of GPIO_HAL_PIN_CFG_xyz macros.

Definition at line 118 of file gpio-hal.h.

◆ gpio_hal_pin_mask_t

typedef uint32_t gpio_hal_pin_mask_t

GPIO pin mask representation.

A mask that can be used to represent multiple pins using a single variable.

When GPIO_HAL_PORT_PIN_NUMBERING is non-zero, such variables can only be used to represent pins within the same port.

Definition at line 142 of file gpio-hal.h.

◆ gpio_hal_port_t

typedef uint8_t gpio_hal_port_t

A data structure that represents ports.

This is only relevant if GPIO_HAL_PORT_PIN_NUMBERING is non-zero

Definition at line 110 of file gpio-hal.h.

Function Documentation

◆ gpio_hal_arch_init()

void gpio_hal_arch_init ( void  )

Perform architecture specific gpio initaliaztion.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Definition at line 46 of file gpio-hal-arch.c.

◆ gpio_hal_arch_no_port_clear_pin()

void gpio_hal_arch_no_port_clear_pin ( gpio_hal_pin_t  pin)

Clear a GPIO pin (logical low)

Parameters
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 132 of file gpio-hal-arch.c.

References GPIO_HAL_PIN_COUNT.

◆ gpio_hal_arch_no_port_clear_pins()

void gpio_hal_arch_no_port_clear_pins ( gpio_hal_pin_mask_t  pins)

Clear multiple pins to logical low.

Parameters
pinsAn ORd pin mask of the pins to clear

A pin will be set to logical low if its position in pins is set. For example you can clear pins 0 and 3 by passing 0x09.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 167 of file gpio-hal-arch.c.

References GPIO_A_BASE, GPIO_B_BASE, GPIO_C_BASE, GPIO_CLR_PIN, GPIO_D_BASE, and GPIO_HAL_PIN_COUNT.

◆ gpio_hal_arch_no_port_interrupt_disable()

void gpio_hal_arch_no_port_interrupt_disable ( gpio_hal_pin_t  pin)

Disable interrupts for a gpio pin.

Parameters
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 63 of file gpio-hal-arch.c.

References GPIO_HAL_PIN_COUNT.

◆ gpio_hal_arch_no_port_interrupt_enable()

void gpio_hal_arch_no_port_interrupt_enable ( gpio_hal_pin_t  pin)

Enable interrupts for a gpio pin.

Parameters
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 52 of file gpio-hal-arch.c.

References GPIO_HAL_PIN_COUNT.

◆ gpio_hal_arch_no_port_pin_cfg_get()

gpio_hal_pin_cfg_t gpio_hal_arch_no_port_pin_cfg_get ( gpio_hal_pin_t  pin)

Read the configuration of a GPIO pin.

Parameters
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)
Returns
An OR mask of GPIO_HAL_PIN_CFG_xyz

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 97 of file gpio-hal-arch.c.

References config(), and GPIO_HAL_PIN_COUNT.

◆ gpio_hal_arch_no_port_pin_cfg_set()

void gpio_hal_arch_no_port_pin_cfg_set ( gpio_hal_pin_t  pin,
gpio_hal_pin_cfg_t  cfg 
)

Configure a gpio pin.

Parameters
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)
cfgThe configuration

cfg is an OR mask of GPIO_HAL_PIN_CFG_xyz

The implementation of this function also has to make sure that pin is configured as software-controlled GPIO.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 48 of file gpio-hal-arch.c.

References config(), and GPIO_HAL_PIN_COUNT.

◆ gpio_hal_arch_no_port_pin_set_input()

void gpio_hal_arch_no_port_pin_set_input ( gpio_hal_pin_t  pin)

Configure a pin as GPIO input.

Parameters
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

The implementation of this function also has to make sure that pin is configured as software-controlled GPIO.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 98 of file gpio-hal-arch.c.

References GPIO_HAL_PIN_COUNT.

◆ gpio_hal_arch_no_port_pin_set_output()

void gpio_hal_arch_no_port_pin_set_output ( gpio_hal_pin_t  pin)

Configure a pin as GPIO output.

Parameters
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

The implementation of this function also has to make sure that pin is configured as software-controlled GPIO.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 109 of file gpio-hal-arch.c.

References GPIO_HAL_PIN_COUNT.

◆ gpio_hal_arch_no_port_read_pin()

uint8_t gpio_hal_arch_no_port_read_pin ( gpio_hal_pin_t  pin)

Read a GPIO pin.

Parameters
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)
Return values
0The pin is logical low
1The pin is logical high

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 146 of file gpio-hal-arch.c.

References GPIO_HAL_PIN_COUNT.

◆ gpio_hal_arch_no_port_read_pins()

gpio_hal_pin_mask_t gpio_hal_arch_no_port_read_pins ( gpio_hal_pin_mask_t  pins)

Read multiple pins.

Parameters
pinsAn ORd pin mask of the pins to read
Return values
AnORd mask of the pins that are high

If the position of the pin in pins is set and the pin is logical high then the position of the pin in the return value will be set. For example, if you pass 0x09 as the value of pins and the return value is 0x08 then pin 3 is logical high and pin 0 is logical low.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 176 of file gpio-hal-arch.c.

References GPIO_A_BASE, GPIO_B_BASE, GPIO_C_BASE, GPIO_D_BASE, GPIO_HAL_PIN_COUNT, and GPIO_READ_PIN.

◆ gpio_hal_arch_no_port_set_pin()

void gpio_hal_arch_no_port_set_pin ( gpio_hal_pin_t  pin)

Set a GPIO pin to logical high.

Parameters
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 120 of file gpio-hal-arch.c.

References GPIO_HAL_PIN_COUNT.

◆ gpio_hal_arch_no_port_set_pins()

void gpio_hal_arch_no_port_set_pins ( gpio_hal_pin_mask_t  pins)

Set multiple pins to logical high.

Parameters
pinsAn ORd pin mask of the pins to set

A pin will be set to logical high if its position in pins is set. For example you can set pins 0 and 3 by passing 0x09.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 158 of file gpio-hal-arch.c.

References GPIO_A_BASE, GPIO_B_BASE, GPIO_C_BASE, GPIO_D_BASE, GPIO_HAL_PIN_COUNT, and GPIO_SET_PIN.

◆ gpio_hal_arch_no_port_toggle_pin()

void gpio_hal_arch_no_port_toggle_pin ( gpio_hal_pin_t  pin)

Toggle a GPIO pin.

Parameters
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

Some MCUs allow GPIO pin toggling directly via register access. In this case, it is a good idea to provide an implementation of this function. However, a default, software-based implementation is also provided by the HAL and can be used if the MCU does not have a pin toggle register. To use the HAL function, define GPIO_HAL_ARCH_SW_TOGGLE as 1. To provide your own implementation, define GPIO_HAL_ARCH_SW_TOGGLE as 0.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

◆ gpio_hal_arch_no_port_toggle_pins()

void gpio_hal_arch_no_port_toggle_pins ( gpio_hal_pin_mask_t  pins)

Toggle multiple pins.

Parameters
pinsAn ORd pin mask of the pins to toggle

A pin will be toggled if its position in pins is set. For example you can toggle pins 0 and 3 by passing 0x09.

Some MCUs allow GPIO pin toggling directly via register access. In this case, it is a good idea to provide an implementation of this function. However, a default, software-based implementation is also provided by the HAL and can be used if the MCU does not have a pin toggle register. To use the HAL function, define GPIO_HAL_ARCH_SW_TOGGLE as 1. To provide your own implementation, define GPIO_HAL_ARCH_SW_TOGGLE as 0.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

◆ gpio_hal_arch_no_port_write_pin()

void gpio_hal_arch_no_port_write_pin ( gpio_hal_pin_t  pin,
uint8_t  value 
)

Write a GPIO pin.

Parameters
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)
value0: Logical low; 1: Logical high

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 148 of file gpio-hal-arch.c.

◆ gpio_hal_arch_no_port_write_pins()

void gpio_hal_arch_no_port_write_pins ( gpio_hal_pin_mask_t  pins,
gpio_hal_pin_mask_t  value 
)

Write multiple pins.

Parameters
pinsAn ORd pin mask of the pins to write
valueAn ORd mask of the value to write

The function will modify GPIO pins that have their position in the mask set. pins, the function will write the value specified in the corresponding position in value.

For example, you can set pin 3 and clear pin 0 by a single call to this function. To achieve this, pins must be 0x09 and value 0x08.

It is the platform developer's responsibility to provide an implementation.

There is no guarantee that this function will result in an atomic operation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 189 of file gpio-hal-arch.c.

◆ gpio_hal_arch_port_clear_pin()

void gpio_hal_arch_port_clear_pin ( gpio_hal_port_t  port,
gpio_hal_pin_t  pin 
)

Clear a GPIO pin (logical low)

Parameters
portThe GPIO port
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

◆ gpio_hal_arch_port_clear_pins()

void gpio_hal_arch_port_clear_pins ( gpio_hal_port_t  port,
gpio_hal_pin_mask_t  pins 
)

Clear multiple pins to logical low.

Parameters
portThe GPIO port
pinsAn ORd pin mask of the pins to clear

A pin will be set to logical low if its position in pins is set. For example you can clear pins 0 and 3 by passing 0x09.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 184 of file gpio-hal-arch.c.

◆ gpio_hal_arch_port_interrupt_disable()

void gpio_hal_arch_port_interrupt_disable ( gpio_hal_port_t  port,
gpio_hal_pin_t  pin 
)

Disable interrupts for a gpio pin.

Parameters
portThe GPIO port
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

◆ gpio_hal_arch_port_interrupt_enable()

void gpio_hal_arch_port_interrupt_enable ( gpio_hal_port_t  port,
gpio_hal_pin_t  pin 
)

Enable interrupts for a gpio pin.

Parameters
portThe GPIO port
pinThe GPIO pin number

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

◆ gpio_hal_arch_port_pin_cfg_get()

gpio_hal_pin_cfg_t gpio_hal_arch_port_pin_cfg_get ( gpio_hal_port_t  port,
gpio_hal_pin_t  pin 
)

Read the configuration of a GPIO pin.

Parameters
portThe GPIO port
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)
Returns
An OR mask of GPIO_HAL_PIN_CFG_xyz

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 113 of file gpio-hal-arch.c.

◆ gpio_hal_arch_port_pin_cfg_set()

void gpio_hal_arch_port_pin_cfg_set ( gpio_hal_port_t  port,
gpio_hal_pin_t  pin,
gpio_hal_pin_cfg_t  cfg 
)

Configure a gpio pin.

Parameters
portThe GPIO port
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)
cfgThe configuration

cfg is an OR mask of GPIO_HAL_PIN_CFG_xyz

The implementation of this function also has to make sure that pin is configured as software-controlled GPIO.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 72 of file gpio-hal-arch.c.

◆ gpio_hal_arch_port_pin_set_input()

void gpio_hal_arch_port_pin_set_input ( gpio_hal_port_t  port,
gpio_hal_pin_t  pin 
)

Configure a pin as GPIO input.

Parameters
portThe GPIO port
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

The implementation of this function also has to make sure that pin is configured as software-controlled GPIO.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

◆ gpio_hal_arch_port_pin_set_output()

void gpio_hal_arch_port_pin_set_output ( gpio_hal_port_t  port,
gpio_hal_pin_t  pin 
)

Configure a pin as GPIO output.

Parameters
portThe GPIO port
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

The implementation of this function also has to make sure that pin is configured as software-controlled GPIO.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

◆ gpio_hal_arch_port_read_pin()

uint8_t gpio_hal_arch_port_read_pin ( gpio_hal_port_t  port,
gpio_hal_pin_t  pin 
)

Read a GPIO pin.

Parameters
portThe GPIO port
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)
Return values
0The pin is logical low
1The pin is logical high

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 167 of file gpio-hal-arch.c.

◆ gpio_hal_arch_port_read_pins()

gpio_hal_pin_mask_t gpio_hal_arch_port_read_pins ( gpio_hal_port_t  port,
gpio_hal_pin_mask_t  pins 
)

Read multiple pins.

Parameters
portThe GPIO port
pinsAn ORd pin mask of the pins to read
Return values
AnORd mask of the pins that are high

If the position of the pin in pins is set and the pin is logical high then the position of the pin in the return value will be set. For example, if you pass 0x09 as the value of pins and the return value is 0x08 then pin 3 is logical high and pin 0 is logical low.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 205 of file gpio-hal-arch.c.

◆ gpio_hal_arch_port_set_pin()

void gpio_hal_arch_port_set_pin ( gpio_hal_port_t  port,
gpio_hal_pin_t  pin 
)

Set a GPIO pin to logical high.

Parameters
portThe GPIO port
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

◆ gpio_hal_arch_port_set_pins()

void gpio_hal_arch_port_set_pins ( gpio_hal_port_t  port,
gpio_hal_pin_mask_t  pins 
)

Set multiple pins to logical high.

Parameters
portThe GPIO port
pinsAn ORd pin mask of the pins to set

A pin will be set to logical high if its position in pins is set. For example you can set pins 0 and 3 by passing 0x09.

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 172 of file gpio-hal-arch.c.

◆ gpio_hal_arch_port_toggle_pin()

void gpio_hal_arch_port_toggle_pin ( gpio_hal_port_t  port,
gpio_hal_pin_t  pin 
)

Toggle a GPIO pin.

Parameters
portThe GPIO port
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)

Some MCUs allow GPIO pin toggling directly via register access. In this case, it is a good idea to provide an implementation of this function. However, a default, software-based implementation is also provided by the HAL and can be used if the MCU does not have a pin toggle register. To use the HAL function, define GPIO_HAL_ARCH_SW_TOGGLE as 1. To provide your own implementation, define GPIO_HAL_ARCH_SW_TOGGLE as 0.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

◆ gpio_hal_arch_port_toggle_pins()

void gpio_hal_arch_port_toggle_pins ( gpio_hal_port_t  port,
gpio_hal_pin_mask_t  pins 
)

Toggle multiple pins.

Parameters
portThe GPIO port
pinsAn ORd pin mask of the pins to toggle

A pin will be toggled if its position in pins is set. For example you can toggle pins 0 and 3 by passing 0x09.

Some MCUs allow GPIO pin toggling directly via register access. In this case, it is a good idea to provide an implementation of this function. However, a default, software-based implementation is also provided by the HAL and can be used if the MCU does not have a pin toggle register. To use the HAL function, define GPIO_HAL_ARCH_SW_TOGGLE as 1. To provide your own implementation, define GPIO_HAL_ARCH_SW_TOGGLE as 0.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 196 of file gpio-hal-arch.c.

◆ gpio_hal_arch_port_write_pin()

void gpio_hal_arch_port_write_pin ( gpio_hal_port_t  port,
gpio_hal_pin_t  pin,
uint8_t  value 
)

Write a GPIO pin.

Parameters
portThe GPIO port
pinThe GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1)
value0: Logical low; 1: Logical high

It is the platform developer's responsibility to provide an implementation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

◆ gpio_hal_arch_port_write_pins()

void gpio_hal_arch_port_write_pins ( gpio_hal_port_t  port,
gpio_hal_pin_mask_t  pins,
gpio_hal_pin_mask_t  value 
)

Write multiple pins.

Parameters
portThe GPIO port
pinsAn ORd pin mask of the pins to write
valueAn ORd mask of the value to write

The function will modify GPIO pins that have their position in the mask set. pins, the function will write the value specified in the corresponding position in value.

For example, you can set pin 3 and clear pin 0 by a single call to this function. To achieve this, pins must be 0x09 and value 0x08.

It is the platform developer's responsibility to provide an implementation.

There is no guarantee that this function will result in an atomic operation.

The implementation can be provided as a global symbol, an inline function or a function-like macro, as described above.

Note
Code should not call this function directly. Use GPIO manipulation macros instead.

Definition at line 217 of file gpio-hal-arch.c.

◆ gpio_hal_event_handler()

void gpio_hal_event_handler ( gpio_hal_port_t  port,
gpio_hal_pin_mask_t  pins 
)

The platform-independent GPIO event handler.

Parameters
portThe GPIO port, if applicable
pinsOR mask of pins that generated an event

Whenever a GPIO input interrupt occurs (edge or level detection) and an ISR is triggered, the ISR must call this function, passing as argument an ORd mask of the pins that triggered the interrupt. This function will then call the registered event handlers (if any) for the pins that triggered the event. The platform code should make no assumptions as to the order that the handlers will be called.

If a pin set in the mask has an event handler registered, this function will call the registered handler.

If GPIO_HAL_PORT_PIN_NUMBERING is non-zero the function will also accept as its first argument the port associated to the pins that triggered the edge detection.

This function will not clear any CPU interrupt flags, this should be done by the calling ISR.

See also
gpio_hal_register_handler

Referenced by gpio_hal_register_handler().

◆ gpio_hal_register_handler()

void gpio_hal_register_handler ( gpio_hal_event_handler_t handler)

Register a function to be called whenever a pin triggers an event.

Parameters
handlerThe handler representation

The handler must be pre-allocated statically by the caller.

This function can be used to register a function to be called by the HAL whenever a GPIO interrupt occurs.

See also
gpio_hal_event_handler

Definition at line 55 of file gpio-hal.c.

References gpio_hal_event_handler(), list_add(), and list_head().