short ftdi bit bang test
This commit is contained in:
52
src/main.c
52
src/main.c
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user