]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/mcp2221/i2c.py
added support for I2C bus 0,1,2 that where missing for the OPI zero2W implementation
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / mcp2221 / i2c.py
index ef7f7849cc9cfccfcb109bf75383d9fbd05a6e27..d8e40c225e8f3395bc39006756ea6ae6199dc880 100644 (file)
@@ -1,24 +1,53 @@
-from adafruit_blinka.microcontroller.mcp2221.pin import Pin
+# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
+"""I2C Class for MCP2221"""
 from .mcp2221 import mcp2221
 
+
 class I2C:
+    """Custom I2C Class for MCP2221"""
 
-    def __init__(self, *, baudrate=100000):
-        mcp2221.i2c_configure(baudrate)
+    def __init__(self, *, frequency=100000):
+        self._mcp2221 = mcp2221
+        self._mcp2221._i2c_configure(frequency)
 
     def scan(self):
-        return mcp2221.i2c_scan()
+        """Perform an I2C Device Scan"""
+        return self._mcp2221.i2c_scan()
 
+    # pylint: disable=unused-argument
     def writeto(self, address, buffer, *, start=0, end=None, stop=True):
-        mcp2221.i2c_writeto(address, buffer, start=start, end=end)
+        """Write data from the buffer to an address"""
+        self._mcp2221.i2c_writeto(address, buffer, start=start, end=end)
 
     def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
-        mcp2221.i2c_readfrom_into(address, buffer, start=start, end=end)
+        """Read data from an address and into the buffer"""
+        self._mcp2221.i2c_readfrom_into(address, buffer, start=start, end=end)
 
-    def writeto_then_readfrom(self, address, buffer_out, buffer_in, *,
-                              out_start=0, out_end=None,
-                              in_start=0, in_end=None, stop=False):
-        mcp2221.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)
+    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._mcp2221.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