372 ), |
372 ), |
373 "firmware": "CircuitPython", |
373 "firmware": "CircuitPython", |
374 }, |
374 }, |
375 |
375 |
376 "rp2040": { |
376 "rp2040": { |
377 "volumes": [ |
377 "volumes": { |
378 |
378 (0x0000, 0x0000): [ |
379 ], |
379 "RPI-RP2", # Raspberry Pi Pico does not present a TTY |
|
380 ], |
|
381 }, |
380 "instructions": QCoreApplication.translate( |
382 "instructions": QCoreApplication.translate( |
381 "UF2FlashDialog", |
383 "UF2FlashDialog", |
382 "<h3>Pi Pico (RP2040) Board</h3>" |
384 "<h3>Pi Pico (RP2040) Board</h3>" |
383 "<p>In order to prepare the board for flashing follow these" |
385 "<p>In order to prepare the board for flashing follow these" |
384 " steps:</p><ol>" |
386 " steps:</p><ol>" |
425 board, |
427 board, |
426 port.description(), |
428 port.description(), |
427 (vid, pid), |
429 (vid, pid), |
428 )) |
430 )) |
429 |
431 |
|
432 # second run for boards needing special treatment (e.g. RP2040) |
|
433 for board in SupportedUF2Boards: |
|
434 if not boardType or (board == boardType): |
|
435 try: |
|
436 # find mounted volume |
|
437 volumes = SupportedUF2Boards[board]["volumes"][(0, 0)] |
|
438 foundVolumes = [] |
|
439 for volume in volumes: |
|
440 foundVolumes += Utilities.findVolume(volume, findAll=True) |
|
441 if foundVolumes: |
|
442 foundDevices.append(( |
|
443 board, |
|
444 QCoreApplication.translate( |
|
445 "UF2FlashDialog", "'{0}' Board").format(board), |
|
446 (0, 0), # VID/PID of (0, 0) is special |
|
447 )) |
|
448 except KeyError: |
|
449 # no special treatment required, carry on |
|
450 pass |
|
451 |
430 return foundDevices |
452 return foundDevices |
431 |
453 |
432 |
454 |
433 class UF2FlashDialog(QDialog, Ui_UF2FlashDialog): |
455 class UF2FlashDialog(QDialog, Ui_UF2FlashDialog): |
434 """ |
456 """ |
487 |
509 |
488 # now populate the entries with data |
510 # now populate the entries with data |
489 devices = getFoundDevices(boardType=self.__boardType) |
511 devices = getFoundDevices(boardType=self.__boardType) |
490 if len(devices) == 0: |
512 if len(devices) == 0: |
491 # no device detected |
513 # no device detected |
492 devices = filter( |
514 devices = list(filter( |
493 lambda x: x[0] in SupportedUF2Boards, |
515 lambda x: x[0] in SupportedUF2Boards, |
494 MicroPythonDevices.getFoundDevices()[0] |
516 MicroPythonDevices.getFoundDevices()[0] |
495 ) |
517 )) |
496 if devices: |
518 if devices: |
497 self.__showSpecificInstructions(list(devices)) |
519 self.__showSpecificInstructions(list(devices)) |
498 else: |
520 else: |
499 self.__showAllInstructions() |
521 self.__showAllInstructions() |
500 self.devicesComboBox.addItem("") |
522 self.devicesComboBox.addItem("") |
708 """ |
730 """ |
709 boardType = self.devicesComboBox.currentData(self.DeviceTypeRole) |
731 boardType = self.devicesComboBox.currentData(self.DeviceTypeRole) |
710 firmwarePath = self.firmwarePicker.text() |
732 firmwarePath = self.firmwarePicker.text() |
711 volumePath = self.bootPicker.text() |
733 volumePath = self.bootPicker.text() |
712 if os.path.exists(firmwarePath) and os.path.exists(volumePath): |
734 if os.path.exists(firmwarePath) and os.path.exists(volumePath): |
713 firmwareType = SupportedUF2Boards[boardType]["firmware"] |
735 if boardType == self.__manualType: |
714 self.infoLabel.setText( |
736 self.infoLabel.setText(self.tr("Flashing Firmware")) |
715 self.tr("Flashing {0}").format(firmwareType)) |
737 self.infoEdit.setHtml(self.tr( |
716 self.infoEdit.setHtml(self.tr( |
738 "<p>Flashing the selected firmware to the device. Please" |
717 "<p>Flashing the {0} firmware to the device. Please wait" |
739 " wait until the device resets automatically.</p>") |
718 " until the device resets automatically.</p>" |
740 ) |
719 ).format(firmwareType)) |
741 else: |
|
742 firmwareType = SupportedUF2Boards[boardType]["firmware"] |
|
743 self.infoLabel.setText( |
|
744 self.tr("Flashing {0}").format(firmwareType)) |
|
745 self.infoEdit.setHtml(self.tr( |
|
746 "<p>Flashing the {0} firmware to the device. Please wait" |
|
747 " until the device resets automatically.</p>" |
|
748 ).format(firmwareType)) |
720 QCoreApplication.processEvents(QEventLoop.ExcludeUserInputEvents) |
749 QCoreApplication.processEvents(QEventLoop.ExcludeUserInputEvents) |
721 shutil.copy2(firmwarePath, volumePath) |
750 shutil.copy2(firmwarePath, volumePath) |
722 QThread.sleep(1) |
751 QThread.sleep(1) |
723 self.on_refreshButton_clicked() |
752 self.on_refreshButton_clicked() |
724 |
753 |