int sendUSB(pickit_dev *d, byte *src, int len) { int r, i; bool rescan = false; if (pickit2mode == NORMAL_MODE) { if ((src[0] == ENTERBOOTLOADER) && (src[1] == END_OF_BFR)) rescan = true; } else { if (src[0] == RESETFWDEVICE) rescan = true; } if (usbdebug & USB_DEBUG_CMD) showUSBCommand(src, len); if (usbdebug & USB_DEBUG_XMIT) { if (!usbFile) usbFile = stdout; fprintf(usbFile, "USB>"); for (r=0, i=0; r<len; r++) { fprintf(usbFile, " %02x", src[r] & 0xff); i++; if ((i > 15) && (i < (len - 1))) { i = 0; fprintf(usbFile, "\n "); } } fprintf(usbFile, "\n"); fflush(usbFile); } r = PICKIT_USB(write)(d, pickit_endpoint_out, (char *) src, reqLen, pickit_timeout); if (rescan) // Microchip code entered/exited bootloader, deviceHandle = NULL; // so reset the device handle if (r != reqLen) { if (verbose) { printf("sendUSB() PICkit USB write failed, returned %d\n", r); fflush(stdout); } return 0; } return 1; }
int sendUSB(pickit_dev *d, byte *src, int len) { int r, i; bool rescan = false; char buf[REPORT_SIZE + 1]; if (pickit2mode == NORMAL_MODE) { if ((src[0] == ENTERBOOTLOADER) && (src[1] == END_OF_BFR)) rescan = true; } else { if (src[0] == RESETFWDEVICE) rescan = true; } bzero(buf, REPORT_SIZE + 1); memcpy(buf, src, REPORT_SIZE); if (usbdebug & USB_DEBUG_CMD) showUSBCommand(src, len); if (usbdebug & USB_DEBUG_XMIT) { if (!usbFile) usbFile = stdout; fprintf(usbFile, "USB>"); for (r=0, i=0; r<len; r++) { fprintf(usbFile, " %02x", src[r] & 0xff); i++; if ((i > 15) && (i < (len - 1))) { i = 0; fprintf(usbFile, "\n "); } } fprintf(usbFile, "\n"); fflush(usbFile); } hidreport_send((hidreport_t) d, buf, REPORT_SIZE); if (rescan) // Microchip code entered/exited bootloader, deviceHandle = NULL; // so reset the device handle return 1; }