]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/am65xx/analogio.py
Added support for Siemens Simatic IOT2050 Basic/Advanced
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / am65xx / analogio.py
diff --git a/src/adafruit_blinka/microcontroller/am65xx/analogio.py b/src/adafruit_blinka/microcontroller/am65xx/analogio.py
new file mode 100644 (file)
index 0000000..aab050e
--- /dev/null
@@ -0,0 +1,57 @@
+# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
+"""
+`analogio` - Analog input and output control
+=================================================
+See `CircuitPython:analogio` in CircuitPython for more details.
+* Author(s): Martin Schnur
+"""
+
+from adafruit_blinka.microcontroller.am65xx.pin import Pin
+from adafruit_blinka import ContextManaged
+
+
+class AnalogIn(ContextManaged):
+    """Analog Input Class"""
+
+    def __init__(self, pin):
+        self._pin = Pin(pin.id)
+        self._pin.init(mode=Pin.ADC)
+
+    @property
+    def value(self):
+        """Read the ADC and return the value"""
+        return self._pin.value()
+
+    # pylint: disable=no-self-use
+    @value.setter
+    def value(self, value):
+        # emulate what CircuitPython does
+        raise AttributeError("'AnalogIn' object has no attribute 'value'")
+
+    # pylint: enable=no-self-use
+
+    def deinit(self):
+        del self._pin
+
+
+class AnalogOut(ContextManaged):
+    """Analog Output Class"""
+
+    def __init__(self, pin):
+        self._pin = Pin(pin.id)
+        self._pin.init(mode=Pin.DAC)
+
+    @property
+    def value(self):
+        """Return an error. This is output only."""
+        # emulate what CircuitPython does
+        raise AttributeError("AM65xx doesn't have an DAC! No Analog Output possible!")
+
+    @value.setter
+    def value(self, value):
+        self._pin.value(value)
+
+    def deinit(self):
+        del self._pin