- static unsigned char last_write = 0, last_data = 0;
- unsigned char data;
- unsigned char writebuf[4096], readbuf[4096], *pos;
+ static unsigned char last_data = 0;
+ static unsigned char last_write = 0x00;
+ static unsigned char writebuf[USBBUFSIZE], *writepos = writebuf;
+ static unsigned char readbuf[USBBUFSIZE], *readpos;
+ unsigned char data, prev_data;
+
+ /* Count reads */
+ for (i = 0; i < num; i++)
+ if (tr[i].cmdTrans == PP_READ)
+ nread++;
+
+ /* Write combining */
+ if ((writepos-writebuf > sizeof(writebuf)-num) || (nread && writepos-writebuf)) {
+ DPRINTF("writing %d bytes due to %d following reads in %d chunks or full buffer\n", writepos-writebuf, nread, num);
+
+ ftdi_write_data(&ftdic, writebuf, writepos-writebuf);
+
+ i = 0;
+ while (i < writepos-writebuf) {
+ i += ftdi_read_data(&ftdic, readbuf, sizeof(readbuf));
+ }
+ DPRINTF("read %d/%d bytes\n", i, writepos-writebuf);
+ writepos = writebuf;
+ }