Compare commits

...

2 Commits

Author SHA1 Message Date
Thomas Klaehn
f4cc51669b Add readme 2019-07-18 11:46:10 +02:00
Thomas Klaehn
3cbcfee449 Add uninstall make target 2019-07-18 11:45:44 +02:00
2 changed files with 126 additions and 6 deletions

View File

@ -1,8 +1,8 @@
CROSS_COMPILE ?=
TARGET_FILE ?= ftdi_gpio
STATIC_LIB_FILE ?= libftdi_gpio.a
DYNAMIC_LIB_FILE ?= libftdi_gpio.so
TARGET_FILE ?= gpio_ftdi
STATIC_LIB_FILE ?= libgpio_ftdi.a
DYNAMIC_LIB_FILE ?= libgpio_ftdi.so
CC = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)cpp
@ -19,8 +19,8 @@ UNIT_TEST_SRC_DIR = test/unit
UNIT_TEST_OBJ_DIR = $(OBJ_DIR)/$(UNIT_TEST_SRC_DIR)
PREFIX ?= /usr
LIB_INSTALL_DIR ?= $(PREFIX)/lib/ftdi_gpio
INC_INSTALL_DIR ?= $(PREFIX)/include/ftdi_gpio
LIB_INSTALL_DIR ?= $(PREFIX)/lib/gpio_ftdi
INC_INSTALL_DIR ?= $(PREFIX)/include/gpio_ftdi
INCLUDES := inc
INCLUDES += /usr/include/libftdi1
@ -52,7 +52,7 @@ UNIT_TEST_TARGET = $(BIN_DIR)/$(UNIT_TEST_SRC_DIR)/$(TARGET_FILE)
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
.PHONY: all install clean
.PHONY: all install uninstall clean
all: $(STATIC_LIB) $(DYNAMIC_LIB)
install: all
@ -62,6 +62,12 @@ install: all
install -m 0777 $(DYNAMIC_LIB) $(LIB_INSTALL_DIR)
install -m 0644 inc/* $(INC_INSTALL_DIR)
uninstall:
rm -f $(LIB_INSTALL_DIR)/$(STATIC_LIB)
rm -f $(LIB_INSTALL_DIR)/$(DYNAMIC_LIB)
rm -f $(addprefix $(INC_INSTALL_DIR)/,$(shell ls inc))
rm -rf $(INC_INSTALL_DIR)
clean:
rm -f $(STATIC_LIB) $(DYNAMIC_LIB)
rm -f $(OBJS) $(patsubst %.o,%.d,$(OBJS))

114
README.md Normal file
View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <stdbool.h>
#include <ftdi_dev.h>
#include <gpio.h>
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). |