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
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)
#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]
#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
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