How to use the pyftdi.misc.to_bool function in pyftdi

To help you get started, we’ve selected a few pyftdi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eblot / pyftdi / pyftdi / ftdi.py View on Github external
where high level defines an output, and low level defines an
                input
           :param initial: a bitfield specifying the initial output value
           :param frequency: serial interface clock in Hz
           :param latency: low-level latency in milliseconds. The shorter
                the delay, the higher the host CPU load. Do not use shorter
                values than the default, as it triggers data loss in FTDI.
           :param bool tracer: use a tracer to decode MPSSE protocol
           :param bool debug: add more debug traces
           :return: actual bus frequency in Hz
        """
        self.open_from_device(device, interface)
        if not self.is_mpsse_interface(interface):
            self.close()
            raise FtdiMpsseError('This interface does not support MPSSE')
        if to_bool(tracer):  # accept strings as boolean
            from .tracer import FtdiMpsseTracer
            self._tracer = FtdiMpsseTracer(self.device_version)
            self.log.debug('Using MPSSE tracer')
        # Set latency timer
        self.set_latency_timer(latency)
        # Set chunk size
        self.write_data_set_chunksize()
        self.read_data_set_chunksize()
        # Reset feature mode
        self.set_bitmode(0, Ftdi.BitMode.RESET)
        # Drain buffers
        self.purge_buffers()
        # Disable event and error characters
        self.set_event_char(0, False)
        self.set_error_char(0, False)
        # Enable MPSSE mode
github eblot / pyftdi / pyftdi / eeprom.py View on Github external
val = to_int(value)
            if not 0 <= val <= 0xFFFF:
                raise ValueError('Invalid value for %s' % name)
            offset = hwords[name]
            self._eeprom[offset:offset+2] = spack('> 1
            self._eeprom[0x09] = val
            return
        if name in self.properties:
            raise NotImplementedError("Change to '%s' is not yet supported" %
                                      name)
        raise ValueError("Unknown property '%s'" % name)
github eblot / pyftdi / pyftdi / eeprom.py View on Github external
try:
            if control == 'drive':
                candidates = (4, 8, 12, 16)
                if value == '?' and out:
                    print(', '.join([str(v) for v in candidates]), file=out)
                    return
                value = int(value)
                if value not in candidates:
                    raise ValueError('Invalid drive current: %d mA' % value)
                value //= 4
                value -= 1
            elif control in ('slow_slew', 'schmitt'):
                if value == '?' and out:
                    print('off, on', file=out)
                    return
                value = int(to_bool(value))
            else:
                raise ValueError('Unsupported control: %s' % control)
        except (ValueError, TypeError):
            raise ValueError('Invalid %s value: %s' % (control, value))
        config = self._eeprom[0x0c]
        if bus == 'd':
            conf = config & 0x0F
            config &= 0xF0
            cshift = 0
        else:
            conf = config >> 4
            config &= 0x0F
            cshift = 4
        if control == 'drive':
            conf &= 0b1100
            conf |= value