Skip to content

Commit 6dc519b

Browse files
authored
Merge pull request #11 from dhalbert/fix-start-wifi
Don't check for startup message if no uart
2 parents 81684ea + c8501b0 commit 6dc519b

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
- id: end-of-file-fixer
1919
- id: trailing-whitespace
2020
- repo: https://github.com/pycqa/pylint
21-
rev: v2.17.4
21+
rev: v3.1.0
2222
hooks:
2323
- id: pylint
2424
name: pylint (library code)

adafruit_airlift/esp32.py

+26-24
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ESP32:
3939
_MODES = (NOT_IN_USE, BOOTLOADER, BLUETOOTH, WIFI)
4040

4141
# pylint: disable=invalid-name
42+
# pylint: disable=too-many-arguments
4243
def __init__(
4344
self,
4445
*,
@@ -54,24 +55,24 @@ def __init__(
5455
"""Create an ESP32 instance, passing the objects needed to reset and communicate
5556
with the adapter.
5657
57-
:param reset ~microcontroller.Pin: ESP32 RESET pin.
58+
:param ~microcontroller.Pin reset: ESP32 RESET pin.
5859
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;
6061
`False` if brought low.
61-
:param gpio0 ~microcontroller.Pin: ESP32 GPIO0 pin.
62+
:param ~microcontroller.Pin gpio0: ESP32 GPIO0 pin.
6263
Used for ESP32 boot selection when reset, and as RTS for UART communication.
6364
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).
6566
Used as CTS indicator for UART communication.
6667
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.
6869
Also used for ESP32 mode selection when reset.
6970
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.
7172
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.
7374
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.
7576
If not supplied, ``board.SPI()`` is used when in WiFi mode.
7677
"""
7778
self._mode = ESP32.NOT_IN_USE
@@ -134,28 +135,28 @@ def reset(self, mode: int, debug: bool = False) -> None:
134135
# No startup message expected.
135136
return
136137

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""
139141
while self._uart.in_waiting: # pylint: disable=no-member
140142
more = self._uart.read()
141143
if more:
142144
startup_message += more
143145

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")
154156

155157
# Everything's fine. Remember mode.
156158
self._mode = mode
157159

158-
# pylint: disable=invalid-name
159160
def start_bluetooth(self, debug: bool = False) -> Adapter:
160161
"""Set up the ESP32 in HCI Bluetooth mode, if it is not already doing something else.
161162
@@ -174,9 +175,7 @@ def start_bluetooth(self, debug: bool = False) -> Adapter:
174175
if self._mode == ESP32.WIFI:
175176
raise RuntimeError("ESP32 is in WiFi mode; use stop_wifi() first")
176177

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.
180179
if self._uart is None:
181180
self._uart = busio.UART(
182181
self._tx or board.ESP_TX,
@@ -186,6 +185,9 @@ def start_bluetooth(self, debug: bool = False) -> Adapter:
186185
receiver_buffer_size=512,
187186
)
188187

188+
# Choose Bluetooth mode.
189+
self._chip_select.switch_to_output(False)
190+
189191
# Reset into Bluetooth mode.
190192
self.reset(ESP32.BLUETOOTH, debug=debug)
191193

0 commit comments

Comments
 (0)