]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/tegra/t186/pin.py
Fixed microcontroller.pin import mappings
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / tegra / t186 / pin.py
1 """Tegra T186 pin names"""
2
3 import atexit
4 import Jetson.GPIO as GPIO
5
6 GPIO.setmode(GPIO.TEGRA_SOC)
7 GPIO.setwarnings(False)  # shh!
8
9
10 class Pin:
11     """Pins dont exist in CPython so...lets make our own!"""
12
13     IN = 0
14     OUT = 1
15     LOW = 0
16     HIGH = 1
17     PULL_NONE = 0
18     PULL_UP = 1
19     PULL_DOWN = 2
20
21     id = None
22     _value = LOW
23     _mode = IN
24
25     def __init__(self, bcm_number):
26         self.id = bcm_number
27
28     def __repr__(self):
29         return str(self.id)
30
31     def __eq__(self, other):
32         return self.id == other
33
34     def init(self, mode=IN, pull=None):
35         """Initialize the Pin"""
36         if mode is not None:
37             if mode == self.IN:
38                 self._mode = self.IN
39                 GPIO.setup(self.id, GPIO.IN)
40             elif mode == self.OUT:
41                 self._mode = self.OUT
42                 GPIO.setup(self.id, GPIO.OUT)
43             else:
44                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
45         if pull is not None:
46             if self._mode != self.IN:
47                 raise RuntimeError("Cannot set pull resistor on output")
48             if pull == self.PULL_UP:
49                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
50             elif pull == self.PULL_DOWN:
51                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
52             else:
53                 raise RuntimeError("Invalid pull for pin: %s" % self.id)
54
55     def value(self, val=None):
56         """Set or return the Pin Value"""
57         if val is not None:
58             if val == self.LOW:
59                 self._value = val
60                 GPIO.output(self.id, val)
61                 return None
62             if val == self.HIGH:
63                 self._value = val
64                 GPIO.output(self.id, val)
65                 return None
66             raise RuntimeError("Invalid value for pin")
67         return GPIO.input(self.id)
68
69     # pylint: disable=no-method-argument
70     @atexit.register
71     def cleanup():
72         """Clean up pins"""
73         print("Exiting... \nCleaning up pins")
74         GPIO.cleanup()
75
76     # pylint: enable=no-method-argument
77
78
79 # Cannot be used as GPIO
80 SDA = Pin("GPIO_SEN9")
81 SCL = Pin("GPIO_SEN8")
82 SDA_1 = Pin("GEN1_I2C_SDA")
83 SCL_1 = Pin("GEN1_I2C_SCL")
84
85 # Jetson TX2 specific
86 J06 = Pin("GPIO_AUD1")
87 AA02 = Pin("CAN_GPIO2")
88 N06 = Pin("GPIO_CAM7")
89 N04 = Pin("GPIO_CAM5")
90 N05 = Pin("GPIO_CAM6")
91 N03 = Pin("GPIO_CAM4")
92 AA01 = Pin("CAN_GPIO1")
93 I05 = Pin("GPIO_PQ5")
94 T03 = Pin("UART1_CTS")
95 T02 = Pin("UART1_RTS")
96 P17 = Pin("GPIO_EXP_P17")
97 AA00 = Pin("CAN_GPIO0")
98 Y01 = Pin("GPIO_MDM2")
99 P16 = Pin("GPIO_EXP_P16")
100 I04 = Pin("GPIO_PQ4")
101 J05 = Pin("GPIO_AUD0")
102
103 # Jetson TX2 NX specific
104 W04 = Pin("UART3_RTS")
105 V01 = Pin("GPIO_SEN1")
106 C02 = Pin("DAP2_DOUT")
107 C03 = Pin("DAP2_DIN")
108 V04 = Pin("GPIO_SEN4")
109 H02 = Pin("GPIO_WAN7")
110 H01 = Pin("GPIO_WAN6")
111 V02 = Pin("GPIO_SEN2")
112 H00 = Pin("GPIO_WAN5")
113 H03 = Pin("GPIO_WAN8")
114 Y03 = Pin("GPIO_MDM4")
115 N01 = Pin("GPIO_CAM2")
116 EE02 = Pin("TOUCH_CLK")
117 U00 = Pin("GPIO_DIS0")
118 U05 = Pin("GPIO_DIS5")
119 W05 = Pin("UART3_CTS")
120 V03 = Pin("GPIO_SEN3")
121
122 # Shared pin
123 J03 = Pin("DAP1_FS")
124 J02 = Pin("DAP1_DIN")
125 J01 = Pin("DAP1_DOUT")
126 J00 = Pin("DAP1_SCLK")
127 J04 = Pin("AUD_MCLK")
128
129 i2cPorts = (
130     (1, SCL, SDA),
131     (0, SCL_1, SDA_1),
132 )
133
134 # ordered as spiId, sckId, mosiId, misoId
135 spiPorts = ((3, N03, N05, N04),)