]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/tegra/t234/pin.py
add pixels
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / tegra / t234 / pin.py
1 # SPDX-FileCopyrightText: 2022 Linh Hoang for NVIDIA
2 # SPDX-FileCopyrightText: 2022 Melissa LeBlanc-Williams for Adafruit Industries
3 #
4 # SPDX-License-Identifier: MIT
5
6 """Tegra T234 pin names"""
7 import atexit
8 from Jetson import GPIO
9
10 GPIO.setmode(GPIO.TEGRA_SOC)
11 GPIO.setwarnings(False)  # shh!
12
13
14 class Pin:
15     """Pins dont exist in CPython so...lets make our own!"""
16
17     IN = 0
18     OUT = 1
19     LOW = 0
20     HIGH = 1
21     PULL_NONE = 0
22     PULL_UP = 1
23     PULL_DOWN = 2
24
25     id = None
26     _value = LOW
27     _mode = IN
28
29     def __init__(self, bcm_number):
30         self.id = bcm_number
31
32     def __repr__(self):
33         return str(self.id)
34
35     def __eq__(self, other):
36         return self.id == other
37
38     def init(self, mode=IN, pull=None):
39         """Initialize the Pin"""
40         if mode is not None:
41             if mode == self.IN:
42                 self._mode = self.IN
43                 GPIO.setup(self.id, GPIO.IN)
44             elif mode == self.OUT:
45                 self._mode = self.OUT
46                 GPIO.setup(self.id, GPIO.OUT)
47             else:
48                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
49         if pull is not None:
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)
56             else:
57                 raise RuntimeError("Invalid pull for pin: %s" % self.id)
58
59     def value(self, val=None):
60         """Set or return the Pin Value"""
61         if val is not None:
62             if val == self.LOW:
63                 self._value = val
64                 GPIO.output(self.id, val)
65                 return None
66             if val == self.HIGH:
67                 self._value = val
68                 GPIO.output(self.id, val)
69                 return None
70             raise RuntimeError("Invalid value for pin")
71         return GPIO.input(self.id)
72
73     # pylint: disable=no-method-argument
74     @atexit.register
75     def cleanup():
76         """Clean up pins"""
77         print("Exiting... \nCleaning up pins")
78         GPIO.cleanup()
79
80     # pylint: enable=no-method-argument
81
82
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")
88
89 # Jetson AGX Orin
90 Q06 = Pin("GP66")
91 R04 = Pin("GP72_UART1_RTS_N")
92 H07 = Pin("GP122")
93 R00 = Pin("GP68")
94 N01 = Pin("GP88_PWM1")
95 BB00 = Pin("GP25")
96 H00 = Pin("GP115")
97 Z05 = Pin("GP49_SPI1_MOSI")
98 Z04 = Pin("GP48_SPI1_MISO")
99 P04 = Pin("GP56")
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")
105 BB01 = Pin("GP26")
106 AA02 = Pin("GP19_CAN1_DOUT")
107 I02 = Pin("GP125")
108 R05 = Pin("GP73_UART1_CTS_N")
109 AA03 = Pin("GP20_CAN1_DIN")
110 I01 = Pin("GP124")
111 I00 = Pin("GP123")
112
113
114 AC06 = Pin("GP167")
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")
120 Q05 = Pin("GP65")
121 G06 = Pin("GP113_PWM7")
122 Y02 = Pin("GP38_SPI3_MOSI")
123
124
125 i2cPorts = (
126     (7, SCL, SDA),
127     (1, SCL_1, SDA_1),
128 )
129
130 # ordered as spiId, sckId, mosiId, misoId
131 spiPorts = ((0, Z03, Z05, Z04),)