arsd.gpio

PRERELEASE EXPERIMENTAL MODULE / SUBJECT TO CHANGE WITHOUT WARNING / LIKELY TO CONTAIN BUGS

Wrapper for gpio use on Linux. It uses the new kernel interface directly, and thus requires a Linux kernel version newer than 4.9. It also requires a Linux kernel newer than 4.9 (apt upgrade your raspian install if you don't already have that).

Note that the kernel documentation is very clear: do NOT use this for anything you plan to distribute to others. It is really just for tinkering, not production. And if the kernel people say that, I say it like 1000x more.

More...

Members

Classes

CErrorException
class CErrorException

Enums

GPIOLINE_CHANGED_REQUESTED
anonymousenum GPIOLINE_CHANGED_REQUESTED

line status change events

Functions

c_dup
string c_dup(char[32] c)

Undocumented in source. Be warned that the author may not have intended to support it.

main
void main()

Undocumented in source. Be warned that the author may not have intended to support it.

Manifest constants

GPIOEVENT_EVENT_FALLING_EDGE
enum GPIOEVENT_EVENT_FALLING_EDGE;

GPIO event types

GPIOEVENT_EVENT_RISING_EDGE
enum GPIOEVENT_EVENT_RISING_EDGE;

GPIO event types

GPIOEVENT_REQUEST_BOTH_EDGES
enum GPIOEVENT_REQUEST_BOTH_EDGES;
GPIOEVENT_REQUEST_FALLING_EDGE
enum GPIOEVENT_REQUEST_FALLING_EDGE;

Eventrequest flags

GPIOEVENT_REQUEST_RISING_EDGE
enum GPIOEVENT_REQUEST_RISING_EDGE;

Eventrequest flags

GPIOHANDLES_MAX
enum GPIOHANDLES_MAX;

Maximum number of requested handles

GPIOHANDLE_GET_LINE_VALUES_IOCTL
enum GPIOHANDLE_GET_LINE_VALUES_IOCTL;

.

GPIOHANDLE_REQUEST_ACTIVE_LOW
enum GPIOHANDLE_REQUEST_ACTIVE_LOW;

Linerequest flags

GPIOHANDLE_REQUEST_BIAS_DISABLE
enum GPIOHANDLE_REQUEST_BIAS_DISABLE;

Undocumented in source.

GPIOHANDLE_REQUEST_BIAS_PULL_UP
enum GPIOHANDLE_REQUEST_BIAS_PULL_UP;

Undocumented in source.

GPIOHANDLE_REQUEST_INPUT
enum GPIOHANDLE_REQUEST_INPUT;
GPIOHANDLE_REQUEST_OPEN_DRAIN
enum GPIOHANDLE_REQUEST_OPEN_DRAIN;
GPIOHANDLE_REQUEST_OPEN_SOURCE
enum GPIOHANDLE_REQUEST_OPEN_SOURCE;
GPIOHANDLE_REQUEST_OUTPUT
enum GPIOHANDLE_REQUEST_OUTPUT;

Linerequest flags

GPIOHANDLE_SET_CONFIG_IOCTL
enum GPIOHANDLE_SET_CONFIG_IOCTL;
GPIOHANDLE_SET_LINE_VALUES_IOCTL
enum GPIOHANDLE_SET_LINE_VALUES_IOCTL;

.

GPIOLINE_FLAG_ACTIVE_LOW
enum GPIOLINE_FLAG_ACTIVE_LOW;
GPIOLINE_FLAG_BIAS_DISABLE
enum GPIOLINE_FLAG_BIAS_DISABLE;
GPIOLINE_FLAG_BIAS_PULL_DOWN
enum GPIOLINE_FLAG_BIAS_PULL_DOWN;
GPIOLINE_FLAG_BIAS_PULL_UP
enum GPIOLINE_FLAG_BIAS_PULL_UP;
GPIOLINE_FLAG_IS_OUT
enum GPIOLINE_FLAG_IS_OUT;

Informational flags

GPIOLINE_FLAG_KERNEL
enum GPIOLINE_FLAG_KERNEL;
GPIOLINE_FLAG_OPEN_DRAIN
enum GPIOLINE_FLAG_OPEN_DRAIN;
GPIOLINE_FLAG_OPEN_SOURCE
enum GPIOLINE_FLAG_OPEN_SOURCE;

Informational flags

GPIO_GET_CHIPINFO_IOCTL
enum GPIO_GET_CHIPINFO_IOCTL;
GPIO_GET_LINEEVENT_IOCTL
enum GPIO_GET_LINEEVENT_IOCTL;
GPIO_GET_LINEHANDLE_IOCTL
enum GPIO_GET_LINEHANDLE_IOCTL;
GPIO_GET_LINEINFO_IOCTL
enum GPIO_GET_LINEINFO_IOCTL;
GPIO_GET_LINEINFO_UNWATCH_IOCTL
enum GPIO_GET_LINEINFO_UNWATCH_IOCTL;
GPIO_GET_LINEINFO_WATCH_IOCTL
enum GPIO_GET_LINEINFO_WATCH_IOCTL;

.

Structs

GpioChip
struct GpioChip
gpiochip_info
struct gpiochip_info

Information about a certain GPIO chip. ioctl GPIO_GET_CHIPINFO_IOCTL

gpioevent_data
struct gpioevent_data

The actual event being pushed to userspace

gpioevent_request
struct gpioevent_request

Information about a GPIO event request

gpiohandle_config
struct gpiohandle_config

Configuration for a GPIO handle request Note: only in kernel newer than early 2020

gpiohandle_data
struct gpiohandle_data

Information of values on a GPIO handle

gpioline_info
struct gpioline_info

Information about a certain GPIO line

gpioline_info_changed
struct gpioline_info_changed

Information about a change in status of a GPIO line

Variables

consumer_label
char[32] consumer_label;

a desired consumer label for the selected GPIO line(s) such as "my-bitbanged-relay"

default_values
ubyte[GPIOHANDLES_MAX] default_values;

if the GPIOHANDLE_REQUEST_OUTPUT is set for a requested line, this specifies the default output value, should be 0 (low) or 1 (high), anything else than 0 or 1 will be interpreted as 1 (high)

fd
int fd;

if successful this field will contain a valid anonymous file handle after a GPIO_GET_LINEHANDLE_IOCTL operation, zero or negative value means error

flags
uint flags;

desired flags for the desired GPIO lines, such as GPIOHANDLE_REQUEST_OUTPUT, GPIOHANDLE_REQUEST_ACTIVE_LOW etc, OR:ed together. Note that even if multiple lines are requested, the same flags must be applicable to all of them, if you want lines with individual flags set, request them one by one. It is possible to select a batch of input or output lines, but they must all have the same characteristics, i.e. all inputs or all outputs, all active low etc

lines
uint lines;

number of lines requested in this request, i.e. the number of valid fields in the above arrays, set to 1 to request a single line

Detailed Description

This is a PRERELEASE EXPERIMENTAL MODULE SUBJECT TO CHANGE WITHOUT WARNING. It is LIKELY TO CONTAIN BUGS!

GPIOHANDLE_REQUEST_BIAS_PULL_UP and friends were added to the kernel in early 2020, so bleeding edge feature that is unlikely to work if you aren't that new too. My rpis do NOT support it. (the python library sets similar values tho by poking memory registers. I'm not gonna do that here, you can also solve it with electric circuit design (6k-ish ohm pull up and/or pull down resistor) or just knowing your own setup... so meh.)

Meta

License

GPL-2.0 WITH Linux-syscall-note because it includes copy/pasted Linux kernel header code.