]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/tegra/t210/pin.py
add support for jetson thor
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / tegra / t210 / pin.py
1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2 #
3 # SPDX-License-Identifier: MIT
4 """Tegra T210 pin names"""
5
6 import atexit
7 from Jetson import GPIO
8
9 GPIO.setmode(GPIO.TEGRA_SOC)
10 GPIO.setwarnings(False)  # shh!
11
12
13 class Pin:
14     """Pins dont exist in CPython so...lets make our own!"""
15
16     IN = 0
17     OUT = 1
18     LOW = 0
19     HIGH = 1
20     PULL_NONE = 0
21     PULL_UP = 1
22     PULL_DOWN = 2
23
24     id = None
25     _value = LOW
26     _mode = IN
27
28     def __init__(self, bcm_number):
29         self.id = bcm_number
30
31     def __repr__(self):
32         return str(self.id)
33
34     def __eq__(self, other):
35         return self.id == other
36
37     def init(self, mode=IN, pull=None):
38         """Initialize the Pin"""
39         if mode is not None:
40             if mode == self.IN:
41                 self._mode = self.IN
42                 GPIO.setup(self.id, GPIO.IN)
43             elif mode == self.OUT:
44                 self._mode = self.OUT
45                 GPIO.setup(self.id, GPIO.OUT)
46             else:
47                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
48         if pull is not None:
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)
55             else:
56                 raise RuntimeError("Invalid pull for pin: %s" % self.id)
57
58     def value(self, val=None):
59         """Set or return the Pin Value"""
60         if val is not None:
61             if val == self.LOW:
62                 self._value = val
63                 GPIO.output(self.id, val)
64                 return None
65             if val == self.HIGH:
66                 self._value = val
67                 GPIO.output(self.id, val)
68                 return None
69             raise RuntimeError("Invalid value for pin")
70         return GPIO.input(self.id)
71
72     # pylint: disable=no-method-argument
73     @atexit.register
74     def cleanup():
75         """Clean up pins"""
76         print("Exiting... \nCleaning up pins")
77         GPIO.cleanup()
78
79     # pylint: enable=no-method-argument
80
81
82 # Cannot be used as GPIO
83 SDA = Pin("GEN1_I2C_SDA")
84 SCL = Pin("GEN1_I2C_SCL")
85 SDA_1 = Pin("GEN2_I2C_SDA")
86 SCL_1 = Pin("GEN2_I2C_SCL")
87
88 # These pins are native to TX1
89 BB03 = Pin("GPIO_X1_AUD")
90 X02 = Pin("MOTION_INT")
91 H07 = Pin("AP_WAKE_NFC")
92 E04 = Pin("DMIC3_CLK")
93 U03 = Pin("UART1_CTS")
94 U02 = Pin("UART1_RTS")
95 B03 = Pin("DAP1_SCLK")
96 B00 = Pin("DAP1_FS")
97 B01 = Pin("DAP1_DIN")
98 B02 = Pin("DAP1_DOUT")
99 P17 = Pin("GPIO_EXP_P17")
100 E05 = Pin("DMIC3_DAT")
101 X00 = Pin("MODEM_WAKE_AP")
102 P16 = Pin("GPIO_EXP_P16")
103 X03 = Pin("ALS_PROX_INT")
104
105 # These pins are native to NANO
106 S05 = Pin("CAM_AF_EN")
107 Z00 = Pin("GPIO_PZ0")
108 V00 = Pin("LCD_BL_PW")
109 G03 = Pin("UART2_CTS")
110 G02 = Pin("UART2_RTS")
111 J07 = Pin("DAP4_SCLK")
112 J04 = Pin("DAP4_FS")
113 J05 = Pin("DAP4_DIN")
114 J06 = Pin("DAP4_DOUT")
115 Y02 = Pin("LCD_TE")
116 DD00 = Pin("SPI2_CS1")
117 B07 = Pin("SPI2_CS0")
118 B05 = Pin("SPI2_MISO")
119 B04 = Pin("SPI2_MOSI")
120 B06 = Pin("SPI2_SCK")
121
122 # These pins are shared across T210
123 BB00 = Pin("AUD_MCLK")
124 C04 = Pin("SPI1_CS1")
125 C03 = Pin("SPI1_CS0")
126 C01 = Pin("SPI1_MISO")
127 C00 = Pin("SPI1_MOSI")
128 C02 = Pin("SPI1_SCK")
129 E06 = Pin("GPIO_PE6")
130
131 i2cPorts = (
132     (0, SCL, SDA),
133     (1, SCL_1, SDA_1),
134 )
135
136 # ordered as spiId, sckId, mosiId, misoId
137 spiPorts = ((0, C02, C00, C01), (1, B06, B04, B05))
138
139 # SysFS pwm outputs, pwm channel and pin in first tuple
140 pwmOuts = (
141     ((0, 0), V00),
142     ((0, 1), E06),
143 )