def __init__(self, bus, frequency=400000): """Initialization""" self.deinit() if detector.board.ftdi_ft232h: from adafruit_blinka.microcontroller.ft232h.i2c import I2C as _I2C self._i2c = _I2C(frequency=frequency) return if detector.board.binho_nova: from adafruit_blinka.microcontroller.nova.i2c import I2C as _I2C self._i2c = _I2C(frequency=frequency) return if detector.board.microchip_mcp2221: from adafruit_blinka.microcontroller.mcp2221.i2c import I2C as _I2C self._i2c = _I2C(frequency=frequency) return if detector.board.greatfet_one: from adafruit_blinka.microcontroller.nxp_lpc4330.i2c import I2C as _I2C self._i2c = _I2C(frequency=frequency) return if detector.board.any_embedded_linux: from adafruit_blinka.microcontroller.generic_linux.i2c import I2C as _I2C else: from machine import I2C as _I2C from microcontroller.pin import i2cPorts # try: self._i2c = _I2C(bus_num=bus, mode=_I2C.MASTER, baudrate=frequency) # except RuntimeError: # raise IOError(f'Could not configure an IC2 bus on bus {bus}.') if threading is not None: self._lock = threading.RLock()
def init(self, scl, sda, frequency): """Initialization""" self.deinit() if detector.board.ftdi_ft232h: from adafruit_blinka.microcontroller.ft232h.i2c import I2C as _I2C self._i2c = _I2C(frequency=frequency) return if detector.board.binho_nova: from adafruit_blinka.microcontroller.nova.i2c import I2C as _I2C self._i2c = _I2C(frequency=frequency) return if detector.board.microchip_mcp2221: from adafruit_blinka.microcontroller.mcp2221.i2c import I2C as _I2C self._i2c = _I2C(frequency=frequency) return if detector.board.greatfet_one: from adafruit_blinka.microcontroller.nxp_lpc4330.i2c import I2C as _I2C self._i2c = _I2C(frequency=frequency) return if detector.board.any_embedded_linux: from adafruit_blinka.microcontroller.generic_linux.i2c import I2C as _I2C else: from machine import I2C as _I2C from microcontroller.pin import i2cPorts for portId, portScl, portSda in i2cPorts: try: if scl == portScl and sda == portSda: self._i2c = _I2C(portId, mode=_I2C.MASTER, baudrate=frequency) break except RuntimeError: pass else: raise ValueError( "No Hardware I2C on (scl,sda)={}\nValid I2C ports: {}".format( (scl, sda), i2cPorts)) if threading is not None: self._lock = threading.RLock()
def init(self, scl, sda, frequency): """Initialization""" self.deinit() if detector.board.ftdi_ft232h: from adafruit_blinka.microcontroller.ft232h.i2c import I2C as _I2C self._i2c = _I2C(frequency=frequency) return if detector.board.binho_nova: from adafruit_blinka.microcontroller.nova.i2c import I2C as _I2C self._i2c = _I2C(frequency=frequency) return if detector.board.microchip_mcp2221: from adafruit_blinka.microcontroller.mcp2221.i2c import I2C as _I2C self._i2c = _I2C(frequency=frequency) return if detector.board.greatfet_one: from adafruit_blinka.microcontroller.nxp_lpc4330.i2c import I2C as _I2C self._i2c = _I2C(frequency=frequency) return if detector.board.pico_u2if: from adafruit_blinka.microcontroller.pico_u2if.i2c import I2C as _I2C self._i2c = _I2C(scl, sda, frequency=frequency) return if detector.chip.id == ap_chip.RP2040: from adafruit_blinka.microcontroller.rp2040.i2c import I2C as _I2C self._i2c = _I2C(scl, sda, frequency=frequency) return if detector.board.any_embedded_linux: from adafruit_blinka.microcontroller.generic_linux.i2c import I2C as _I2C else: from adafruit_blinka.microcontroller.generic_micropython.i2c import ( I2C as _I2C, ) from microcontroller.pin import i2cPorts for portId, portScl, portSda in i2cPorts: try: # pylint: disable=unexpected-keyword-arg if scl == portScl and sda == portSda: self._i2c = _I2C(portId, mode=_I2C.MASTER, baudrate=frequency) break # pylint: enable=unexpected-keyword-arg except RuntimeError: pass else: raise ValueError( "No Hardware I2C on (scl,sda)={}\nValid I2C ports: {}".format( (scl, sda), i2cPorts)) if threading is not None: self._lock = threading.RLock()