1 # SPDX-FileCopyrightText: 2022 Linh Hoang for NVIDIA
2 # SPDX-FileCopyrightText: 2022 Melissa LeBlanc-Williams for Adafruit Industries
4 # SPDX-License-Identifier: MIT
6 """Tegra T234 pin names"""
8 from Jetson import GPIO
10 GPIO.setmode(GPIO.TEGRA_SOC)
11 GPIO.setwarnings(False) # shh!
15 """Pins dont exist in CPython so...lets make our own!"""
29 def __init__(self, bcm_number):
35 def __eq__(self, other):
36 return self.id == other
38 def init(self, mode=IN, pull=None):
39 """Initialize the Pin"""
43 GPIO.setup(self.id, GPIO.IN)
44 elif mode == self.OUT:
46 GPIO.setup(self.id, GPIO.OUT)
48 raise RuntimeError("Invalid mode for pin: %s" % self.id)
50 if self._mode != self.IN:
51 raise RuntimeError("Cannot set pull resistor on output")
52 if pull == self.PULL_UP:
53 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
54 elif pull == self.PULL_DOWN:
55 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
57 raise RuntimeError("Invalid pull for pin: %s" % self.id)
59 def value(self, val=None):
60 """Set or return the Pin Value"""
64 GPIO.output(self.id, val)
68 GPIO.output(self.id, val)
70 raise RuntimeError("Invalid value for pin")
71 return GPIO.input(self.id)
73 # pylint: disable=no-method-argument
77 print("Exiting... \nCleaning up pins")
80 # pylint: enable=no-method-argument
83 # Cannot be used as GPIO
84 SDA = Pin("GP16_I2C8_DAT") # I2C4
85 SCL = Pin("GP81_I2C9_CLK")
86 SDA_1 = Pin("GP14_I2C2_DAT") # I2C2
87 SCL_1 = Pin("GP13_I2C2_CLK")
91 R04 = Pin("GP72_UART1_RTS_N")
94 N01 = Pin("GP88_PWM1")
97 Z05 = Pin("GP49_SPI1_MOSI")
98 Z04 = Pin("GP48_SPI1_MISO")
100 Z03 = Pin("GP47_SPI1_CLK")
101 Z06 = Pin("GP50_SPI1_CS0_N")
102 Z07 = Pin("GP51_SPI1_CS1_N")
103 AA01 = Pin("GP18_CAN0_DIN")
104 AA00 = Pin("GP17_CAN0_DOUT")
106 AA02 = Pin("GP19_CAN1_DOUT")
108 R05 = Pin("GP73_UART1_CTS_N")
109 AA03 = Pin("GP20_CAN1_DIN")
115 Y00 = Pin("SPI1_SCK")
116 N01 = Pin("GP88_PWM1")
117 Y04 = Pin("GP40_SPI3_CS1_N")
118 Y03 = Pin("GP39_SPI3_CS0_N")
119 Y01 = Pin("GP37_SPI3_MISO")
121 G06 = Pin("GP113_PWM7")
122 Y02 = Pin("GP38_SPI3_MOSI")
130 # ordered as spiId, sckId, mosiId, misoId
131 spiPorts = ((0, Z03, Z05, Z04),)