Compare commits
2 Commits
e2c5431bfa
...
7da732b5e1
Author | SHA1 | Date | |
---|---|---|---|
|
7da732b5e1 | ||
|
9d22af507d |
99
README.md
Normal file
99
README.md
Normal file
@ -0,0 +1,99 @@
|
||||
# GPIO_SYS
|
||||
|
||||
Gpio driver using sys file systeme.g.:
|
||||
|
||||
```shell
|
||||
echo "4" > /sys/class/gpio/export
|
||||
echo "out" > /sys/class/gpio/gpio4/direction
|
||||
echo "1"> /sys/class/gpio/gpio4/value
|
||||
echo "4" > /sys/class/gpio/unexport
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
make install
|
||||
```
|
||||
|
||||
Installs `libgpio_sys.a` and `libgpio_sys.so` in the directory `$(PREFIX)/lib/`. It also installs the include header file `gpio.h` in the directory `$(PREFIX)/include/gpio_sys/`. The default value for `PREFIX` is: `PREFIX=usr`. To use another location for installation changing the value of the `PREFIX` variable is needed. E.g.:
|
||||
|
||||
```shell
|
||||
PREFIX=/usr/local/ make install
|
||||
```
|
||||
|
||||
## Uninstallation
|
||||
|
||||
```shell
|
||||
make install
|
||||
```
|
||||
|
||||
Removes the files installed with the `install` make target.
|
||||
> **NOTE:** If `PREFIX` variable was changed during installation process the same value needs to be set for uninstallation. E.g.:
|
||||
|
||||
```shell
|
||||
PREFIX=/usr/local/ make install
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```C
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <stdbool.h>
|
||||
#include <gpio_sys/gpio.h>
|
||||
|
||||
|
||||
static const struct gpio_sys gpio_4 = {
|
||||
.pin = 4,
|
||||
.direction = 0, // out
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int res, cnt;
|
||||
int value;
|
||||
|
||||
openlog("gpio_sys", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
|
||||
|
||||
res = gpio_open(&gpio_4);
|
||||
if(res != EXIT_SUCCESS) {
|
||||
syslog(LOG_ERR, "Unable to open gpio %d\n", gpio_4.pin);
|
||||
return res;
|
||||
}
|
||||
|
||||
gpio_write(&gpio_4, 1);
|
||||
for(cnt = 0; cnt < 10; cnt++) {
|
||||
if(cnt % 2) {
|
||||
gpio_write(&gpio_4, 1);
|
||||
} else {
|
||||
gpio_write(&gpio_4, 0);
|
||||
}
|
||||
value = gpio_read(&gpio_4);
|
||||
if(value < 0) {
|
||||
syslog(LOG_ERR, "Unable to read from gpio %d\n", gpio_4.pin);
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
printf("Gpio 4: %d\n", value);
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
gpio_close(&gpio_4);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
## Additional make targets
|
||||
|
||||
| Target | Meaning |
|
||||
| --------------- | ----------------------------------------------------------- |
|
||||
| all | Build the code, assemble the static and shared library. |
|
||||
| install | Install the libraries and necessary include header files. |
|
||||
| uninstall | Uninstall the libraries and necessary include header files. |
|
||||
| clean | Clean up build artifacts. |
|
||||
| build_unit_test | Build the unit tests. |
|
||||
| exec_unit_test | Execute the unit tests. |
|
||||
| coverage | Determine code coverage of the unit tests. |
|
||||
| check | Static code analysis (cppcheck). |
|
Loading…
Reference in New Issue
Block a user