From 808e574e11b469f73d57630a463b5c5e01520eef Mon Sep 17 00:00:00 2001 From: claudio Date: Mon, 4 Dec 2017 14:41:06 -0500 Subject: [PATCH] Fixed usb_sendata on PC side to be portable. --- firmware/sys/target_pc/usbdriver.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/firmware/sys/target_pc/usbdriver.c b/firmware/sys/target_pc/usbdriver.c index a3e2507..943cbf1 100644 --- a/firmware/sys/target_pc/usbdriver.c +++ b/firmware/sys/target_pc/usbdriver.c @@ -473,7 +473,7 @@ int usb_transmitdata(BYTEPTR data,BINT size) BYTEPTR buf; // ONLY ALLOCATE MEMORY FOR DATA BLOCKS LARGER THAN 1 PACKET - if(size>RAWHID_TX_SIZE-8) buf=simpmallocb(size+8); + if(size>RAWHID_TX_SIZE-8) buf=simpmallocb(size+9); else buf=__usb_txtmpbuffer; if(!buf) return 0; // FAILED TO SEND - NOT ENOUGH MEMORY @@ -482,23 +482,24 @@ int usb_transmitdata(BYTEPTR data,BINT size) __usb_count[1]=size+8; - buf[0]=USB_BLOCKSTART_MARKER; // START OF BLOCK MARKER - buf[1]=size&0xff; - buf[2]=(size>>8)&0xff; - buf[3]=(size>>16)&0xff; + buf[0]=0; // REPORT ID + buf[1]=USB_BLOCKSTART_MARKER; // START OF BLOCK MARKER + buf[2]=size&0xff; + buf[3]=(size>>8)&0xff; + buf[4]=(size>>16)&0xff; WORD crc=usb_crc32(data,size); - buf[4]=crc&0xff; - buf[5]=(crc>>8)&0xff; - buf[6]=(crc>>16)&0xff; - buf[7]=(crc>>24)&0xff; + buf[5]=crc&0xff; + buf[6]=(crc>>8)&0xff; + buf[7]=(crc>>16)&0xff; + buf[8]=(crc>>24)&0xff; - memmoveb(buf+8,data,size); + memmoveb(buf+9,data,size); - err=hid_write(__usb_curdevice,__usb_bufptr[1],__usb_count[1]); + err=hid_write(__usb_curdevice,__usb_bufptr[1],__usb_count[1]+1); if(buf!=__usb_txtmpbuffer) simpfree(buf);