/* This program is distributed under the GPL, version 2 */ /* based on examples/bitbang.c in libftdi-0.10 */ #include #include #include int main(int argc, char **argv) { struct ftdi_context ftdic; int f,i; char buf[1]; unsigned char c; int dir = 0; ftdi_init(&ftdic); f = ftdi_usb_open(&ftdic, 0x0403, 0x6001); if(f < 0 && f != -5) { fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(&ftdic)); exit(-1); } printf("ftdi open succeeded: %d\n",f); printf("enabling bitbang mode\n"); ftdi_enable_bitbang(&ftdic, 0xFF); sleep(1); buf[0] = 0x0; printf("turning everything on\n"); f = ftdi_write_data(&ftdic, buf, 1); c = 1; dir = 0; while (1) { f = ftdi_write_data(&ftdic, &c, 1); // fprintf(stderr, "%02x ", c); if (dir == 0) c <<= 1; else c >>= 1; if (c == 0) { if (dir == 0) { c = 0x80; dir = 1; } else { c = 1; dir = 0; } } usleep(70*1000); } printf("disabling bitbang mode\n"); ftdi_disable_bitbang(&ftdic); ftdi_usb_close(&ftdic); ftdi_deinit(&ftdic); }