1 # SPDX-FileCopyrightText: 2025 Gautham Srinivasan for NVIDIA
 
   3 # SPDX-License-Identifier: MIT
 
   5 """Tegra T264 pin names"""
 
   7 from Jetson import GPIO
 
   9 GPIO.setmode(GPIO.TEGRA_SOC)
 
  10 GPIO.setwarnings(False)  # shh!
 
  14     """Pins dont exist in CPython so...lets make our own!"""
 
  28     def __init__(self, bcm_number):
 
  34     def __eq__(self, other):
 
  35         return self.id == other
 
  37     def init(self, mode=IN, pull=None):
 
  38         """Initialize the Pin"""
 
  42                 GPIO.setup(self.id, GPIO.IN)
 
  43             elif mode == self.OUT:
 
  45                 GPIO.setup(self.id, GPIO.OUT)
 
  47                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
 
  49             if self._mode != self.IN:
 
  50                 raise RuntimeError("Cannot set pull resistor on output")
 
  51             if pull == self.PULL_UP:
 
  52                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 
  53             elif pull == self.PULL_DOWN:
 
  54                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
 
  56                 raise RuntimeError("Invalid pull for pin: %s" % self.id)
 
  58     def value(self, val=None):
 
  59         """Set or return the Pin Value"""
 
  63                 GPIO.output(self.id, val)
 
  67                 GPIO.output(self.id, val)
 
  69             raise RuntimeError("Invalid value for pin")
 
  70         return GPIO.input(self.id)
 
  72     # pylint: disable=no-method-argument
 
  76         print("Exiting... \nCleaning up pins")
 
  79     # pylint: enable=no-method-argument
 
  82 # Cannot be used as GPIO
 
  83 SDA = Pin("GP16_I2C8_DAT")  # I2C4
 
  84 SCL = Pin("GP81_I2C9_CLK")
 
  85 SDA_1 = Pin("GP14_I2C2_DAT")  # I2C2
 
  86 SCL_1 = Pin("GP13_I2C2_CLK")
 
  90 M04 = Pin("GP136_UART9_RTS_N")
 
  91 V06 = Pin("GP184_DAP2_CLK")
 
  92 M00 = Pin("GP132_PWM9")
 
  93 F07 = Pin("GP257_PWM2")
 
  96 K01 = Pin("GP117_SPI1_MOSI")
 
  97 K00 = Pin("GP116_SPI1_MISO")
 
  99 J07 = Pin("GP115_SPI1_CLK")
 
 100 K02 = Pin("GP118_SPI1_CS0_N")
 
 101 K03 = Pin("GP119_SPI1_CS1_N")
 
 102 AD01 = Pin("GP211_CAN2_DIN")
 
 103 AD00 = Pin("GP210_CAN2_DOUT")
 
 104 DD04 = Pin("GGP22_SOCKET_ID_STRA")
 
 105 AE00 = Pin("GP215_CAN3_DOUT")
 
 106 W01 = Pin("GP187_DAP2_FS")
 
 107 M05 = Pin("GP137_UART9_CTS_N")
 
 108 AE01 = Pin("GP216_CAN3_DIN")
 
 109 W00 = Pin("GP186_DAP2_DIN")
 
 110 V07 = Pin("GP185_DAP2_DOUT")
 
 117 # ordered as spiId, sckId, mosiId, misoId
 
 118 spiPorts = ((K02, J07, K01, K00),)