2 * Copyright (c) 2013-2014 Rui Paulo <rpaulo@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
23 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
34 #define GPIO_INVALID_HANDLE -1
35 typedef int gpio_handle_t;
36 typedef uint32_t gpio_pin_t;
39 * Structure describing a GPIO pin configuration.
43 char g_name[GPIOMAXNAME];
49 GPIO_VALUE_INVALID = -1,
50 GPIO_VALUE_LOW = GPIO_PIN_LOW,
51 GPIO_VALUE_HIGH = GPIO_PIN_HIGH
55 * Open /dev/gpiocN or a specific device.
57 gpio_handle_t gpio_open(unsigned int);
58 gpio_handle_t gpio_open_device(const char *);
59 void gpio_close(gpio_handle_t);
61 * Get a list of all the GPIO pins.
63 int gpio_pin_list(gpio_handle_t, gpio_config_t **);
65 * GPIO pin configuration.
67 * Retrieve the configuration of a specific GPIO pin. The pin number is
68 * passed through the gpio_config_t structure.
70 int gpio_pin_config(gpio_handle_t, gpio_config_t *);
72 * Sets the GPIO pin name. The pin number and pin name to be set are passed
75 int gpio_pin_set_name(gpio_handle_t, gpio_pin_t, char *);
77 * Sets the GPIO flags on a specific GPIO pin. The pin number and the flags
78 * to be set are passed through the gpio_config_t structure.
80 int gpio_pin_set_flags(gpio_handle_t, gpio_config_t *);
84 int gpio_pin_get(gpio_handle_t, gpio_pin_t);
85 int gpio_pin_set(gpio_handle_t, gpio_pin_t, int);
86 int gpio_pin_toggle(gpio_handle_t, gpio_pin_t);
88 * Helper functions to set pin states.
90 int gpio_pin_low(gpio_handle_t, gpio_pin_t);
91 int gpio_pin_high(gpio_handle_t, gpio_pin_t);
93 * Helper functions to configure pins.
95 int gpio_pin_input(gpio_handle_t, gpio_pin_t);
96 int gpio_pin_output(gpio_handle_t, gpio_pin_t);
97 int gpio_pin_opendrain(gpio_handle_t, gpio_pin_t);
98 int gpio_pin_pushpull(gpio_handle_t, gpio_pin_t);
99 int gpio_pin_tristate(gpio_handle_t, gpio_pin_t);
100 int gpio_pin_pullup(gpio_handle_t, gpio_pin_t);
101 int gpio_pin_pulldown(gpio_handle_t, gpio_pin_t);
102 int gpio_pin_invin(gpio_handle_t, gpio_pin_t);
103 int gpio_pin_invout(gpio_handle_t, gpio_pin_t);
104 int gpio_pin_pulsate(gpio_handle_t, gpio_pin_t);
108 #endif /* _LIBGPIO_H_ */