28
28
"""
29
29
from micropython import const
30
30
31
+ # Enums
31
32
class DriveMode ():
32
33
PUSH_PULL = None
33
34
OPEN_DRAIN = None
@@ -42,16 +43,6 @@ class Direction:
42
43
Direction .INPUT = Direction ()
43
44
Direction .OUTPUT = Direction ()
44
45
45
- class Pull :
46
- UP = None
47
- DOWN = None
48
-
49
- Pull .UP = Pull ()
50
- Pull .DOWN = Pull ()
51
-
52
- # ESP32-WROOM GPIO Pins
53
-
54
-
55
46
class Pin :
56
47
IN = const (0x00 )
57
48
OUT = const (0x01 )
@@ -67,18 +58,16 @@ class Pin:
67
58
21 , 22 , 23 , 25 ,
68
59
26 , 27 , 32 , 33 ])
69
60
70
-
71
61
def __init__ (self , esp_pin , esp ):
72
62
if esp_pin in self .ESP32_GPIO_PINS :
73
63
self .id = esp_pin
74
64
else :
75
65
raise AttributeError ("Pin %d is not a valid ESP32 GPIO Pin." % esp_pin )
76
66
self ._esp = esp
77
67
78
- def init (self , mode = IN , pull = None ):
68
+ def init (self , mode = IN ):
79
69
"""Initalizes a pre-defined pin.
80
- :param mode: Pin mode (IN, OUT, LOW, HIGH)
81
- :param pull: Pull value (PULL_NONE, PULL_UP, PULL_DOWN)
70
+ :param mode: Pin mode (IN, OUT, LOW, HIGH).
82
71
"""
83
72
print ('pin init' )
84
73
if mode != None :
@@ -90,8 +79,6 @@ def init(self, mode=IN, pull=None):
90
79
self ._esp .set_pin_mode (self .id , 1 )
91
80
else :
92
81
raise RuntimeError ("Invalid mode defined" )
93
- if pull != None :
94
- raise RuntimeError ("ESP32 does not have pull-up resistors defined." )
95
82
96
83
def value (self , val = None ):
97
84
"""Sets ESP32 Pin GPIO output mode.
@@ -107,13 +94,13 @@ def value(self, val=None):
107
94
else :
108
95
raise RuntimeError ("Invalid value for pin" )
109
96
else :
110
- raise AttributeError ( "ESP32SPI does not allow for a digital input. " )
97
+ raise NotImplementedError ( "digitalRead not currently implemented in esp32spi " )
111
98
112
99
def __repr__ (self ):
113
100
return str (self .id )
114
101
115
-
116
102
class DigitalInOut ():
103
+
117
104
"""Mock DigitalIO CircuitPython API Implementation for ESP32SPI.
118
105
Provides access to ESP_SPIcontrol methods.
119
106
"""
@@ -143,7 +130,6 @@ def direction(self, dir):
143
130
self .drive_mode = DriveMode .PUSH_PULL
144
131
elif dir is Direction .INPUT :
145
132
self ._pin .init (mode = Pin .IN )
146
- self .pull = None
147
133
else :
148
134
raise AttributeError ("Not a Direction" )
149
135
@@ -156,4 +142,19 @@ def value(self, val):
156
142
if self .direction is Direction .OUTPUT :
157
143
self ._pin .value (1 if val else 0 )
158
144
else :
159
- raise AttributeError ("Not an output" )
145
+ raise AttributeError ("Not an output" )
146
+
147
+ @property
148
+ def drive_mode (self ):
149
+ if self .direction is Direction .OUTPUT :
150
+ return self .__drive_mode
151
+ else :
152
+ raise AttributeError ("Not an output" )
153
+
154
+ @drive_mode .setter
155
+ def drive_mode (self , mode ):
156
+ self .__drive_mode = mode
157
+ if mode is DriveMode .OPEN_DRAIN :
158
+ self ._pin .init (mode = Pin .OPEN_DRAIN )
159
+ elif mode is DriveMode .PUSH_PULL :
160
+ self ._pin .init (mode = Pin .OUT )
0 commit comments