.\" man page for Munts Technologies Linux Simple I/O Library .\" .\" Copyright (C)2016-2023, Philip Munts dba Munts Technologies. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions are met: .\" .\" * Redistributions of source code must retain the above copyright notice, .\" this list of conditions and the following disclaimer. .\" .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" .\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .TH libgpio 2 "21 December 2018" "version 1" "Linux Simple I/O Library" .SH NAME .B libgpio \-\- Linux Simple I/O Library: GPIO Module .SH SYNOPSIS .nf .B #include .BI "void GPIO_chip_info(int32_t " chip ", char *" name ", int32_t " namesize "," .BI " char *" label ", int32_t " labelsize ", int32_t *" lines ", int32_t *" error ");" .BI "void GPIO_line_info(int32_t " chip ", int32_t " line ", int32_t *" flags "," .BI " char *" name ", int32_t " namesize ", char *" label ", int32_t " labelsize "," .BI " int32_t " error ");" .BI "void GPIO_line_open(int32_t " chip ", int32_t " line ", int32_t " flags "," .BI " int32_t " events ", int32_t " state ", int32_t *" fd ", int32_t *" error ");" .BI "void GPIO_line_close(int32_t " fd ", int32_t *" error ");" .BI "void GPIO_line_read(int32_t " fd ", int32_t *" state ", int32_t *" error ");" .BI "void GPIO_line_write(int32_t " fd ", int32_t " state ", int32_t *" error ");" .BI "void GPIO_line_event(int32_t " fd ", int32_t *" state ", int32_t *" error ");" .I Deprecated sysfs API: .B typedef enum .B { .B " GPIO_DIRECTION_INPUT," .B " GPIO_DIRECTION_OUTPUT," .B } GPIO_DIRECTION_t; .B typedef enum .B { .B " GPIO_EDGE_NONE," .B " GPIO_EDGE_RISING," .B " GPIO_EDGE_FALLING," .B " GPIO_EDGE_BOTH" .B } GPIO_EDGE_t; .B typedef enum .B { .B " GPIO_POLARITY_ACTIVELOW," .B " GPIO_POLARITY_ACTIVEHIGH," .B } GPIO_POLARITY_t; .BI "void GPIO_configure(int32_t " pin ", int32_t " direction ", int32_t " state "," .BI " int32_t " edge ", int32_t " polarity ", int32_t *" error ");" .BI "void GPIO_open(int32_t " pin ", int32_t *" fd ", int32_t *" error ");" .BI "void GPIO_close(int32_t " fd ", int32_t *" error ");" .BI "void GPIO_read(int32_t " fd ", int32_t *" state ", int32_t *" error ");" .BI "void GPIO_write(int32_t " fd ", int32_t " state ", int32_t *" error ");" .fi Link with .BR -lsimpleio . .SH DESCRIPTION .nh All functions return either .B 0 (upon success) or an .B errno value (upon failure) in .IR *error . .PP .B GPIO_chip_info() retrieves information about a particular GPIO chip (subsystem). The .I chip parameter selects the particular GPIO chip. Information strings are returned in .IR name " and " label (with maximum sizes indicated by .IR namesize " and " labelsize ")" and the number of GPIO lines (pins) available from this chip is returned in .IR lines . .PP .B GPIO_line_info() retrieves information about a particular GPIO pin. The .IR chip " and " line parmeters select the particular GPIO pin. Current configuration flags for the GPIO pin are returned in .IR flags . Information strings are returned in .IR name " and " label (with maximum sizes indicated by .IR namesize " and " labelsize ")." .PP .B GPIO_line_open() configures and opens a single GPIO pin. The .IR chip " and " line parmeters select the particular GPIO pin. Requested configuration flags are passed in .IR flags , requested event (interrupt edge) flags are passed in .IR events , and the initial state .RB ( 0 " or " 1 ) for output pins is passed in .IR state . Upon success, a file descriptor for the GPIO pin will be returned in .IR *fd . .PP .B GPIO_line_close() closes a previously opened GPIO pin. .PP .B GPIO_line_read() gets the current state of a GPIO pin. The state .RB ( 0 " or " 1 ) of the GPIO pin will be returned in .IR *state . .PP .B GPIO_line_write() sets a GPIO pin output state. The new state .RB ( 0 " or " 1 ) is passed in the .I state parameter. .PP .B GPIO_line_event() waits (blocking the calling process) for an interrupt on an GPIO interrupt input pin (configured with .BR GPIOHANDLE_REQUEST_INPUT " in the " .IR flags " parameter and " .BR GPIOEVENT_REQUEST_RISING_EDGE ", " GPIOEVENT_REQUEST_FALLING_EDGE ", or " .BR GPIOEVENT_REQUEST_BOTH_EDGES " in the " .IR events " parameter to " .IR GPIO_line_open() ")." The state .RB ( 0 " or " 1 ) of the GPIO pin .B after the interrupt will be returned in .IR *state . .PP .I Deprecated sysfs API: .B GPIO_configure() configures a single GPIO pin. The .I pin parameter selects the GPIO pin (as numbered by the Linux kernel) to be configured. The .I direction parameter may be .B GPIO_DIRECTION_INPUT or .BR GPIO_DIRECTION_OUTPUT . For input pins, the .I state parameter must be .BR 0 . For output pins, the .I state parameter may be .B 0 or .B 1 to set the initial state. For input pins, the .I edge parameter may be .BR GPIO_EDGE_NONE , .BR GPIO_EDGE_RISING , .BR GPIO_EDGE_FALLING , or .BR GPIO_EDGE_BOTH . For output pins, the .I edge parameter must be .B GPIO_EDGE_NONE. The .I polarity parameter may be .B GPIO_POLARITY_ACTIVELOW or .BR GPIO_POLARITY_ACTIVEHIGH . .PP The .B udev rules included in the .B libsimpleio package will create a symbolic link from .B /dev/gpioxx to .B /sys/class/gpio/gpioxx/value when a GPIO pin is configured. .PP .B GPIO_open() opens a GPIO pin device. The GPIO pin number is passed in the .IR pin parameter. Upon success, a file descriptor for the GPIO pin device is returned in .IR *fd . .PP .B GPIO_close() closes a previously opened GPIO pin device. .PP .B GPIO_read() gets the current state of a GPIO pin. Upon success, the current state .RB ( 0 " or " 1 ) of the GPIO pin will be returned in .IR *state . .PP .B GPIO_write() sets a GPIO pin output state. The new state .RB ( 0 " or " 1 ) is passed in the .I state parameter. .SH SEE ALSO .BR libsimpleio "(2), " libadc "(2), " libdac "(2), " libevent "(2), " libhidraw "(2)," .br .BR libi2c "(2), " libipv4 "(2), " liblinux "(2), " liblinx "(2), " libpwm "(2)," .br .BR libserial "(2), " libspi "(2), " libstream "(2), " libwatchdog "(2)" .SH AUTHOR Philip Munts dba Munts Technologies.