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
35 class AnalogIn_Pico(AnalogIn):
36 """AnalogIn Base Class for Pico u2if"""
38 def __init__(self, pin):
39 # per their pinout, why only two?
40 if pin.id not in (26, 27):
41 raise ValueError("Pin does not support ADC.")
45 class AnalogIn_Feather(AnalogIn):
46 """AnalogIn Base Class for Feather u2if"""
48 def __init__(self, pin):
49 if pin.id not in (26, 27, 28):
50 raise ValueError("Pin does not support ADC.")
54 class AnalogIn_QTPY(AnalogIn):
55 """AnalogIn Base Class for QT Py 2040 u2if"""
57 def __init__(self, pin):
58 if pin.id not in (26, 27, 28):
59 raise ValueError("Pin does not support ADC.")
63 class AnalogIn_ItsyBitsy(AnalogIn):
64 """AnalogIn Base Class for ItsyBitsy 2040 u2if"""
66 def __init__(self, pin):
67 if pin.id not in (26, 27, 28):
68 raise ValueError("Pin does not support ADC.")