gpio.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freie Universit├Ąt Berlin
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 
70 #ifndef PERIPH_GPIO_H
71 #define PERIPH_GPIO_H
72 
73 #include <limits.h>
74 
75 #include "periph_cpu.h"
76 #include "periph_conf.h"
77 
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 
82 #ifndef HAVE_GPIO_T
83 
86 typedef unsigned int gpio_t;
87 #endif
88 
89 #ifndef GPIO_PIN
90 
93 /* Default GPIO macro maps port-pin tuples to the pin value */
94 #define GPIO_PIN(x,y) ((gpio_t)((x & 0) | y))
95 #endif
96 
97 #ifndef GPIO_UNDEF
98 
101 #define GPIO_UNDEF ((gpio_t)(UINT_MAX))
102 #endif
103 
112 #ifndef HAVE_GPIO_MODE_T
113 typedef enum {
122 } gpio_mode_t;
123 #endif
124 
128 #ifndef HAVE_GPIO_FLANK_T
129 typedef enum {
133 } gpio_flank_t;
134 #endif
135 
141 typedef void (*gpio_cb_t)(void *arg);
142 
146 #ifndef HAVE_GPIO_ISR_CTX_T
147 typedef struct {
149  void *arg;
151 #endif
152 
166 int gpio_init(gpio_t pin, gpio_mode_t mode);
167 
168 #if defined(MODULE_PERIPH_GPIO_IRQ) || defined(DOXYGEN)
169 
189 int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
190  gpio_cb_t cb, void *arg);
191 
200 void gpio_irq_enable(gpio_t pin);
201 
210 void gpio_irq_disable(gpio_t pin);
211 
212 #endif /* defined(MODULE_PERIPH_GPIO_IRQ) || defined(DOXYGEN) */
213 
222 int gpio_read(gpio_t pin);
223 
229 void gpio_set(gpio_t pin);
230 
236 void gpio_clear(gpio_t pin);
237 
243 void gpio_toggle(gpio_t pin);
244 
251 void gpio_write(gpio_t pin, int value);
252 
253 #ifdef __cplusplus
254 }
255 #endif
256 
257 #endif /* PERIPH_GPIO_H */
258 
configure as output in push-pull mode
Definition: gpio.h:117
emit interrupt on rising flank
Definition: gpio.h:131
void gpio_toggle(gpio_t pin)
Toggle the value of the given pin.
void * arg
optional argument
Definition: gpio.h:149
emit interrupt on both flanks
Definition: gpio.h:132
void gpio_irq_enable(gpio_t pin)
Enable pin interrupt if configured as interrupt source.
gpio_flank_t
Definition of possible active flanks for external interrupt mode.
Definition: gpio.h:129
Default interrupt context for GPIO pins.
Definition: gpio.h:147
int gpio_init(gpio_t pin, gpio_mode_t mode)
Initialize the given pin as general purpose input or output.
int gpio_read(gpio_t pin)
Get the current value of the given pin.
unsigned int gpio_t
GPIO type identifier.
Definition: gpio.h:86
gpio_cb_t cb
interrupt callback
Definition: gpio.h:148
void gpio_set(gpio_t pin)
Set the given pin to HIGH.
emit interrupt on falling flank
Definition: gpio.h:130
configure as input with pull-up resistor
Definition: gpio.h:116
void gpio_irq_disable(gpio_t pin)
Disable the pin interrupt if configured as interrupt source.
gpio_mode_t
Available pin modes.
Definition: gpio.h:113
configure as input without pull resistor
Definition: gpio.h:114
void gpio_write(gpio_t pin, int value)
Set the given pin to the given value.
configure as output in open-drain mode without pull resistor
Definition: gpio.h:118
configure as input with pull-down resistor
Definition: gpio.h:115
configure as output in open-drain mode with pull resistor enabled
Definition: gpio.h:120
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_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition: gpio.h:141
void gpio_clear(gpio_t pin)
Set the given pin to LOW.