libgpio

Section: Linux Simple I/O Library (2)
Updated: 21 December 2018
Index Return to Main Contents
 

NAME

libgpio -- Linux Simple I/O Library: GPIO Module  

SYNOPSIS

#include <libsimpleio/libgpio.h>

void GPIO_chip_info(int32_t chip, char *name, int32_t namesize,
  char *label, int32_t labelsize, int32_t *lines, int32_t *error);

void GPIO_line_info(int32_t chip, int32_t line, int32_t *flags,
  char *name, int32_t namesize, char *label, int32_t labelsize,
  int32_t error);

void GPIO_line_open(int32_t chip, int32_t line, int32_t flags,
  int32_t events, int32_t state, int32_t *fd, int32_t *error);

void GPIO_line_close(int32_t fd, int32_t *error);

void GPIO_line_read(int32_t fd, int32_t *state, int32_t *error);

void GPIO_line_write(int32_t fd, int32_t state, int32_t *error);

void GPIO_line_event(int32_t fd, int32_t *state, int32_t *error);

Deprecated sysfs API:

typedef enum
{
  GPIO_DIRECTION_INPUT,
  GPIO_DIRECTION_OUTPUT,
} GPIO_DIRECTION_t;

typedef enum
{
  GPIO_EDGE_NONE,
  GPIO_EDGE_RISING,
  GPIO_EDGE_FALLING,
  GPIO_EDGE_BOTH
} GPIO_EDGE_t;

typedef enum
{
  GPIO_POLARITY_ACTIVELOW,
  GPIO_POLARITY_ACTIVEHIGH,
} GPIO_POLARITY_t;

void GPIO_configure(int32_t pin, int32_t direction, int32_t state,
  int32_t edge, int32_t polarity, int32_t *error);

void GPIO_open(int32_t pin, int32_t *fd, int32_t *error);

void GPIO_close(int32_t fd, int32_t *error);

void GPIO_read(int32_t fd, int32_t *state, int32_t *error);

void GPIO_write(int32_t fd, int32_t state, int32_t *error);

Link with -lsimpleio.  

DESCRIPTION

All functions return either 0 (upon success) or an errno value (upon failure) in *error.

GPIO_chip_info() retrieves information about a particular GPIO chip (subsystem). The chip parameter selects the particular GPIO chip. Information strings are returned in name and label (with maximum sizes indicated by namesize and labelsize) and the number of GPIO lines (pins) available from this chip is returned in lines.

GPIO_line_info() retrieves information about a particular GPIO pin. The chip and line parmeters select the particular GPIO pin. Current configuration flags for the GPIO pin are returned in flags. Information strings are returned in name and label (with maximum sizes indicated by namesize and labelsize).

GPIO_line_open() configures and opens a single GPIO pin. The chip and line parmeters select the particular GPIO pin. Requested configuration flags are passed in flags, requested event (interrupt edge) flags are passed in events, and the initial state (0 or 1) for output pins is passed in state. Upon success, a file descriptor for the GPIO pin will be returned in *fd.

GPIO_line_close() closes a previously opened GPIO pin.

GPIO_line_read() gets the current state of a GPIO pin. The state (0 or 1) of the GPIO pin will be returned in *state.

GPIO_line_write() sets a GPIO pin output state. The new state (0 or 1) is passed in the state parameter.

GPIO_line_event() waits (blocking the calling process) for an interrupt on an GPIO interrupt input pin (configured with GPIOHANDLE_REQUEST_INPUT in the flags parameter and GPIOEVENT_REQUEST_RISING_EDGE, GPIOEVENT_REQUEST_FALLING_EDGE, or GPIOEVENT_REQUEST_BOTH_EDGES in the events parameter to GPIO_line_open()). The state (0 or 1) of the GPIO pin after the interrupt will be returned in *state.

Deprecated sysfs API:

GPIO_configure() configures a single GPIO pin. The pin parameter selects the GPIO pin (as numbered by the Linux kernel) to be configured. The direction parameter may be GPIO_DIRECTION_INPUT or GPIO_DIRECTION_OUTPUT. For input pins, the state parameter must be 0. For output pins, the state parameter may be 0 or 1 to set the initial state. For input pins, the edge parameter may be GPIO_EDGE_NONE, GPIO_EDGE_RISING, GPIO_EDGE_FALLING, or GPIO_EDGE_BOTH. For output pins, the edge parameter must be GPIO_EDGE_NONE. The polarity parameter may be GPIO_POLARITY_ACTIVELOW or GPIO_POLARITY_ACTIVEHIGH.

The udev rules included in the libsimpleio package will create a symbolic link from /dev/gpioxx to /sys/class/gpio/gpioxx/value when a GPIO pin is configured.

GPIO_open() opens a GPIO pin device. The GPIO pin number is passed in the pin parameter. Upon success, a file descriptor for the GPIO pin device is returned in *fd.

GPIO_close() closes a previously opened GPIO pin device.

GPIO_read() gets the current state of a GPIO pin. Upon success, the current state (0 or 1) of the GPIO pin will be returned in *state.

GPIO_write() sets a GPIO pin output state. The new state (0 or 1) is passed in the state parameter.  

SEE ALSO

libsimpleio(2), libadc(2), libdac(2), libevent(2), libhidraw(2),
libi2c(2), libipv4(2), liblinux(2), liblinx(2), libpwm(2),
libserial(2), libspi(2), libstream(2), libwatchdog(2)  

AUTHOR

Philip Munts dba Munts Technologies


 

Index

NAME
SYNOPSIS
DESCRIPTION
SEE ALSO
AUTHOR

This document was created by man2html, using the manual pages.
Time: 03:28:51 GMT, October 30, 2023