libgslutil  1.2.3
Enumerations | Functions
GPIO via sysfs (gpiolib)

Enumerations

enum  gsl_gpiolib_dir { gsl_gpiolib_dir_in, gsl_gpiolib_dir_out }
 GPIO direction. More...
 

Functions

int gsl_gpiolib_export (unsigned int gpio)
 Export GPIO to userspace. More...
 
int gsl_gpiolib_direction (unsigned int gpio, enum gsl_gpiolib_dir dir, int value)
 Set GPIO direction. More...
 
int gsl_gpiolib_read (unsigned int gpio, int *value)
 Read GPIO value. More...
 
int gsl_gpiolib_write (unsigned int gpio, int value)
 Set GPIO value. More...
 

Detailed Description

Routines for manipulating GPIO lines via gpiolib (the kernel's sysfs-based interface). GPIO lines are referred to by number.

A GPIO line must first be exported to user pace before it can be manipulated; this can be done with gsl_gpiolib_export(). From there it may be set to input or output with gsl_gpiolib_direction(). Its level may be read with gsl_gpiolib_read() and written with gsl_gpiolib_write().

Enumeration Type Documentation

◆ gsl_gpiolib_dir

GPIO direction.

Used to select whether a GPIO is an input or an output.

Enumerator
gsl_gpiolib_dir_in 

Input line (high-impedance).

gsl_gpiolib_dir_out 

Output line (low-impedance).

Function Documentation

◆ gsl_gpiolib_export()

int gsl_gpiolib_export ( unsigned int  gpio)

Export GPIO to userspace.

Parameters
gpioThe GPIO line number.
Return values
0on success.
-1on error (and see errno).

Requests that the kernel exports a GPIO line to userspace. If the line is already exported, this function returns success. Otherwise, it attempts to export the line, returning success or failure as per the kernel's report.

◆ gsl_gpiolib_direction()

int gsl_gpiolib_direction ( unsigned int  gpio,
enum gsl_gpiolib_dir  dir,
int  value 
)

Set GPIO direction.

Parameters
gpioThe GPIO line number.
dirDirection to set.
valueInitial value for output; ignored for input.
Return values
0on success.
-1on error (and see errno).

Sets the direction of an exported GPIO line. If setting the line to be an output, pass value as 0 for low or non-0 for high. If setting the line to be an input, value is ignored.

◆ gsl_gpiolib_read()

int gsl_gpiolib_read ( unsigned int  gpio,
int *  value 
)

Read GPIO value.

Parameters
gpioThe GPIO line number.
[out]valueThe value of the GPIO line.
Return values
0on success.
-1on error (and see errno).

Reads the current value of an exported GPIO line. value will be set to 0 if low or 1 if high. On error, value is left unchanged.

◆ gsl_gpiolib_write()

int gsl_gpiolib_write ( unsigned int  gpio,
int  value 
)

Set GPIO value.

Parameters
gpioThe GPIO line number.
[out]valueThe value of the GPIO line.
Return values
0on success.
-1on error (and see errno).

Sets the current value of an exported GPIO line, if it is an output. value should be 0 to set the line low or 1 to set it high.