diff --git a/qt5_src/Bootloader/MainWindow.cpp b/qt5_src/Bootloader/MainWindow.cpp index ee75200..c099bb2 100644 --- a/qt5_src/Bootloader/MainWindow.cpp +++ b/qt5_src/Bootloader/MainWindow.cpp @@ -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;ivendor_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) diff --git a/qt5_src/Bootloader/MainWindow.ui b/qt5_src/Bootloader/MainWindow.ui index 19d932f..7ac7d38 100644 --- a/qt5_src/Bootloader/MainWindow.ui +++ b/qt5_src/Bootloader/MainWindow.ui @@ -26,7 +26,7 @@ - :/MainWindow/img/Microchip_logo.Ico:/MainWindow/img/Microchip_logo.Ico + :/MainWindow/img/amx_logo.ico:/MainWindow/img/amx_logo.ico @@ -518,58 +518,25 @@ QGroupBox::title { - + + + false + + + + 0 + 0 + + Segoe UI + 10 - - - - - false - - - - 0 - 0 - - - - - Segoe UI - 10 - - - - Reset Device - - - - - - - false - - - - 0 - 0 - - - - - Segoe UI - 10 - - - - Reset Device into FW Update Mode - - - - + + Reset Device + diff --git a/qt5_src/Bootloader/img/amx_logo.ico b/qt5_src/Bootloader/img/amx_logo.ico new file mode 100644 index 0000000..9dbc43c Binary files /dev/null and b/qt5_src/Bootloader/img/amx_logo.ico differ diff --git a/qt5_src/Bootloader/main.cpp b/qt5_src/Bootloader/main.cpp index bab4af7..5fc25aa 100644 --- a/qt5_src/Bootloader/main.cpp +++ b/qt5_src/Bootloader/main.cpp @@ -34,30 +34,12 @@ int main(int argc, char *argv[]) { - hid_device *dev = hid_open(0x1209, 0x0600, NULL); - if (dev == NULL) - { - qCritical("failed to open device"); - return 1; - } - - unsigned char data[2] = { 0, 0xBB }; - - int written = hid_write(dev, &data[0], sizeof(data)); - qWarning("Wrote %d bytes", written); - qWarning("%s", QString::fromWCharArray(hid_error(dev)).toStdString().c_str()); - - hid_close(dev); - //hid_exit(); - return 0; - - ///////////////////////////////////////////////// QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication a(argc, argv); QCoreApplication::setOrganizationName("JOJCorp"); QCoreApplication::setOrganizationDomain("source.jojcorp.com"); - QCoreApplication::setApplicationName("Dancepad Interface FW Flash Tool"); + QCoreApplication::setApplicationName("BIA MicroDDR FW Flash Tool"); MainWindow w; w.show(); diff --git a/qt5_src/Bootloader/resources.qrc b/qt5_src/Bootloader/resources.qrc index 399435c..c412fde 100644 --- a/qt5_src/Bootloader/resources.qrc +++ b/qt5_src/Bootloader/resources.qrc @@ -10,5 +10,6 @@ img/Reset.png img/help.png img/Microchip_logo.Ico + img/amx_logo.ico