1 # SPDX-FileCopyrightText: 2024 Brent Rubell for Adafruit Industries
 
   3 # SPDX-License-Identifier: MIT
 
   5 `analogio` - Analog input and output control
 
   6 =================================================
 
   7 See `CircuitPython:analogio` in CircuitPython for more details.
 
   8 * Author(s): Carter Nelson
 
  11 from adafruit_blinka.microcontroller.generic_agnostic_board.pin import Pin
 
  12 from adafruit_blinka import ContextManaged
 
  15 class AnalogIn(ContextManaged):
 
  16     """Analog Input Class"""
 
  18     def __init__(self, pin):
 
  19         self._pin = Pin(pin.id)
 
  20         self._pin.init(mode=Pin.ADC)
 
  24         """Read the ADC and return the value"""
 
  25         return self._pin.value()
 
  27     # pylint: disable=no-self-use
 
  29     def value(self, value):
 
  30         # emulate what CircuitPython does
 
  31         raise AttributeError("'AnalogIn' object has no attribute 'value'")
 
  33     # pylint: enable=no-self-use
 
  39 class AnalogOut(ContextManaged):
 
  40     """Analog Output Class"""
 
  42     def __init__(self, pin):
 
  43         self._pin = Pin(pin.id)
 
  44         self._pin.init(mode=Pin.DAC)
 
  48         """Fake the output."""
 
  49         return self._pin.value()
 
  52     def value(self, value):
 
  53         self._pin.value(value)