utility now detects devices connected in their normal operating mode and sends command to make them jump into bootloader mode
This commit is contained in:
@@ -69,8 +69,18 @@
|
||||
#define DEFAULT_VID 0x04D8
|
||||
#define DEFAULT_PID 0x003C
|
||||
|
||||
// the command to make the device jump into bootloader mode
|
||||
#define COMMAND_JUMP_BOOTLOADER 0xBB
|
||||
|
||||
|
||||
struct USBDevIds
|
||||
{
|
||||
unsigned short vendor_id;
|
||||
unsigned short product_id;
|
||||
} NormalModeDevIds[2] =
|
||||
{
|
||||
{0x1209, 0x0600}, // from pid.codes
|
||||
{0x04D8, 0xECEE} // from microchip sublicense
|
||||
};
|
||||
|
||||
|
||||
//Surely the micro doesn't have a programmable memory region greater than 268 Megabytes...
|
||||
@@ -367,6 +377,50 @@ void MainWindow::Connection(void)
|
||||
emit SetProgressBar(0);
|
||||
}
|
||||
}
|
||||
|
||||
// check if a device is found in normal non-bootloader mode
|
||||
hid_device_info *hidDevs = hid_enumerate(0, 0);
|
||||
hid_device_info *d = hidDevs;
|
||||
while (d)
|
||||
{
|
||||
for (unsigned int i=0;i<sizeof(NormalModeDevIds)/sizeof(USBDevIds);i++)
|
||||
{
|
||||
USBDevIds ids = NormalModeDevIds[i];
|
||||
if (d->vendor_id == ids.vendor_id &&
|
||||
d->product_id == ids.product_id)
|
||||
{
|
||||
// a device was found, prompt user that it will need to be reset into bootloader mode
|
||||
QMessageBox msgbox(QMessageBox::Information,
|
||||
"Device detected in non-FW update mode",
|
||||
"A device was detected in normal operating mode. Press OK to reset the device into firmware update mode and proceed.",
|
||||
QMessageBox::Ok,
|
||||
this,
|
||||
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
|
||||
msgbox.setWindowModality(Qt::ApplicationModal);
|
||||
msgbox.exec();
|
||||
|
||||
// the user has closed the message box - send the bootloader entry command to the device
|
||||
hid_device *dev = hid_open_path(d->path);
|
||||
if (dev == NULL)
|
||||
{
|
||||
QMessageBox::critical(this, "Error", "Failed to open the HID device");
|
||||
break;
|
||||
}
|
||||
unsigned char hidOutData[2] = {0, COMMAND_JUMP_BOOTLOADER};
|
||||
int bytesWritten = hid_write(dev, &hidOutData[0], sizeof(hidOutData));
|
||||
if (bytesWritten == -1)
|
||||
{
|
||||
QString errMsg = QString("Failed to send mode switch command to the device:\n\n%1").arg(hid_error(dev));
|
||||
QMessageBox::critical(this, "Error", errMsg);
|
||||
}
|
||||
hid_close(dev);
|
||||
}
|
||||
}
|
||||
|
||||
d = d->next;
|
||||
}
|
||||
|
||||
hid_free_enumeration(hidDevs);
|
||||
}
|
||||
|
||||
void MainWindow::setBootloadEnabled(bool enable)
|
||||
|
||||
Reference in New Issue
Block a user