]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/tegra/t210/pin.py
tweak pixel order
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / tegra / t210 / pin.py
1 """Tegra T210 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("GEN1_I2C_SDA")
81 SCL = Pin("GEN1_I2C_SCL")
82 SDA_1 = Pin("GEN2_I2C_SDA")
83 SCL_1 = Pin("GEN2_I2C_SCL")
84
85 # These pins are native to TX1
86 BB03 = Pin("GPIO_X1_AUD")
87 X02 = Pin("MOTION_INT")
88 H07 = Pin("AP_WAKE_NFC")
89 E04 = Pin("DMIC3_CLK")
90 U03 = Pin("UART1_CTS")
91 U02 = Pin("UART1_RTS")
92 B03 = Pin("DAP1_SCLK")
93 B00 = Pin("DAP1_FS")
94 B01 = Pin("DAP1_DIN")
95 B02 = Pin("DAP1_DOUT")
96 P17 = Pin("GPIO_EXP_P17")
97 E05 = Pin("DMIC3_DAT")
98 X00 = Pin("MODEM_WAKE_AP")
99 P16 = Pin("GPIO_EXP_P16")
100 X03 = Pin("ALS_PROX_INT")
101
102 # These pins are native to NANO
103 S05 = Pin("CAM_AF_EN")
104 Z00 = Pin("GPIO_PZ0")
105 V00 = Pin("LCD_BL_PW")
106 G03 = Pin("UART2_CTS")
107 G02 = Pin("UART2_RTS")
108 J07 = Pin("DAP4_SCLK")
109 J04 = Pin("DAP4_FS")
110 J05 = Pin("DAP4_DIN")
111 J06 = Pin("DAP4_DOUT")
112 Y02 = Pin("LCD_TE")
113 DD00 = Pin("SPI2_CS1")
114 B07 = Pin("SPI2_CS0")
115 B05 = Pin("SPI2_MISO")
116 B04 = Pin("SPI2_MOSI")
117 B06 = Pin("SPI2_SCK")
118
119 # These pins are shared across T210
120 BB00 = Pin("AUD_MCLK")
121 C04 = Pin("SPI1_CS1")
122 C03 = Pin("SPI1_CS0")
123 C01 = Pin("SPI1_MISO")
124 C00 = Pin("SPI1_MOSI")
125 C02 = Pin("SPI1_SCK")
126 E06 = Pin("GPIO_PE6")
127
128 i2cPorts = (
129     (0, SCL, SDA),
130     (1, SCL_1, SDA_1),
131 )
132
133 # ordered as spiId, sckId, mosiId, misoId
134 spiPorts = ((0, C02, C00, C01), (1, B06, B04, B05))