Esempio n. 1
0
 def test_gpio_values(self):
     """Simple test to demonstrate bit-banging.
     """
     if self.skip_loopback:
         raise SkipTest('Skip loopback test on multiport device')
     direction = 0xFF & ~((1 << 4) - 1)  # 4 Out, 4 In
     gpio = GpioSyncController()
     gpio.configure(self.url, direction=direction, initial=0xee)
     outs = bytes([(out & 0xf) << 4 for out in range(1000)])
     ins = gpio.exchange(outs)
     exp_in_count = min(len(outs), gpio.ftdi.fifo_sizes[0])
     self.assertEqual(len(ins), exp_in_count)
     last = None
     for sout, sin in zip(outs, ins):
         if last is not None:
             # output nibble
             sin_out = sin >> 4
             # input nibble
             sin_in = sin & 0xF
             # check inputs match last output
             self.assertEqual(sin_out, last)
             # check level of output match the last written
             self.assertEqual(sin_in, last)
         # an IN sample if captured on the next clock of the OUT sample
         # keep the MSB nibble, i.e. the nibble configured as output
         last = sout >> 4
     gpio.close()
Esempio n. 2
0
 def test_gpio_baudate(self):
     # this test requires an external device (logic analyser or scope) to
     # check the bitbang read and bitbang write signal (BB_RD, BB_WR) and
     # mesure their frequency. The EEPROM should be configured to enable
     # those signal on some of the CBUS pins, for example.
     gpio = GpioSyncController()
     direction = 0xFF & ~((1 << 4) - 1)  # 4 Out, 4 In
     gpio.configure(self.url, direction=direction)
     buf = bytes([0xf0, 0x00] * 64)
     freqs = [50e3, 200e3, 1e6, 3e6]
     if gpio.ftdi.is_H_series:
         freqs.extend([6e6, 10e6, 12e6])
     for freq in freqs:
         # set the bitbang refresh rate
         gpio.set_frequency(freq)
         self.assertEqual(gpio.frequency, freq)
         # be sure to leave enough time to purge buffers (HW FIFO) or
         # the frequency changes occur on the current buffer...
         gpio.exchange(buf)
         sleep(0.01)
     gpio.close()
Esempio n. 3
0
	def transmitSync(self):
		gpio = GpioSyncController()
		gpio.configure(self.device, direction=self.direction, frequency=self.frequency)
		# txBytes = bytearray()
		# for byte in self.txList:
		# 	txBytes.append(byte)
		# print(txBytes)
		rxBytes = gpio.exchange( self.txList );
		# print(rxBytes)
		gpio.close()
		self.rxList = []
		for byte in rxBytes:
			self.rxList.append(byte)
Esempio n. 4
0
PORT_DIRECTION = TCK_MASK | TDO_MASK | TMS_MASK

HOST, PORT = "localhost", 5555
FTDI_PATH = "ftdi:///1"

# Protocol definitions
CMD_HEADER_LEN = 2
CMD_PARAM_LEN = 2
CMD_RESET = 1
CMD_SCAN = 2
CMD_TMS_SEQ = 3
VER_1 = 1

CMD_NAME = {CMD_SCAN: "scan", CMD_RESET: "reset", CMD_TMS_SEQ: "tms_seq"}

gpio = GpioSyncController()


# Utility functions to convert between bits packed into a bytestring, and a list of 0/1 ints.
# This is similar to the bitstring package, except that bits within byte are counted from the LSB.
def list_to_bits(list_of_ints):
    n_bits = len(list_of_ints)
    n_bytes = (n_bits + 7) // 8
    pos = 0
    res = b''
    for i_byte in range(n_bytes):
        byte_val = 0
        for i_bit in range(8):
            if pos == n_bits:
                break
            if list_of_ints[pos]:
import time
import sys
from pyftdi.spi import SpiController
from pyftdi.gpio import GpioSyncController
import FTDISPI
import JSONFile

SCLK = 0x01
MOSI = 0x02
MISO = 0x20
CS = 0x04

lmkAdc = GpioSyncController()
# lmkAdc = SpiController()
lmkAdc.configure('ftdi:///3', direction=(SCLK | MOSI | CS), frequency=1e3)
# lmkAdc.configure('ftdi:///2')

lmk = FTDISPI.Interface( \
    FTDISPI.GPIO(
        lmkAdc, \
        SCLK = SCLK, \
        MOSI = MOSI, \
        MISO = MISO, \
        CS = CS, \
    ), \
    defaultMap  = "LMK04828.json", \
    currentState = "LMK_current_state.json", \
    previousState = "LMK_previous_state.json",
                        )

FTDISPI.uiLoop(lmk)
Esempio n. 6
0
	def transmitSync(self, frequency):
		gpio = GpioSyncController()
		gpio.configure(self.device, self.directionArray[0], frequency=frequency)
		self.rxArray = gpio.exchange( self.txArray );
		gpio.close()
Esempio n. 7
0

def disable(gpio):
    gpio.exchange(0b0100_0000)


parser = argparse.ArgumentParser(description='TEC-1 controller.')
parser.add_argument("serial", type=str, nargs=1)
parser.add_argument("-t", "--type", type=str, required=False, default="232")
parser.add_argument("-i", "--instance", type=str, required=False, default="1")
parser.add_argument("-l", "--load", type=str, nargs=1, required=False)
args = parser.parse_args()

url = "ftdi://ftdi:{}:{}/{}".format(args.type, args.serial[0], args.instance)

gpio = GpioSyncController()
gpio.configure(url, direction=0b1111_1111)
gpio.set_frequency(200)


def signal_handler(sig, frame):
    print('You pressed Ctrl+C!')
    disable(gpio)
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)

enable(gpio)

if "load" in args:
import time
import sys
from pyftdi.gpio import GpioSyncController
import FTDISPI
import JSONFile

SCLK = 0x10
MOSI = 0x20
MISO = 0x40
CS = 0x80

gpio = GpioSyncController()
gpio.configure('ftdi:///2', direction=(SCLK | MOSI | CS), frequency=1e4)

lmk = FTDISPI.Interface( \
    FTDISPI.GPIO(
        gpio, \
        SCLK = SCLK, \
        MOSI = MOSI, \
        MISO = MISO, \
        CS = CS, \
    ), \
    defaultMap  = "LMK04828.json", \
    currentState = "LMK_current_state.json", \
    previousState = "LMK_previous_state.json",
                        )

# lmk.readState()


def ui_hex(str):