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().
◆ 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).
|
◆ gsl_gpiolib_export()
int gsl_gpiolib_export |
( |
unsigned int |
gpio | ) |
|
Export GPIO to userspace.
- Parameters
-
gpio | The GPIO line number. |
- Return values
-
0 | on success. |
-1 | on 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
-
gpio | The GPIO line number. |
dir | Direction to set. |
value | Initial value for output; ignored for input. |
- Return values
-
0 | on success. |
-1 | on 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
-
| gpio | The GPIO line number. |
[out] | value | The value of the GPIO line. |
- Return values
-
0 | on success. |
-1 | on 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
-
| gpio | The GPIO line number. |
[out] | value | The value of the GPIO line. |
- Return values
-
0 | on success. |
-1 | on 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.