|
30 | 30 | # SPDX-License-Identifier: BSD-3-Clause
|
31 | 31 |
|
32 | 32 | import logging
|
| 33 | +import os |
33 | 34 | import socket
|
34 | 35 | import sys
|
35 | 36 | import threading
|
36 | 37 | import time
|
37 | 38 |
|
| 39 | +from esptool.config import load_config_file |
| 40 | +from esptool.reset import ClassicReset, CustomReset, DEFAULT_RESET_DELAY, UnixTightReset |
| 41 | + |
38 | 42 | import serial
|
39 | 43 | import serial.rfc2217
|
40 | 44 | from serial.rfc2217 import (
|
|
46 | 50 | SET_CONTROL_RTS_ON,
|
47 | 51 | )
|
48 | 52 |
|
| 53 | +cfg, _ = load_config_file(verbose=True) |
| 54 | +cfg = cfg["esptool"] |
| 55 | + |
49 | 56 |
|
50 | 57 | class EspPortManager(serial.rfc2217.PortManager):
|
51 | 58 | """
|
@@ -78,34 +85,25 @@ def _telnet_process_subnegotiation(self, suboption):
|
78 | 85 | # only in cases not handled above do the original implementation in PortManager
|
79 | 86 | super(EspPortManager, self)._telnet_process_subnegotiation(suboption)
|
80 | 87 |
|
81 |
| - def _setDTR(self, state): |
82 |
| - self.serial.setDTR(state) |
83 |
| - |
84 |
| - def _setRTS(self, state): |
85 |
| - self.serial.setRTS(state) |
86 |
| - # Work-around for adapters on Windows using the usbser.sys driver: |
87 |
| - # generate a dummy change to DTR so that the set-control-line-state |
88 |
| - # request is sent with the updated RTS state and the same DTR state |
89 |
| - self.serial.setDTR(self.serial.dtr) |
90 |
| - |
91 | 88 | def _reset_thread(self):
|
92 | 89 | """
|
93 | 90 | The reset logic is used from esptool.py because the RTS and DTR signals
|
94 | 91 | cannot be retransmitted through RFC 2217 with proper timing.
|
95 | 92 | """
|
96 | 93 | if self.logger:
|
97 | 94 | self.logger.info("Activating reset in thread")
|
98 |
| - self._setDTR(False) # IO0=HIGH |
99 |
| - self._setRTS(True) # EN=LOW, chip in reset |
100 |
| - time.sleep(0.1) |
101 |
| - if self.esp32r0_delay: |
102 |
| - time.sleep(1.2) |
103 |
| - self._setDTR(True) # IO0=LOW |
104 |
| - self._setRTS(False) # EN=HIGH, chip out of reset |
| 95 | + |
| 96 | + delay = DEFAULT_RESET_DELAY |
105 | 97 | if self.esp32r0_delay:
|
106 |
| - time.sleep(0.4) |
107 |
| - time.sleep(0.05) |
108 |
| - self._setDTR(False) # IO0=HIGH, done |
| 98 | + delay += 0.5 |
| 99 | + |
| 100 | + cfg_custom_reset_sequence = cfg.get("custom_reset_sequence") |
| 101 | + if cfg_custom_reset_sequence is not None: |
| 102 | + CustomReset(self.serial, cfg_custom_reset_sequence)() |
| 103 | + elif os.name != "nt": |
| 104 | + UnixTightReset(self.serial, delay)() |
| 105 | + else: |
| 106 | + ClassicReset(self.serial, delay)() |
109 | 107 |
|
110 | 108 |
|
111 | 109 | class Redirector(object):
|
|
0 commit comments