From: Dan White Date: Fri, 13 Apr 2012 21:29:06 +0000 (-0500) Subject: AtoI-specific classes and testing X-Git-Tag: calibrations~108 X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=89a4af13e0d29d714b9374dcbea4446307cb4ea3;p=430.git AtoI-specific classes and testing --- diff --git a/python-lib/mpsse-test.py b/python-lib/mpsse-test.py new file mode 100644 index 0000000..953c4ab --- /dev/null +++ b/python-lib/mpsse-test.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python + +import time +import struct + +from myhdl import bin as b + +import mpsse +import usbio + + + +class AtoiSPI0(mpsse.MPSSE): + def __init__(self, freq): + super(AtoiSPI0, self).__init__() + self.Open(0x0403, 0x6011, mpsse.SPI0, int(freq), + interface=mpsse.IFACE_A) + self.SetCS('flash') + + def SetCS(self, name): + """Setup the chip-select pins for a given 'name'.""" + if name == 'flash': + self.context.pidle = self.context.pstop = 0x08 + self.context.pstart = 0x00 + elif name == 'dac': + self.context.pidle = self.context.pstop = 0x08 + self.context.pstart = 0x10 + elif name == 'adc': + self.context.pidle = self.context.pstop = 0x08 + self.context.pstart = 0x20 + elif name == 'convst': + self.context.pidle = self.context.pstop = 0x08 + self.context.pstart = 0x30 + else: + raise Exception, 'Unknown CS name: %s' % name + + +class AtoiI2C(mpsse.MPSSE): + def __init__(self, freq): + super(AtoiI2C, self).__init__() + self.Open(0x0403, 0x6011, mpsse.I2C, int(freq), + interface=mpsse.IFACE_B) + + def _tostring(self, c): + r = c + if not isinstance(c, str): + if isinstance(c, (tuple, list)): + r = r''.join(map(chr, c)) + else: + raise TypeError, 'Cannot convert type %s to raw string.' % type(c) + return r + + def write(self, c): + outdata = self._tostring(c) + + n = 0 + i = len(outdata)-1 + s = [] + for d in outdata: + r = struct.unpack('>B', d)[0] + s.append(b(r, 8)) + n += r << (i*8) + i -= 1 + #print ' '.join(s) + + + self.Start() + self.Write(outdata) + self.Stop() + + def read(self, c, n): + outdata = self._tostring(c) + self.Start() + self.Write(outdata) + r = self.Read(n) + self.Stop() + return r + + +spi = AtoiSPI0(1e5) +spi.SetLoopback(0) + + +i2c = AtoiI2C(10e3) + + +ibias = usbio.AD524x(i2c, 0) +vatoi = usbio.AD524x(i2c, 2) +v430 = usbio.AD524x(i2c, 3) + +