Skip to content

Commit

Permalink
DM: add support for INPUT_PULLDOWN
Browse files Browse the repository at this point in the history
  • Loading branch information
deanm1278 committed May 21, 2018
1 parent 39fae2e commit 71f3947
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion adafruit_seesaw/seesaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class Seesaw:
INPUT = const(0x00)
OUTPUT = const(0x01)
INPUT_PULLUP = const(0x02)
INPUT_PULLDOWN = const(0x03)

def __init__(self, i2c_bus, addr=0x49, drdy=None):
self._drdy = drdy
Expand Down Expand Up @@ -186,13 +187,14 @@ def digital_read(self, pin):
def digital_read_bulk(self, pins):
buf = bytearray(4)
self.read(_GPIO_BASE, _GPIO_BULK, buf)
buf[0] = buf[0] & 0x3F
ret = struct.unpack(">I", buf)[0]
return ret & pins

def digital_read_bulk_b(self, pins):
buf = bytearray(8)
self.read(_GPIO_BASE, _GPIO_BULK, buf)
ret = struct.unpack(">II", buf)[1]
ret = struct.unpack(">I", buf[4:])[0]
return ret & pins


Expand Down Expand Up @@ -235,6 +237,14 @@ def pin_mode_bulk(self, pins, mode):
self.write(_GPIO_BASE, _GPIO_PULLENSET, cmd)
self.write(_GPIO_BASE, _GPIO_BULK_SET, cmd)

elif mode == self.INPUT_PULLDOWN:
self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd)
self.write(_GPIO_BASE, _GPIO_PULLENSET, cmd)
self.write(_GPIO_BASE, _GPIO_BULK_CLR, cmd)

else:
raise ValueError("Invalid pin mode")

def pin_mode_bulk_b(self, pins, mode):
cmd = bytearray(8)
cmd[4:] = struct.pack(">I", pins)
Expand All @@ -248,6 +258,14 @@ def pin_mode_bulk_b(self, pins, mode):
self.write(_GPIO_BASE, _GPIO_PULLENSET, cmd)
self.write(_GPIO_BASE, _GPIO_BULK_SET, cmd)

elif mode == self.INPUT_PULLDOWN:
self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd)
self.write(_GPIO_BASE, _GPIO_PULLENSET, cmd)
self.write(_GPIO_BASE, _GPIO_BULK_CLR, cmd)

else:
raise ValueError("Invalid pin mode")

def digital_write_bulk(self, pins, value):
cmd = struct.pack(">I", pins)
if value:
Expand Down

0 comments on commit 71f3947

Please sign in to comment.