1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
 
   3 # SPDX-License-Identifier: MIT
 
   4 """Tegra T186 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("GPIO_SEN9")
 
  84 SCL = Pin("GPIO_SEN8")
 
  85 SDA_1 = Pin("GEN1_I2C_SDA")
 
  86 SCL_1 = Pin("GEN1_I2C_SCL")
 
  89 J06 = Pin("GPIO_AUD1")
 
  90 AA02 = Pin("CAN_GPIO2")
 
  91 N06 = Pin("GPIO_CAM7")
 
  92 N04 = Pin("GPIO_CAM5")
 
  93 N05 = Pin("GPIO_CAM6")
 
  94 N03 = Pin("GPIO_CAM4")
 
  95 AA01 = Pin("CAN_GPIO1")
 
  97 T03 = Pin("UART1_CTS")
 
  98 T02 = Pin("UART1_RTS")
 
  99 P17 = Pin("GPIO_EXP_P17")
 
 100 AA00 = Pin("CAN_GPIO0")
 
 101 Y01 = Pin("GPIO_MDM2")
 
 102 P16 = Pin("GPIO_EXP_P16")
 
 103 I04 = Pin("GPIO_PQ4")
 
 104 J05 = Pin("GPIO_AUD0")
 
 106 # Jetson TX2 NX specific
 
 107 W04 = Pin("UART3_RTS")
 
 108 V01 = Pin("GPIO_SEN1")
 
 109 C02 = Pin("DAP2_DOUT")
 
 110 C03 = Pin("DAP2_DIN")
 
 111 V04 = Pin("GPIO_SEN4")
 
 112 H02 = Pin("GPIO_WAN7")
 
 113 H01 = Pin("GPIO_WAN6")
 
 114 V02 = Pin("GPIO_SEN2")
 
 115 H00 = Pin("GPIO_WAN5")
 
 116 H03 = Pin("GPIO_WAN8")
 
 117 Y03 = Pin("GPIO_MDM4")
 
 118 N01 = Pin("GPIO_CAM2")
 
 119 EE02 = Pin("TOUCH_CLK")
 
 120 U00 = Pin("GPIO_DIS0")
 
 121 U05 = Pin("GPIO_DIS5")
 
 122 W05 = Pin("UART3_CTS")
 
 123 V03 = Pin("GPIO_SEN3")
 
 127 J02 = Pin("DAP1_DIN")
 
 128 J01 = Pin("DAP1_DOUT")
 
 129 J00 = Pin("DAP1_SCLK")
 
 130 J04 = Pin("AUD_MCLK")
 
 137 # ordered as spiId, sckId, mosiId, misoId
 
 138 spiPorts = ((3, N03, N05, N04),)