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"""
 
  11 # pylint: disable=too-many-branches,too-many-statements
 
  12 # pylint: disable=pointless-string-statement
 
  16     """Pins don't exist in CPython so...lets make our own!"""
 
  36     def __init__(self, pin_id=None):
 
  45     def __eq__(self, other):
 
  46         return self.id == other
 
  48     def init(self, mode=IN, pull=None):
 
  49         """Initialize the Pin"""
 
  51             raise RuntimeError("Can not init a None type pin.")
 
  55                 mypin = mraa.Gpio(self.id)
 
  56                 mypin.dir(mraa.DIR_IN)
 
  57             elif mode == self.OUT:
 
  59                 mypin = mraa.Gpio(self.id)
 
  60                 mypin.dir(mraa.DIR_OUT)
 
  61             elif mode in (self.ADC, self.DAC):
 
  62                 # ADC (DAC not available) only available on Pin 0-5 (X12 Pin 1-6)
 
  63                 if self.id not in (0, 1, 2, 3, 4, 5):
 
  64                     raise ValueError("Pin does not have ADC capabilities")
 
  65                 self._pin = mraa.Aio(self.id)
 
  66             elif mode == self.PWM:
 
  67                 # PWM only available on Pin 4-9 (X10 Pin 1-2, X11 Pin 5-8)
 
  68                 if self.id not in (4, 5, 6, 7, 8, 9):
 
  69                     raise ValueError("Pin does not have PWM capabilities")
 
  72                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
 
  75             if self._mode != self.IN:
 
  76                 raise RuntimeError("Cannot set pull resistor on output")
 
  77             if pull == self.PULL_UP:
 
  78                 mypin = mraa.Gpio(self.id)
 
  79                 mypin.dir(mraa.DIR_IN)
 
  80             elif pull == self.PULL_DOWN:
 
  81                 mypin = mraa.Gpio(self.id)
 
  82                 mypin.dir(mraa.DIR_IN)
 
  84                 raise RuntimeError("Invalid pull for pin: %s" % self.id)
 
  86     def value(self, val=None):
 
  87         """Set or return the Pin Value"""
 
  89         if self._mode in (Pin.IN, Pin.OUT):
 
  93                     mypin = mraa.Gpio(self.id)
 
  95                 elif val == self.HIGH:
 
  97                     mypin = mraa.Gpio(self.id)
 
 100                     raise RuntimeError("Invalid value for pin")
 
 102             return mraa.Gpio.read(mraa.Gpio(self.id))
 
 104         if self._mode == Pin.ADC:
 
 107                 mypin = mraa.Aio(self.id)
 
 111             raise AttributeError("'AnalogIn' object has no attribute 'value'")
 
 113         if self._mode == Pin.DAC:
 
 116                 raise AttributeError("unreadable attribute")
 
 118             mypin = mraa.Aio(self.id)
 
 120             raise AttributeError(
 
 121                 "AM65xx doesn't have an DAC! No Analog Output possible!"
 
 124             "No action for mode {} with value {}".format(self._mode, val)
 
 128 # Digital Pins (GPIO 0-19)
 
 150 # Analog Pins (AIO 0-5, only ADC!)
 
 181 # ordered as sclID, sdaID
 
 182 # i2c-4 (/dev/i2c-4) -> X10 Pin9, Pin10 (SDA, SCL)
 
 183 i2cPorts = ((4, I2C_SCL, I2C_SDA),)
 
 186 # ordered as spiId, sckId, mosiID, misoID
 
 187 spiPorts = ((0, SPIO_SCLK, SPIO_MOSI, SPIO_MISO),)
 
 190 # use pySerial = dev/ttyS1
 
 191 # ordered as uartID, txID, rxID
 
 192 uartPorts = ((0, UART_TX, UART_RX),)