]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/tegra/t194/pin.py
Adding A3
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / tegra / t194 / pin.py
1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2 #
3 # SPDX-License-Identifier: MIT
4 """Tegra T194 pin names"""
5 import atexit
6 from Jetson import GPIO
7
8 GPIO.setmode(GPIO.TEGRA_SOC)
9 GPIO.setwarnings(False)  # shh!
10
11
12 class Pin:
13     """Pins dont exist in CPython so...lets make our own!"""
14
15     IN = 0
16     OUT = 1
17     LOW = 0
18     HIGH = 1
19     PULL_NONE = 0
20     PULL_UP = 1
21     PULL_DOWN = 2
22
23     id = None
24     _value = LOW
25     _mode = IN
26
27     def __init__(self, bcm_number):
28         self.id = bcm_number
29
30     def __repr__(self):
31         return str(self.id)
32
33     def __eq__(self, other):
34         return self.id == other
35
36     def init(self, mode=IN, pull=None):
37         """Initialize the Pin"""
38         if mode is not None:
39             if mode == self.IN:
40                 self._mode = self.IN
41                 GPIO.setup(self.id, GPIO.IN)
42             elif mode == self.OUT:
43                 self._mode = self.OUT
44                 GPIO.setup(self.id, GPIO.OUT)
45             else:
46                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
47         if pull is not None:
48             if self._mode != self.IN:
49                 raise RuntimeError("Cannot set pull resistor on output")
50             if pull == self.PULL_UP:
51                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
52             elif pull == self.PULL_DOWN:
53                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
54             else:
55                 raise RuntimeError("Invalid pull for pin: %s" % self.id)
56
57     def value(self, val=None):
58         """Set or return the Pin Value"""
59         if val is not None:
60             if val == self.LOW:
61                 self._value = val
62                 GPIO.output(self.id, val)
63                 return None
64             if val == self.HIGH:
65                 self._value = val
66                 GPIO.output(self.id, val)
67                 return None
68             raise RuntimeError("Invalid value for pin")
69         return GPIO.input(self.id)
70
71     # pylint: disable=no-method-argument
72     @atexit.register
73     def cleanup():
74         """Clean up pins"""
75         print("Exiting... \nCleaning up pins")
76         GPIO.cleanup()
77
78     # pylint: enable=no-method-argument
79
80
81 # Cannot be used as GPIO
82 SDA = Pin("DP_AUX_CH3_N")
83 SCL = Pin("DP_AUX_CH3_P")
84 SDA_1 = Pin("GEN2_I2C_SDA")
85 SCL_1 = Pin("GEN2_I2C_SCL")
86
87 # Jetson Xavier only
88 Q06 = Pin("SOC_GPIO42")
89 AA03 = Pin("CAN0_DIN")
90 AA02 = Pin("CAN0_DOUT")
91 BB01 = Pin("CAN1_EN")
92 AA00 = Pin("CAN1_DOUT")
93 H07 = Pin("DAP2_SCLK")
94 I02 = Pin("DAP2_FS")
95 I01 = Pin("DAP2_DIN")
96 I00 = Pin("DAP2_DOUT")
97 BB00 = Pin("CAN1_STB")
98 H00 = Pin("SOC_GPIO12")
99 Q01 = Pin("SOC_GPIO21")
100 AA01 = Pin("CAN1_DIN")
101
102 # Jetson NX only
103 S04 = Pin("AUD_MCLK")
104 T05 = Pin("DAP5_SCLK")
105 Y00 = Pin("SPI3_SCK")
106 CC04 = Pin("TOUCH_CLK")
107 Y04 = Pin("SPI3_CS1_N")
108 Y03 = Pin("SPI3_CS0_N")
109 Y01 = Pin("SPI3_MISO")
110 Q05 = Pin("SOC_GPIO41")
111 Q06 = Pin("SOC_GPIO42")
112 U00 = Pin("DAP5_FS")
113 Y02 = Pin("SPI3_MOSI")
114 T07 = Pin("DAP5_DIN")
115 T06 = Pin("DAP5_DOUT")
116
117 # Clara AGX Xavier only
118 P04 = Pin("SOC_GPIO04")
119
120 # Shared
121 N01 = Pin("SOC_GPIO54")
122 R00 = Pin("SOC_GPIO44")
123 R04 = Pin("UART1_RTS")
124 R05 = Pin("UART1_CTS")
125 Z03 = Pin("SPI1_SCK")
126 Z04 = Pin("SPI1_MISO")
127 Z05 = Pin("SPI1_MOSI")
128 Z06 = Pin("SPI1_CS0_N")
129 Z07 = Pin("SPI1_CS1_N")
130
131 i2cPorts = (
132     (8, SCL, SDA),
133     (1, SCL_1, SDA_1),
134 )
135
136 # ordered as spiId, sckId, mosiId, misoId
137 spiPorts = ((0, Z03, Z05, Z04),)