1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
3 # SPDX-License-Identifier: MIT
4 # SPDX-FileCopyrightText: 2022 Martin Schnur for Siemens AG
6 # SPDX-License-Identifier: MIT
7 """TI AM65XX pin names"""
13 """Pins don't exist in CPython so...lets make our own!"""
33 def __init__(self, pin_id=None):
42 def __eq__(self, other):
43 return self.id == other
45 def init(self, mode=IN, pull=None):
46 """Initialize the Pin"""
48 raise RuntimeError("Can not init a None type pin.")
52 mypin = mraa.Gpio(self.id)
53 mypin.dir(mraa.DIR_IN)
54 elif mode == self.OUT:
56 mypin = mraa.Gpio(self.id)
57 mypin.dir(mraa.DIR_OUT)
58 elif mode in (self.ADC, self.DAC):
59 # ADC (DAC not available) only available on Pin 0-5 (X12 Pin 1-6)
60 if self.id not in (0, 1, 2, 3, 4, 5):
61 raise ValueError("Pin does not have ADC capabilities")
62 self._pin = mraa.Aio(self.id)
63 elif mode == self.PWM:
64 # PWM only available on Pin 4-9 (X10 Pin 1-2, X11 Pin 5-8)
65 if self.id not in (4, 5, 6, 7, 8, 9):
66 raise ValueError("Pin does not have PWM capabilities")
69 raise RuntimeError("Invalid mode for pin: %s" % self.id)
72 if self._mode != self.IN:
73 raise RuntimeError("Cannot set pull resistor on output")
74 if pull == self.PULL_UP:
75 mypin = mraa.Gpio(self.id)
76 mypin.dir(mraa.DIR_IN)
77 elif pull == self.PULL_DOWN:
78 mypin = mraa.Gpio(self.id)
79 mypin.dir(mraa.DIR_IN)
81 raise RuntimeError("Invalid pull for pin: %s" % self.id)
83 def value(self, val=None):
84 """Set or return the Pin Value"""
86 if self._mode in (Pin.IN, Pin.OUT):
90 mypin = mraa.Gpio(self.id)
92 elif val == self.HIGH:
94 mypin = mraa.Gpio(self.id)
97 raise RuntimeError("Invalid value for pin")
99 return mraa.Gpio.read(mraa.Gpio(self.id))
101 if self._mode == Pin.ADC:
104 mypin = mraa.Aio(self.id)
108 raise AttributeError("'AnalogIn' object has no attribute 'value'")
110 if self._mode == Pin.DAC:
113 raise AttributeError("unreadable attribute")
115 mypin = mraa.Aio(self.id)
117 raise AttributeError(
118 "AM65xx doesn't have an DAC! No Analog Output possible!"
121 "No action for mode {} with value {}".format(self._mode, val)
125 # Digital Pins (GPIO 0-19)
147 # Analog Pins (AIO 0-5, only ADC!)
178 # ordered as sclID, sdaID
179 # i2c-4 (/dev/i2c-4) -> X10 Pin9, Pin10 (SDA, SCL)
180 i2cPorts = ((4, I2C_SCL, I2C_SDA),)
183 # ordered as spiId, sckId, mosiID, misoID
184 spiPorts = ((0, SPIO_SCLK, SPIO_MOSI, SPIO_MISO),)
187 # use pySerial = dev/ttyS1
188 # ordered as uartID, txID, rxID
189 uartPorts = ((0, UART_TX, UART_RX),)