# setup the driver for this interface, init usb
self.ftdi = ftdi #local reference to speed lookups
self.context = self.ftdi.new()
+ self.ftdi.init(self.context)
self.ftdi.set_interface(self.context, interface)
# TODO: what should chunksize be? 4k is libftdi default,
self.ftdi.set_bitmode(self.context, int(pindir), self.ftdi.BITMODE_RESET)
self.ftdi.set_bitmode(self.context, int(pindir), self.ftdi.BITMODE_MPSSE)
self.set_freq(freq)
- self._pindir = 0
- self._pinstate = 0
- self.set_pins(pinstate, pindir)
+ self._pindir = pindir
+ self._pinstate = pinstate
+ self.set_pins(pinstate, pindir, audit_cs=False)
#cs doesn't (shouldn't) change, cache the values for SPEED
self._cs_cmd_cache = {}
states (idle mode). If audit_cs==False, allows setting the output
state of the configured chip-select pins.
"""
+ print pinstate, pindir
if pindir is not None:
self._pindir = pindir
#we are changing pin directions, audit them
if audit_cs:
mask = self.cs['_mask'][1]
idle = self.cs['_idle'][1]
- self._pinstate = ((pinstate & mask) +
- (idle & mask))
+ self._pinstate = ((pinstate & mask) | (idle & mask))
else:
self._pinstate = pinstate
- #print 'set pins: %02x, %02x' % (self._pinstate, self._pindir)
+ print 'set pins: %02x, %02x' % (self._pinstate, self._pindir)
cmd = chr(self.ftdi.SET_BITS_LOW) + chr(self._pinstate) + chr(self._pindir)
self._raw_write(cmd)
mode, pins = self.cs[device]
# set SK before asserting CS to not violate timing
- if False:
+ if True:
# first, ensure SK starts in the correct state
p = self._pinstate
#if mode == 0:
#print 'pins: %02x' % p
p &= ~mask
- p += pins & mask
+ p |= pins & mask
self._pinstate = p
cmd += chr(self.ftdi.SET_BITS_LOW) + chr(p) + chr(self._pindir)
#print 'set pins: %02x, %02x' % (self._pinstate, self._pindir)
return tuple(data)
def write(self):
- self.bus.SetCS(self.csname)
- self.bus.Start()
+ #self.bus.SetCS(self.csname)
+ #self.bus.Start()
s = str(self)
- out = self.bus.Exchange(s)
- self.bus.Stop()
+ out = self.bus.exchange(self.csname, s)
+ #self.bus.Stop()
return out
return tuple(b)
def write(self):
- self.bus.SetCS(self.csname)
+ #self.bus.SetCS(self.csname)
s = str(self)
- self.bus.Start()
- sleep(0.01)
- out = self.bus.Exchange(s)
- sleep(0.01)
- self.bus.Stop()
+ #self.bus.Start()
+ #sleep(0.01)
+ out = self.bus.exchange(self.csname, s)
+ #sleep(0.01)
+ #self.bus.Stop()
return out
)
-class AtoiSPI1(mpsse.MPSSE):
- def __init__(self, freq):
- super(AtoiSPI1, self).__init__()
- self.Open(0x0403, 0x6011, mpsse.SPI0, int(freq),
- interface=mpsse.IFACE_B)
- self.SetCS('chain0_conf')
-
- def SetCS(self, name):
- """Setup the chip-select pins for a given 'name'."""
- if name == 'chain0_conf':
- self.context.pidle = self.context.pstop = 0xf8
- self.context.pstart = 0xf0
- elif name == 'chain0_mux':
- self.context.pidle = self.context.pstop = 0xf8
- self.context.pstart = 0xe8
- elif name == 'chain1_conf':
- self.context.pidle = self.context.pstop = 0xf8
- self.context.pstart = 0xd8
- elif name == 'chain1_mux':
- self.context.pidle = self.context.pstop = 0xf8
- self.context.pstart = 0xb8
- else:
- raise Exception, 'Unknown CS name: %s' % name
+if 0:
+ class AtoiSPI1(mpsse.MPSSE):
+ def __init__(self, freq):
+ super(AtoiSPI1, self).__init__()
+ self.Open(0x0403, 0x6011, mpsse.SPI0, int(freq),
+ interface=mpsse.IFACE_B)
+ self.SetCS('chain0_conf')
+
+ def SetCS(self, name):
+ """Setup the chip-select pins for a given 'name'."""
+ if name == 'chain0_conf':
+ self.context.pidle = self.context.pstop = 0xf8
+ self.context.pstart = 0xf0
+ elif name == 'chain0_mux':
+ self.context.pidle = self.context.pstop = 0xf8
+ self.context.pstart = 0xe8
+ elif name == 'chain1_conf':
+ self.context.pidle = self.context.pstop = 0xf8
+ self.context.pstart = 0xd8
+ elif name == 'chain1_mux':
+ self.context.pidle = self.context.pstop = 0xf8
+ self.context.pstart = 0xb8
+ else:
+ raise Exception, 'Unknown CS name: %s' % name
+class AtoiSPI1(SPI):
+ def __init__(self, freq):
+ super(AtoiSPI1, self).__init__(
+ interface=ftdi.INTERFACE_B,
+ cs={'_idle': (-1, 0xf8),
+ '_mask': (-1, 0xf8), #TODO
+ 'chain0_conf': (0, 0xf0),
+ 'chain0_mux': (0, 0xe8),
+ 'chain1_conf': (0, 0xd8),
+ 'chain1_mux': (0, 0xb8)},
+ freq=int(freq),
+ vid=0x0403,
+ pid=0x6011,
+ pindir=0xf8,
+ pinstate=0xf8,
+ latency=1
+ )
#