Each
GPIO
controller with an attached
gpio
device has an associated device file under the
/dev
directory, e.g.
/dev/gpio0
.
Access from userland is performed through
ioctl(2)
calls on these devices.
sys/gpio.h
>
header file:
GPIOINFO
(struct
gpio_info)
gpio_info
structure:
struct gpio_info {
int gpio_npins; /* total number of pins available */
};
GPIOPINREAD
(struct
gpio_pin_op)
gpio_pin_op
structure:
struct gpio_pin_op {
int gp_pin; /* pin number */
int gp_value; /* value */
};
The
gp_pin
field must be set before calling.
GPIOPINWRITE
(struct
gpio_pin_op)
gp_value
field must be either
GPIO_PIN_LOW
(logical 0) or
GPIO_PIN_HIGH
(logical 1).
On return, the
gp_value
field contains the old pin state.
GPIOPINTOGGLE
(struct
gpio_pin_op)
gp_value
field is ignored and on return contains the old pin state.
GPIOPINCTL
(struct
gpio_pin_ctl)
gpio_pin_ctl
structure:
struct gpio_pin_ctl {
int gp_pin; /* pin number */
int gp_caps; /* pin capabilities (read-only) */
int gp_flags; /* pin configuration flags */
};
The
gp_flags
field is a combination of the following flags:
GPIO_PIN_INPUT
GPIO_PIN_OUTPUT
GPIO_PIN_INOUT
GPIO_PIN_OPENDRAIN
GPIO_PIN_PUSHPULL
GPIO_PIN_TRISTATE
GPIO_PIN_PULLUP
GPIO_PIN_PULLDOWN
GPIO_PIN_INVIN
GPIO_PIN_INVOUT
Note that the
GPIO
controller
may not support all of these flags.
On return the
gp_caps
field contains flags that are supported.
If no flags are specified, the pin configuration stays unchanged.
The gpio driver was written by Alexander Yurchenko <grange@openbsd.org>. gpio and was ported to NetBSD by Jared D. McNeill <jmcneill@NetBSD.org>.