Contiki-NG
|
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 | |
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:
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.
#define gpio_hal_arch_write_pin(port, pin, v) sdk_function(port, pin, v)
#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) |
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.
#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()
Definition at line 89 of file gpio-hal.h.
#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.
#define GPIO_HAL_PIN_COUNT 32 |
Specifies the total number of pins on a device.
This macro has no effect if GPIO_HAL_PORT_PIN_NUMBERING is non-zero.
Definition at line 128 of file gpio-hal.h.
Referenced by gpio_hal_arch_no_port_clear_pin(), gpio_hal_arch_no_port_clear_pins(), gpio_hal_arch_no_port_interrupt_disable(), gpio_hal_arch_no_port_interrupt_enable(), gpio_hal_arch_no_port_pin_cfg_get(), gpio_hal_arch_no_port_pin_cfg_set(), gpio_hal_arch_no_port_pin_set_input(), gpio_hal_arch_no_port_pin_set_output(), gpio_hal_arch_no_port_read_pin(), gpio_hal_arch_no_port_read_pins(), gpio_hal_arch_no_port_set_pin(), and gpio_hal_arch_no_port_set_pins().
#define gpio_hal_pin_to_mask | ( | pin | ) | ((gpio_hal_pin_mask_t)1 << (pin)) |
Convert a pin to a pin mask.
pin | The pin |
Definition at line 255 of file gpio-hal.h.
#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().
#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 struct gpio_hal_event_handler_s 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.
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.
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.
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.
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.
void gpio_hal_arch_no_port_clear_pin | ( | gpio_hal_pin_t | pin | ) |
Clear a GPIO pin (logical low)
pin | The 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.
Definition at line 132 of file gpio-hal-arch.c.
References GPIO_HAL_PIN_COUNT.
void gpio_hal_arch_no_port_clear_pins | ( | gpio_hal_pin_mask_t | pins | ) |
Clear multiple pins to logical low.
pins | An 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.
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.
void gpio_hal_arch_no_port_interrupt_disable | ( | gpio_hal_pin_t | pin | ) |
Disable interrupts for a gpio pin.
pin | The 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.
Definition at line 63 of file gpio-hal-arch.c.
References GPIO_HAL_PIN_COUNT.
void gpio_hal_arch_no_port_interrupt_enable | ( | gpio_hal_pin_t | pin | ) |
Enable interrupts for a gpio pin.
pin | The 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.
Definition at line 52 of file gpio-hal-arch.c.
References GPIO_HAL_PIN_COUNT.
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.
pin | The 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.
Definition at line 97 of file gpio-hal-arch.c.
References config(), and GPIO_HAL_PIN_COUNT.
void gpio_hal_arch_no_port_pin_cfg_set | ( | gpio_hal_pin_t | pin, |
gpio_hal_pin_cfg_t | cfg | ||
) |
Configure a gpio pin.
pin | The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) |
cfg | The 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.
Definition at line 48 of file gpio-hal-arch.c.
References config(), and GPIO_HAL_PIN_COUNT.
void gpio_hal_arch_no_port_pin_set_input | ( | gpio_hal_pin_t | pin | ) |
Configure a pin as GPIO input.
pin | The 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.
Definition at line 98 of file gpio-hal-arch.c.
References GPIO_HAL_PIN_COUNT.
void gpio_hal_arch_no_port_pin_set_output | ( | gpio_hal_pin_t | pin | ) |
Configure a pin as GPIO output.
pin | The 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.
Definition at line 109 of file gpio-hal-arch.c.
References GPIO_HAL_PIN_COUNT.
uint8_t gpio_hal_arch_no_port_read_pin | ( | gpio_hal_pin_t | pin | ) |
Read a GPIO pin.
pin | The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) |
0 | The pin is logical low |
1 | The 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.
Definition at line 146 of file gpio-hal-arch.c.
References GPIO_HAL_PIN_COUNT.
gpio_hal_pin_mask_t gpio_hal_arch_no_port_read_pins | ( | gpio_hal_pin_mask_t | pins | ) |
Read multiple pins.
pins | An ORd pin mask of the pins to read |
An | ORd 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.
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.
void gpio_hal_arch_no_port_set_pin | ( | gpio_hal_pin_t | pin | ) |
Set a GPIO pin to logical high.
pin | The 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.
Definition at line 120 of file gpio-hal-arch.c.
References GPIO_HAL_PIN_COUNT.
void gpio_hal_arch_no_port_set_pins | ( | gpio_hal_pin_mask_t | pins | ) |
Set multiple pins to logical high.
pins | An 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.
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.
void gpio_hal_arch_no_port_toggle_pin | ( | gpio_hal_pin_t | pin | ) |
Toggle a GPIO pin.
pin | The 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.
void gpio_hal_arch_no_port_toggle_pins | ( | gpio_hal_pin_mask_t | pins | ) |
Toggle multiple pins.
pins | An 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.
void gpio_hal_arch_no_port_write_pin | ( | gpio_hal_pin_t | pin, |
uint8_t | value | ||
) |
Write a GPIO pin.
pin | The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) |
value | 0: 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.
Definition at line 148 of file gpio-hal-arch.c.
void gpio_hal_arch_no_port_write_pins | ( | gpio_hal_pin_mask_t | pins, |
gpio_hal_pin_mask_t | value | ||
) |
Write multiple pins.
pins | An ORd pin mask of the pins to write |
value | An 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.
Definition at line 189 of file gpio-hal-arch.c.
void gpio_hal_arch_port_clear_pin | ( | gpio_hal_port_t | port, |
gpio_hal_pin_t | pin | ||
) |
Clear a GPIO pin (logical low)
port | The GPIO port |
pin | The 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.
void gpio_hal_arch_port_clear_pins | ( | gpio_hal_port_t | port, |
gpio_hal_pin_mask_t | pins | ||
) |
Clear multiple pins to logical low.
port | The GPIO port |
pins | An 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.
Definition at line 200 of file gpio-hal-arch.c.
void gpio_hal_arch_port_interrupt_disable | ( | gpio_hal_port_t | port, |
gpio_hal_pin_t | pin | ||
) |
Disable interrupts for a gpio pin.
port | The GPIO port |
pin | The 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.
void gpio_hal_arch_port_interrupt_enable | ( | gpio_hal_port_t | port, |
gpio_hal_pin_t | pin | ||
) |
Enable interrupts for a gpio pin.
port | The GPIO port |
pin | The 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.
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.
port | The GPIO port |
pin | The 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.
Definition at line 128 of file gpio-hal-arch.c.
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.
port | The GPIO port |
pin | The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) |
cfg | The 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.
Definition at line 87 of file gpio-hal-arch.c.
void gpio_hal_arch_port_pin_set_input | ( | gpio_hal_port_t | port, |
gpio_hal_pin_t | pin | ||
) |
Configure a pin as GPIO input.
port | The GPIO port |
pin | The 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.
void gpio_hal_arch_port_pin_set_output | ( | gpio_hal_port_t | port, |
gpio_hal_pin_t | pin | ||
) |
Configure a pin as GPIO output.
port | The GPIO port |
pin | The 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.
uint8_t gpio_hal_arch_port_read_pin | ( | gpio_hal_port_t | port, |
gpio_hal_pin_t | pin | ||
) |
Read a GPIO pin.
port | The GPIO port |
pin | The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) |
0 | The pin is logical low |
1 | The 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.
Definition at line 182 of file gpio-hal-arch.c.
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.
port | The GPIO port |
pins | An ORd pin mask of the pins to read |
An | ORd 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.
Definition at line 221 of file gpio-hal-arch.c.
void gpio_hal_arch_port_set_pin | ( | gpio_hal_port_t | port, |
gpio_hal_pin_t | pin | ||
) |
Set a GPIO pin to logical high.
port | The GPIO port |
pin | The 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.
void gpio_hal_arch_port_set_pins | ( | gpio_hal_port_t | port, |
gpio_hal_pin_mask_t | pins | ||
) |
Set multiple pins to logical high.
port | The GPIO port |
pins | An 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.
Definition at line 188 of file gpio-hal-arch.c.
void gpio_hal_arch_port_toggle_pin | ( | gpio_hal_port_t | port, |
gpio_hal_pin_t | pin | ||
) |
Toggle a GPIO pin.
port | The GPIO port |
pin | The 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.
void gpio_hal_arch_port_toggle_pins | ( | gpio_hal_port_t | port, |
gpio_hal_pin_mask_t | pins | ||
) |
Toggle multiple pins.
port | The GPIO port |
pins | An 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.
Definition at line 212 of file gpio-hal-arch.c.
void gpio_hal_arch_port_write_pin | ( | gpio_hal_port_t | port, |
gpio_hal_pin_t | pin, | ||
uint8_t | value | ||
) |
Write a GPIO pin.
port | The GPIO port |
pin | The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) |
value | 0: 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.
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.
port | The GPIO port |
pins | An ORd pin mask of the pins to write |
value | An 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.
Definition at line 233 of file gpio-hal-arch.c.
void gpio_hal_event_handler | ( | gpio_hal_port_t | port, |
gpio_hal_pin_mask_t | pins | ||
) |
The platform-independent GPIO event handler.
port | The GPIO port, if applicable |
pins | OR 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.
Referenced by 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.
handler | The 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.
Definition at line 55 of file gpio-hal.c.
References gpio_hal_event_handler(), list_add(), and list_head().