ADS8201 interrupt setup
authorDan White <dan@whiteaudio.com>
Tue, 17 Jul 2012 17:27:52 +0000 (12:27 -0500)
committerDan White <dan@whiteaudio.com>
Tue, 17 Jul 2012 17:27:52 +0000 (12:27 -0500)
python-lib/usbio.py

index 0308b55e481f91d9b6605133eb7a1ad84e198c10..8e8fdbc7a244d925c5da54a8ccec775f16bbeb80 100644 (file)
@@ -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