Example #1
0
    def open(self, use_10bit_address=False):
        """ I2CDev.open(use_10bit_address=False) -> None
        
        Initialize the I2C bus interface.
        If use_10bit_address=True the bus will use 10-bit slave addresses
        instead of 7-bit addresses. 
    """
        if self._is_open: return
        if self.bus_num == 1 and not cape_manager.isLoaded("BB-I2C1"):
            # I2C2 is already enabled for reading cape EEPROMs,
            # so only need to load overlay for I2C1
            cape_manager.load("BB-I2C1", auto_unload=False)
            bbio.common.delay(10)
            # Make sure it initialized correctly:
            if not cape_manager.isLoaded("BB-I2C1"):
                raise IOError("could not enable I2C1")

        # Detect bus number:
        # (since I2C2 is always enabled at boot, it's kernel assigned
        # bus number will always be the same, and I2C1 will always be
        # the next consecutive bus number, so this isn't actually
        # required)
        for i in glob.glob("/sys/bus/i2c/devices/i2c-*"):
            path = os.path.realpath(i)
            module_addr = int(path.split("/")[4].split(".")[0], 16)
            if module_addr == I2C_BASE_ADDRESSES[self.bus_num]:
                self.bus_num = int(path.split("/")[5][-1])
                break

        super(I2CBus, self).open(use_10bit_address=use_10bit_address)
        self._is_open = True
Example #2
0
  def open(self, use_10bit_address=False):
    """ I2CDev.open(use_10bit_address=False) -> None
        
        Initialize the I2C bus interface.
        If use_10bit_address=True the bus will use 10-bit slave addresses
        instead of 7-bit addresses. 
    """
    if self._is_open: return
    if self.bus_num == 1 and not cape_manager.isLoaded("BB-I2C1"):
      # I2C2 is already enabled for reading cape EEPROMs, 
      # so only need to load overlay for I2C1
      cape_manager.load("BB-I2C1", auto_unload=False)
      bbio.common.delay(10)
      # Make sure it initialized correctly:
      if not cape_manager.isLoaded("BB-I2C1"):
        raise IOError("could not enable I2C1")

    # Detect bus number:
    # (since I2C2 is always enabled at boot, it's kernel assigned 
    # bus number will always be the same, and I2C1 will always be
    # the next consecutive bus number, so this isn't actually 
    # required)
    for i in glob.glob("/sys/bus/i2c/devices/i2c-*"):
      path = os.path.realpath(i)
      module_addr = int(path.split("/")[4].split(".")[0], 16)
      if module_addr == I2C_BASE_ADDRESSES[self.bus_num]:
        self.bus_num = int(path.split("/")[5][-1])
        break

    super(I2CBus, self).open(use_10bit_address=use_10bit_address)
    self._is_open = True
Example #3
0
 def open(self):
   overlay = 'BB-SPIDEV%i' % (self.bus-1)
   cape_manager.load(overlay, auto_unload=False)
   bbio.common.delay(250) # Give driver time to load
   assert cape_manager.isLoaded(overlay), "Could not load SPI overlay"
   super(SPIBus, self).open()
   # Initialize to default parameters:
   self.setCSActiveLow(0)
   self.setBitsPerWord(0, 8)
   self.setMaxFrequency(0, 8000000)
   self.setClockMode(0, 0)
Example #4
0
  def open(self):
    overlay = "BB-SPIDEV%i" % (self.bus)
    cape_manager.load(overlay, auto_unload=False)
    bbio.common.delay(250) # Give driver time to load
    assert cape_manager.isLoaded(overlay), "Could not load SPI overlay"

    for i in glob.glob("/sys/bus/spi/devices/*.0"):
      path = os.path.realpath(i)
      module_addr = int(path.split("/")[4].split(".")[0], 16)
      if module_addr == SPI_BASE_ADDRESSES[self.bus]:
        self.bus = int(path.split("/")[6][-1])
        break
    super(SPIBus, self).open()
    # Initialize to default parameters:
    self.setCSActiveLow(0)
    self.setBitsPerWord(0, 8)
    self.setMaxFrequency(0, 8000000)
    self.setClockMode(0, 0)
Example #5
0
    def open(self):
        overlay = "BB-SPIDEV%i" % (self.bus)
        cape_manager.load(overlay, auto_unload=False)
        bbio.common.delay(250)  # Give driver time to load
        assert cape_manager.isLoaded(overlay), "Could not load SPI overlay"

        for i in glob.glob("/sys/bus/spi/devices/*.0"):
            path = os.path.realpath(i)
            module_addr = int(path.split("/")[4].split(".")[0], 16)
            if module_addr == SPI_BASE_ADDRESSES[self.bus]:
                self.bus = int(path.split("/")[6][-1])
                break
        super(SPIBus, self).open()
        # Initialize to default parameters:
        self.setCSActiveLow(0)
        self.setBitsPerWord(0, 8)
        self.setMaxFrequency(0, 8000000)
        self.setClockMode(0, 0)