Skip to content

Commit 71f3947

Browse files
committed
DM: add support for INPUT_PULLDOWN
1 parent 39fae2e commit 71f3947

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

adafruit_seesaw/seesaw.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class Seesaw:
125125
INPUT = const(0x00)
126126
OUTPUT = const(0x01)
127127
INPUT_PULLUP = const(0x02)
128+
INPUT_PULLDOWN = const(0x03)
128129

129130
def __init__(self, i2c_bus, addr=0x49, drdy=None):
130131
self._drdy = drdy
@@ -186,13 +187,14 @@ def digital_read(self, pin):
186187
def digital_read_bulk(self, pins):
187188
buf = bytearray(4)
188189
self.read(_GPIO_BASE, _GPIO_BULK, buf)
190+
buf[0] = buf[0] & 0x3F
189191
ret = struct.unpack(">I", buf)[0]
190192
return ret & pins
191193

192194
def digital_read_bulk_b(self, pins):
193195
buf = bytearray(8)
194196
self.read(_GPIO_BASE, _GPIO_BULK, buf)
195-
ret = struct.unpack(">II", buf)[1]
197+
ret = struct.unpack(">I", buf[4:])[0]
196198
return ret & pins
197199

198200

@@ -235,6 +237,14 @@ def pin_mode_bulk(self, pins, mode):
235237
self.write(_GPIO_BASE, _GPIO_PULLENSET, cmd)
236238
self.write(_GPIO_BASE, _GPIO_BULK_SET, cmd)
237239

240+
elif mode == self.INPUT_PULLDOWN:
241+
self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd)
242+
self.write(_GPIO_BASE, _GPIO_PULLENSET, cmd)
243+
self.write(_GPIO_BASE, _GPIO_BULK_CLR, cmd)
244+
245+
else:
246+
raise ValueError("Invalid pin mode")
247+
238248
def pin_mode_bulk_b(self, pins, mode):
239249
cmd = bytearray(8)
240250
cmd[4:] = struct.pack(">I", pins)
@@ -248,6 +258,14 @@ def pin_mode_bulk_b(self, pins, mode):
248258
self.write(_GPIO_BASE, _GPIO_PULLENSET, cmd)
249259
self.write(_GPIO_BASE, _GPIO_BULK_SET, cmd)
250260

261+
elif mode == self.INPUT_PULLDOWN:
262+
self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd)
263+
self.write(_GPIO_BASE, _GPIO_PULLENSET, cmd)
264+
self.write(_GPIO_BASE, _GPIO_BULK_CLR, cmd)
265+
266+
else:
267+
raise ValueError("Invalid pin mode")
268+
251269
def digital_write_bulk(self, pins, value):
252270
cmd = struct.pack(">I", pins)
253271
if value:

0 commit comments

Comments
 (0)