Loading...
Searching...
No Matches
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
75#ifndef PERIPH_GPIO_H
76#define PERIPH_GPIO_H
77
78#include <limits.h>
79
80#include "periph_cpu.h"
81#include "periph_conf.h"
82
83#ifdef __cplusplus
84extern "C" {
85#endif
86
87#ifndef HAVE_GPIO_T
91typedef unsigned int gpio_t;
92#endif
93
94#ifndef GPIO_PIN
98/* Default GPIO macro maps port-pin tuples to the pin value */
99#define GPIO_PIN(x,y) ((gpio_t)((x & 0) | y))
100#endif
101
102#ifndef GPIO_UNDEF
106#define GPIO_UNDEF ((gpio_t)(UINT_MAX))
107#endif
108
117#ifndef HAVE_GPIO_MODE_T
128#endif
129
133#ifndef HAVE_GPIO_FLANK_T
139#endif
140
146typedef void (*gpio_cb_t)(void *arg);
147
151#ifndef HAVE_GPIO_ISR_CTX_T
152typedef struct {
154 void *arg;
156#endif
157
171int gpio_init(gpio_t pin, gpio_mode_t mode);
172
173#if defined(MODULE_PERIPH_GPIO_IRQ) || defined(DOXYGEN)
196int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
197 gpio_cb_t cb, void *arg);
198
210void gpio_irq_enable(gpio_t pin);
211
220void gpio_irq_disable(gpio_t pin);
221
222#endif /* defined(MODULE_PERIPH_GPIO_IRQ) || defined(DOXYGEN) */
223
232int gpio_read(gpio_t pin);
233
239void gpio_set(gpio_t pin);
240
246void gpio_clear(gpio_t pin);
247
253void gpio_toggle(gpio_t pin);
254
261void gpio_write(gpio_t pin, int value);
262
269static inline int gpio_is_equal(gpio_t gpio1, gpio_t gpio2)
270{
271 return (gpio1 == gpio2);
272}
273
279static inline int gpio_is_valid(gpio_t gpio)
280{
281 return (gpio != GPIO_UNDEF);
282}
283
284#ifdef __cplusplus
285}
286#endif
287
288#endif /* PERIPH_GPIO_H */
gpio_flank_t
Definition periph_cpu.h:180
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
static int gpio_is_valid(gpio_t gpio)
Test if a GPIO pin is a valid pin and not declared as undefined.
Definition gpio.h:279
gpio_flank_t
Definition of possible active flanks for external interrupt mode.
Definition gpio.h:134
void gpio_clear(gpio_t pin)
Set the given pin to LOW.
#define GPIO_UNDEF
GPIO pin not defined.
Definition gpio.h:106
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.
gpio_mode_t
Available pin modes.
Definition gpio.h:118
void gpio_set(gpio_t pin)
Set the given pin to HIGH.
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.
unsigned int gpio_t
GPIO type identifier.
Definition gpio.h:91
static int gpio_is_equal(gpio_t gpio1, gpio_t gpio2)
Test if a GPIO pin is equal to another GPIO pin.
Definition gpio.h:269
@ GPIO_FALLING
emit interrupt on falling flank
Definition gpio.h:135
@ GPIO_RISING
emit interrupt on rising flank
Definition gpio.h:136
@ GPIO_BOTH
emit interrupt on both flanks
Definition gpio.h:137
@ GPIO_OUT
configure as output in push-pull mode
Definition gpio.h:122
@ GPIO_IN
configure as input without pull resistor
Definition gpio.h:119
@ GPIO_OD
configure as output in open-drain mode without pull resistor
Definition gpio.h:123
@ GPIO_IN_PU
configure as input with pull-up resistor
Definition gpio.h:121
@ GPIO_OD_PU
configure as output in open-drain mode with pull resistor enabled
Definition gpio.h:125
@ GPIO_IN_PD
configure as input with pull-down resistor
Definition gpio.h:120
gpio_mode_t
Available pin modes.
Definition periph_cpu.h:82
Default interrupt context for GPIO pins.
Definition gpio.h:152
void * arg
optional argument
Definition gpio.h:154
gpio_cb_t cb
interrupt callback
Definition gpio.h:153