Convert to library

This commit is contained in:
Thomas Klaehn
2019-07-17 00:08:17 +02:00
parent 8f5d0dd7f8
commit 1d358b1086
4 changed files with 39 additions and 98 deletions

View File

@@ -1,63 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <stdbool.h>
#include <ftdi_dev.h>
#include <gpio.h>
/*
#define GPIO1 0x08 // TX (brown)
#define GPIO2 0x01 // TX (orange)
#define GPIO3 0x02 // RX (yellow)
#define GPIO4 0x14 // RTS (green on FTDI) + DTR (on SparkFun breakout)
*/
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,
};
static const struct gpio gpio_2 = {
.pin = 0x01, /* TX (orange 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);
res |= gpio_open(&gpio_2);
if(res != EXIT_SUCCESS) {
syslog(LOG_ERR, "Unable to open gpio\n");
return res;
}
gpio_write(&gpio_1, 1);
gpio_write(&gpio_2, 0);
for(cnt = 0; cnt < 10; cnt++) {
gpio_toggle(&gpio_1);
gpio_toggle(&gpio_2);
gpio_read(&gpio_1, &value);
printf("Gpio1: %u\n", value);
gpio_read(&gpio_2, &value);
printf("Gpio2: %u\n", value);
sleep(1);
}
gpio_close(&gpio_1);
gpio_close(&gpio_2);
return EXIT_SUCCESS;
}