Skip to content

Commit

Permalink
Fix hexpansions not being consistently detected on hotplug
Browse files Browse the repository at this point in the history
For mysterious reasons the GPIO expanders seem to not always update the
state of port 1 when doing a multi-byte read. If we instead do two
single-byte reads, we appear to get the correct state 100% of the time.
The datasheet has some confusing lines about how you always need to send
a write command before reading the port states - I believe readfrom_mem
actually does this, but since it's not actually sending any data for the
write, it's only technically writing to address 0, which only updates
port 0 (hence why buttons work consistently - they're all port 0!)
  • Loading branch information
hedgehog1029 committed Jun 9, 2024
1 parent 6b2c29e commit e8b7477
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions modules/tildagonos.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ def set_egpio_pin(self, pin, state):

def read_egpios(self):
for i in [0x58, 0x59, 0x5A]:
portstates = list(map(int, self.system_i2c.readfrom_mem(i, 0x00, 2)))
self.gpiodata[i] = tuple(portstates)
self.gpiodata[i] = (
self.system_i2c.readfrom_mem(i, 0, 1)[0],
self.system_i2c.readfrom_mem(i, 1, 1)[0],
)

def check_egpio_state(self, pin, readgpios=True):
if pin[0] not in self.gpiodata or readgpios:
Expand Down

0 comments on commit e8b7477

Please sign in to comment.