Skip to content

Commit

Permalink
Merge pull request #65 from emfcamp/move_egpio_pin_wrapper
Browse files Browse the repository at this point in the history
Move eGPIO interface
  • Loading branch information
MatthewWilkes authored May 29, 2024
2 parents 581a98f + 77eca2d commit ff91f96
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 56 deletions.
4 changes: 2 additions & 2 deletions modules/system/hexpansion/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from machine import Pin, I2C
from tildagonos import ExtendedPin
from tildagon import Pin as ePin

_pin_mapping = {
1: {
Expand Down Expand Up @@ -34,5 +34,5 @@ class HexpansionConfig:
def __init__(self, port):
self.port = port
self.pin = [Pin(x) for x in _pin_mapping[port]["hs"]]
self.ls_pin = [ExtendedPin(x) for x in _pin_mapping[port]["ls"]]
self.ls_pin = [ePin(x) for x in _pin_mapping[port]["ls"]]
self.i2c = I2C(port)
57 changes: 57 additions & 0 deletions modules/tildagon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import machine
from tildagonos import tildagonos


HEXPANSION_GPIOS = {
"1_LS_A": (0x5A, 0, 1 << 3),
"1_LS_B": (0x5A, 1, 1 << 0),
"1_LS_C": (0x5A, 1, 1 << 1),
"1_LS_D": (0x5A, 1, 1 << 2),
"1_LS_E": (0x5A, 1, 1 << 3),
"2_LS_A": (0x5A, 0, 1 << 0),
"2_LS_B": (0x5A, 0, 1 << 1),
"2_LS_C": (0x59, 1, 1 << 5),
"2_LS_D": (0x59, 1, 1 << 6),
"2_LS_E": (0x59, 1, 1 << 7),
"3_LS_A": (0x59, 0, 1 << 4),
"3_LS_B": (0x59, 0, 1 << 5),
"3_LS_C": (0x59, 0, 1 << 6),
"3_LS_D": (0x59, 0, 1 << 7),
"3_LS_E": (0x59, 1, 1 << 4),
"4_LS_A": (0x58, 1, 1 << 0),
"4_LS_B": (0x58, 1, 1 << 1),
"4_LS_C": (0x58, 1, 1 << 2),
"4_LS_D": (0x58, 1, 1 << 3),
"4_LS_E": (0x58, 0, 1 << 0),
"5_LS_A": (0x58, 0, 1 << 2),
"5_LS_B": (0x58, 0, 1 << 3),
"5_LS_C": (0x58, 0, 1 << 4),
"5_LS_D": (0x58, 0, 1 << 5),
"5_LS_E": (0x58, 1, 1 << 6),
"6_LS_A": (0x58, 0, 1 << 7),
"6_LS_B": (0x58, 1, 1 << 4),
"6_LS_C": (0x58, 1, 1 << 5),
"6_LS_D": (0x58, 1, 1 << 6),
"6_LS_E": (0x58, 1, 1 << 7),
}


class Pin:
def __init__(self, pin_name, mode=-1):
self.name = pin_name
self.pin = HEXPANSION_GPIOS[pin_name]
self.mode = mode

def on(self):
self.value(1)

def off(self):
self.value(0)

def value(self, value=None, read=True):
if self.mode in (machine.Pin.IN, -1) and value is None:
return tildagonos.check_egpio_state(self.pin, readgpios=read)
elif self.mode in (machine.Pin.OUT, -1):
return tildagonos.set_egpio_pin(self.pin, value)
else:
raise ValueError("Wrong pin state")
54 changes: 0 additions & 54 deletions modules/tildagonos.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,6 @@
(255, 0, 255),
]

HEXPANSION_GPIOS = {
"1_LS_A": (0x5A, 0, 1 << 3),
"1_LS_B": (0x5A, 1, 1 << 0),
"1_LS_C": (0x5A, 1, 1 << 1),
"1_LS_D": (0x5A, 1, 1 << 2),
"1_LS_E": (0x5A, 1, 1 << 3),
"2_LS_A": (0x5A, 0, 1 << 0),
"2_LS_B": (0x5A, 0, 1 << 1),
"2_LS_C": (0x59, 1, 1 << 5),
"2_LS_D": (0x59, 1, 1 << 6),
"2_LS_E": (0x59, 1, 1 << 7),
"3_LS_A": (0x59, 0, 1 << 4),
"3_LS_B": (0x59, 0, 1 << 5),
"3_LS_C": (0x59, 0, 1 << 6),
"3_LS_D": (0x59, 0, 1 << 7),
"3_LS_E": (0x59, 1, 1 << 4),
"4_LS_A": (0x58, 1, 1 << 0),
"4_LS_B": (0x58, 1, 1 << 1),
"4_LS_C": (0x58, 1, 1 << 2),
"4_LS_D": (0x58, 1, 1 << 3),
"4_LS_E": (0x58, 0, 1 << 0),
"5_LS_A": (0x58, 0, 1 << 2),
"5_LS_B": (0x58, 0, 1 << 3),
"5_LS_C": (0x58, 0, 1 << 4),
"5_LS_D": (0x58, 0, 1 << 5),
"5_LS_E": (0x58, 1, 1 << 6),
"6_LS_A": (0x58, 0, 1 << 7),
"6_LS_B": (0x58, 1, 1 << 4),
"6_LS_C": (0x58, 1, 1 << 5),
"6_LS_D": (0x58, 1, 1 << 6),
"6_LS_E": (0x58, 1, 1 << 7),
}


class ExtendedPin:
def __init__(self, pin_name, mode=-1):
self.name = pin_name
self.pin = HEXPANSION_GPIOS[pin_name]
self.mode = mode

def on(self):
self.value(1)

def off(self):
self.value(0)

def value(self, value=None, read=True):
if self.mode in (Pin.IN, -1) and value is None:
return tildagonos.check_egpio_state(self.pin, readgpios=read)
elif self.mode in (Pin.OUT, -1):
return tildagonos.set_egpio_pin(self.pin, value)
else:
raise ValueError("Wrong pin state")


class _tildagonos:
def __init__(self):
Expand Down

0 comments on commit ff91f96

Please sign in to comment.