From 7d6db69257ef819e29a6c4e34cfa73f7dbe57fff Mon Sep 17 00:00:00 2001 From: Dan White Date: Sun, 8 Apr 2012 18:50:31 -0500 Subject: [PATCH] usbio.py: add AD5242 GP outputs setting --- python-lib/usbio.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/python-lib/usbio.py b/python-lib/usbio.py index f5971f2..a4a2174 100644 --- a/python-lib/usbio.py +++ b/python-lib/usbio.py @@ -356,13 +356,18 @@ class AD524x(object): O1_POS = 4 O2_POS = 3 # instruction bits 2..0 are unused + READ = 1 WRITE = 0 + + # cache for lazy updating lastA = None lastB = None lastSel = None + lastO1 = None + lastO2 = None - def __init__(self, i2cbus, addr=0): + def __init__(self, i2cbus, addr): self.bus = i2cbus self.addr = intbv(ADDR_BASE + intbv(addr, max=2**2), max=2**7) self._sel = intbv(0, max=1) @@ -438,6 +443,7 @@ class AD524x(object): else: v = intbv(0)[0] self._gpo1 = v + self.updateGPO() @property def gpo2(self): return self.gpo2 @@ -449,6 +455,7 @@ class AD524x(object): else: v = intbv(0)[0] self._gpo2 = v + self.updateGPO() @property def instruction(self): @@ -475,6 +482,11 @@ class AD524x(object): if force or (self.posB != self.lastB): self.send(1) + def updateGPO(self, force=False): + if force or (self.gpo1 != self.lastO1) or + (self.gpo2 != self.lastO2): + self.sendGPO() + def send(self, sel): self.sel = sel cmd = ((self.addr << 1) + self.WRITE, @@ -489,6 +501,14 @@ class AD524x(object): self.bus.write(cmd) + def sendGPO(self): + cmd = ((self.addr << 1) + self.WRITE, + self.instruction) + self.lastSel = self.sel + self.lastO1 = self.gpo1 + self.lastO2 = self.gpo2 + self.bus.write(cmd) + def read(self, sel): if sel != self.lastSel: self.send(sel) -- 2.25.1