|  | gpio
    1.4.2
    General Purpose I/O Package | 
GPIO library definitions using the /sys/class/gpio interface. More...
#include <sys/types.h>#include <sys/stat.h>#include <sys/time.h>#include <sys/select.h>#include <fcntl.h>#include <unistd.h>#include <stdio.h>#include <errno.h>#include <string.h>#include "rnr/rnrconfig.h"#include "rnr/log.h"#include "rnr/gpio.h"Go to the source code of this file.
| Functions | |
| static int | gpioReadDirection (int gpio) | 
| Read GPIO current direction.  More... | |
| static int | gpioReadEdge (int gpio) | 
| Read GPIO current edge trigger.  More... | |
| int | gpioExport (int gpio) | 
| Export (create) a GPIO interface.  More... | |
| int | gpioUnexport (int gpio) | 
| Unexport (delete) a GPIO interface.  More... | |
| int | gpioSetDirection (int gpio, int dir) | 
| Set GPIO signal direction.  More... | |
| int | gpioSetEdge (int gpio, int edge) | 
| Set GPIO edge trigger type.  More... | |
| int | gpioSetPull (int gpio, int pull) | 
| Set GPIO pull.  More... | |
| int | gpioProbe (int gpio, gpio_info_t *p) | 
| Safely probe GPIO parameters.  More... | |
| int | gpioRead (int gpio) | 
| Read GPIO pin's current value.  More... | |
| int | gpioWrite (int gpio, int value) | 
| Write GPIO value.  More... | |
| int | gpioNotify (int fd, double timeout) | 
| Notify on GPIO input value change.  More... | |
| int | gpioOpen (int gpio) | 
| Open GPIO pin.  More... | |
| int | gpioClose (int fd) | 
| Close GPIO pin.  More... | |
| int | gpioQuickRead (int fd) | 
| Quick read GPIO pin's current value.  More... | |
| int | gpioQuickWrite (int fd, int value) | 
| Quick write GPIO pin value.  More... | |
| int | gpioBitBang (int fd, byte_t pattern[], size_t bitCount, unsigned int usecIbd) | 
| Bit-bang bits out a GPIO pin.  More... | |
| void | gpioMakeDirname (int gpio, char buf[], size_t size) | 
| Make GPIO directory name.  More... | |
| Variables | |
| static const char * | GpioRoot = "/sys/class/gpio" | 
GPIO library definitions using the /sys/class/gpio interface.
Definition in file gpio.c.
| int gpioBitBang | ( | int | fd, | 
| byte_t | pattern[], | ||
| size_t | bitCount, | ||
| unsigned int | usecIbd | ||
| ) | 
Bit-bang bits out a GPIO pin.
Bits from pattern[0] ... pattern[N] sequentially drive the GPIO output pin. If bit == 0 then the pin is driven low, if bit == 1 then the pin is driven high.
The pattern buffer must be at least (bitCount + 7) / 8 bytes long. The bits in pattern[i] are read out in big-endian order b7 b6 ...
Between bit output, an inter-bit delay of usecIbd is enforced.
Method: sysfs
| fd | Open GPIO pin file descriptor. | 
| pattern | Bit pattern buffer to bang. The bytes are big-endian. | 
| bitCount | Count of bits to bang. | 
| usecIbd | Inter-bit delay in microseconds. A 0 value means a fast as the architecture can bang. | 
Definition at line 558 of file gpio.c.
References gpioQuickWrite().
Referenced by sysfsBitBang().
| int gpioClose | ( | int | fd | ) | 
Close GPIO pin.
Method: sysfs
| fd | Open GPIO pin file descriptor. | 
Definition at line 510 of file gpio.c.
Referenced by sysfsBitBang(), and sysfsRead().
| int gpioExport | ( | int | gpio | ) | 
| void gpioMakeDirname | ( | int | gpio, | 
| char | buf[], | ||
| size_t | size | ||
| ) | 
Make GPIO directory name.
Director name: /sys/class/gpio/gpio<gpio>
The base directory holds key special files such as value, direction, and edge.
Method: sysfs
| gpio | The sysfs exported GPIO number. | |
| [out] | buf | Buffer to hold directory name. | 
| size | Size of buffer in bytes. | 
Definition at line 587 of file gpio.c.
Referenced by main().
| int gpioNotify | ( | int | fd, | 
| double | timeout | ||
| ) | 
Notify on GPIO input value change.
This function blocks until 1) value has changed, 2) a timeout has occurred, or 3) an error was encoutered.
Method: sysfs
| fd | Open GPIO pin file descriptor. | 
| timeout | Wait timeout. A value of 0.0 is no timeout. | 
Definition at line 442 of file gpio.c.
References gpioQuickRead().
Referenced by mainInit().
| int gpioOpen | ( | int | gpio | ) | 
Open GPIO pin.
Leaving the file descriptor open allows for quick reads or writes. It is the responsibility of the user to close the file descriptor.
Method: sysfs
| gpio | The sysfs exported GPIO number. | 
Definition at line 492 of file gpio.c.
Referenced by mainInit(), sysfsBitBang(), and sysfsRead().
| int gpioProbe | ( | int | gpio, | 
| gpio_info_t * | p | ||
| ) | 
Safely probe GPIO parameters.
Method: sysfs
| gpio | The sysfs exported GPIO number. | |
| [out] | p | GPIO info. | 
Definition at line 346 of file gpio.c.
References gpio_info_t::dir, gpio_info_t::edge, gpio_info_t::gpio, GPIO_DIR_IN, GPIO_EDGE_NONE, GPIO_PULL_DS, gpioRead(), gpioReadDirection(), gpioReadEdge(), gpio_info_t::pin, gpio_info_t::pull, and gpio_info_t::value.
Referenced by sysfsProbe().
| int gpioQuickRead | ( | int | fd | ) | 
Quick read GPIO pin's current value.
Method: sysfs
| fd | Open GPIO pin file descriptor. | 
Definition at line 520 of file gpio.c.
Referenced by gpioNotify(), mainInit(), and sysfsRead().
| int gpioQuickWrite | ( | int | fd, | 
| int | value | ||
| ) | 
Quick write GPIO pin value.
Method: sysfs
| fd | Open GPIO pin file descriptor. | 
| value | GPIO pin value. One of: 0 (low) or 1 (high). | 
Definition at line 538 of file gpio.c.
Referenced by gpioBitBang().
| int gpioRead | ( | int | gpio | ) | 
Read GPIO pin's current value.
Method: sysfs
| gpio | The sysfs exported GPIO number. | 
Definition at line 388 of file gpio.c.
Referenced by gpioProbe().
| 
 | static | 
Read GPIO current direction.
Method: sysfs
| gpio | The sysfs exported GPIO number. | 
Definition at line 87 of file gpio.c.
References GPIO_DIR_IN, GPIO_DIR_IN_STR, GPIO_DIR_OUT, and GPIO_DIR_OUT_STR.
Referenced by gpioProbe().
| 
 | static | 
Read GPIO current edge trigger.
Method: sysfs
| gpio | The sysfs exported GPIO number. | 
Definition at line 139 of file gpio.c.
References GPIO_EDGE_BOTH, GPIO_EDGE_BOTH_STR, GPIO_EDGE_FALLING, GPIO_EDGE_FALLING_STR, GPIO_EDGE_NONE, GPIO_EDGE_NONE_STR, GPIO_EDGE_RISING, and GPIO_EDGE_RISING_STR.
Referenced by gpioProbe().
| int gpioSetDirection | ( | int | gpio, | 
| int | dir | ||
| ) | 
Set GPIO signal direction.
Method: sysfs
| gpio | The sysfs exported GPIO number. | 
| dir | Direction. One of: GPIO_DIR_IN(0) GPIO_DIR_OUT(1) | 
Definition at line 250 of file gpio.c.
References GPIO_DIR_IN, GPIO_DIR_IN_STR, GPIO_DIR_OUT, and GPIO_DIR_OUT_STR.
Referenced by main(), and sysfsSetDirection().
| int gpioSetEdge | ( | int | gpio, | 
| int | edge | ||
| ) | 
Set GPIO edge trigger type.
Method: sysfs
| gpio | The sysfs exported GPIO number. | 
| edge | Edge. One of: GPIO_EDGE_NONE(0) GPIO_EDGE_RISING(1) GPIO_EDGE_FALLING(2) GPIO_EDGE_BOTH(3) | 
Definition at line 292 of file gpio.c.
References GPIO_EDGE_BOTH, GPIO_EDGE_BOTH_STR, GPIO_EDGE_FALLING, GPIO_EDGE_FALLING_STR, GPIO_EDGE_NONE, GPIO_EDGE_NONE_STR, GPIO_EDGE_RISING, and GPIO_EDGE_RISING_STR.
Referenced by main().
| int gpioSetPull | ( | int | gpio, | 
| int | pull | ||
| ) | 
Set GPIO pull.
Methodsys mmap
| gpio | The sysfs exported GPIO number. | 
| pull | Pull type. One of: GPIO_PULL_DS(0) to disabled GPIO_PULL_UP(1) to pull-up GPIO_PULL_DN(2) to pull-down | 
| int gpioUnexport | ( | int | gpio | ) | 
| int gpioWrite | ( | int | gpio, | 
| int | value | ||
| ) | 
Write GPIO value.
Method: sysfs
| gpio | The sysfs exported GPIO number. | 
| value | GPIO pin value. One of: 0 (low) or 1 (high). | 
Definition at line 414 of file gpio.c.
Referenced by sysfsWrite().