16
16
import busio
17
17
from digitalio import DigitalInOut
18
18
19
+ try :
20
+ from typing import Optional
21
+ from microcontroller import Pin
22
+ from busio import SPI
23
+ from _bleio import Adapter
24
+ except ImportError :
25
+ pass
26
+
19
27
20
28
class ESP32 :
21
29
"""Class to manage ESP32 running NINA firmware for WiFi or Bluetooth."""
@@ -34,14 +42,14 @@ class ESP32:
34
42
def __init__ (
35
43
self ,
36
44
* ,
37
- reset = None ,
38
- reset_high = False ,
39
- gpio0 = None ,
40
- busy = None ,
41
- chip_select = None ,
42
- tx = None ,
43
- rx = None ,
44
- spi = None
45
+ reset : Optional [ Pin ] = None ,
46
+ reset_high : bool = False ,
47
+ gpio0 : Optional [ Pin ] = None ,
48
+ busy : Optional [ Pin ] = None ,
49
+ chip_select : Optional [ Pin ] = None ,
50
+ tx : Optional [ Pin ] = None ,
51
+ rx : Optional [ Pin ] = None ,
52
+ spi : Optional [ SPI ] = None
45
53
):
46
54
47
55
"""Create an ESP32 instance, passing the objects needed to reset and communicate
@@ -89,7 +97,7 @@ def __init__(
89
97
# Used for WiFi mode.
90
98
self ._spi = spi
91
99
92
- def reset (self , mode , debug = False ):
100
+ def reset (self , mode : int , debug : bool = False ) -> None :
93
101
"""Do hard reset of the ESP32.
94
102
95
103
:param mode: One of `ESP32.NOT_IN_USE`, `ESP32.BOOTLOADER`, `ESP32.BLUETOOTH`, `ESP32.WIFI`.
@@ -145,7 +153,7 @@ def reset(self, mode, debug=False):
145
153
self ._mode = mode
146
154
147
155
# pylint: disable=invalid-name
148
- def start_bluetooth (self , debug = False ):
156
+ def start_bluetooth (self , debug : bool = False ) -> Adapter :
149
157
"""Set up the ESP32 in HCI Bluetooth mode, if it is not already doing something else.
150
158
151
159
:param debug bool: Print out some debugging information.
@@ -196,7 +204,7 @@ def stop_bluetooth(self):
196
204
self ._uart .deinit ()
197
205
self ._uart = None
198
206
199
- def start_wifi (self , debug = False ):
207
+ def start_wifi (self , debug : bool = False ) -> SPI :
200
208
"""Start WiFi on the ESP32.
201
209
202
210
:return: the ``busio.SPI`` object that will be used to communicate with the ESP32.
0 commit comments