2 `analogio` - Analog input and output control
3 =================================================
4 See `CircuitPython:analogio` in CircuitPython for more details.
5 * Author(s): Carter Nelson
7 from adafruit_blinka import ContextManaged
8 from .rp2040_u2if import rp2040_u2if
11 class AnalogIn(ContextManaged):
12 """AnalogIn Base Class for RP2040 u2if"""
14 def __init__(self, pin):
16 rp2040_u2if.adc_init_pin(self.pin_id)
20 """Read the ADC and return the value"""
21 return rp2040_u2if.adc_get_value(self.pin_id) << 4
23 # pylint: disable=no-self-use
25 def value(self, value):
26 # emulate what CircuitPython does
27 raise AttributeError("'AnalogIn' object has no attribute 'value'")
29 # pylint: enable=no-self-use
34 class AnalogIn_Pico(AnalogIn):
35 """AnalogIn Base Class for Pico u2if"""
37 def __init__(self, pin):
38 # per their pinout, why only two?
39 if pin.id not in (26, 27):
40 raise ValueError("Pin does not support ADC.")
43 class AnalogIn_Feather(AnalogIn):
44 """AnalogIn Base Class for Feather u2if"""
46 def __init__(self, pin):
47 if pin.id not in (26, 27, 28):
48 raise ValueError("Pin does not support ADC.")
51 class AnalogIn_QTPY(AnalogIn):
52 """AnalogIn Base Class for QT Py 2040 u2if"""
54 def __init__(self, pin):
55 if pin.id not in (26, 27, 28):
56 raise ValueError("Pin does not support ADC.")