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 
53 #ifndef PERIPH_GPIO_H
54 #define PERIPH_GPIO_H
55 
56 #include <limits.h>
57 
58 #include "periph_cpu.h"
59 #include "periph_conf.h"
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 #ifndef HAVE_GPIO_T
66 
69 typedef unsigned int gpio_t;
70 #endif
71 
72 #ifndef GPIO_PIN
73 
76 /* Default GPIO macro maps port-pin tuples to the pin value */
77 #define GPIO_PIN(x,y) ((gpio_t)((x & 0) | y))
78 #endif
79 
80 #ifndef GPIO_UNDEF
81 
84 #define GPIO_UNDEF ((gpio_t)(UINT_MAX))
85 #endif
86 
95 #ifndef HAVE_GPIO_MODE_T
96 typedef enum {
105 } gpio_mode_t;
106 #endif
107 
111 #ifndef HAVE_GPIO_FLANK_T
112 typedef enum {
116 } gpio_flank_t;
117 #endif
118 
124 typedef void (*gpio_cb_t)(void *arg);
125 
130 #ifndef HAVE_GPIO_ISR_CTX_T
131 typedef struct {
133  void *arg;
135 #endif
136 
151 int gpio_init(gpio_t pin, gpio_mode_t mode);
152 
170 int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
171  gpio_cb_t cb, void *arg);
172 
178 void gpio_irq_enable(gpio_t pin);
179 
185 void gpio_irq_disable(gpio_t pin);
186 
195 int gpio_read(gpio_t pin);
196 
202 void gpio_set(gpio_t pin);
203 
209 void gpio_clear(gpio_t pin);
210 
216 void gpio_toggle(gpio_t pin);
217 
224 void gpio_write(gpio_t pin, int value);
225 
226 #ifdef __cplusplus
227 }
228 #endif
229 
230 #endif /* PERIPH_GPIO_H */
231 
configure as output in push-pull mode
Definition: gpio.h:100
emit interrupt on rising flank
Definition: gpio.h:114
void gpio_toggle(gpio_t pin)
Toggle the value of the given pin.
void * arg
optional argument
Definition: gpio.h:133
emit interrupt on both flanks
Definition: gpio.h:115
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:112
Default interrupt context for GPIO pins.
Definition: gpio.h:131
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:69
gpio_cb_t cb
interrupt callback
Definition: gpio.h:132
void gpio_set(gpio_t pin)
Set the given pin to HIGH.
emit interrupt on falling flank
Definition: gpio.h:113
configure as input with pull-up resistor
Definition: gpio.h:99
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:96
configure as input without pull resistor
Definition: gpio.h:97
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:101
configure as input with pull-down resistor
Definition: gpio.h:98
configure as output in open-drain mode with pull resistor enabled
Definition: gpio.h:103
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:124
void gpio_clear(gpio_t pin)
Set the given pin to LOW.