X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/2ac9e76bea9e29fcda185b73ff374d84b8439858..4ce7761a8b73ddc453ec6f64b35e73b33e43a3a2:/src/busio.py diff --git a/src/busio.py b/src/busio.py index 2de9e60..08761c4 100644 --- a/src/busio.py +++ b/src/busio.py @@ -9,7 +9,7 @@ See `CircuitPython:busio` in CircuitPython for more details. * Author(s): cefn """ - +import os try: import threading except ImportError: @@ -29,6 +29,8 @@ class I2C(Lockable): """ Busio I2C Class for CircuitPython Compatibility. Used for both MicroPython and Linux. + + NOTE: Frequency has no effect on Linux systems. The argument is only there for compatibility. """ def __init__(self, scl, sda, frequency=100000): @@ -52,6 +54,13 @@ class I2C(Lockable): self._i2c = _I2C(frequency=frequency) return + + if "BLINKA_FORCECHIP" in os.environ and os.environ["BLINKA_FORCEBOARD"] == "GENERIC_AGNOSTIC_BOARD": + from adafruit_blinka.microcontroller.generic_agnostic_board.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 @@ -136,6 +145,9 @@ class I2C(Lockable): if detector.board.any_embedded_linux: from adafruit_blinka.microcontroller.generic_linux.i2c import I2C as _I2C + + if frequency == 100000: + frequency = None # Set to None if default to avoid triggering warning elif detector.board.ftdi_ft2232h: from adafruit_blinka.microcontroller.ftdi_mpsse.mpsse.i2c import I2C as _I2C else: @@ -189,18 +201,17 @@ class I2C(Lockable): if end is None: end = len(buffer) buffer = memoryview(buffer)[start:end] - stop = True # remove for efficiency later - return self._i2c.readfrom_into(address, buffer, stop=stop) + return self._i2c.readfrom_into(address, buffer, stop=True) - def writeto(self, address, buffer, *, start=0, end=None, stop=True): + def writeto(self, address, buffer, *, start=0, end=None): """Write to a device at specified address from a buffer""" if isinstance(buffer, str): buffer = bytes([ord(x) for x in buffer]) if start != 0 or end is not None: if end is None: - return self._i2c.writeto(address, memoryview(buffer)[start:], stop=stop) - return self._i2c.writeto(address, memoryview(buffer)[start:end], stop=stop) - return self._i2c.writeto(address, buffer, stop=stop) + return self._i2c.writeto(address, memoryview(buffer)[start:], stop=True) + return self._i2c.writeto(address, memoryview(buffer)[start:end], stop=True) + return self._i2c.writeto(address, buffer, stop=True) def writeto_then_readfrom( self,