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
26 extern "C" {
27 #endif
28 
32 enum {
39 };
44 
48 enum {
49 #ifdef GPIO_NONE
50  HAL_GPIO_TRIG_NONE = GPIO_NONE,
51 #endif
52 
59 #ifdef GPIO_LOW
60  HAL_GPIO_TRIG_LOW = GPIO_LOW,
61 #endif
62 
63 #ifdef GPIO_HIGH
64  HAL_GPIO_TRIG_HIGH = GPIO_HIGH
65 #endif
66 };
71 
76 
85 static inline int hal_gpio_init_in(gpio_t pin, hal_gpio_pull_t pull)
86 {
87  return gpio_init(pin, pull);
88 }
89 
99 static 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 
112 static inline void hal_gpio_write(gpio_t pin, int val)
113 {
114  gpio_write(pin, val);
115 }
116 
124 static inline int hal_gpio_read(gpio_t pin)
125 {
126  return gpio_read(pin);
127 }
128 
136 static inline int hal_gpio_toggle(gpio_t pin)
137 {
138  gpio_toggle(pin);
139  return gpio_read(pin);
140 }
141 
153 static inline int hal_gpio_irq_init(gpio_t pin,
154  hal_gpio_irq_handler_t handler,
155  void *arg,
156  hal_gpio_irq_trig_t trig,
157  hal_gpio_pull_t pull)
158 {
159  return gpio_init_int(pin, pull, trig, handler, arg);
160 }
161 
167 static 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 
178 static inline void hal_gpio_irq_enable(gpio_t pin)
179 {
180  gpio_irq_enable(pin);
181 }
182 
188 static 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 */
HAL_GPIO_TRIG_BOTH
@ HAL_GPIO_TRIG_BOTH
IRQ occurs on either edge.
Definition: hal_gpio.h:57
gpio_irq_disable
void gpio_irq_disable(gpio_t pin)
Disable the pin interrupt if configured as interrupt source.
HAL_GPIO_TRIG_FALLING
@ HAL_GPIO_TRIG_FALLING
IRQ occurs on falling edge.
Definition: hal_gpio.h:55
GPIO_IN_PD
@ GPIO_IN_PD
configure as input with pull-down resistor
Definition: gpio.h:120
hal_gpio_irq_release
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
hal_gpio_init_in
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
hal_gpio_read
static int hal_gpio_read(gpio_t pin)
Reads the specified pin.
Definition: hal_gpio.h:124
GPIO_OUT
@ GPIO_OUT
configure as output in push-pull mode
Definition: gpio.h:122
gpio_init
int gpio_init(gpio_t pin, gpio_mode_t mode)
Initialize the given pin as general purpose input or output.
GPIO_FALLING
@ GPIO_FALLING
emit interrupt on falling flank
Definition: periph_cpu.h:81
HAL_GPIO_PULL_UP
@ HAL_GPIO_PULL_UP
Pull-up enabled.
Definition: hal_gpio.h:36
hal_gpio_irq_init
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
GPIO_IN_PU
@ GPIO_IN_PU
configure as input with pull-up resistor
Definition: gpio.h:121
GPIO_RISING
@ GPIO_RISING
emit interrupt on rising flank
Definition: periph_cpu.h:82
gpio_write
void gpio_write(gpio_t pin, int value)
Set the given pin to the given value.
hal_gpio_toggle
static int hal_gpio_toggle(gpio_t pin)
Toggles the specified pin.
Definition: hal_gpio.h:136
GPIO_IN
@ GPIO_IN
configure as input without pull resistor
Definition: gpio.h:119
hal_gpio_pull_t
gpio_mode_t hal_gpio_pull_t
hal_gpio_pull type
Definition: hal_gpio.h:43
hal_gpio_irq_disable
static void hal_gpio_irq_disable(gpio_t pin)
Disable IRQs on the passed pin.
Definition: hal_gpio.h:188
hal_gpio_init_out
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
gpio_flank_t
gpio_flank_t
Definition: periph_cpu.h:80
gpio_read
int gpio_read(gpio_t pin)
Get the current value of the given pin.
gpio_toggle
void gpio_toggle(gpio_t pin)
Toggle the value of the given pin.
gpio_init_int
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.
HAL_GPIO_PULL_DOWN
@ HAL_GPIO_PULL_DOWN
Pull-down enabled.
Definition: hal_gpio.h:38
GPIO_BOTH
@ GPIO_BOTH
emit interrupt on both flanks
Definition: periph_cpu.h:83
hal_gpio_irq_trig_t
gpio_flank_t hal_gpio_irq_trig_t
hal_gpio_irq_trig type
Definition: hal_gpio.h:70
gpio_irq_enable
void gpio_irq_enable(gpio_t pin)
Enable pin interrupt if configured as interrupt source.
HAL_GPIO_PULL_NONE
@ HAL_GPIO_PULL_NONE
Pull-up/down not enabled.
Definition: hal_gpio.h:34
gpio_cb_t
void(* gpio_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition: gpio.h:146
hal_gpio_write
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.h
Low-level GPIO peripheral driver interface definitions.
gpio_mode_t
gpio_mode_t
Available pin modes.
Definition: periph_cpu.h:70
hal_gpio_irq_handler_t
gpio_cb_t hal_gpio_irq_handler_t
Function proto for GPIO irq handler functions.
Definition: hal_gpio.h:75
hal_gpio_irq_enable
static void hal_gpio_irq_enable(gpio_t pin)
Enable IRQs on the passed pin.
Definition: hal_gpio.h:178
HAL_GPIO_TRIG_RISING
@ HAL_GPIO_TRIG_RISING
IRQ occurs on rising edge.
Definition: hal_gpio.h:53