]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/tegra/t186/pin.py
Merge pull request #848 from nopnop2002/main
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / tegra / t186 / pin.py
1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2 #
3 # SPDX-License-Identifier: MIT
4 """Tegra T186 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("GPIO_SEN9")
84 SCL = Pin("GPIO_SEN8")
85 SDA_1 = Pin("GEN1_I2C_SDA")
86 SCL_1 = Pin("GEN1_I2C_SCL")
87
88 # Jetson TX2 specific
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")
96 I05 = Pin("GPIO_PQ5")
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")
105
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")
124
125 # Shared pin
126 J03 = Pin("DAP1_FS")
127 J02 = Pin("DAP1_DIN")
128 J01 = Pin("DAP1_DOUT")
129 J00 = Pin("DAP1_SCLK")
130 J04 = Pin("AUD_MCLK")
131
132 i2cPorts = (
133     (1, SCL, SDA),
134     (0, SCL_1, SDA_1),
135 )
136
137 # ordered as spiId, sckId, mosiId, misoId
138 spiPorts = ((3, N03, N05, N04),)