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.
36 #define GPIO_INVALID_HANDLE -1
37 typedef int gpio_handle_t
;
38 typedef uint32_t gpio_pin_t
;
41 * Structure describing a GPIO pin configuration.
45 char g_name
[GPIOMAXNAME
];
51 GPIO_VALUE_INVALID
= -1,
52 GPIO_VALUE_LOW
= GPIO_PIN_LOW
,
53 GPIO_VALUE_HIGH
= GPIO_PIN_HIGH
57 * Open /dev/gpiocN or a specific device.
59 gpio_handle_t
gpio_open(unsigned int);
60 gpio_handle_t
gpio_open_device(const char *);
61 void gpio_close(gpio_handle_t
);
63 * Get a list of all the GPIO pins.
65 int gpio_pin_list(gpio_handle_t
, gpio_config_t
**);
67 * GPIO pin configuration.
69 * Retrieve the configuration of a specific GPIO pin. The pin number is
70 * passed through the gpio_config_t structure.
72 int gpio_pin_config(gpio_handle_t
, gpio_config_t
*);
74 * Sets the GPIO pin name. The pin number and pin name to be set are passed
77 int gpio_pin_set_name(gpio_handle_t
, gpio_pin_t
, char *);
79 * Sets the GPIO flags on a specific GPIO pin. The pin number and the flags
80 * to be set are passed through the gpio_config_t structure.
82 int gpio_pin_set_flags(gpio_handle_t
, gpio_config_t
*);
86 int gpio_pin_get(gpio_handle_t
, gpio_pin_t
);
87 int gpio_pin_set(gpio_handle_t
, gpio_pin_t
, int);
88 int gpio_pin_toggle(gpio_handle_t
, gpio_pin_t
);
90 * Helper functions to set pin states.
92 int gpio_pin_low(gpio_handle_t
, gpio_pin_t
);
93 int gpio_pin_high(gpio_handle_t
, gpio_pin_t
);
95 * Helper functions to configure pins.
97 int gpio_pin_input(gpio_handle_t
, gpio_pin_t
);
98 int gpio_pin_output(gpio_handle_t
, gpio_pin_t
);
99 int gpio_pin_opendrain(gpio_handle_t
, gpio_pin_t
);
100 int gpio_pin_pushpull(gpio_handle_t
, gpio_pin_t
);
101 int gpio_pin_tristate(gpio_handle_t
, gpio_pin_t
);
102 int gpio_pin_pullup(gpio_handle_t
, gpio_pin_t
);
103 int gpio_pin_pulldown(gpio_handle_t
, gpio_pin_t
);
104 int gpio_pin_invin(gpio_handle_t
, gpio_pin_t
);
105 int gpio_pin_invout(gpio_handle_t
, gpio_pin_t
);
106 int gpio_pin_pulsate(gpio_handle_t
, gpio_pin_t
);
110 #endif /* _LIBGPIO_H_ */