2 .\" Copyright (c) 2014 Rui Paulo
3 .\" All rights reserved.
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 AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .Nd "library to handle GPIO pins"
40 .Fn gpio_open "unsigned int unit"
42 .Fn gpio_open_device "const char *device"
44 .Fn gpio_close "gpio_handle_t handle"
46 .Fn gpio_pin_list "gpio_handle_t handle" "gpio_config_t **pcfgs"
48 .Fn gpio_pin_config "gpio_handle_t handle" "gpio_config_t *cfg"
50 .Fn gpio_pin_set_name "gpio_handle_t handle" "gpio_pin_t pin" "char *name"
52 .Fn gpio_pin_set_flags "gpio_handle_t handle" "gpio_config_t *cfg"
54 .Fn gpio_pin_get "gpio_handle_t handle" "gpio_pin_t pin"
56 .Fn gpio_pin_set "gpio_handle_t handle" "gpio_pin_t pin" "gpio_value_t value"
58 .Fn gpio_pin_toggle "gpio_handle_t handle" "gpio_pin_t pin"
60 .Fn gpio_pin_low "gpio_handle_t handle" "gpio_pin_t pin"
62 .Fn gpio_pin_high "gpio_handle_t handle" "gpio_pin_t pin"
64 .Fn gpio_pin_input "gpio_handle_t handle" "gpio_pin_t pin"
66 .Fn gpio_pin_output "gpio_handle_t handle" "gpio_pin_t pin"
68 .Fn gpio_pin_opendrain "gpio_handle_t handle" "gpio_pin_t pin"
70 .Fn gpio_pin_pushpull "gpio_handle_t handle" "gpio_pin_t pin"
72 .Fn gpio_pin_tristate "gpio_handle_t handle" "gpio_pin_t pin"
74 .Fn gpio_pin_pullup "gpio_handle_t handle" "gpio_pin_t pin"
76 .Fn gpio_pin_pulldown "gpio_handle_t handle" "gpio_pin_t pin"
78 .Fn gpio_pin_invin "gpio_handle_t handle" "gpio_pin_t pin"
80 .Fn gpio_pin_invout "gpio_handle_t handle" "gpio_pin_t pin"
82 .Fn gpio_pin_pulsate "gpio_handle_t handle" "gpio_pin_t pin"
86 library provides an interface to configure GPIO pins.
87 The library operates with a
89 opaque type which can be created with
92 .Fn gpio_open_device .
93 When no more GPIO operations are needed, this handle can be destroyed
97 To get a list of all available pins, one can call
99 This function takes a pointer to a
101 which is dynamically allocated.
102 This pointer should be freed with
104 when it is no longer necessary.
108 retrieves the current configuration of a pin.
109 The pin number should be passed in via the
111 variable which is part of the
116 .Fn gpio_pin_set_name
117 sets the name used to describe a pin.
120 .Fn gpio_pin_set_flags
121 configures a pin with the flags passed in by the
124 The pin number should also be passed in through the
127 All other structure members will be ignored by this function.
128 The list of flags can be found in
129 .Pa /usr/include/sys/gpio.h .
131 The get or set the state of a GPIO pin, the functions
135 are available, respectively.
136 To toggle the state, use
137 .Fn gpio_pin_toggle .
148 .Fn gpio_pin_output ,
149 .Fn gpio_pin_opendrain ,
150 .Fn gpio_pin_pushpull ,
151 .Fn gpio_pin_tristate ,
152 .Fn gpio_pin_pullup ,
153 .Fn gpio_pin_pulldown ,
159 .Fn gpio_pin_set_flags .
161 The following example shows how to configure pin 16 as output and then
167 gpio_handle_t handle;
169 handle = gpio_open(0);
170 if (handle == GPIO_HANDLE_INVALID)
171 err(1, "gpio_open failed");
172 gpio_pin_output(handle, 16);
173 gpio_pin_high(handle, 16);
177 The following example shows how to get a configuration of a pin:
182 gpio_pin_config(handle, &cfg);
185 The structure will contain the name of the pin and its flags.
192 library first appeared in
197 library was implemented by
198 .An Rui Paulo Aq Mt rpaulo@FreeBSD.org .