From: Dan White Date: Tue, 17 Jul 2012 17:27:52 +0000 (-0500) Subject: ADS8201 interrupt setup X-Git-Tag: calibrations~22 X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=9c9d5467a1b1d6ed32a6e20b905517023a4065ff;p=430.git ADS8201 interrupt setup --- diff --git a/python-lib/usbio.py b/python-lib/usbio.py index 0308b55..8e8fdbc 100644 --- a/python-lib/usbio.py +++ b/python-lib/usbio.py @@ -123,8 +123,8 @@ class I2C(object): ftdi.usb_purge_buffers(self.context) self.started = False - self.pinDir(pindir) - self.pinState(pinstate) + self.set_pindir(pindir) + self.set_pinstate(pinstate) def _clear_scl(self): self.io[self.scl] = 1 @@ -253,7 +253,7 @@ class I2C(object): data.append(self._read_byte(0, stop=True)) return data - def pinDir(self, dirs): + def set_pindir(self, dirs): """dirs bitfield has '1' for output, ignores scl/sda bit positions. """ d = intbv(dirs, max=2**8) @@ -264,7 +264,7 @@ class I2C(object): #print b(self.io, 8) ftdi.set_bitmode(self.context, int(self.io), ftdi.BITMODE_BITBANG) - def pinState(self, bitfield): + def set_pinstate(self, bitfield): """Set GPIO pins to given bitfield state, ignoring scl/sda pins.""" bits = intbv(bitfield, max=2**8) bits[self.scl] = self.io[self.scl] @@ -274,6 +274,11 @@ class I2C(object): #print b(self.port, 8) ftdi.write_data(self.context, chr(self.port), 1) + def get_pinstate(self): + """Return the state of all the pins. + """ + return ftdi.read_pins(self.context) + def RESET(self, value): """Set pin connected to RESET line on devboard.""" reset_pin = 6 @@ -1355,7 +1360,15 @@ class ADS8201(object): self._INT_SCR[7] = pd self.setRegister(self.INT_SCR, self._INT_SCR) - # TODO: set/get interrupt sources + INT_FIFO_NOT_EMPTY = (1 << 3) + INT_FIFO_FULL = (1 << 2) + INT_SCAN_DATA_READY = (1 << 1) + INT_ADC_DATA_READY = (1 << 0) + def interruptMode(self, mode): + if mode not in range(16): + raise Exception, 'Invalid interrupt mode: %i' % mode + self._INT_SCR[4:0] = mode + self.setRegister(self.INT_SCR, self._INT_SCR) # # TRIGGER_SCR