GPIO(4) | Device Drivers Manual | GPIO(4) |
gpio
—
gpio* at elansc?
gpio* at epgpio?
gpio* at gcscpcib?
gpio* at gpiosim?
gpio* at gscpcib?
gpio* at ichlpcib?
gpio* at nsclpcsio?
gpio* at soekrisgpio?
gpio* at ppbus?
gpio* at ptcd?
gpio* at wbsio?
#include <sys/types.h>
#include <sys/gpio.h>
#include <sys/ioctl.h>
gpio
device attaches to the GPIO controller and
provides a uniform programming interface to its pins.
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.
Whether the layout of the GPIO device can be configured is subject to authorization by the kauth(9) framework.
If for example
secmodel_securelevel(9)
is active, the layout of the GPIO device is defined at a securelevel less
than 1, i.e. typically during system boot, and cannot be changed later. GPIO
pins can be configured and given a symbolic name and device drivers that use
GPIO pins can be attached to the gpio
device at a
securelevel less than 1. All other pins will not be accessible once the
runlevel has been raised.
<sys/gpio.h>
header file:
GPIOINFO
(struct gpio_info
)struct gpio_info { int gpio_npins; /* total number of pins available */ };
GPIOREAD
(struct gpio_req
)#define GPIOMAXNAME 64 struct gpio_req { char gp_name[GPIOMAXNAME]; /* pin name */ int gp_pin; /* pin number */ int gp_value; /* value */ };
The gp_name or gp_pin field must be set before calling.
GPIOWRITE
(struct gpio_req
)GPIO_PIN_LOW
(logical 0) or
GPIO_PIN_HIGH
(logical 1). On return, the
gp_value field contains the old pin state.
GPIOTOGGLE
(struct gpio_req
)GPIOSET
(struct gpio_set
)#define GPIOMAXNAME 64 struct gpio_set { char gp_name[GPIOMAXNAME]; /* pin name */ int gp_pin; /* pin number */ int gp_caps; /* pin capabilities (ro) */ int gp_flags; /* pin configuration flags */ char gp_name2[GPIOMAXNAME]; /* new name */ };
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
GPIO_PIN_PULSATE
GPIO_PIN_ALT0
-
GPIO_PIN_ALT7
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.
Only GPIO pins that have been set using GPIOSET will be accessible at securelevels greater than 0.
GPIOUNSET
(struct gpio_set
)GPIOATTACH
(struct gpio_attach
)struct gpio_attach { char ga_dvname[16]; /* device name */ int ga_offset; /* pin number */ uint32_t ga_mask; /* binary mask */ uint32_t ga_flags; /* driver dependent */ };
The drvctl(8) command can be used to detach a device from a gpio pin.
gpio
device first appeared in
OpenBSD 3.6 and NetBSD 4.0.
gpio
driver was written by
Alexander Yurchenko
<grange@openbsd.org>.
gpio
and was ported to NetBSD
by Jared D. McNeill
<jmcneill@NetBSD.org>.
Runtime device attachment was added by Marc Balmer
<marc@msys.ch>.
February 20, 2018 | NetBSD 9.4 |