Skip to content

Eliminate duplicated code in pin_mode_bulk* #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions adafruit_seesaw/seesaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ def moisture_read(self):

return ret

def pin_mode_bulk(self, pins, mode):
cmd = struct.pack(">I", pins)
def _pin_mode_bulk_x(self, capacity, offset, pins, mode):
cmd = bytearray(capacity)
cmd[offset:] = struct.pack(">I", pins)
if mode == self.OUTPUT:
self.write(_GPIO_BASE, _GPIO_DIRSET_BULK, cmd)
elif mode == self.INPUT:
Expand All @@ -273,26 +274,11 @@ def pin_mode_bulk(self, pins, mode):
else:
raise ValueError("Invalid pin mode")

def pin_mode_bulk_b(self, pins, mode):
cmd = bytearray(8)
cmd[4:] = struct.pack(">I", pins)
if mode == self.OUTPUT:
self.write(_GPIO_BASE, _GPIO_DIRSET_BULK, cmd)
elif mode == self.INPUT:
self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd)

elif mode == self.INPUT_PULLUP:
self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd)
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)
def pin_mode_bulk(self, pins, mode):
self._pin_mode_bulk_x(4, 0, pins, mode)

else:
raise ValueError("Invalid pin mode")
def pin_mode_bulk_b(self, pins, mode):
self._pin_mode_bulk_x(8, 4, pins, mode)

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