Compare commits

...

1 Commits

Author SHA1 Message Date
Thomas Klaehn
99c2fb28bb short ftdi bit bang test 2019-07-13 19:17:18 +02:00
2 changed files with 52 additions and 4 deletions

View File

@ -10,7 +10,9 @@ OBJ_DIR = obj
BIN_DIR = bin
INCLUDES := inc
LIBS := ftdi
LD_FLAGS :=
C_FLAGS := -O0 -g
CPP_FLAGS := $(addprefix -I, $(INCLUDES))
@ -27,7 +29,7 @@ all: $(TARGET)
$(TARGET): $(OBJS) $(THIS_MAKEFILE)
@mkdir -p $(BIN_DIR)
$(CC) $(LD_FLAGS) $(OBJS) $(LIBS) -o $@
$(CC) $(C_FLAGS) $(LD_FLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -o $@
.PRECIOUS: $(OBJ_DIR)/%.d
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.c

View File

@ -1,10 +1,56 @@
#include <stdio.h>
#include <syslog.h>
#include <ftdi.h>
#include <def.h>
#define LED 0x08
int main(int argc, char *argv[])
{
printf("%s\n", HELLO);
struct ftdi_context *ftdi;
int f, retval, cnt;
unsigned char buf[1];
return 0;
openlog("ftdi_gpio", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
setlogmask(LOG_DEBUG);
if ((ftdi = ftdi_new()) == 0) {
syslog(LOG_ERR, "ftdi_new failed\n");
return EXIT_FAILURE;
}
f = ftdi_usb_open(ftdi, 0x0403, 0x6001);
if (f < 0 && f != -5) {
syslog(LOG_ERR, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(ftdi));
retval = 1;
goto done;
}
f = ftdi_set_bitmode(ftdi, LED, BITMODE_BITBANG);
if(f < 0) {
syslog(LOG_ERR, "unable to set bit bang mode: %d (%s)\n", f, ftdi_get_error_string(ftdi));
retval = 1;
goto done;
}
buf[0] = 0;
for(cnt = 0; cnt < 10; cnt++) {
buf[0] ^= LED,
f = ftdi_write_data(ftdi, buf, 1);
if(f < 0) {
syslog(LOG_ERR, "write failed for 0x%x, error %d (%s)\n",buf[0], f, ftdi_get_error_string(ftdi));
cnt = 10;
} else {
syslog(LOG_DEBUG, "set LED to: %u\n", (unsigned int)buf[0]);
}
sleep(1);
}
ftdi_usb_close(ftdi);
done:
ftdi_free(ftdi);
closelog();
return retval;
}