Sat, 15 Jan 2022 18:42:21 +0100
MicroPython
- added support for ESP32-C3, ESP32-S2 and ESP32-S3 chips
7352 | 1 | # -*- coding: utf-8 -*- |
2 | ||
8881
54e42bc2437a
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8358
diff
changeset
|
3 | # Copyright (c) 2019 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
7352 | 4 | # |
5 | ||
6 | """ | |
7 | Module implementing a dialog to select the ESP chip type and the backup and | |
8 | restore parameters. | |
9 | """ | |
10 | ||
11 | import os | |
12 | ||
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
13 | from PyQt6.QtCore import pyqtSlot |
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
14 | from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
7352 | 15 | |
8358
144a6b854f70
Sorted the eric specific extensions into packages named like the corresponding PyQt packages (i.e. EricCore,EricGui and EricWidgets).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8356
diff
changeset
|
16 | from EricWidgets.EricPathPicker import EricPathPickerModes |
7352 | 17 | |
18 | from .Ui_EspBackupRestoreFirmwareDialog import ( | |
19 | Ui_EspBackupRestoreFirmwareDialog | |
20 | ) | |
21 | ||
22 | ||
23 | class EspBackupRestoreFirmwareDialog(QDialog, | |
24 | Ui_EspBackupRestoreFirmwareDialog): | |
25 | """ | |
26 | Class implementing a dialog to select the ESP chip type and the backup and | |
27 | restore parameters. | |
28 | """ | |
8924 | 29 | Chips = ( |
30 | ("", ""), | |
31 | ("ESP32", "esp32"), | |
32 | ("ESP32-C3", "esp32c3"), | |
33 | ("ESP32-S2", "esp32s2"), | |
34 | ("ESP32-S3", "esp32s3"), | |
35 | ("ESP8266", "esp8266"), | |
36 | ) | |
37 | ||
7595
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
38 | FlashModes = [ |
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
39 | ("Quad I/O", "qio"), |
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
40 | ("Quad Output", "qout"), |
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
41 | ("Dual I/O", "dio"), |
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
42 | ("Dual Output", "dout"), |
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
43 | ] |
8924 | 44 | |
7352 | 45 | FlashSizes = { |
8924 | 46 | "esp32": [ |
47 | (" 1 MB", "0x100000"), | |
48 | (" 2 MB", "0x200000"), | |
49 | (" 4 MB", "0x400000"), | |
50 | (" 8 MB", "0x800000"), | |
51 | ("16 MB", "0x1000000"), | |
52 | ], | |
53 | "esp32c3": [ | |
7352 | 54 | (" 1 MB", "0x100000"), |
55 | (" 2 MB", "0x200000"), | |
56 | (" 4 MB", "0x400000"), | |
57 | (" 8 MB", "0x800000"), | |
58 | ("16 MB", "0x1000000"), | |
59 | ], | |
8924 | 60 | "esp32s2": [ |
61 | (" 1 MB", "0x100000"), | |
62 | (" 2 MB", "0x200000"), | |
63 | (" 4 MB", "0x400000"), | |
64 | (" 8 MB", "0x800000"), | |
65 | ("16 MB", "0x1000000"), | |
66 | ], | |
67 | "esp32s3": [ | |
68 | (" 1 MB", "0x100000"), | |
69 | (" 2 MB", "0x200000"), | |
70 | (" 4 MB", "0x400000"), | |
71 | (" 8 MB", "0x800000"), | |
72 | ("16 MB", "0x1000000"), | |
73 | ], | |
74 | "esp8266": [ | |
7352 | 75 | ("256 KB", "0x40000"), |
76 | ("512 KB", "0x80000"), | |
77 | (" 1 MB", "0x100000"), | |
78 | (" 2 MB", "0x200000"), | |
79 | (" 4 MB", "0x400000"), | |
80 | (" 8 MB", "0x800000"), | |
81 | ("16 MB", "0x1000000"), | |
82 | ], | |
83 | } | |
84 | ||
85 | def __init__(self, backupMode=True, parent=None): | |
86 | """ | |
87 | Constructor | |
88 | ||
89 | @param backupMode flag indicating parameters for a firmware backup are | |
90 | requested | |
91 | @type bool | |
92 | @param parent reference to the parent widget | |
93 | @type QWidget | |
94 | """ | |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
95 | super().__init__(parent) |
7352 | 96 | self.setupUi(self) |
97 | ||
98 | self.__isBackupMode = backupMode | |
99 | ||
8924 | 100 | for text, chip in self.Chips: |
101 | self.espComboBox.addItem(text, chip) | |
7352 | 102 | |
103 | self.firmwarePicker.setFilters( | |
104 | self.tr("Firmware Files (*.img);;All Files (*)")) | |
105 | if self.__isBackupMode: | |
106 | self.firmwarePicker.setMode( | |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8327
diff
changeset
|
107 | EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE) |
7352 | 108 | self.modeComboBox.setEnabled(False) |
109 | self.setWindowTitle(self.tr("Backup Firmware")) | |
110 | else: | |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8327
diff
changeset
|
111 | self.firmwarePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
7595
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
112 | for text, mode in self.FlashModes: |
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
113 | self.modeComboBox.addItem(text, mode) |
7352 | 114 | self.setWindowTitle(self.tr("Restore Firmware")) |
115 | ||
116 | msh = self.minimumSizeHint() | |
117 | self.resize(max(self.width(), msh.width()), msh.height()) | |
118 | ||
119 | def __updateOkButton(self): | |
120 | """ | |
121 | Private method to update the state of the OK button. | |
122 | """ | |
123 | firmwareFile = self.firmwarePicker.text() | |
124 | enable = (bool(self.espComboBox.currentText()) and | |
125 | bool(firmwareFile)) | |
126 | if self.__isBackupMode: | |
127 | enable &= bool(self.sizeComboBox.currentText()) | |
128 | else: | |
129 | enable &= os.path.exists(firmwareFile) | |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
130 | self.buttonBox.button( |
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
131 | QDialogButtonBox.StandardButton.Ok).setEnabled(enable) |
7352 | 132 | |
133 | @pyqtSlot(str) | |
134 | def on_espComboBox_currentTextChanged(self, chip): | |
135 | """ | |
136 | Private slot to handle the selection of a chip type. | |
137 | ||
138 | @param chip selected chip type | |
139 | @type str | |
140 | """ | |
141 | selectedSize = self.sizeComboBox.currentText() | |
142 | self.sizeComboBox.clear() | |
8924 | 143 | chipType = self.espComboBox.currentData() |
144 | if chipType and chipType in self.FlashSizes: | |
7352 | 145 | self.sizeComboBox.addItem("") |
8924 | 146 | for text, data in self.FlashSizes[chipType]: |
7352 | 147 | self.sizeComboBox.addItem(text, data) |
148 | ||
149 | self.sizeComboBox.setCurrentText(selectedSize) | |
150 | ||
151 | self.__updateOkButton() | |
152 | ||
153 | @pyqtSlot(str) | |
154 | def on_firmwarePicker_textChanged(self, firmware): | |
155 | """ | |
156 | Private slot handling a change of the firmware path. | |
157 | ||
158 | @param firmware path to the firmware | |
159 | @type str | |
160 | """ | |
161 | self.__updateOkButton() | |
162 | ||
163 | def getData(self): | |
164 | """ | |
165 | Public method to get the entered data. | |
166 | ||
167 | @return tuple containing the selected chip type, the firmware size, | |
168 | the flash mode and the path of the firmware file | |
169 | @rtype tuple of (str, str, str, str) | |
170 | """ | |
171 | return ( | |
8924 | 172 | self.espComboBox.currentData(), |
7352 | 173 | self.sizeComboBox.currentData(), |
7595
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
174 | self.modeComboBox.currentData(), |
7352 | 175 | self.firmwarePicker.text(), |
176 | ) |