X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/4782c180b240d80a772f63ca81e0876f39a69c26..7c00779e475ef10923dc53fddb20ad23eae484af:/src/adafruit_blinka/microcontroller/generic_micropython/i2c.py?ds=sidebyside diff --git a/src/adafruit_blinka/microcontroller/generic_micropython/i2c.py b/src/adafruit_blinka/microcontroller/generic_micropython/i2c.py new file mode 100755 index 0000000..3ace77a --- /dev/null +++ b/src/adafruit_blinka/microcontroller/generic_micropython/i2c.py @@ -0,0 +1,51 @@ +"""I2C Class for Generic MicroPython""" +from machine import I2C as _I2C + + +class I2C: + """I2C Class for Generic MicroPython""" + + MASTER = 0 + + # pylint: disable=unused-argument + def __init__(self, portId, *, mode=MASTER, baudrate=100000): + self._i2c = _I2C(portId, freq=baudrate) + + def scan(self): + """Perform an I2C Device Scan""" + return self._i2c.scan() + + def writeto(self, address, buffer, *, stop=True): + """Write the data from the buffer to the address""" + return self._i2c.writeto(address, buffer) + + def readfrom_into(self, address, buffer, *, stop=True): + """Read data from an address and into the buffer""" + return self._i2c.readfrom_into(address, buffer) + + def writeto_then_readfrom( + self, + address, + buffer_out, + buffer_in, + *, + out_start=0, + out_end=None, + in_start=0, + in_end=None, + stop=False + ): + """Write data from buffer_out to an address and then + read data from an address and into buffer_in + """ + self._i2c.writeto_then_readfrom( + address, + buffer_out, + buffer_in, + out_start=out_start, + out_end=out_end, + in_start=in_start, + in_end=in_end, + ) + + # pylint: enable=unused-argument