Пример #1
0
        def __init__(self):
            logger.debug('Initializing __VecHandles')
            self.vec = MPSSE()
            logger.debug('opening vec')
            self.vec.Open(0x0403, 0x6011, I2C, ONE_HUNDRED_KHZ, MSB, IFACE_A)

            # Port B I2C for debug leds (don't need the io expander for the DPS sensors)
            self.gpio = MPSSE()
            logger.debug('opening gpio')
            self.gpio.Open(0x0403, 0x6011, I2C, ONE_HUNDRED_KHZ, MSB, IFACE_B)

            # Set RESET line on PCA9546A to high to activate switch
            logger.debug('GPIOL0 high')
            self.vec.PinHigh(GPIOL0)

            # Make sure reset line is held high on MCP23017 in order to use it
            logger.debug('GPIOL2 high')
            self.vec.PinHigh(GPIOL2)

            time.sleep(0.005)
            # Since the control line has a pull up resistor we want to only set it low to
            # active and use the pull up to make it inactive. To do this we need to use
            # the IO direction register in the actual setting of low and high (pull line
            # low or leave in high impedance which uses the pull up resistor)

            # In order to use the IO direction register we must set associated latch
            # register to 1 so when the IO direction is set to an output it will cause the
            # IO pin connected to the control line to go high

            # Set Port A and B latches on CE (card edge).
            self.gpio.Start()
            logger.debug('writing: {}'.format(
                hexlify(WRITE_23017 + OLATA_23017 + LATCHA_CE)))
            self.gpio.Write(WRITE_23017 + OLATA_23017 + LATCHA_CE)
            self.gpio.Stop()

            # Set Port B latches.
            self.gpio.Start()
            logger.debug('writing: {}'.format(
                hexlify(WRITE_23017 + OLATB_23017 + LATCHB_CE)))
            self.gpio.Write(WRITE_23017 + OLATB_23017 + LATCHB_CE)
            self.gpio.Stop()

            # Set Port A latches on expansion.
            # Need to set the PCA9546A to channel 3 first.
            self.vec.Start()
            logger.debug('writing: {}'.format(hexlify(CHANNEL3)))
            self.vec.Write(CHANNEL3)
            self.vec.Stop()

            self.vec.Start()
            logger.debug('writing: {}'.format(
                hexlify(WRITE_23017 + OLATA_23017 + LATCH_OCTO)))
            self.vec.Write(WRITE_23017 + OLATA_23017 + LATCH_OCTO)
            self.vec.Stop()

            logger.debug('vec and gpio initialized')
Пример #2
0
def _open_i2c_lock(interface):
    """
    Open and initialize the port in the FT4232H for i2c lock operations.
    :param interface: The port index of the FT4232H. IFACE_A or IFACE_B.
    :return: Handle to i2c interface for the port.
    """
    vec = MPSSE()
    vec.Open(
        0x0403,  # VID
        0x6011,  # PID
        I2C,     # mode
        ONE_HUNDRED_KHZ,  # Clock frequency
        MSB,  # endianess. I2C is always MSB.
        interface)  # interface
    return vec
Пример #3
0
def get_default_mpsse(speed_mhz):
	"""Open the first MPSSE device found and return it.  Throws an exception if 
	no MPSSE device is found."""
	from mpsse import MPSSE
	mpsse = MPSSE(SPI0, speed_mhz, MSB)
	if mpsse is None:
		RuntimeError('Could not find a connected MPSSE device!')
	return mpsse
Пример #4
0
def _open_vec_i2c():
    """Open the i2c port on the VEC USB for i2c operations."""
    # Port A I2C for PCA9546A
    vec = MPSSE()
    vec.Open(0x0403, 0x6011, I2C, ONE_HUNDRED_KHZ, MSB, IFACE_A)

    # Port B I2C for debug leds (don't need the io expander for the DPS sensors)
    gpio = MPSSE()
    gpio.Open(0x0403, 0x6011, I2C, ONE_HUNDRED_KHZ, MSB, IFACE_B)

    # Set RESET line on PCA9546A to high to activate switch
    vec.PinHigh(GPIOL0)
    time.sleep(0.001)

    # Read channel of PCA9546A
    vec.Start()
    vec.Write(PCA9546_READ_ADDRESS)

    return vec, gpio
Пример #5
0
def configure_differential_pressure(channel):
    """ Configure the differential pressure sensor for 9 bit resolution.

    Default is 12. This needs to be done once per power up. For our case we call this
    on synse container startup.

    Args:
        channel: The channel to configure.
    """
    logger.debug(
        'Configuring Differential Pressure sensor on channel {}'.format(
            channel))

    # Port A I2C for PCA9546A
    vec = MPSSE()
    vec.Open(0x0403, 0x6011, I2C, ONE_HUNDRED_KHZ, MSB, IFACE_A)

    # Set RESET line on PCA9546A to high to activate switch
    vec.PinHigh(GPIOL0)
    time.sleep(0.001)

    channel_str = PCA9546_WRITE_ADDRESS + chr(channel)
    logger.debug('PCA9546_WRITE_ADDRESS is: {}'.format(
        hexlify(PCA9546_WRITE_ADDRESS)))
    logger.debug('channel_str is: {}'.format(hexlify(channel_str)))

    vec.Start()
    vec.Write(channel_str)
    vec.Stop()

    logger.debug('PCA9546_READ_ADDRESS is: {}'.format(
        hexlify(PCA9546_READ_ADDRESS)))

    # verify channel was set
    vec.Start()
    vec.Write(PCA9546_READ_ADDRESS)
    vec.SendNacks()
    reg = vec.Read(1)
    vec.Stop()
    vec.SendAcks()

    logger.debug('PCA9546A Control Register: 0x{:02x}'.format(ord(reg)))

    # Configure Sensor
    # In the application note for changing measurement resolution three things must be met.
    # 1. Read the advanced user register.
    # 2. Define the new register entry according to the desired resolution.
    # 3. Write the new value to the advanced register.
    vec.Start()
    vec.Write('\x80\xE5')
    vec.Start()
    vec.Write('\x81')

    # At this point the sensor needs to hold the master but the FT4232 doesn't do clock stretching.
    time.sleep(0.001)  # This stays at 1 ms regardless of sensor resolution.

    # Read the three bytes out of the DPS sensor (two data bytes and crc)
    sensor_data = vec.Read(3)
    logger.debug('Raw sensor_data: {}'.format(hexlify(sensor_data)))
    vec.Stop()

    # write new value for 9 bit resolution (0b000 for bits 9 - 11)
    if _crc8(sensor_data):

        # Hardcoded 9 bit sensor resolution.
        sensor_int = 0x7182

        msb = sensor_int >> 8
        lsb = sensor_int & 0xFF
        register_str = '\x80\xE4' + chr(msb) + chr(lsb)

        vec.Start()
        vec.Write(register_str)
        vec.Stop()
        logger.debug(
            'Configured DP Sensor on channel {} for 9 bit resolution.'.format(
                channel))
        rc = 0
    else:
        logger.error('CRC failed configuring DP Sensor.')
        rc = 1

    vec.Stop()
    vec.Close()
    return rc
Пример #6
0
def _open_led_i2c():
    """Open the i2c port on the VEC USB for led controller operations."""
    # Construct string to set channel number to 3
    channel_str = PCA9546_WRITE_ADDRESS + '\x08'

    # Port A I2C for PCA9546A
    vec = MPSSE()
    vec.Open(0x0403, 0x6011, I2C, ONE_HUNDRED_KHZ, MSB, IFACE_A)

    # Port B I2C for debug leds (don't need the io expander for the LED Port)
    gpio = MPSSE()
    gpio.Open(0x0403, 0x6011, I2C, ONE_HUNDRED_KHZ, MSB, IFACE_B)

    # Set RESET line on PCA9546A to high to activate switch
    vec.PinHigh(GPIOL0)

    # Set channel on PCA9546A to 3 for PCA9632 (LED Port) Keep in mind this
    # also is connected to the MAX11608
    vec.Start()
    vec.Write(channel_str)
    vec.Stop()

    # verify channel was set.
    vec.Start()
    vec.Write(PCA9546_READ_ADDRESS)
    vec.SendNacks()
    reg = vec.Read(1)
    vec.Stop()
    reg = ord(reg)
    if reg != 0x08:
        raise ValueError('Failed to set PCA9546A Control Register to 0x08. Is 0x{:02x}'.format(reg))

    vec.SendAcks()
    vec.Start()

    # Configure PCA9632 for our setup (IE totem pole with inverted driver output, etc)
    # Writes to Mode 1 and Mode 2 Registers
    vec.Start()
    vec.Write('\xC4\x80\x00\x35')
    vec.Stop()

    return vec, gpio