int bufferSize = packetsPerTransfer * ftdi->max_packet_size;
int xferIndex;
int err = 0;
+
+ /* Only FT2232H and FT232H know about the synchronous FIFO Mode*/
+ if ((ftdi->type != TYPE_2232H) && (ftdi->type != TYPE_232H))
+ {
+ fprintf(stderr,"Device doesn't support synchronous FIFO mode\n");
+ return 1;
+ }
- fprintf(stderr, "ftdi_readstream\n");
+ /* We don't know in what state we are, switch to reset*/
+ if (ftdi_set_bitmode(ftdi, 0xff, BITMODE_RESET) < 0)
+ {
+ fprintf(stderr,"Can't reset mode\n");
+ return 1;
+ }
+
+ /* Purge anything remaining in the buffers*/
+ if (ftdi_usb_purge_buffers(ftdi) < 0)
+ {
+ fprintf(stderr,"Can't Purge\n");
+ return 1;
+ }
+
/*
* Set up all transfers
*/
*/
if (ftdi_set_bitmode(ftdi, 0xff, BITMODE_SYNCFF) < 0)
{
- fprintf(stderr,"Can't set synchronous fifo mode\n",
+ fprintf(stderr,"Can't set synchronous fifo mode: %s\n",
ftdi_get_error_string(ftdi));
goto cleanup;
}
struct timeval timeout = { 0, ftdi->usb_read_timeout };
struct timeval now;
- int err = libusb_handle_events_timeout(NULL, &timeout);
+ int err = libusb_handle_events_timeout(ftdi->usb_ctx, &timeout);
if (err == LIBUSB_ERROR_INTERRUPTED)
/* restart interrupted events */
- err = libusb_handle_events_timeout(NULL, &timeout);
+ err = libusb_handle_events_timeout(ftdi->usb_ctx, &timeout);
if (!state.result)
{
state.result = err;