]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/rp2040/i2c.py
Added pre-commit support
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / rp2040 / i2c.py
index 16ff2e35b5c42d1a9c87085742470864f1566a0f..8daf2490a9c53c934bfa6d2d37cc1f2fc90efd3b 100644 (file)
@@ -1,3 +1,6 @@
+# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
 """I2C Class for RP2040"""
 from machine import I2C as _I2C
 from machine import Pin
@@ -28,14 +31,13 @@ class I2C:
         """Perform an I2C Device Scan"""
         return self._i2c.scan()
 
-    # pylint: disable=unused-argument
     def writeto(self, address, buffer, *, stop=True):
         "Write data to the address from the buffer"
-        return self._i2c.writeto(address, buffer)
+        return self._i2c.writeto(address, buffer, stop)
 
     def readfrom_into(self, address, buffer, *, stop=True):
         """Read data from an address and into the buffer"""
-        return self._i2c.readfrom_into(address, buffer)
+        return self._i2c.readfrom_into(address, buffer, stop)
 
     def writeto_then_readfrom(
         self,
@@ -47,19 +49,17 @@ class I2C:
         out_end=None,
         in_start=0,
         in_end=None,
-        stop=False
+        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,
-        )
+        if out_end:
+            self.writeto(address, buffer_out[out_start:out_end], stop=stop)
+        else:
+            self.writeto(address, buffer_out[out_start:], stop=stop)
 
-    # pylint: enable=unused-argument
+        if not in_end:
+            in_end = len(buffer_in)
+        read_buffer = memoryview(buffer_in)[in_start:in_end]
+        self.readfrom_into(address, read_buffer, stop=stop)