From 7da732b5e1e6ddc05e3759afb3ab32bd15ac335c Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Mon, 29 Jul 2019 14:00:17 +0200 Subject: [PATCH] Add Readme --- README.md | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..078344a --- /dev/null +++ b/README.md @@ -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 + #include + #include + #include + #include + #include + + + 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). |