src/eric7/MicroPython/UF2FlashDialog.py

branch
eric7
changeset 9954
7c5fa3eef082
parent 9953
1aa8517bc61f
child 10112
dcbb8703b5b2
diff -r 1aa8517bc61f -r 7c5fa3eef082 src/eric7/MicroPython/UF2FlashDialog.py
--- a/src/eric7/MicroPython/UF2FlashDialog.py	Fri Mar 31 09:53:27 2023 +0200
+++ b/src/eric7/MicroPython/UF2FlashDialog.py	Fri Mar 31 13:39:51 2023 +0200
@@ -7,7 +7,6 @@
 Module implementing a dialog to flash any UF2 capable device.
 """
 
-import contextlib
 import os
 import shutil
 
@@ -582,38 +581,6 @@
         "show_all": True,
         "firmware": "CircuitPython",
     },
-    "circuitpython_rp2040": {
-        "volumes": {
-            (0x239A, 0x80F4): [
-                ("RPI-RP2", "Raspberry Pi Pico"),
-            ],
-        },
-        "instructions": QCoreApplication.translate(
-            "UF2FlashDialog",
-            "<h3>Pi Pico (RP2040) Board</h3>"
-            "<p>In order to prepare the board for flashing follow these"
-            " steps:</p><ol>"
-            "<li>Enter 'bootloader' mode (board <b>without</b> RESET button):"
-            "<ul>"
-            "<li>Plug in your board while holding the BOOTSEL button.</li>"
-            "</ul>"
-            "Enter 'bootloader' mode (board <b>with</b> RESET button):"
-            "<ul>"
-            "<li>hold down RESET</li>"
-            "<li>hold down BOOTSEL</li>"
-            "<li>release RESET</li>"
-            "<li>release BOOTSEL</li>"
-            "</ul></li>"
-            "<li>Wait until the device has entered 'bootloader' mode.</li>"
-            "<li>Ensure the boot volume is available (this may require"
-            " mounting it).</li>"
-            "<li>Select the firmware file to be flashed and click the"
-            " flash button.</li>"
-            "</ol>",
-        ),
-        "show_all": False,
-        "firmware": "CircuitPython",
-    },
     "rp2040": {
         "volumes": {
             (0x0000, 0x0000): [
@@ -661,6 +628,15 @@
     """
     foundDevices = set()
 
+    # step 1: determine all known UF2 volumes that are mounted
+    boardTypes = [boardType] if boardType else list(SupportedUF2Boards.keys())
+    for board in boardTypes:
+        for vidpid, volumes in SupportedUF2Boards[board]["volumes"].items():
+            for volume, description in volumes:
+                if FileSystemUtilities.findVolume(volume, findAll=True):
+                    foundDevices.add((board, description, vidpid))
+
+    # set 2: determine all devices that have their UF2 volume not mounted
     availablePorts = QSerialPortInfo.availablePorts()
     for port in availablePorts:
         vid = port.vendorIdentifier()
@@ -675,37 +651,17 @@
                 vid,
                 pid,
             ) in SupportedUF2Boards[board]["volumes"]:
-                foundDevices.add(
-                    (
-                        board,
-                        port.description(),
-                        (vid, pid),
+                for device in foundDevices:
+                    if (vid, pid) == device[2]:
+                        break
+                else:
+                    foundDevices.add(
+                        (
+                            board,
+                            port.description(),
+                            (vid, pid),
+                        )
                     )
-                )
-
-    # second run for boards needing special treatment (e.g. RP2040)
-    for board in SupportedUF2Boards:
-        if not boardType or (board == boardType):
-            with contextlib.suppress(KeyError):
-                # find mounted volume
-                volumes = SupportedUF2Boards[board]["volumes"][(0, 0)]
-                for volume, description in volumes:
-                    if FileSystemUtilities.findVolume(volume, findAll=True):
-                        foundDevices.add(
-                            (board, port.description() or description, (0, 0))
-                        )
-
-    # third run for CircuitPython boards in UF2 mode but with VID/PID being invalid
-    for vidpid, volumes in SupportedUF2Boards["circuitpython"]["volumes"].items():
-        for volume, description in volumes:
-            if FileSystemUtilities.findVolume(volume, findAll=True):
-                foundDevices.add(
-                    (
-                        "circuitpython",
-                        port.description() or description,
-                        vidpid,
-                    )
-                )
 
     return list(foundDevices)
 
@@ -753,7 +709,6 @@
         self.__boardType = boardType
 
         self.__populate()
-
         self.__updateFlashButton()
 
     def __populate(self):
@@ -810,6 +765,9 @@
         # select the remembered device, if it is still there
         if currentDevice:
             self.devicesComboBox.setCurrentText(currentDevice)
+            if self.devicesComboBox.currentIndex() == -1 and len(devices) == 1:
+                # the device name has changed but only one is present; select it
+                self.devicesComboBox.setCurrentIndex(0)
             self.firmwarePicker.setText(firmwareFile)
         elif len(devices) == 1:
             self.devicesComboBox.setCurrentIndex(0)
@@ -1032,11 +990,8 @@
         """
         Private slot to refresh the dialog.
         """
-        # special treatment for RPi Pico
-        if self.__boardType == "circuitpython_rp2040":
-            self.__boardType = "rp2040"
-
         self.__populate()
+        self.__updateFlashButton()
 
     @pyqtSlot(int)
     def on_devicesComboBox_currentIndexChanged(self, index):
@@ -1069,7 +1024,7 @@
             elif len(foundVolumes) == 1:
                 self.bootPicker.setText(foundVolumes[0])
             else:
-                self.__showMultipleVolumesInformation()
+                self.__showMultipleVolumesInformation(foundVolumes)
                 self.bootPicker.clear()
 
         self.__updateFlashButton()

eric ide

mercurial