From f4cc51669b14d4a4dbea13bda4cae14c97b9741d Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Thu, 18 Jul 2019 11:46:10 +0200 Subject: [PATCH] Add readme --- README.md | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..081b0ca --- /dev/null +++ b/README.md @@ -0,0 +1,114 @@ +# GPIO_FTDI + +Gpio driver using ftdi usb chips e.g.: + +```shell +$ lsusb +Bus 001 Device 008: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC +``` + +## Requirements + +* libftdi1 +* libftdi1-dev + +### Debian + +```shell +apt install libftdi1 libftdi1-dev +``` + +### Alpine Linux + +```shell +apk add libftdi1 libftdi1-dev +``` + +## Installation + +```shell +make install +``` + +Installs `lobgpio_ftdi.a` and `libgpio_ftdi.so` in the directory `$(PREFIX)/lib/`. It also installs the include header files `ftdi_dev.h` and `gpio.h` in the directory `$(PREFIX)/include/gpio_ftdi`. 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:** When `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 + #include + + static struct ftdi_dev ftdi_obj = { + .ftdi = NULL, + .is_open = false, + .vendor_id = 0x0403, + .product_id = 0x6001, + .bit_mask = 0, + .status_mask = 0, + }; + + static const struct gpio gpio_1 = { + .pin = 0x08, /* CTS (brown wire on FTDI cable) */ + .ftdi_dev = &ftdi_obj, + }; + + int main(void) + { + int res, cnt; + unsigned int value; + + openlog("ftdi_gpio", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); + + res = gpio_open(&gpio_1); + if(res != EXIT_SUCCESS) { + syslog(LOG_ERR, "Unable to open gpio\n"); + return res; + } + + gpio_write(&gpio_1, 1); + for(cnt = 0; cnt < 10; cnt++) { + gpio_toggle(&gpio_1); + gpio_read(&gpio_1, &value); + printf("Gpio1: %u\n", value); + sleep(1); + } + gpio_close(&gpio_1); + + 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). |