]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/am335x/pin.py
[am335x] added NonGPIO pins as comments
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / am335x / pin.py
1 import Adafruit_BBIO.GPIO as GPIO
2
3 # Pins dont exist in CPython so...lets make our own!
4 class Pin:
5     IN = 0
6     OUT = 1
7     LOW = 0
8     HIGH = 1
9     PULL_NONE = 0
10     PULL_UP = 1
11     PULL_DOWN = 2
12
13     id = None
14     _value = LOW
15     _mode = IN
16
17     def __init__(self, pin_name):
18         self.id = pin_name
19
20     def __repr__(self):
21         return str(self.id)
22
23     def __eq__(self, other):
24         return self.id == other
25
26     def init(self, mode=IN, pull=None):
27         if mode != None:
28             if mode == self.IN:
29                 self._mode = self.IN
30                 GPIO.setup(self.id, GPIO.IN)
31             elif mode == self.OUT:
32                 self._mode = self.OUT
33                 GPIO.setup(self.id, GPIO.OUT)
34             else:
35                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
36         if pull != None:
37             if self._mode != self.IN:
38                 raise RuntimeError("Cannot set pull resistor on output")
39             if pull == self.PULL_UP:
40                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
41             elif pull == self.PULL_DOWN:
42                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
43             else:
44                 raise RuntimeError("Invalid pull for pin: %s" % self.id)
45
46     def value(self, val=None):
47         if val != None:
48             if val == self.LOW:
49                 self._value = val
50                 GPIO.output(self.id, val)
51             elif val == self.HIGH:
52                 self._value = val
53                 GPIO.output(self.id, val)
54             else:
55                 raise RuntimeError("Invalid value for pin")
56         else:
57             return GPIO.input(self.id)
58
59
60 # PocketBeagle
61 # P1_1 = SYS VIN
62 P1_2 = Pin('P1_2')
63 P1_3 = Pin('P1_3')
64 P1_4 = Pin('P1_4')
65 # P1_5 = USB VBUS
66 P1_6 = Pin('P1_6')
67 # P1_7 = USB VIN
68 P1_8 = Pin('P1_8')
69 # P1_9 = USB DN
70 P1_10 = Pin('P1_10')
71 # P1_11 = USB DP
72 P1_12 = Pin('P1_12')
73 # P1_13 = USB ID
74 # P1_14 = SYS 3.3V
75 # P1_15 = SYS GND
76 # P1_16 = SYS GND
77 # P1_17 = AIN 1.8V REF-
78 # P1_18 = AIN 1.8V REF+
79 P1_19 = Pin('P1_19')
80 P1_20 = Pin('P1_20')
81 P1_21 = Pin('P1_21')
82 # P1_22 = SYS GND
83 P1_23 = Pin('P1_23')
84 # P1_22 = SYS VOUT
85 P1_25 = Pin('P1_25')
86 P1_26 = Pin('P1_26')
87 P1_27 = Pin('P1_27')
88 P1_28 = Pin('P1_28')
89 P1_29 = Pin('P1_29')
90 P1_30 = Pin('P1_30')
91 P1_31 = Pin('P1_31')
92 P1_32 = Pin('P1_32')
93 P1_33 = Pin('P1_33')
94 P1_34 = Pin('P1_34')
95 P1_35 = Pin('P1_35')
96 P1_36 = Pin('P1_36')
97
98
99 P2_1 = Pin('P2_1')
100 P2_2 = Pin('P2_2')
101 P2_3 = Pin('P2_3')
102 P2_4 = Pin('P2_4')
103 P2_5 = Pin('P2_5')
104 P2_6 = Pin('P2_6')
105 P2_7 = Pin('P2_7')
106 P2_8 = Pin('P2_8')
107 P2_9 = Pin('P2_9')
108 P2_10 = Pin('P2_10')
109 P2_11 = Pin('P2_11')
110 # P2_12 = SYS  PWR BTN
111 # P2_13 = SYS VOUT
112 # P2_14 = BAT VIN
113 # P2_15 = SYS GND
114 # P2_16 = BAT TEMP
115 P2_17 = Pin('P2_17')
116 P2_18 = Pin('P2_18')
117 P2_19 = Pin('P2_19')
118 P2_20 = Pin('P2_20')
119 # P2_21 = SYS GND
120 P2_22 = Pin('P2_22')
121 # P2_23 = SYS 3.3V
122 P2_24 = Pin('P2_24')
123 P2_25 = Pin('P2_25')
124 # P2_26 = SYS NRST
125 P2_27 = Pin('P2_27')
126 P2_28 = Pin('P2_28')
127 P2_29 = Pin('P2_29')
128 P2_30 = Pin('P2_30')
129 P2_31 = Pin('P2_31')
130 P2_32 = Pin('P2_32')
131 P2_33 = Pin('P2_33')
132 P2_34 = Pin('P2_34')
133 P2_35 = Pin('P2_35')
134 P2_36 = Pin('P2_36')
135
136
137 # BeagleBone Black
138 # P8_1 = ?
139 # P8_2 = ?
140 P8_3 = Pin('P8_3')
141 P8_4 = Pin('P8_4')
142 P8_5 = Pin('P8_5')
143 P8_6 = Pin('P8_6')
144 P8_7 = Pin('P8_7')
145 P8_8 = Pin('P8_8')
146 P8_9 = Pin('P8_9')
147 P8_10 = Pin('P8_10')
148 P8_11 = Pin('P8_11')
149 P8_12 = Pin('P8_12')
150 P8_13 = Pin('P8_13')
151 P8_14 = Pin('P8_14')
152 P8_15 = Pin('P8_15')
153 P8_16 = Pin('P8_16')
154 P8_17 = Pin('P8_17')
155 P8_18 = Pin('P8_18')
156 P8_19 = Pin('P8_19')
157 P8_20 = Pin('P8_20')
158 P8_21 = Pin('P8_21')
159 P8_22 = Pin('P8_22')
160 P8_23 = Pin('P8_23')
161 P8_24 = Pin('P8_24')
162 P8_25 = Pin('P8_25')
163 P8_26 = Pin('P8_26')
164 P8_27 = Pin('P8_27')
165 P8_28 = Pin('P8_28')
166 P8_29 = Pin('P8_29')
167 P8_30 = Pin('P8_30')
168 P8_31 = Pin('P8_31')
169 P8_32 = Pin('P8_32')
170 P8_33 = Pin('P8_33')
171 P8_34 = Pin('P8_34')
172 P8_35 = Pin('P8_35')
173 P8_36 = Pin('P8_36')
174 P8_37 = Pin('P8_37')
175 P8_38 = Pin('P8_38')
176 P8_39 = Pin('P8_39')
177 P8_40 = Pin('P8_40')
178 P8_41 = Pin('P8_41')
179 P8_42 = Pin('P8_42')
180 P8_43 = Pin('P8_43')
181 P8_44 = Pin('P8_44')
182 P8_45 = Pin('P8_45')
183 P8_46 = Pin('P8_46')
184
185 # P9_1 = ?
186 # P9_2 = ?
187 # P9_3 = ?
188 # P9_4 = ?
189 # P9_5 = ?
190 # P9_6 = ?
191 # P9_7 = ?
192 # P9_8 = ?
193 # P9_9 = ?
194 # P9_10 = ?
195 P9_11 = Pin('P9_11')
196 P9_12 = Pin('P9_12')
197 P9_13 = Pin('P9_13')
198 P9_14 = Pin('P9_14')
199 P9_15 = Pin('P9_15')
200 P9_16 = Pin('P9_16')
201 P9_17 = Pin('P9_17')
202 P9_18 = Pin('P9_18')
203 P9_19 = Pin('P9_19')
204 P9_20 = Pin('P9_20')
205 P9_21 = Pin('P9_21')
206 P9_22 = Pin('P9_22')
207 P9_23 = Pin('P9_23')
208 P9_24 = Pin('P9_24')
209 P9_25 = Pin('P9_25')
210 P9_26 = Pin('P9_26')
211 P9_27 = Pin('P9_27')
212 P9_28 = Pin('P9_28')
213 P9_29 = Pin('P9_29')
214 P9_30 = Pin('P9_30')
215 P9_31 = Pin('P9_31')
216 # P9_32 = ?
217 # P9_33 = ?
218 # P9_34 = ?
219 # P9_35 = ?
220 # P9_36 = ?
221 # P9_37 = ?
222 # P9_38 = ?
223 # P9_39 = ?
224 # P9_40 = ?
225 P9_41 = Pin('P9_41')
226 P9_42 = Pin('P9_42')
227 # P9_43 = ?
228 # P9_44 = ?
229 # P9_45 = ?
230 # P9_46 = ?
231
232 # common to all beagles
233 USR0 = Pin('USR0')
234 USR1 = Pin('USR1')
235 USR2 = Pin('USR2')
236 USR3 = Pin('USR3')
237
238 # all special functions (SPI / I2C) are moved to
239 # src/adafruit_blinka/board/beaglebone_black.py
240
241 # # ordered as spiId, sckId, mosiId, misoId
242 # spiPorts = (
243 #     (0, SCLK, MOSI, MISO),
244 #     (1, SCLK_1, MOSI_1, MISO_1)
245 # )
246 #
247 # # ordered as uartId, txId, rxId
248 # uartPorts = (
249 #     (),
250 # )
251 #
252 # i2cPorts = (
253 #     (2, SCL, SDA),
254 # )