+ 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)) {
+ unsigned char *pos = writebuf;
+ int len;
+ DPRINTF("writing %d bytes due to %d following reads in %d chunks or full buffer\n", writepos-writebuf, nread, num);
+
+ while (pos < writepos) {
+ len = writepos-pos;
+
+ if (len > usb_maxlen)
+ len = usb_maxlen;
+
+ DPRINTF("combined write of %d/%d\n",len,writepos-pos);
+ ftdi_write_data(&ftdic, pos, len);
+ pos += len;
+ }
+
+ DPRINTF("read %d/%d bytes\n", i, writepos-writebuf);
+ writepos = writebuf;
+ }