Loading...
Searching...
No Matches
hal_gpio.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Inria
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
20#ifndef HAL_HAL_GPIO_H
21#define HAL_HAL_GPIO_H
22
23#include "periph/gpio.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
32enum {
36 HAL_GPIO_PULL_UP = GPIO_IN_PU,
38 HAL_GPIO_PULL_DOWN = GPIO_IN_PD
39};
44
48enum {
49#ifdef GPIO_NONE
50 HAL_GPIO_TRIG_NONE = GPIO_NONE,
51#endif
53 HAL_GPIO_TRIG_RISING = GPIO_RISING,
55 HAL_GPIO_TRIG_FALLING = GPIO_FALLING,
57 HAL_GPIO_TRIG_BOTH = GPIO_BOTH,
59#ifdef GPIO_LOW
60 HAL_GPIO_TRIG_LOW = GPIO_LOW,
61#endif
63#ifdef GPIO_HIGH
64 HAL_GPIO_TRIG_HIGH = GPIO_HIGH
65#endif
66};
71
76
85static inline int hal_gpio_init_in(gpio_t pin, hal_gpio_pull_t pull)
86{
87 return gpio_init(pin, pull);
88}
89
99static inline int hal_gpio_init_out(gpio_t pin, int val)
100{
101 int res = gpio_init(pin, GPIO_OUT);
102 gpio_write(pin, val);
103 return res;
104}
105
112static inline void hal_gpio_write(gpio_t pin, int val)
113{
114 gpio_write(pin, val);
115}
116
124static inline int hal_gpio_read(gpio_t pin)
125{
126 return gpio_read(pin);
127}
128
136static inline int hal_gpio_toggle(gpio_t pin)
137{
138 gpio_toggle(pin);
139 return gpio_read(pin);
140}
141
153static inline int hal_gpio_irq_init(gpio_t pin,
155 void *arg,
157 hal_gpio_pull_t pull)
158{
159 return gpio_init_int(pin, pull, trig, handler, arg);
160}
161
167static inline void hal_gpio_irq_release(gpio_t pin)
168{
169 /* can't release the interrupt so ar least disable it */
170 gpio_irq_disable(pin);
171}
172
178static inline void hal_gpio_irq_enable(gpio_t pin)
179{
180 gpio_irq_enable(pin);
181}
182
188static inline void hal_gpio_irq_disable(gpio_t pin)
189{
190 gpio_irq_disable(pin);
191}
192
193#ifdef __cplusplus
194}
195#endif
196
197#endif /* HAL_HAL_GPIO_H */
gpio_flank_t
Definition periph_cpu.h:180
@ GPIO_OUT
select GPIO MASK as output
Definition periph_cpu.h:165
@ GPIO_IN
select GPIO MASK as input
Definition periph_cpu.h:164
Low-level GPIO peripheral driver interface definitions.
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:146
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_write(gpio_t pin, int value)
Set the given pin to the given value.
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.
int 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.
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:85
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:153
static void hal_gpio_irq_enable(gpio_t pin)
Enable IRQs on the passed pin.
Definition hal_gpio.h:178
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:167
static int hal_gpio_read(gpio_t pin)
Reads the specified pin.
Definition hal_gpio.h:124
gpio_cb_t hal_gpio_irq_handler_t
Function proto for GPIO irq handler functions.
Definition hal_gpio.h:75
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:112
gpio_flank_t hal_gpio_irq_trig_t
hal_gpio_irq_trig type
Definition hal_gpio.h:70
static int hal_gpio_toggle(gpio_t pin)
Toggles the specified pin.
Definition hal_gpio.h:136
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:99
@ HAL_GPIO_PULL_NONE
Pull-up/down not enabled.
Definition hal_gpio.h:34
@ HAL_GPIO_PULL_DOWN
Pull-down enabled.
Definition hal_gpio.h:38
@ HAL_GPIO_PULL_UP
Pull-up enabled.
Definition hal_gpio.h:36
@ HAL_GPIO_TRIG_FALLING
IRQ occurs on falling edge.
Definition hal_gpio.h:55
@ HAL_GPIO_TRIG_RISING
IRQ occurs on rising edge.
Definition hal_gpio.h:53
@ HAL_GPIO_TRIG_BOTH
IRQ occurs on either edge.
Definition hal_gpio.h:57
static void hal_gpio_irq_disable(gpio_t pin)
Disable IRQs on the passed pin.
Definition hal_gpio.h:188
gpio_mode_t hal_gpio_pull_t
hal_gpio_pull type
Definition hal_gpio.h:43
gpio_mode_t
Available pin modes.
Definition periph_cpu.h:82