Loading...
Searching...
No Matches
hal_gpio.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Inria
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
18
19#include "periph/gpio.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
28enum {
32 HAL_GPIO_PULL_UP = GPIO_IN_PU,
34 HAL_GPIO_PULL_DOWN = GPIO_IN_PD
35};
40
44enum {
45#ifdef GPIO_NONE
46 HAL_GPIO_TRIG_NONE = GPIO_NONE,
47#endif
49 HAL_GPIO_TRIG_RISING = GPIO_RISING,
51 HAL_GPIO_TRIG_FALLING = GPIO_FALLING,
53 HAL_GPIO_TRIG_BOTH = GPIO_BOTH,
55#ifdef GPIO_LOW
56 HAL_GPIO_TRIG_LOW = GPIO_LOW,
57#endif
59#ifdef GPIO_HIGH
60 HAL_GPIO_TRIG_HIGH = GPIO_HIGH
61#endif
62};
67
72
81static inline int hal_gpio_init_in(gpio_t pin, hal_gpio_pull_t pull)
82{
83 return gpio_init(pin, pull);
84}
85
95static inline int hal_gpio_init_out(gpio_t pin, int val)
96{
97 int res = gpio_init(pin, GPIO_OUT);
98 gpio_write(pin, val);
99 return res;
100}
101
108static inline void hal_gpio_write(gpio_t pin, int val)
109{
110 gpio_write(pin, val);
111}
112
120static inline int hal_gpio_read(gpio_t pin)
121{
122 return gpio_read(pin);
123}
124
132static inline int hal_gpio_toggle(gpio_t pin)
133{
134 gpio_toggle(pin);
135 return gpio_read(pin);
136}
137
149static inline int hal_gpio_irq_init(gpio_t pin,
151 void *arg,
153 hal_gpio_pull_t pull)
154{
155 return gpio_init_int(pin, pull, trig, handler, arg);
156}
157
163static inline void hal_gpio_irq_release(gpio_t pin)
164{
165 /* can't release the interrupt so ar least disable it */
166 gpio_irq_disable(pin);
167}
168
174static inline void hal_gpio_irq_enable(gpio_t pin)
175{
176 gpio_irq_enable(pin);
177}
178
184static inline void hal_gpio_irq_disable(gpio_t pin)
185{
186 gpio_irq_disable(pin);
187}
188
189#ifdef __cplusplus
190}
191#endif
gpio_flank_t
Definition periph_cpu.h:176
@ GPIO_OUT
select GPIO MASK as output
Definition periph_cpu.h:161
@ GPIO_IN
select GPIO MASK as input
Definition periph_cpu.h:160
Low-level GPIO peripheral driver interface definitions.
gpio_mode_t
Available pin modes.
Definition periph_cpu.h:96
void gpio_toggle(gpio_t pin)
Toggle the value of the given pin.
void(* gpio_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition gpio.h:143
void gpio_write(gpio_t pin, bool value)
Set the given pin to the given value.
int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, gpio_cb_t cb, void *arg)
Initialize a GPIO pin for external interrupt usage.
void gpio_irq_disable(gpio_t pin)
Disable the pin interrupt if configured as interrupt source.
void gpio_irq_enable(gpio_t pin)
Enable pin interrupt if configured as interrupt source.
bool gpio_read(gpio_t pin)
Get the current value of the given pin.
int gpio_init(gpio_t pin, gpio_mode_t mode)
Initialize the given pin as general purpose input or output.
@ HAL_GPIO_TRIG_FALLING
IRQ occurs on falling edge.
Definition hal_gpio.h:51
@ HAL_GPIO_TRIG_RISING
IRQ occurs on rising edge.
Definition hal_gpio.h:49
@ HAL_GPIO_TRIG_BOTH
IRQ occurs on either edge.
Definition hal_gpio.h:53
static int hal_gpio_init_in(gpio_t pin, hal_gpio_pull_t pull)
Initializes the specified pin as an input.
Definition hal_gpio.h:81
static int hal_gpio_irq_init(gpio_t pin, hal_gpio_irq_handler_t handler, void *arg, hal_gpio_irq_trig_t trig, hal_gpio_pull_t pull)
Initialize a given pin to trigger a GPIO IRQ callback.
Definition hal_gpio.h:149
static void hal_gpio_irq_enable(gpio_t pin)
Enable IRQs on the passed pin.
Definition hal_gpio.h:174
static void hal_gpio_irq_release(gpio_t pin)
Release a pin from being configured to trigger IRQ on state change.
Definition hal_gpio.h:163
static int hal_gpio_read(gpio_t pin)
Reads the specified pin.
Definition hal_gpio.h:120
gpio_cb_t hal_gpio_irq_handler_t
Function proto for GPIO irq handler functions.
Definition hal_gpio.h:71
static void hal_gpio_write(gpio_t pin, int val)
Write a value (either high or low) to the specified pin.
Definition hal_gpio.h:108
gpio_flank_t hal_gpio_irq_trig_t
hal_gpio_irq_trig type
Definition hal_gpio.h:66
static int hal_gpio_toggle(gpio_t pin)
Toggles the specified pin.
Definition hal_gpio.h:132
static int hal_gpio_init_out(gpio_t pin, int val)
Initialize the specified pin as an output, setting the pin to the specified value.
Definition hal_gpio.h:95
static void hal_gpio_irq_disable(gpio_t pin)
Disable IRQs on the passed pin.
Definition hal_gpio.h:184
gpio_mode_t hal_gpio_pull_t
hal_gpio_pull type
Definition hal_gpio.h:39
@ HAL_GPIO_PULL_NONE
Pull-up/down not enabled.
Definition hal_gpio.h:30
@ HAL_GPIO_PULL_DOWN
Pull-down enabled.
Definition hal_gpio.h:34
@ HAL_GPIO_PULL_UP
Pull-up enabled.
Definition hal_gpio.h:32