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 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. 3
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. 4
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. 5
0
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:
    with open(args.load[0], "rb") as fh:
        data = fh.read(1)
        while data:
            data_value = int.from_bytes(data, byteorder='big', signed=False)
            write_byte(gpio, data_value)
            data = fh.read(1)

disable(gpio)

gpio.close()