21 from .MicroPythonDevices import MicroPythonDevice |
21 from .MicroPythonDevices import MicroPythonDevice |
22 from .MicroPythonWidget import HAS_QTCHART |
22 from .MicroPythonWidget import HAS_QTCHART |
23 |
23 |
24 import Preferences |
24 import Preferences |
25 |
25 |
26 |
|
27 # TODO: add backupFlash: python ./esptool.py --port /dev/ttyUSB4 --baud 115200 read_flash 0x00000 0x400000 backup.img |
|
28 # selection of sizes: 1MB, 2MB, 4MB, 8MB, 16M (0x100000, 0x200000, 0x400000, 0x800000, 0x1000000) |
|
29 # ESP8266: 256KB, 512KB (0x40000, 0x80000) |
|
30 # TODO: add restoreFlash: python esptool.py --port /dev/ttyUSB4 write_flash --flash_mode qio 0x00000 backup.img |
|
31 # alternative modes for --flash_mode: qio,qout,dio,dout |
|
32 # optional: --flash_size 1MB, 2MB, 4MB, 8MB, 16M (ESP8266 zusätzlich 256KB, 512KB) |
|
33 |
26 |
34 class EspDevice(MicroPythonDevice): |
27 class EspDevice(MicroPythonDevice): |
35 """ |
28 """ |
36 Class implementing the device for ESP32 and ESP8266 based boards. |
29 Class implementing the device for ESP32 and ESP8266 based boards. |
37 """ |
30 """ |
139 self.__flashMicroPython) |
132 self.__flashMicroPython) |
140 act.setEnabled(not connected) |
133 act.setEnabled(not connected) |
141 menu.addSeparator() |
134 menu.addSeparator() |
142 act = menu.addAction(self.tr("Flash Additional Firmware"), |
135 act = menu.addAction(self.tr("Flash Additional Firmware"), |
143 self.__flashAddons) |
136 self.__flashAddons) |
|
137 act.setEnabled(not connected) |
|
138 menu.addSeparator() |
|
139 act = menu.addAction(self.tr("Backup Firmware"), |
|
140 self.__backupFlash) |
|
141 act.setEnabled(not connected) |
|
142 act = menu.addAction(self.tr("Restore Firmware"), |
|
143 self.__restoreFlash) |
144 act.setEnabled(not connected) |
144 act.setEnabled(not connected) |
145 menu.addSeparator() |
145 menu.addSeparator() |
146 act = menu.addAction(self.tr("Show Chip ID"), |
146 act = menu.addAction(self.tr("Show Chip ID"), |
147 self.__showChipID) |
147 self.__showChipID) |
148 act.setEnabled(not connected) |
148 act.setEnabled(not connected) |
236 res = dlg.startProcess(sys.executable, flashArgs) |
236 res = dlg.startProcess(sys.executable, flashArgs) |
237 if res: |
237 if res: |
238 dlg.exec_() |
238 dlg.exec_() |
239 |
239 |
240 @pyqtSlot() |
240 @pyqtSlot() |
|
241 def __backupFlash(self): |
|
242 """ |
|
243 Private slot to backup the currently flashed firmware. |
|
244 """ |
|
245 from .EspBackupRestoreFirmwareDialog import ( |
|
246 EspBackupRestoreFirmwareDialog |
|
247 ) |
|
248 dlg = EspBackupRestoreFirmwareDialog(backupMode=True) |
|
249 if dlg.exec_() == QDialog.Accepted: |
|
250 chip, flashSize, flashMode, firmware = dlg.getData() |
|
251 flashArgs = [ |
|
252 "-u", |
|
253 "-m", "esptool", |
|
254 "--chip", chip, |
|
255 "--port", self.microPython.getCurrentPort(), |
|
256 "read_flash", |
|
257 "0x0", flashSize, |
|
258 firmware, |
|
259 ] |
|
260 dlg = E5ProcessDialog(self.tr("'esptool read_flash' Output"), |
|
261 self.tr("Backup Firmware")) |
|
262 res = dlg.startProcess(sys.executable, flashArgs) |
|
263 if res: |
|
264 dlg.exec_() |
|
265 |
|
266 @pyqtSlot() |
|
267 def __restoreFlash(self): |
|
268 """ |
|
269 Private slot to restore a previously saved firmware. |
|
270 """ |
|
271 from .EspBackupRestoreFirmwareDialog import ( |
|
272 EspBackupRestoreFirmwareDialog |
|
273 ) |
|
274 dlg = EspBackupRestoreFirmwareDialog(backupMode=False) |
|
275 if dlg.exec_() == QDialog.Accepted: |
|
276 chip, flashSize, flashMode, firmware = dlg.getData() |
|
277 flashArgs = [ |
|
278 "-u", |
|
279 "-m", "esptool", |
|
280 "--chip", chip, |
|
281 "--port", self.microPython.getCurrentPort(), |
|
282 "write_flash", |
|
283 "--flash_mode", flashMode, |
|
284 ] |
|
285 if bool(flashSize): |
|
286 flashArgs.extend([ |
|
287 "--flash_size", flashSize, |
|
288 ]) |
|
289 flashArgs.extend([ |
|
290 "0x0", |
|
291 firmware, |
|
292 ]) |
|
293 dlg = E5ProcessDialog(self.tr("'esptool write_flash' Output"), |
|
294 self.tr("Restore Firmware")) |
|
295 res = dlg.startProcess(sys.executable, flashArgs) |
|
296 if res: |
|
297 dlg.exec_() |
|
298 |
|
299 @pyqtSlot() |
241 def __showChipID(self): |
300 def __showChipID(self): |
242 """ |
301 """ |
243 Private slot to show the ID of the ESP chip. |
302 Private slot to show the ID of the ESP chip. |
244 """ |
303 """ |
245 args = [ |
304 args = [ |