]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/generic_micropython/__init__.py
fix wrongly assuming "of_node/compatible" will always exist for all gpiochips
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / generic_micropython / __init__.py
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..cb3683c4e69fc246c70335d69424d9b945859d90 100644 (file)
@@ -0,0 +1,33 @@
+# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
+"""Genereic Pin class for use with MicroPython boards"""
+from adafruit_blinka import Enum
+
+
+class Pin(Enum):
+    """
+    Identifies an IO pin on the microcontroller.
+
+    They are fixed by the hardware so they cannot be constructed on demand. Instead, use board or
+    microcontroller.pin to reference the desired pin.
+    """
+
+    def __init__(self, pin_id):
+        """Identifier for pin, referencing platform-specific pin id"""
+        self.id = pin_id
+
+    def __repr__(self):
+        # pylint: disable=import-outside-toplevel, cyclic-import
+        import board
+        import microcontroller.pin
+
+        for key in dir(board):
+            if getattr(board, key) is self:
+                return "board.{}".format(key)
+        # pylint: enable=import-outside-toplevel, cyclic-import
+
+        for key in dir(microcontroller.pin):
+            if getattr(microcontroller.pin, key) is self:
+                return "microcontroller.pin.{}".format(key)
+        return repr(self)