]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/tegra/t194/pin.py
add HID delay
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / tegra / t194 / pin.py
1 import sys
2 import atexit
3 import Jetson.GPIO as GPIO
4 GPIO.setmode(GPIO.TEGRA_SOC)
5 GPIO.setwarnings(False)   # shh!
6
7 # Pins dont exist in CPython so...lets make our own!
8 class Pin:
9     IN = 0
10     OUT = 1
11     LOW = 0
12     HIGH = 1
13     PULL_NONE = 0
14     PULL_UP = 1
15     PULL_DOWN = 2
16
17     id = None
18     _value = LOW
19     _mode = IN
20
21     def __init__(self, bcm_number):
22         self.id = bcm_number
23
24     def __repr__(self):
25         return str(self.id)
26
27     def __eq__(self, other):
28         return self.id == other
29
30     def init(self, mode=IN, pull=None):
31         if mode != None:
32             if mode == self.IN:
33                 self._mode = self.IN
34                 GPIO.setup(self.id, GPIO.IN)
35             elif mode == self.OUT:
36                 self._mode = self.OUT
37                 GPIO.setup(self.id, GPIO.OUT)
38             else:
39                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
40         if pull != None:
41             if self._mode != self.IN:
42                 raise RuntimeError("Cannot set pull resistor on output")
43             if pull == self.PULL_UP:
44                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
45             elif pull == self.PULL_DOWN:
46                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
47             else:
48                 raise RuntimeError("Invalid pull for pin: %s" % self.id)
49
50     def value(self, val=None):
51         if val != None:
52             if val == self.LOW:
53                 self._value = val
54                 GPIO.output(self.id, val)
55             elif val == self.HIGH:
56                 self._value = val
57                 GPIO.output(self.id, val)
58             else:
59                 raise RuntimeError("Invalid value for pin")
60         else:
61             return GPIO.input(self.id)
62
63     @atexit.register
64     def cleanup():
65         print("Exiting... \nCleaning up pins")
66         GPIO.cleanup()
67
68 # Cannot be used as GPIO
69 SDA = Pin('DP_AUX_CH3_N')
70 SCL = Pin('DP_AUX_CH3_P')
71 SDA_1 = Pin('GEN2_I2C_SDA')
72 SCL_1 = Pin('GEN2_I2C_SCL')
73
74 Q06 = Pin('SOC_GPIO42')
75 AA03 = Pin('CAN0_DIN')
76 AA02 = Pin('CAN0_DOUT')
77 Z07 = Pin('SPI1_CS1_N')
78 Z06 = Pin('SPI1_CS0_N')
79 Z04 = Pin('SPI1_MISO')
80 Z05 = Pin('SPI1_MOSI')
81 Z03 = Pin('SPI1_SCK')
82 BB01 = Pin('CAN1_EN')
83 AA00 = Pin('CAN1_DOUT')
84 R05 = Pin('UART1_CTS')
85 R04 = Pin('UART1_RTS')
86 H07 = Pin('DAP2_SCLK')
87 I02 = Pin('DAP2_FS')
88 I01 = Pin('DAP2_DIN')
89 I00 = Pin('DAP2_DOUT')
90 N01 = Pin('SOC_GPIO54')
91 BB00 = Pin('CAN1_STB')
92 H00 = Pin('SOC_GPIO12')
93 Q01 = Pin('SOC_GPIO21')
94 AA01 = Pin('CAN1_DIN')
95 R00 = Pin('SOC_GPIO44')
96
97 i2cPorts = (
98     (8, SCL, SDA), (1, SCL_1, SDA_1),
99 )
100
101 # ordered as spiId, sckId, mosiId, misoId
102 spiPorts = ((0, Z03, Z05, Z04), )