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