Example #1
0
 def test(self):
     """Check simple GPIO write and read sequence."""
     gpio = GpioController()
     # access to the virtual GPIO port
     out_pins = 0xAA
     gpio.configure('ftdi://:232h/1', direction=out_pins)
     bus, address, iface = gpio.ftdi.usb_path
     self.assertEqual((bus, address, iface), (4, 5, 0))
     vftdi = self.loader.get_virtual_ftdi(bus, address)
     gpio.write_port(0xF3)
     self.assertEqual(vftdi.gpio, 0xAA & 0xF3)
     vftdi.gpio = 0x0c
     vio = gpio.read_port()
     self.assertEqual(vio, (0xAA & 0xF3) | (~0xAA & 0x0c))
     gpio.close()
Example #2
0
 def _test_gpio(self):
     """Check simple GPIO write and read sequence."""
     with open('pyftdi/tests/resources/ft232h.yaml', 'rb') as yfp:
         self.loader.load(yfp)
     gpio = GpioController()
     # access to the virtual GPIO port
     out_pins = 0xAA
     gpio.configure('ftdi://:232h/1', direction=out_pins)
     bus, address, iface = gpio.ftdi.usb_path
     self.assertEqual((bus, address, iface), (4, 5, 0))
     vftdi = self.loader.get_virtual_ftdi(bus, address)
     vport = vftdi.get_port(1)
     gpio.write_port(0xF3)
     self.assertEqual(vport.gpio, 0xAA & 0xF3)
     vport.gpio = 0x0c
     vio = gpio.read_port()
     self.assertEqual(vio, (0xAA & 0xF3) | (~0xAA & 0x0c))
     gpio.close()
Example #3
0
 def test_baudrate(self):
     """Check simple GPIO write and read sequence."""
     # load custom CBUS config, with:
     # CBUS0: GPIO (gpio)
     # CBUS1: GPIO (gpio)
     # CBUS0: DRIVE1 (forced to high level)
     # CBUS0: TXLED  (eq. to highz for tests)
     with open('pyftdi/tests/resources/ft230x_io.yaml', 'rb') as yfp:
         self.loader.load(yfp)
     gpio = GpioController()
     # access to the virtual GPIO port
     out_pins = 0xAA
     gpio.configure('ftdi://:230x/1', direction=out_pins)
     vftdi = self.loader.get_virtual_ftdi(1, 1)
     vftdi.get_port(1)
     baudrate = 1000000
     gpio.set_frequency(baudrate)
     gpio.close()
Example #4
0
    def __init__(self, req, res, clk=0x01, mosi=0x02, miso=0x04, cs=0x08):
        ''' Ensure a logger is setup, and access to the GPIO is possible. '''
        super(Executor, self).__init__()
        self.log = logging.getLogger(__name__)

        # The initial state is everything pulled HIGH.
        self.state = 0xFF

        # Ensure the work queue is accessible - this is used for the parent
        # to push request to bang onto the wire.
        self._in = req
        self._out = res

        # Defaults are:
        #     Pin D0 - 0x01 - OUT (CLOCK)
        #     Pin D1 - 0x02 - OUT (MOSI)
        #     Pin D2 - 0x04 - IN  (MISO)
        #     Pin D3 - 0x08 - OUT (CHIP SELECT)
        self.clk = clk
        self.miso = miso
        self.mosi = mosi
        self.cs = cs

        # Setup the clock interval. This isn't the cycle time, but half the
        # target cycle time.
        self.clock_interval = 0.0

        # Setup the interface, ensuring that MISO is set to GPIO IN.
        self.gpio = GpioController()
        direction = xor(0xFF, self.miso)
        self.log.debug("Setting up FT2232 for GPIO (%s)",
                       "{0:08b}".format(direction))
        self.gpio.open_from_url(
            url='ftdi://0x0403:0x6010/1',
            direction=direction,
        )

        # Set the initial GPIO state.
        self.gpio.write_port(self.state)
        self.log.debug("Set the initial GPIO state to %s", self.state)
Example #5
0
    def __init__(self, serial_number=None, debug=False):
        """
            Create a new instance of the Papilio One.

            serial_number -- The serial number of the board to connect to, or None to use
                             the first available bitbangable FTDI. Use caution with this one!
                             NOTE: This is IGNORED.
        """

        # Instead of using BitBangDevice(), use GpioController() from PyFTDI
        self._gpio = GpioController()

        # If FTDI_DEVICE environment variable, use it instead of self.FTDI_URL
        url = environ.get('FTDI_DEVICE', self.FTDI_URL)

        # Open the PyFTDI URL with outputs set as per set_up_jtag_port()
        self._gpio.open_from_url(url, direction=self.set_up_jtag_port())

        atexit.register(self.cleanup)

        #Initiatialize the core JTAG subsystem.
        super().__init__(self._gpio)
Example #6
0
 def __init__(self):
     self._gpio = GpioController()
     self._state = 0  # SW cache of the GPIO output lines
Example #7
0
 def __init__(s, url):
     # init gpio mode with gray (conncted to RESET) and green (TOOL0) as outputs
     s.gpio = GpioController()
     s.gpio.open_from_url(url, direction = WIRE_GRAY | WIRE_GREEN)
Example #8
0
#!/usr/bin/env python3

# deps can be satisfied on Linux with `sudo pip3 install pyftdi`

from pyftdi.gpio import GpioController, GpioException
from time import sleep
import sys
import serial
import bitstring

bitstring.bytealigned = True  # change the default behaviour

bitbang = GpioController()
bitbang.open_from_url('ftdi:///1')

ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=None)

DELAY = 0.0000005  #strict worst-case delay is 0.54ms -- we can relax that due to lots of delays in the many layers of software between us.
#on my machine this results in a minimum CLK pulse width of 0.58 ms on my machine
HARD_DELAY = 0.00054  # for cases where strict delay adherence is necessary (e.g. when begining shift-out)

state = 0


def pin_output(line):
    bitbang.set_direction(1 << line, 1 << line)
    return


def pin_input(line):
    bitbang.set_direction(1 << line, 0)
Example #9
0
 def __init__(self, address='ftdi://ftdi:232/1'):
     self.gpio = GpioController()
     self.state = None
     self.address = address
Example #10
0
        self.i2c_end()
        return v

    def i2c_read_from_reg(self, reg):
        """Reads a single byte from specified register.

		:param reg: Register to be read.
		:return: Byte that was read.
		"""
        v = self.i2c_write_address(0, self.address)
        v &= self.i2c_write_byte(reg)
        self.i2c_end()
        v &= self.i2c_write_address(1, self.address)
        byte = self.i2c_read_byte()
        if not v:
            print("Error")
        self.i2c_end()
        return byte


if __name__ == '__main__':
    mask = 0x13  # in, in,in  Out, In, In, out, out
    gpio = GpioController()
    gpio.open_from_url('ftdi://ftdi:4232h/1', mask)
    port = I2CPort(gpio)
    switch2 = I2CDevice(port, 0x71)
    switch2.i2c_write_byte_to(0x04)
    i = switch2.i2c_read_byte_from()
    print("%x" % i)
    gpio.close()