eric6/MicroPython/UF2FlashDialog.py

changeset 8111
a8e9b387f701
parent 8101
dee984e05647
child 8120
84928e9f446f
--- a/eric6/MicroPython/UF2FlashDialog.py	Thu Feb 18 17:21:12 2021 +0100
+++ b/eric6/MicroPython/UF2FlashDialog.py	Thu Feb 18 17:29:53 2021 +0100
@@ -374,9 +374,11 @@
     },
     
     "rp2040": {
-        "volumes": [
-            
-        ],
+        "volumes": {
+            (0x0000, 0x0000): [
+                "RPI-RP2",        # Raspberry Pi Pico does not present a TTY
+            ],
+        },
         "instructions": QCoreApplication.translate(
             "UF2FlashDialog",
             "<h3>Pi Pico (RP2040) Board</h3>"
@@ -427,6 +429,26 @@
                         (vid, pid),
                     ))
     
+    # second run for boards needing special treatment (e.g. RP2040)
+    for board in SupportedUF2Boards:
+        if not boardType or (board == boardType):
+            try:
+                # find mounted volume
+                volumes = SupportedUF2Boards[board]["volumes"][(0, 0)]
+                foundVolumes = []
+                for volume in volumes:
+                    foundVolumes += Utilities.findVolume(volume, findAll=True)
+                if foundVolumes:
+                    foundDevices.append((
+                        board,
+                        QCoreApplication.translate(
+                            "UF2FlashDialog", "'{0}' Board").format(board),
+                        (0, 0),             # VID/PID of (0, 0) is special
+                    ))
+            except KeyError:
+                # no special treatment required, carry on
+                pass
+    
     return foundDevices
 
 
@@ -489,10 +511,10 @@
         devices = getFoundDevices(boardType=self.__boardType)
         if len(devices) == 0:
             # no device detected
-            devices = filter(
+            devices = list(filter(
                 lambda x: x[0] in SupportedUF2Boards,
                 MicroPythonDevices.getFoundDevices()[0]
-            )
+            ))
             if devices:
                 self.__showSpecificInstructions(list(devices))
             else:
@@ -710,13 +732,20 @@
         firmwarePath = self.firmwarePicker.text()
         volumePath = self.bootPicker.text()
         if os.path.exists(firmwarePath) and os.path.exists(volumePath):
-            firmwareType = SupportedUF2Boards[boardType]["firmware"]
-            self.infoLabel.setText(
-                self.tr("Flashing {0}").format(firmwareType))
-            self.infoEdit.setHtml(self.tr(
-                "<p>Flashing the {0} firmware to the device. Please wait"
-                " until the device resets automatically.</p>"
-            ).format(firmwareType))
+            if boardType == self.__manualType:
+                self.infoLabel.setText(self.tr("Flashing Firmware"))
+                self.infoEdit.setHtml(self.tr(
+                    "<p>Flashing the selected firmware to the device. Please"
+                    " wait until the device resets automatically.</p>")
+                )
+            else:
+                firmwareType = SupportedUF2Boards[boardType]["firmware"]
+                self.infoLabel.setText(
+                    self.tr("Flashing {0}").format(firmwareType))
+                self.infoEdit.setHtml(self.tr(
+                    "<p>Flashing the {0} firmware to the device. Please wait"
+                    " until the device resets automatically.</p>"
+                ).format(firmwareType))
             QCoreApplication.processEvents(QEventLoop.ExcludeUserInputEvents)
             shutil.copy2(firmwarePath, volumePath)
             QThread.sleep(1)

eric ide

mercurial