@@ -39,6 +39,7 @@ class ESP32:
39
39
_MODES = (NOT_IN_USE , BOOTLOADER , BLUETOOTH , WIFI )
40
40
41
41
# pylint: disable=invalid-name
42
+ # pylint: disable=too-many-arguments
42
43
def __init__ (
43
44
self ,
44
45
* ,
@@ -54,24 +55,24 @@ def __init__(
54
55
"""Create an ESP32 instance, passing the objects needed to reset and communicate
55
56
with the adapter.
56
57
57
- :param reset ~microcontroller.Pin: ESP32 RESET pin.
58
+ :param ~microcontroller.Pin reset : ESP32 RESET pin.
58
59
If `None`, use ``board.ESP_RESET``.
59
- :param reset_high bool: True if `reset` is brought high to reset;
60
+ :param bool reset_high : True if `reset` is brought high to reset;
60
61
`False` if brought low.
61
- :param gpio0 ~microcontroller.Pin: ESP32 GPIO0 pin.
62
+ :param ~microcontroller.Pin gpio0 : ESP32 GPIO0 pin.
62
63
Used for ESP32 boot selection when reset, and as RTS for UART communication.
63
64
If `None`, use ``board.ESP_GPIO0``.
64
- :param busy ~microcontroller.Pin: ESP32 BUSY pin (sometimes called READY).
65
+ :param ~microcontroller.Pin busy : ESP32 BUSY pin (sometimes called READY).
65
66
Used as CTS indicator for UART communication.
66
67
If `None`, use ``board.ESP_BUSY``.
67
- :param chip_select ~microcontroller.Pin: ESP32 CS (chip select) pin.
68
+ :param ~microcontroller.Pin chip_select : ESP32 CS (chip select) pin.
68
69
Also used for ESP32 mode selection when reset.
69
70
If `None`, use ``board.ESP_CS``.
70
- :param tx ~microcontroller.Pin: ESP32 TX pin for Bluetooth UART communication.
71
+ :param ~microcontroller.Pin tx : ESP32 TX pin for Bluetooth UART communication.
71
72
If `None`, use ``board.ESP_TX`` when in Bluetooth mode.
72
- :param rx ~microcontroller.Pin: ESP32 RX pin for Bluetooth UART communication.
73
+ :param ~microcontroller.Pin rx : ESP32 RX pin for Bluetooth UART communication.
73
74
If `None`, use ``board.ESP_RX`` when in Bluetooth mode.
74
- :param spi busio.SPI: Used for communication with the ESP32.
75
+ :param busio.SPI spi : Used for communication with the ESP32.
75
76
If not supplied, ``board.SPI()`` is used when in WiFi mode.
76
77
"""
77
78
self ._mode = ESP32 .NOT_IN_USE
@@ -134,28 +135,28 @@ def reset(self, mode: int, debug: bool = False) -> None:
134
135
# No startup message expected.
135
136
return
136
137
137
- startup_message = b""
138
- if self ._uart is not None :
138
+ # Don't look for a startup message if there is no UART
139
+ if self ._uart :
140
+ startup_message = b""
139
141
while self ._uart .in_waiting : # pylint: disable=no-member
140
142
more = self ._uart .read ()
141
143
if more :
142
144
startup_message += more
143
145
144
- if startup_message :
145
- if debug :
146
- try :
147
- print (startup_message .decode ("utf-8" ))
148
- except UnicodeError :
149
- raise RuntimeError (
150
- "Garbled ESP32 startup message"
151
- ) from UnicodeError
152
- else :
153
- raise RuntimeError ("ESP32 did not respond with a startup message" )
146
+ if startup_message :
147
+ if debug :
148
+ try :
149
+ print (startup_message .decode ("utf-8" ))
150
+ except UnicodeError :
151
+ raise RuntimeError (
152
+ "Garbled ESP32 startup message"
153
+ ) from UnicodeError
154
+ else :
155
+ raise RuntimeError ("ESP32 did not respond with a startup message" )
154
156
155
157
# Everything's fine. Remember mode.
156
158
self ._mode = mode
157
159
158
- # pylint: disable=invalid-name
159
160
def start_bluetooth (self , debug : bool = False ) -> Adapter :
160
161
"""Set up the ESP32 in HCI Bluetooth mode, if it is not already doing something else.
161
162
@@ -174,9 +175,7 @@ def start_bluetooth(self, debug: bool = False) -> Adapter:
174
175
if self ._mode == ESP32 .WIFI :
175
176
raise RuntimeError ("ESP32 is in WiFi mode; use stop_wifi() first" )
176
177
177
- # Choose Bluetooth mode.
178
- self ._chip_select .switch_to_output (False )
179
-
178
+ # For bluetooth, we must be able to talk over UART to the ESP32.
180
179
if self ._uart is None :
181
180
self ._uart = busio .UART (
182
181
self ._tx or board .ESP_TX ,
@@ -186,6 +185,9 @@ def start_bluetooth(self, debug: bool = False) -> Adapter:
186
185
receiver_buffer_size = 512 ,
187
186
)
188
187
188
+ # Choose Bluetooth mode.
189
+ self ._chip_select .switch_to_output (False )
190
+
189
191
# Reset into Bluetooth mode.
190
192
self .reset (ESP32 .BLUETOOTH , debug = debug )
191
193
0 commit comments