Пример #1
0
    def reset(self, enter_bsl=False):
        del self.s

        # Create a bitbang device to do the secret handshake
        ctl = pylibftdi.BitBangDevice()

        if enter_bsl:
            # RTS (0x04) is TEST, CTS (0x08) is RST
            ctl.direction = 0x0C  # Drive pins
            ctl.port = 0x00  # Drive all low
            ctl.port = 0x04  # Set TEST
            ctl.port = 0x00  # Clear
            ctl.port = 0x04  # Set TEST
            ctl.port = 0x0C  # "Release" RST
            ctl.port = 0x08  # "Release" TEST
            ctl.direction = 0x00  # Release pins
        else:
            ctl.direction = 0x0C  # Drive pins
            ctl.port = 0x00  # Drive all low
            ctl.port = 0x04  # "Release" RST
            ctl.port = 0x0C  # "Release" TEST
            ctl.direction = 0x00  # Release pins

        del ctl

        # Create a simple serial port device for the BSL.
        # N.B the even parity bit!
        self.s = pylibftdi.Device()
        if enter_bsl:
            # 8 bits, even parity, 1 stop bit
            self.s.ftdi_fn.ftdi_set_line_property(8, 0, 2)
        else:
            self.s.ftdi_fn.ftdi_set_line_property(8, 0, 0)
        self.s.baudrate = 9600
        self.s.flush()
Пример #2
0
    def set_bitbang_mode(self, bus, output_enable=0xFF):
        """Sets a specified bus to bit-bang mode.

    This operation should only be performed once per bus as a bus is typically
    hardwired to either serial or bit-bang circuitry.

    Args:
      bus: ID of the bus to index. This can either be a cardinal bus index
        or a name like 'ADBUS'.
      output_enable: 8-bit value representing the output_enable of the bus
        port with the LSB corresponding to bit 0 and the MSB corresponding
        to bit 7 of the bus. A high value signifies an enabled output.
    Raises:
      ValueError: When output_enable value is out of range.
      FtdiException: When deivce is already in bit-bang mode.
    """
        if output_enable not in range(256):
            raise ValueError(
                'Illegal output_enable value: {}'.format(output_enable))
        bus = self._get_bus_index(bus)
        if self._bb_devices[bus]:
            raise FtdiException(
                'Bus {} already set to bit-bang mode.'.format(bus))
        self._bb_devices[bus] = pylibftdi.BitBangDevice(self.serial_number,
                                                        interface_select=bus)
Пример #3
0
    def __init__(self, device_id=None):
        # Get all the devices and pull the first one in the list
        allDevices = self._get_ftdi_device_list()
        self._device_id = (allDevices or [None])[0]

        # Check if the one we were give is in the list
        if device_id is not None:
            if device_id not in allDevices:
                raise FtdiGpioException(
                    'The specified FTDI device is not attached')
            else:
                self._device_id = device_id

        # If we still have None here either we couldn't find our devices, or there are no devices
        if self._device_id is None:
            raise FtdiGpioException(
                'Failed to find any FTDI GPIO device attached')

        try:
            # Now try and open the device
            self._bb = ftdi.BitBangDevice(device_id=self._device_id,
                                          direction=self.Pins.PIN_ALL_IN)
        except pylibftdi._base.FtdiError:
            raise FtdiGpioException('Failed to open device in BitBang mode')

        self._bb.port = self.Pins.PIN_ALL
Пример #4
0
    def bitbang_device_init(self):
        """Creates BitBangDevices for each button and initializes to 'off'."""
        for button in list(self._button_map.keys()):
            interface = self._button_map[button]["interface"]
            pin = self._button_map[button]["pin"]

            if interface not in self._bb_map:
                ftdi_device = pylibftdi.BitBangDevice(
                    device_id=self._ftdi_serial_number,
                    interface_select=interface,
                    direction=(1 << pin))
                ftdi_device.port = 0 if self._polarity else 255
                self._bb_map[interface] = ftdi_device
            else:
                self._bb_map[interface].direction |= (1 << pin)
            self._button_down[button] = False

        self._bitbang_device_init = True
Пример #5
0
 def __init__(self, serial):
     self.device = pylibftdi.BitBangDevice(serial)
     self.device.direction = 0xFF