Skip to content

Commit 00e7f97

Browse files
brentrubrentru
brentru
authored and
brentru
committed
drop all pull functionality since we dont have it defined in adafruit_esp32spi.py
1 parent 7772894 commit 00e7f97

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

adafruit_esp32spi/digitalio.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"""
2929
from micropython import const
3030

31+
# Enums
3132
class DriveMode():
3233
PUSH_PULL = None
3334
OPEN_DRAIN = None
@@ -42,16 +43,6 @@ class Direction:
4243
Direction.INPUT = Direction()
4344
Direction.OUTPUT = Direction()
4445

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-
5546
class Pin:
5647
IN = const(0x00)
5748
OUT = const(0x01)
@@ -67,18 +58,16 @@ class Pin:
6758
21, 22, 23, 25,
6859
26, 27, 32, 33])
6960

70-
7161
def __init__(self, esp_pin, esp):
7262
if esp_pin in self.ESP32_GPIO_PINS:
7363
self.id = esp_pin
7464
else:
7565
raise AttributeError("Pin %d is not a valid ESP32 GPIO Pin."%esp_pin)
7666
self._esp = esp
7767

78-
def init(self, mode=IN, pull=None):
68+
def init(self, mode=IN):
7969
"""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).
8271
"""
8372
print('pin init')
8473
if mode != None:
@@ -90,8 +79,6 @@ def init(self, mode=IN, pull=None):
9079
self._esp.set_pin_mode(self.id, 1)
9180
else:
9281
raise RuntimeError("Invalid mode defined")
93-
if pull != None:
94-
raise RuntimeError("ESP32 does not have pull-up resistors defined.")
9582

9683
def value(self, val=None):
9784
"""Sets ESP32 Pin GPIO output mode.
@@ -107,13 +94,13 @@ def value(self, val=None):
10794
else:
10895
raise RuntimeError("Invalid value for pin")
10996
else:
110-
raise AttributeError("ESP32SPI does not allow for a digital input.")
97+
raise NotImplementedError("digitalRead not currently implemented in esp32spi")
11198

11299
def __repr__(self):
113100
return str(self.id)
114101

115-
116102
class DigitalInOut():
103+
117104
"""Mock DigitalIO CircuitPython API Implementation for ESP32SPI.
118105
Provides access to ESP_SPIcontrol methods.
119106
"""
@@ -143,7 +130,6 @@ def direction(self, dir):
143130
self.drive_mode = DriveMode.PUSH_PULL
144131
elif dir is Direction.INPUT:
145132
self._pin.init(mode=Pin.IN)
146-
self.pull = None
147133
else:
148134
raise AttributeError("Not a Direction")
149135

@@ -156,4 +142,19 @@ def value(self, val):
156142
if self.direction is Direction.OUTPUT:
157143
self._pin.value(1 if val else 0)
158144
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

Comments
 (0)