diff options
Diffstat (limited to 'lib/usbhost/USB_Host_Shield_2.0/avrpins.h')
-rw-r--r-- | lib/usbhost/USB_Host_Shield_2.0/avrpins.h | 1130 |
1 files changed, 1130 insertions, 0 deletions
diff --git a/lib/usbhost/USB_Host_Shield_2.0/avrpins.h b/lib/usbhost/USB_Host_Shield_2.0/avrpins.h new file mode 100644 index 000000000..4e60e3a22 --- /dev/null +++ b/lib/usbhost/USB_Host_Shield_2.0/avrpins.h | |||
@@ -0,0 +1,1130 @@ | |||
1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. | ||
2 | |||
3 | This software may be distributed and modified under the terms of the GNU | ||
4 | General Public License version 2 (GPL2) as published by the Free Software | ||
5 | Foundation and appearing in the file GPL2.TXT included in the packaging of | ||
6 | this file. Please note that GPL2 Section 2[b] requires that all works based | ||
7 | on this software must also be made publicly available under the terms of | ||
8 | the GPL2 ("Copyleft"). | ||
9 | |||
10 | Contact information | ||
11 | ------------------- | ||
12 | |||
13 | Circuits At Home, LTD | ||
14 | Web : http://www.circuitsathome.com | ||
15 | e-mail : support@circuitsathome.com | ||
16 | */ | ||
17 | |||
18 | /* derived from Konstantin Chizhov's AVR port templates */ | ||
19 | |||
20 | #if !defined(_usb_h_) || defined(_avrpins_h_) | ||
21 | #error "Never include avrpins.h directly; include Usb.h instead" | ||
22 | #else | ||
23 | #define _avrpins_h_ | ||
24 | |||
25 | #if defined(__AVR__) | ||
26 | |||
27 | // pointers are 16 bits on AVR | ||
28 | #define pgm_read_pointer(p) pgm_read_word(p) | ||
29 | |||
30 | // Support for these boards needs to be manually activated in settings.h or in a makefile | ||
31 | #if !defined(BOARD_MEGA_ADK) && defined(__AVR_ATmega2560__) && (USE_UHS_MEGA_ADK || defined(ARDUINO_AVR_ADK)) | ||
32 | #define BOARD_MEGA_ADK | ||
33 | #elif !defined(BOARD_BLACK_WIDDOW) && USE_UHS_BLACK_WIDDOW | ||
34 | #define BOARD_BLACK_WIDDOW | ||
35 | #endif | ||
36 | |||
37 | #ifdef PORTA | ||
38 | #define USE_PORTA | ||
39 | #endif | ||
40 | #ifdef PORTB | ||
41 | #define USE_PORTB | ||
42 | #endif | ||
43 | #ifdef PORTC | ||
44 | #define USE_PORTC | ||
45 | #endif | ||
46 | #ifdef PORTD | ||
47 | #define USE_PORTD | ||
48 | #endif | ||
49 | #ifdef PORTE | ||
50 | #define USE_PORTE | ||
51 | #endif | ||
52 | #ifdef PORTF | ||
53 | #define USE_PORTF | ||
54 | #endif | ||
55 | #ifdef PORTG | ||
56 | #define USE_PORTG | ||
57 | #endif | ||
58 | #ifdef PORTH | ||
59 | #define USE_PORTH | ||
60 | #endif | ||
61 | #ifdef PORTJ | ||
62 | #define USE_PORTJ | ||
63 | #endif | ||
64 | #ifdef PORTK | ||
65 | #define USE_PORTK | ||
66 | #endif | ||
67 | #ifdef PORTL | ||
68 | #define USE_PORTL | ||
69 | #endif | ||
70 | #ifdef PORTQ | ||
71 | #define USE_PORTQ | ||
72 | #endif | ||
73 | #ifdef PORTR | ||
74 | #define USE_PORTR | ||
75 | #endif | ||
76 | |||
77 | #ifdef TCCR0A | ||
78 | #define USE_TCCR0A | ||
79 | #endif | ||
80 | #ifdef TCCR1A | ||
81 | #define USE_TCCR1A | ||
82 | #endif | ||
83 | #ifdef TCCR2A | ||
84 | #define USE_TCCR2A | ||
85 | #endif | ||
86 | |||
87 | //Port definitions for AtTiny, AtMega families. | ||
88 | |||
89 | #define MAKE_PORT(portName, ddrName, pinName, className, ID) \ | ||
90 | class className{\ | ||
91 | public:\ | ||
92 | typedef uint8_t DataT;\ | ||
93 | public:\ | ||
94 | static void Write(DataT value){portName = value;}\ | ||
95 | static void ClearAndSet(DataT clearMask, DataT value){portName = (portName & ~clearMask) | value;}\ | ||
96 | static DataT Read(){return portName;}\ | ||
97 | static void DirWrite(DataT value){ddrName = value;}\ | ||
98 | static DataT DirRead(){return ddrName;}\ | ||
99 | static void Set(DataT value){portName |= value;}\ | ||
100 | static void Clear(DataT value){portName &= ~value;}\ | ||
101 | static void Toggle(DataT value){portName ^= value;}\ | ||
102 | static void DirSet(DataT value){ddrName |= value;}\ | ||
103 | static void DirClear(DataT value){ddrName &= ~value;}\ | ||
104 | static void DirToggle(DataT value){ddrName ^= value;}\ | ||
105 | static DataT PinRead(){return pinName;}\ | ||
106 | enum{Id = ID};\ | ||
107 | enum{Width=sizeof(DataT)*8};\ | ||
108 | }; | ||
109 | |||
110 | // TCCR registers to set/clear Arduino PWM | ||
111 | #define MAKE_TCCR(TccrName, className) \ | ||
112 | class className{\ | ||
113 | public:\ | ||
114 | typedef uint8_t DataT;\ | ||
115 | public:\ | ||
116 | static void Write(DataT value){TccrName = value;}\ | ||
117 | static void ClearAndSet(DataT clearMask, DataT value){TccrName = (TccrName & ~clearMask) | value;}\ | ||
118 | static DataT Read(){return TccrName;}\ | ||
119 | static void Set(DataT value){TccrName |= value;}\ | ||
120 | static void Clear(DataT value){TccrName &= ~value;}\ | ||
121 | static void Toggle(DataT value){TccrName ^= value;}\ | ||
122 | enum{Width=sizeof(DataT)*8};\ | ||
123 | }; | ||
124 | |||
125 | #ifdef USE_PORTA | ||
126 | |||
127 | MAKE_PORT(PORTA, DDRA, PINA, Porta, 'A') | ||
128 | #endif | ||
129 | #ifdef USE_PORTB | ||
130 | MAKE_PORT(PORTB, DDRB, PINB, Portb, 'B') | ||
131 | #endif | ||
132 | #ifdef USE_PORTC | ||
133 | MAKE_PORT(PORTC, DDRC, PINC, Portc, 'C') | ||
134 | #endif | ||
135 | #ifdef USE_PORTD | ||
136 | MAKE_PORT(PORTD, DDRD, PIND, Portd, 'D') | ||
137 | #endif | ||
138 | #ifdef USE_PORTE | ||
139 | MAKE_PORT(PORTE, DDRE, PINE, Porte, 'E') | ||
140 | #endif | ||
141 | #ifdef USE_PORTF | ||
142 | MAKE_PORT(PORTF, DDRF, PINF, Portf, 'F') | ||
143 | #endif | ||
144 | #ifdef USE_PORTG | ||
145 | MAKE_PORT(PORTG, DDRG, PING, Portg, 'G') | ||
146 | #endif | ||
147 | #ifdef USE_PORTH | ||
148 | MAKE_PORT(PORTH, DDRH, PINH, Porth, 'H') | ||
149 | #endif | ||
150 | #ifdef USE_PORTJ | ||
151 | MAKE_PORT(PORTJ, DDRJ, PINJ, Portj, 'J') | ||
152 | #endif | ||
153 | #ifdef USE_PORTK | ||
154 | MAKE_PORT(PORTK, DDRK, PINK, Portk, 'K') | ||
155 | #endif | ||
156 | #ifdef USE_PORTL | ||
157 | MAKE_PORT(PORTL, DDRL, PINL, Portl, 'L') | ||
158 | #endif | ||
159 | #ifdef USE_PORTQ | ||
160 | MAKE_PORT(PORTQ, DDRQ, PINQ, Portq, 'Q') | ||
161 | #endif | ||
162 | #ifdef USE_PORTR | ||
163 | MAKE_PORT(PORTR, DDRR, PINR, Portr, 'R') | ||
164 | #endif | ||
165 | |||
166 | #ifdef USE_TCCR0A | ||
167 | MAKE_TCCR(TCCR0A, Tccr0a) | ||
168 | #endif | ||
169 | #ifdef USE_TCCR1A | ||
170 | MAKE_TCCR(TCCR1A, Tccr1a) | ||
171 | #endif | ||
172 | #ifdef USE_TCCR2A | ||
173 | MAKE_TCCR(TCCR2A, Tccr2a) | ||
174 | #endif | ||
175 | |||
176 | // this class represents one pin in a IO port. | ||
177 | // It is fully static. | ||
178 | template<typename PORT, uint8_t PIN> | ||
179 | class TPin { | ||
180 | // BOOST_STATIC_ASSERT(PIN < PORT::Width); | ||
181 | public: | ||
182 | typedef PORT Port; | ||
183 | |||
184 | enum { | ||
185 | Number = PIN | ||
186 | }; | ||
187 | |||
188 | static void Set() { | ||
189 | PORT::Set(1 << PIN); | ||
190 | } | ||
191 | |||
192 | static void Set(uint8_t val) { | ||
193 | if(val) | ||
194 | Set(); | ||
195 | else Clear(); | ||
196 | } | ||
197 | |||
198 | static void SetDir(uint8_t val) { | ||
199 | if(val) | ||
200 | SetDirWrite(); | ||
201 | else SetDirRead(); | ||
202 | } | ||
203 | |||
204 | static void Clear() { | ||
205 | PORT::Clear(1 << PIN); | ||
206 | } | ||
207 | |||
208 | static void Toggle() { | ||
209 | PORT::Toggle(1 << PIN); | ||
210 | } | ||
211 | |||
212 | static void SetDirRead() { | ||
213 | PORT::DirClear(1 << PIN); | ||
214 | } | ||
215 | |||
216 | static void SetDirWrite() { | ||
217 | PORT::DirSet(1 << PIN); | ||
218 | } | ||
219 | |||
220 | static uint8_t IsSet() { | ||
221 | return PORT::PinRead() & (uint8_t)(1 << PIN); | ||
222 | } | ||
223 | |||
224 | static void WaiteForSet() { | ||
225 | while(IsSet() == 0) { | ||
226 | } | ||
227 | } | ||
228 | |||
229 | static void WaiteForClear() { | ||
230 | while(IsSet()) { | ||
231 | } | ||
232 | } | ||
233 | }; //class TPin... | ||
234 | |||
235 | // this class represents one bit in TCCR port. | ||
236 | // used to set/clear TCCRx bits | ||
237 | // It is fully static. | ||
238 | |||
239 | template<typename TCCR, uint8_t COM> | ||
240 | class TCom { | ||
241 | // BOOST_STATIC_ASSERT(PIN < PORT::Width); | ||
242 | public: | ||
243 | typedef TCCR Tccr; | ||
244 | |||
245 | enum { | ||
246 | Com = COM | ||
247 | }; | ||
248 | |||
249 | static void Set() { | ||
250 | TCCR::Set(1 << COM); | ||
251 | } | ||
252 | |||
253 | static void Clear() { | ||
254 | TCCR::Clear(1 << COM); | ||
255 | } | ||
256 | |||
257 | static void Toggle() { | ||
258 | TCCR::Toggle(1 << COM); | ||
259 | } | ||
260 | }; //class TCom... | ||
261 | |||
262 | //Short pin definitions | ||
263 | #ifdef USE_PORTA | ||
264 | typedef TPin<Porta, 0 > Pa0; | ||
265 | typedef TPin<Porta, 1 > Pa1; | ||
266 | typedef TPin<Porta, 2 > Pa2; | ||
267 | typedef TPin<Porta, 3 > Pa3; | ||
268 | typedef TPin<Porta, 4 > Pa4; | ||
269 | typedef TPin<Porta, 5 > Pa5; | ||
270 | typedef TPin<Porta, 6 > Pa6; | ||
271 | typedef TPin<Porta, 7 > Pa7; | ||
272 | #endif | ||
273 | |||
274 | #ifdef USE_PORTB | ||
275 | typedef TPin<Portb, 0 > Pb0; | ||
276 | typedef TPin<Portb, 1 > Pb1; | ||
277 | typedef TPin<Portb, 2 > Pb2; | ||
278 | typedef TPin<Portb, 3 > Pb3; | ||
279 | typedef TPin<Portb, 4 > Pb4; | ||
280 | typedef TPin<Portb, 5 > Pb5; | ||
281 | typedef TPin<Portb, 6 > Pb6; | ||
282 | typedef TPin<Portb, 7 > Pb7; | ||
283 | #endif | ||
284 | |||
285 | #ifdef USE_PORTC | ||
286 | typedef TPin<Portc, 0 > Pc0; | ||
287 | typedef TPin<Portc, 1 > Pc1; | ||
288 | typedef TPin<Portc, 2 > Pc2; | ||
289 | typedef TPin<Portc, 3 > Pc3; | ||
290 | typedef TPin<Portc, 4 > Pc4; | ||
291 | typedef TPin<Portc, 5 > Pc5; | ||
292 | typedef TPin<Portc, 6 > Pc6; | ||
293 | typedef TPin<Portc, 7 > Pc7; | ||
294 | #endif | ||
295 | |||
296 | #ifdef USE_PORTD | ||
297 | typedef TPin<Portd, 0 > Pd0; | ||
298 | typedef TPin<Portd, 1 > Pd1; | ||
299 | typedef TPin<Portd, 2 > Pd2; | ||
300 | typedef TPin<Portd, 3 > Pd3; | ||
301 | typedef TPin<Portd, 4 > Pd4; | ||
302 | typedef TPin<Portd, 5 > Pd5; | ||
303 | typedef TPin<Portd, 6 > Pd6; | ||
304 | typedef TPin<Portd, 7 > Pd7; | ||
305 | #endif | ||
306 | |||
307 | #ifdef USE_PORTE | ||
308 | typedef TPin<Porte, 0 > Pe0; | ||
309 | typedef TPin<Porte, 1 > Pe1; | ||
310 | typedef TPin<Porte, 2 > Pe2; | ||
311 | typedef TPin<Porte, 3 > Pe3; | ||
312 | typedef TPin<Porte, 4 > Pe4; | ||
313 | typedef TPin<Porte, 5 > Pe5; | ||
314 | typedef TPin<Porte, 6 > Pe6; | ||
315 | typedef TPin<Porte, 7 > Pe7; | ||
316 | #endif | ||
317 | |||
318 | #ifdef USE_PORTF | ||
319 | typedef TPin<Portf, 0 > Pf0; | ||
320 | typedef TPin<Portf, 1 > Pf1; | ||
321 | typedef TPin<Portf, 2 > Pf2; | ||
322 | typedef TPin<Portf, 3 > Pf3; | ||
323 | typedef TPin<Portf, 4 > Pf4; | ||
324 | typedef TPin<Portf, 5 > Pf5; | ||
325 | typedef TPin<Portf, 6 > Pf6; | ||
326 | typedef TPin<Portf, 7 > Pf7; | ||
327 | #endif | ||
328 | |||
329 | #ifdef USE_PORTG | ||
330 | typedef TPin<Portg, 0 > Pg0; | ||
331 | typedef TPin<Portg, 1 > Pg1; | ||
332 | typedef TPin<Portg, 2 > Pg2; | ||
333 | typedef TPin<Portg, 3 > Pg3; | ||
334 | typedef TPin<Portg, 4 > Pg4; | ||
335 | typedef TPin<Portg, 5 > Pg5; | ||
336 | typedef TPin<Portg, 6 > Pg6; | ||
337 | typedef TPin<Portg, 7 > Pg7; | ||
338 | #endif | ||
339 | |||
340 | #ifdef USE_PORTH | ||
341 | typedef TPin<Porth, 0 > Ph0; | ||
342 | typedef TPin<Porth, 1 > Ph1; | ||
343 | typedef TPin<Porth, 2 > Ph2; | ||
344 | typedef TPin<Porth, 3 > Ph3; | ||
345 | typedef TPin<Porth, 4 > Ph4; | ||
346 | typedef TPin<Porth, 5 > Ph5; | ||
347 | typedef TPin<Porth, 6 > Ph6; | ||
348 | typedef TPin<Porth, 7 > Ph7; | ||
349 | #endif | ||
350 | |||
351 | #ifdef USE_PORTJ | ||
352 | typedef TPin<Portj, 0 > Pj0; | ||
353 | typedef TPin<Portj, 1 > Pj1; | ||
354 | typedef TPin<Portj, 2 > Pj2; | ||
355 | typedef TPin<Portj, 3 > Pj3; | ||
356 | typedef TPin<Portj, 4 > Pj4; | ||
357 | typedef TPin<Portj, 5 > Pj5; | ||
358 | typedef TPin<Portj, 6 > Pj6; | ||
359 | typedef TPin<Portj, 7 > Pj7; | ||
360 | #endif | ||
361 | |||
362 | #ifdef USE_PORTK | ||
363 | typedef TPin<Portk, 0 > Pk0; | ||
364 | typedef TPin<Portk, 1 > Pk1; | ||
365 | typedef TPin<Portk, 2 > Pk2; | ||
366 | typedef TPin<Portk, 3 > Pk3; | ||
367 | typedef TPin<Portk, 4 > Pk4; | ||
368 | typedef TPin<Portk, 5 > Pk5; | ||
369 | typedef TPin<Portk, 6 > Pk6; | ||
370 | typedef TPin<Portk, 7 > Pk7; | ||
371 | #endif | ||
372 | |||
373 | #ifdef USE_PORTL | ||
374 | typedef TPin<Portl, 0 > Pl0; | ||
375 | typedef TPin<Portl, 1 > Pl1; | ||
376 | typedef TPin<Portl, 2 > Pl2; | ||
377 | typedef TPin<Portl, 3 > Pl3; | ||
378 | typedef TPin<Portl, 4 > Pl4; | ||
379 | typedef TPin<Portl, 5 > Pl5; | ||
380 | typedef TPin<Portl, 6 > Pl6; | ||
381 | typedef TPin<Portl, 7 > Pl7; | ||
382 | #endif | ||
383 | |||
384 | #ifdef USE_PORTQ | ||
385 | typedef TPin<Portq, 0 > Pq0; | ||
386 | typedef TPin<Portq, 1 > Pq1; | ||
387 | typedef TPin<Portq, 2 > Pq2; | ||
388 | typedef TPin<Portq, 3 > Pq3; | ||
389 | typedef TPin<Portq, 4 > Pq4; | ||
390 | typedef TPin<Portq, 5 > Pq5; | ||
391 | typedef TPin<Portq, 6 > Pq6; | ||
392 | typedef TPin<Portq, 7 > Pq7; | ||
393 | #endif | ||
394 | |||
395 | #ifdef USE_PORTR | ||
396 | typedef TPin<Portr, 0 > Pr0; | ||
397 | typedef TPin<Portr, 1 > Pr1; | ||
398 | typedef TPin<Portr, 2 > Pr2; | ||
399 | typedef TPin<Portr, 3 > Pr3; | ||
400 | typedef TPin<Portr, 4 > Pr4; | ||
401 | typedef TPin<Portr, 5 > Pr5; | ||
402 | typedef TPin<Portr, 6 > Pr6; | ||
403 | typedef TPin<Portr, 7 > Pr7; | ||
404 | #endif | ||
405 | |||
406 | #ifdef USE_TCCR0A | ||
407 | typedef TCom<Tccr0a, COM0A1> Tc0a; //P6 | ||
408 | typedef TCom<Tccr0a, COM0B1> Tc0b; //P5 | ||
409 | #endif | ||
410 | |||
411 | #ifdef USE_TCCR1A | ||
412 | typedef TCom<Tccr1a, COM1A1> Tc1a; //P9 | ||
413 | typedef TCom<Tccr1a, COM1B1> Tc1b; //P10 | ||
414 | #endif | ||
415 | |||
416 | #ifdef USE_TCCR2A | ||
417 | typedef TCom<Tccr2a, COM2A1> Tc2a; //P11 | ||
418 | typedef TCom<Tccr2a, COM2B1> Tc2b; //P3 | ||
419 | #endif | ||
420 | |||
421 | template<typename Tp_pin, typename Tc_bit> | ||
422 | class Tp_Tc { | ||
423 | public: | ||
424 | |||
425 | static void SetDir(uint8_t val) { | ||
426 | if(val) | ||
427 | SetDirWrite(); | ||
428 | else SetDirRead(); | ||
429 | } | ||
430 | |||
431 | static void SetDirRead() { | ||
432 | Tp_pin::SetDirRead(); //set pin direction | ||
433 | Tc_bit::Clear(); //disconnect pin from PWM | ||
434 | } | ||
435 | |||
436 | static void SetDirWrite() { | ||
437 | Tp_pin::SetDirWrite(); | ||
438 | Tc_bit::Clear(); | ||
439 | } | ||
440 | }; | ||
441 | |||
442 | /* pin definitions for cases where it's necessary to clear compare output mode bits */ | ||
443 | |||
444 | //typedef Tp_Tc<Pd3, Tc2b> P3; //Arduino pin 3 | ||
445 | //typedef Tp_Tc<Pd5, Tc0b> P5; //Arduino pin 5 | ||
446 | //typedef Tp_Tc<Pd6, Tc0a> P6; //Arduino pin 6 | ||
447 | //typedef Tp_Tc<Pb1, Tc1a> P9; //Arduino pin 9 | ||
448 | //typedef Tp_Tc<Pb2, Tc1b> P10; //Arduino pin 10 | ||
449 | //typedef Tp_Tc<Pb3, Tc2a> P11; //Arduino pin 11 | ||
450 | |||
451 | /* Arduino pin definitions */ | ||
452 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) | ||
453 | // "Mega" Arduino pin numbers | ||
454 | |||
455 | #define P0 Pe0 | ||
456 | #define P1 Pe1 | ||
457 | #define P2 Pe4 | ||
458 | #define P3 Pe5 | ||
459 | #define P4 Pg5 | ||
460 | #define P5 Pe3 | ||
461 | #define P6 Ph3 | ||
462 | #define P7 Ph4 | ||
463 | |||
464 | #define P8 Ph5 | ||
465 | #define P9 Ph6 | ||
466 | #define P10 Pb4 | ||
467 | #define P11 Pb5 | ||
468 | #define P12 Pb6 | ||
469 | #define P13 Pb7 | ||
470 | |||
471 | #define P14 Pj1 | ||
472 | #define P15 Pj0 | ||
473 | #define P16 Ph1 | ||
474 | #define P17 Ph0 | ||
475 | #define P18 Pd3 | ||
476 | #define P19 Pd2 | ||
477 | #define P20 Pd1 | ||
478 | #define P21 Pd0 | ||
479 | |||
480 | #define P22 Pa0 | ||
481 | #define P23 Pa1 | ||
482 | #define P24 Pa2 | ||
483 | #define P25 Pa3 | ||
484 | #define P26 Pa4 | ||
485 | #define P27 Pa5 | ||
486 | #define P28 Pa6 | ||
487 | #define P29 Pa7 | ||
488 | #define P30 Pc7 | ||
489 | #define P31 Pc6 | ||
490 | #define P32 Pc5 | ||
491 | #define P33 Pc4 | ||
492 | #define P34 Pc3 | ||
493 | #define P35 Pc2 | ||
494 | #define P36 Pc1 | ||
495 | #define P37 Pc0 | ||
496 | |||
497 | #define P38 Pd7 | ||
498 | #define P39 Pg2 | ||
499 | #define P40 Pg1 | ||
500 | #define P41 Pg0 | ||
501 | #define P42 Pl7 | ||
502 | #define P43 Pl6 | ||
503 | #define P44 Pl5 | ||
504 | #define P45 Pl4 | ||
505 | #define P46 Pl3 | ||
506 | #define P47 Pl2 | ||
507 | #define P48 Pl1 | ||
508 | #define P49 Pl0 | ||
509 | #define P50 Pb3 | ||
510 | #define P51 Pb2 | ||
511 | #define P52 Pb1 | ||
512 | #define P53 Pb0 | ||
513 | |||
514 | #ifdef BOARD_MEGA_ADK // These pins are not broken out on the Arduino ADK | ||
515 | #define P54 Pe6 // INT on Arduino ADK | ||
516 | #define P55 Pj2 // MAX_RESET on Arduino ADK | ||
517 | #endif | ||
518 | |||
519 | // "Mega" pin numbers | ||
520 | |||
521 | #elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) | ||
522 | // "Classic" Arduino pin numbers | ||
523 | |||
524 | #define P0 Pd0 | ||
525 | #define P1 Pd1 | ||
526 | #define P2 Pd2 | ||
527 | #define P3 Pd3 | ||
528 | #define P4 Pd4 | ||
529 | #define P5 Pd5 | ||
530 | #define P6 Pd6 | ||
531 | #define P7 Pd7 | ||
532 | |||
533 | #define P8 Pb0 | ||
534 | #define P9 Pb1 | ||
535 | #define P10 Pb2 | ||
536 | #define P11 Pb3 | ||
537 | #define P12 Pb4 | ||
538 | #define P13 Pb5 | ||
539 | |||
540 | #define P14 Pc0 | ||
541 | #define P15 Pc1 | ||
542 | #define P16 Pc2 | ||
543 | #define P17 Pc3 | ||
544 | #define P18 Pc4 | ||
545 | #define P19 Pc5 | ||
546 | |||
547 | // "Classic" Arduino pin numbers | ||
548 | |||
549 | #elif defined(CORE_TEENSY) && defined(__AVR_ATmega32U4__) | ||
550 | // Teensy 2.0 pin numbers | ||
551 | // http://www.pjrc.com/teensy/pinout.html | ||
552 | #define P0 Pb0 | ||
553 | #define P1 Pb1 | ||
554 | #define P2 Pb2 | ||
555 | #define P3 Pb3 | ||
556 | #define P4 Pb7 | ||
557 | #define P5 Pd0 | ||
558 | #define P6 Pd1 | ||
559 | #define P7 Pd2 | ||
560 | #define P8 Pd3 | ||
561 | #define P9 Pc6 | ||
562 | #define P10 Pc7 | ||
563 | #define P11 Pd6 | ||
564 | #define P12 Pd7 | ||
565 | #define P13 Pb4 | ||
566 | #define P14 Pb5 | ||
567 | #define P15 Pb6 | ||
568 | #define P16 Pf7 | ||
569 | #define P17 Pf6 | ||
570 | #define P18 Pf5 | ||
571 | #define P19 Pf4 | ||
572 | #define P20 Pf1 | ||
573 | #define P21 Pf0 | ||
574 | #define P22 Pd4 | ||
575 | #define P23 Pd5 | ||
576 | #define P24 Pe6 | ||
577 | // Teensy 2.0 | ||
578 | |||
579 | #elif defined(__AVR_ATmega32U4__) | ||
580 | // Arduino Leonardo pin numbers | ||
581 | |||
582 | #define P0 Pd2 // D0 - PD2 | ||
583 | #define P1 Pd3 // D1 - PD3 | ||
584 | #define P2 Pd1 // D2 - PD1 | ||
585 | #define P3 Pd0 // D3 - PD0 | ||
586 | #define P4 Pd4 // D4 - PD4 | ||
587 | #define P5 Pc6 // D5 - PC6 | ||
588 | #define P6 Pd7 // D6 - PD7 | ||
589 | #define P7 Pe6 // D7 - PE6 | ||
590 | |||
591 | #define P8 Pb4 // D8 - PB4 | ||
592 | #define P9 Pb5 // D9 - PB5 | ||
593 | #define P10 Pb6 // D10 - PB6 | ||
594 | #define P11 Pb7 // D11 - PB7 | ||
595 | #define P12 Pd6 // D12 - PD6 | ||
596 | #define P13 Pc7 // D13 - PC7 | ||
597 | |||
598 | #define P14 Pb3 // D14 - MISO - PB3 | ||
599 | #define P15 Pb1 // D15 - SCK - PB1 | ||
600 | #define P16 Pb2 // D16 - MOSI - PB2 | ||
601 | #define P17 Pb0 // D17 - SS - PB0 | ||
602 | |||
603 | #define P18 Pf7 // D18 - A0 - PF7 | ||
604 | #define P19 Pf6 // D19 - A1 - PF6 | ||
605 | #define P20 Pf5 // D20 - A2 - PF5 | ||
606 | #define P21 Pf4 // D21 - A3 - PF4 | ||
607 | #define P22 Pf1 // D22 - A4 - PF1 | ||
608 | #define P23 Pf0 // D23 - A5 - PF0 | ||
609 | |||
610 | #define P24 Pd4 // D24 / D4 - A6 - PD4 | ||
611 | #define P25 Pd7 // D25 / D6 - A7 - PD7 | ||
612 | #define P26 Pb4 // D26 / D8 - A8 - PB4 | ||
613 | #define P27 Pb5 // D27 / D9 - A9 - PB5 | ||
614 | #define P28 Pb6 // D28 / D10 - A10 - PB6 | ||
615 | #define P29 Pd6 // D29 / D12 - A11 - PD6 | ||
616 | |||
617 | // Arduino Leonardo pin numbers | ||
618 | |||
619 | #elif defined(CORE_TEENSY) && (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)) | ||
620 | // Teensy++ 1.0 and 2.0 pin numbers | ||
621 | // http://www.pjrc.com/teensy/pinout.html | ||
622 | #define P0 Pd0 | ||
623 | #define P1 Pd1 | ||
624 | #define P2 Pd2 | ||
625 | #define P3 Pd3 | ||
626 | #define P4 Pd4 | ||
627 | #define P5 Pd5 | ||
628 | #define P6 Pd6 | ||
629 | #define P7 Pd7 | ||
630 | #define P8 Pe0 | ||
631 | #define P9 Pe1 | ||
632 | #define P10 Pc0 | ||
633 | #define P11 Pc1 | ||
634 | #define P12 Pc2 | ||
635 | #define P13 Pc3 | ||
636 | #define P14 Pc4 | ||
637 | #define P15 Pc5 | ||
638 | #define P16 Pc6 | ||
639 | #define P17 Pc7 | ||
640 | #define P18 Pe6 | ||
641 | #define P19 Pe7 | ||
642 | #define P20 Pb0 | ||
643 | #define P21 Pb1 | ||
644 | #define P22 Pb2 | ||
645 | #define P23 Pb3 | ||
646 | #define P24 Pb4 | ||
647 | #define P25 Pb5 | ||
648 | #define P26 Pb6 | ||
649 | #define P27 Pb7 | ||
650 | #define P28 Pa0 | ||
651 | #define P29 Pa1 | ||
652 | #define P30 Pa2 | ||
653 | #define P31 Pa3 | ||
654 | #define P32 Pa4 | ||
655 | #define P33 Pa5 | ||
656 | #define P34 Pa6 | ||
657 | #define P35 Pa7 | ||
658 | #define P36 Pe4 | ||
659 | #define P37 Pe5 | ||
660 | #define P38 Pf0 | ||
661 | #define P39 Pf1 | ||
662 | #define P40 Pf2 | ||
663 | #define P41 Pf3 | ||
664 | #define P42 Pf4 | ||
665 | #define P43 Pf5 | ||
666 | #define P44 Pf6 | ||
667 | #define P45 Pf7 | ||
668 | // Teensy++ 1.0 and 2.0 | ||
669 | |||
670 | #elif defined(ARDUINO_AVR_BALANDUINO) && (defined(__AVR_ATmega644__) || defined(__AVR_ATmega1284P__)) | ||
671 | // Balanduino pin numbers | ||
672 | // http://balanduino.net/ | ||
673 | #define P0 Pd0 /* 0 - PD0 */ | ||
674 | #define P1 Pd1 /* 1 - PD1 */ | ||
675 | |||
676 | #if BALANDUINO_REVISION < 13 | ||
677 | #define P2 Pb2 /* 2 - PB2 */ | ||
678 | #define P3 Pd6 /* 3 - PD6 */ | ||
679 | #define P4 Pd7 /* 4 - PD7 */ | ||
680 | #define P5 Pb3 /* 5 - PB3 */ | ||
681 | #else | ||
682 | #define P2 Pd2 /* 2 - PD2 */ | ||
683 | #define P3 Pd3 /* 3 - PD3 */ | ||
684 | #define P4 Pd6 /* 4 - PD6 */ | ||
685 | #define P5 Pd7 /* 5 - PD7 */ | ||
686 | #endif | ||
687 | |||
688 | #define P6 Pb4 /* 6 - PB4 */ | ||
689 | #define P7 Pa0 /* 7 - PA0 */ | ||
690 | #define P8 Pa1 /* 8 - PA1 */ | ||
691 | #define P9 Pa2 /* 9 - PA2 */ | ||
692 | #define P10 Pa3 /* 10 - PA3 */ | ||
693 | #define P11 Pa4 /* 11 - PA4 */ | ||
694 | #define P12 Pa5 /* 12 - PA5 */ | ||
695 | #define P13 Pc1 /* 13 - PC1 */ | ||
696 | #define P14 Pc0 /* 14 - PC0 */ | ||
697 | |||
698 | #if BALANDUINO_REVISION < 13 | ||
699 | #define P15 Pd2 /* 15 - PD2 */ | ||
700 | #define P16 Pd3 /* 16 - PD3 */ | ||
701 | #else | ||
702 | #define P15 Pb2 /* 15 - PB2 */ | ||
703 | #define P16 Pb3 /* 16 - PB2 */ | ||
704 | #endif | ||
705 | |||
706 | #define P17 Pd4 /* 17 - PD4 */ | ||
707 | #define P18 Pd5 /* 18 - PD5 */ | ||
708 | #define P19 Pc2 /* 19 - PC2 */ | ||
709 | #define P20 Pc3 /* 20 - PC3 */ | ||
710 | #define P21 Pc4 /* 21 - PC4 */ | ||
711 | #define P22 Pc5 /* 22 - PC5 */ | ||
712 | #define P23 Pc6 /* 23 - PC6 */ | ||
713 | #define P24 Pc7 /* 24 - PC7 */ | ||
714 | #define P25 Pb0 /* 25 - PB0 */ | ||
715 | #define P26 Pb1 /* 26 - PB1 */ | ||
716 | #define P27 Pb5 /* 27 - PB5 */ | ||
717 | #define P28 Pb6 /* 28 - PB6 */ | ||
718 | #define P29 Pb7 /* 29 - PB7 */ | ||
719 | #define P30 Pa6 /* 30 - PA6 */ | ||
720 | #define P31 Pa7 /* 31 - PA7 */ | ||
721 | // Balanduino | ||
722 | |||
723 | #elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) | ||
724 | // Sanguino pin numbers | ||
725 | // Homepage: http://sanguino.cc/hardware | ||
726 | // Hardware add-on: https://github.com/Lauszus/Sanguino | ||
727 | #define P0 Pb0 | ||
728 | #define P1 Pb1 | ||
729 | #define P2 Pb2 | ||
730 | #define P3 Pb3 | ||
731 | #define P4 Pb4 | ||
732 | #define P5 Pb5 | ||
733 | #define P6 Pb6 | ||
734 | #define P7 Pb7 | ||
735 | #define P8 Pd0 | ||
736 | #define P9 Pd1 | ||
737 | #define P10 Pd2 | ||
738 | #define P11 Pd3 | ||
739 | #define P12 Pd4 | ||
740 | #define P13 Pd5 | ||
741 | #define P14 Pd6 | ||
742 | #define P15 Pd7 | ||
743 | #define P16 Pc0 | ||
744 | #define P17 Pc1 | ||
745 | #define P18 Pc2 | ||
746 | #define P19 Pc3 | ||
747 | #define P20 Pc4 | ||
748 | #define P21 Pc5 | ||
749 | #define P22 Pc6 | ||
750 | #define P23 Pc7 | ||
751 | #define P24 Pa0 | ||
752 | #define P25 Pa1 | ||
753 | #define P26 Pa2 | ||
754 | #define P27 Pa3 | ||
755 | #define P28 Pa4 | ||
756 | #define P29 Pa5 | ||
757 | #define P30 Pa6 | ||
758 | #define P31 Pa7 | ||
759 | // Sanguino | ||
760 | |||
761 | #else | ||
762 | #error "Please define board in avrpins.h" | ||
763 | |||
764 | #endif // Arduino pin definitions | ||
765 | |||
766 | #elif defined(__arm__) | ||
767 | |||
768 | // pointers are 32 bits on ARM | ||
769 | #define pgm_read_pointer(p) pgm_read_dword(p) | ||
770 | |||
771 | #if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__)) | ||
772 | |||
773 | #include "core_pins.h" | ||
774 | #include "avr_emulation.h" | ||
775 | |||
776 | #define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000) | ||
777 | #define GPIO_BITBAND_PTR(reg, bit) ((uint8_t *)GPIO_BITBAND_ADDR((reg), (bit))) | ||
778 | |||
779 | #define MAKE_PIN(className, baseReg, pinNum, configReg) \ | ||
780 | class className { \ | ||
781 | public: \ | ||
782 | static void Set() { \ | ||
783 | *GPIO_BITBAND_PTR(baseReg, pinNum) = 1; \ | ||
784 | } \ | ||
785 | static void Clear() { \ | ||
786 | *GPIO_BITBAND_PTR(baseReg, pinNum) = 0; \ | ||
787 | } \ | ||
788 | static void SetDirRead() { \ | ||
789 | configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \ | ||
790 | *(GPIO_BITBAND_PTR(baseReg, pinNum) + 640) = 0; \ | ||
791 | } \ | ||
792 | static void SetDirWrite() { \ | ||
793 | configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \ | ||
794 | *(GPIO_BITBAND_PTR(baseReg, pinNum) + 640) = 1; \ | ||
795 | } \ | ||
796 | static uint8_t IsSet() { \ | ||
797 | return *(GPIO_BITBAND_PTR(baseReg, pinNum) + 512); \ | ||
798 | } \ | ||
799 | }; | ||
800 | |||
801 | MAKE_PIN(P0, CORE_PIN0_PORTREG, CORE_PIN0_BIT, CORE_PIN0_CONFIG); | ||
802 | MAKE_PIN(P1, CORE_PIN1_PORTREG, CORE_PIN1_BIT, CORE_PIN1_CONFIG); | ||
803 | MAKE_PIN(P2, CORE_PIN2_PORTREG, CORE_PIN2_BIT, CORE_PIN2_CONFIG); | ||
804 | MAKE_PIN(P3, CORE_PIN3_PORTREG, CORE_PIN3_BIT, CORE_PIN3_CONFIG); | ||
805 | MAKE_PIN(P4, CORE_PIN4_PORTREG, CORE_PIN4_BIT, CORE_PIN4_CONFIG); | ||
806 | MAKE_PIN(P5, CORE_PIN5_PORTREG, CORE_PIN5_BIT, CORE_PIN5_CONFIG); | ||
807 | MAKE_PIN(P6, CORE_PIN6_PORTREG, CORE_PIN6_BIT, CORE_PIN6_CONFIG); | ||
808 | MAKE_PIN(P7, CORE_PIN7_PORTREG, CORE_PIN7_BIT, CORE_PIN7_CONFIG); | ||
809 | MAKE_PIN(P8, CORE_PIN8_PORTREG, CORE_PIN8_BIT, CORE_PIN8_CONFIG); | ||
810 | MAKE_PIN(P9, CORE_PIN9_PORTREG, CORE_PIN9_BIT, CORE_PIN9_CONFIG); | ||
811 | MAKE_PIN(P10, CORE_PIN10_PORTREG, CORE_PIN10_BIT, CORE_PIN10_CONFIG); | ||
812 | MAKE_PIN(P11, CORE_PIN11_PORTREG, CORE_PIN11_BIT, CORE_PIN11_CONFIG); | ||
813 | MAKE_PIN(P12, CORE_PIN12_PORTREG, CORE_PIN12_BIT, CORE_PIN12_CONFIG); | ||
814 | MAKE_PIN(P13, CORE_PIN13_PORTREG, CORE_PIN13_BIT, CORE_PIN13_CONFIG); | ||
815 | MAKE_PIN(P14, CORE_PIN14_PORTREG, CORE_PIN14_BIT, CORE_PIN14_CONFIG); | ||
816 | MAKE_PIN(P15, CORE_PIN15_PORTREG, CORE_PIN15_BIT, CORE_PIN15_CONFIG); | ||
817 | MAKE_PIN(P16, CORE_PIN16_PORTREG, CORE_PIN16_BIT, CORE_PIN16_CONFIG); | ||
818 | MAKE_PIN(P17, CORE_PIN17_PORTREG, CORE_PIN17_BIT, CORE_PIN17_CONFIG); | ||
819 | MAKE_PIN(P18, CORE_PIN18_PORTREG, CORE_PIN18_BIT, CORE_PIN18_CONFIG); | ||
820 | MAKE_PIN(P19, CORE_PIN19_PORTREG, CORE_PIN19_BIT, CORE_PIN19_CONFIG); | ||
821 | MAKE_PIN(P20, CORE_PIN20_PORTREG, CORE_PIN20_BIT, CORE_PIN20_CONFIG); | ||
822 | MAKE_PIN(P21, CORE_PIN21_PORTREG, CORE_PIN21_BIT, CORE_PIN21_CONFIG); | ||
823 | MAKE_PIN(P22, CORE_PIN22_PORTREG, CORE_PIN22_BIT, CORE_PIN22_CONFIG); | ||
824 | MAKE_PIN(P23, CORE_PIN23_PORTREG, CORE_PIN23_BIT, CORE_PIN23_CONFIG); | ||
825 | MAKE_PIN(P24, CORE_PIN24_PORTREG, CORE_PIN24_BIT, CORE_PIN24_CONFIG); | ||
826 | MAKE_PIN(P25, CORE_PIN25_PORTREG, CORE_PIN25_BIT, CORE_PIN25_CONFIG); | ||
827 | MAKE_PIN(P26, CORE_PIN26_PORTREG, CORE_PIN26_BIT, CORE_PIN26_CONFIG); | ||
828 | MAKE_PIN(P27, CORE_PIN27_PORTREG, CORE_PIN27_BIT, CORE_PIN27_CONFIG); | ||
829 | MAKE_PIN(P28, CORE_PIN28_PORTREG, CORE_PIN28_BIT, CORE_PIN28_CONFIG); | ||
830 | MAKE_PIN(P29, CORE_PIN29_PORTREG, CORE_PIN29_BIT, CORE_PIN29_CONFIG); | ||
831 | MAKE_PIN(P30, CORE_PIN30_PORTREG, CORE_PIN30_BIT, CORE_PIN30_CONFIG); | ||
832 | MAKE_PIN(P31, CORE_PIN31_PORTREG, CORE_PIN31_BIT, CORE_PIN31_CONFIG); | ||
833 | MAKE_PIN(P32, CORE_PIN32_PORTREG, CORE_PIN32_BIT, CORE_PIN32_CONFIG); | ||
834 | MAKE_PIN(P33, CORE_PIN33_PORTREG, CORE_PIN33_BIT, CORE_PIN33_CONFIG); | ||
835 | |||
836 | #undef MAKE_PIN | ||
837 | |||
838 | #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) | ||
839 | |||
840 | // SetDirRead: | ||
841 | // Disable interrupts | ||
842 | // Disable the pull up resistor | ||
843 | // Set to INPUT | ||
844 | // Enable PIO | ||
845 | |||
846 | // SetDirWrite: | ||
847 | // Disable interrupts | ||
848 | // Disable the pull up resistor | ||
849 | // Set to OUTPUT | ||
850 | // Enable PIO | ||
851 | |||
852 | #define MAKE_PIN(className, pio, pinMask) \ | ||
853 | class className { \ | ||
854 | public: \ | ||
855 | static void Set() { \ | ||
856 | pio->PIO_SODR = pinMask; \ | ||
857 | } \ | ||
858 | static void Clear() { \ | ||
859 | pio->PIO_CODR = pinMask; \ | ||
860 | } \ | ||
861 | static void SetDirRead() { \ | ||
862 | pio->PIO_IDR = pinMask ; \ | ||
863 | pio->PIO_PUDR = pinMask; \ | ||
864 | pio->PIO_ODR = pinMask; \ | ||
865 | pio->PIO_PER = pinMask; \ | ||
866 | } \ | ||
867 | static void SetDirWrite() { \ | ||
868 | pio->PIO_IDR = pinMask ; \ | ||
869 | pio->PIO_PUDR = pinMask; \ | ||
870 | pio->PIO_OER = pinMask; \ | ||
871 | pio->PIO_PER = pinMask; \ | ||
872 | } \ | ||
873 | static uint8_t IsSet() { \ | ||
874 | return pio->PIO_PDSR & pinMask; \ | ||
875 | } \ | ||
876 | }; | ||
877 | |||
878 | // See: http://arduino.cc/en/Hacking/PinMappingSAM3X and variant.cpp | ||
879 | |||
880 | MAKE_PIN(P0, PIOA, PIO_PA8); | ||
881 | MAKE_PIN(P1, PIOA, PIO_PA9); | ||
882 | MAKE_PIN(P2, PIOB, PIO_PB25); | ||
883 | MAKE_PIN(P3, PIOC, PIO_PC28); | ||
884 | MAKE_PIN(P4, PIOC, PIO_PC26); | ||
885 | MAKE_PIN(P5, PIOC, PIO_PC25); | ||
886 | MAKE_PIN(P6, PIOC, PIO_PC24); | ||
887 | MAKE_PIN(P7, PIOC, PIO_PC23); | ||
888 | MAKE_PIN(P8, PIOC, PIO_PC22); | ||
889 | MAKE_PIN(P9, PIOC, PIO_PC21); | ||
890 | MAKE_PIN(P10, PIOC, PIO_PC29); | ||
891 | MAKE_PIN(P11, PIOD, PIO_PD7); | ||
892 | MAKE_PIN(P12, PIOD, PIO_PD8); | ||
893 | MAKE_PIN(P13, PIOB, PIO_PB27); | ||
894 | MAKE_PIN(P14, PIOD, PIO_PD4); | ||
895 | MAKE_PIN(P15, PIOD, PIO_PD5); | ||
896 | MAKE_PIN(P16, PIOA, PIO_PA13); | ||
897 | MAKE_PIN(P17, PIOA, PIO_PA12); | ||
898 | MAKE_PIN(P18, PIOA, PIO_PA11); | ||
899 | MAKE_PIN(P19, PIOA, PIO_PA10); | ||
900 | MAKE_PIN(P20, PIOB, PIO_PB12); | ||
901 | MAKE_PIN(P21, PIOB, PIO_PB13); | ||
902 | MAKE_PIN(P22, PIOB, PIO_PB26); | ||
903 | MAKE_PIN(P23, PIOA, PIO_PA14); | ||
904 | MAKE_PIN(P24, PIOA, PIO_PA15); | ||
905 | MAKE_PIN(P25, PIOD, PIO_PD0); | ||
906 | MAKE_PIN(P26, PIOD, PIO_PD1); | ||
907 | MAKE_PIN(P27, PIOD, PIO_PD2); | ||
908 | MAKE_PIN(P28, PIOD, PIO_PD3); | ||
909 | MAKE_PIN(P29, PIOD, PIO_PD6); | ||
910 | MAKE_PIN(P30, PIOD, PIO_PD9); | ||
911 | MAKE_PIN(P31, PIOA, PIO_PA7); | ||
912 | MAKE_PIN(P32, PIOD, PIO_PD10); | ||
913 | MAKE_PIN(P33, PIOC, PIO_PC1); | ||
914 | MAKE_PIN(P34, PIOC, PIO_PC2); | ||
915 | MAKE_PIN(P35, PIOC, PIO_PC3); | ||
916 | MAKE_PIN(P36, PIOC, PIO_PC4); | ||
917 | MAKE_PIN(P37, PIOC, PIO_PC5); | ||
918 | MAKE_PIN(P38, PIOC, PIO_PC6); | ||
919 | MAKE_PIN(P39, PIOC, PIO_PC7); | ||
920 | MAKE_PIN(P40, PIOC, PIO_PC8); | ||
921 | MAKE_PIN(P41, PIOC, PIO_PC9); | ||
922 | MAKE_PIN(P42, PIOA, PIO_PA19); | ||
923 | MAKE_PIN(P43, PIOA, PIO_PA20); | ||
924 | MAKE_PIN(P44, PIOC, PIO_PC19); | ||
925 | MAKE_PIN(P45, PIOC, PIO_PC18); | ||
926 | MAKE_PIN(P46, PIOC, PIO_PC17); | ||
927 | MAKE_PIN(P47, PIOC, PIO_PC16); | ||
928 | MAKE_PIN(P48, PIOC, PIO_PC15); | ||
929 | MAKE_PIN(P49, PIOC, PIO_PC14); | ||
930 | MAKE_PIN(P50, PIOC, PIO_PC13); | ||
931 | MAKE_PIN(P51, PIOC, PIO_PC12); | ||
932 | MAKE_PIN(P52, PIOB, PIO_PB21); | ||
933 | MAKE_PIN(P53, PIOB, PIO_PB14); | ||
934 | MAKE_PIN(P54, PIOA, PIO_PA16); | ||
935 | MAKE_PIN(P55, PIOA, PIO_PA24); | ||
936 | MAKE_PIN(P56, PIOA, PIO_PA23); | ||
937 | MAKE_PIN(P57, PIOA, PIO_PA22); | ||
938 | MAKE_PIN(P58, PIOA, PIO_PA6); | ||
939 | MAKE_PIN(P59, PIOA, PIO_PA4); | ||
940 | MAKE_PIN(P60, PIOA, PIO_PA3); | ||
941 | MAKE_PIN(P61, PIOA, PIO_PA2); | ||
942 | MAKE_PIN(P62, PIOB, PIO_PB17); | ||
943 | MAKE_PIN(P63, PIOB, PIO_PB18); | ||
944 | MAKE_PIN(P64, PIOB, PIO_PB19); | ||
945 | MAKE_PIN(P65, PIOB, PIO_PB20); | ||
946 | MAKE_PIN(P66, PIOB, PIO_PB15); | ||
947 | MAKE_PIN(P67, PIOB, PIO_PB16); | ||
948 | MAKE_PIN(P68, PIOA, PIO_PA1); | ||
949 | MAKE_PIN(P69, PIOA, PIO_PA0); | ||
950 | MAKE_PIN(P70, PIOA, PIO_PA17); | ||
951 | MAKE_PIN(P71, PIOA, PIO_PA18); | ||
952 | MAKE_PIN(P72, PIOC, PIO_PC30); | ||
953 | MAKE_PIN(P73, PIOA, PIO_PA21); | ||
954 | MAKE_PIN(P74, PIOA, PIO_PA25); // MISO | ||
955 | MAKE_PIN(P75, PIOA, PIO_PA26); // MOSI | ||
956 | MAKE_PIN(P76, PIOA, PIO_PA27); // CLK | ||
957 | MAKE_PIN(P77, PIOA, PIO_PA28); | ||
958 | MAKE_PIN(P78, PIOB, PIO_PB23); // Unconnected | ||
959 | |||
960 | #undef MAKE_PIN | ||
961 | |||
962 | #elif defined(RBL_NRF51822) | ||
963 | |||
964 | #define MAKE_PIN(className, pin) \ | ||
965 | class className { \ | ||
966 | public: \ | ||
967 | static void Set() { \ | ||
968 | nrf_gpio_pin_set(pin); \ | ||
969 | } \ | ||
970 | static void Clear() { \ | ||
971 | nrf_gpio_pin_clear(pin); \ | ||
972 | } \ | ||
973 | static void SetDirRead() { \ | ||
974 | nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL); \ | ||
975 | } \ | ||
976 | static void SetDirWrite() { \ | ||
977 | nrf_gpio_cfg_output(pin); \ | ||
978 | } \ | ||
979 | static uint8_t IsSet() { \ | ||
980 | return (uint8_t)nrf_gpio_pin_read(pin); \ | ||
981 | } \ | ||
982 | }; | ||
983 | |||
984 | // See: pin_transform.c in RBL nRF51822 SDK | ||
985 | MAKE_PIN(P0, Pin_nRF51822_to_Arduino(D0)); | ||
986 | MAKE_PIN(P1, Pin_nRF51822_to_Arduino(D1)); | ||
987 | MAKE_PIN(P2, Pin_nRF51822_to_Arduino(D2)); | ||
988 | MAKE_PIN(P3, Pin_nRF51822_to_Arduino(D3)); | ||
989 | MAKE_PIN(P4, Pin_nRF51822_to_Arduino(D4)); | ||
990 | MAKE_PIN(P5, Pin_nRF51822_to_Arduino(D5)); | ||
991 | MAKE_PIN(P6, Pin_nRF51822_to_Arduino(D6)); | ||
992 | MAKE_PIN(P7, Pin_nRF51822_to_Arduino(D7)); | ||
993 | MAKE_PIN(P8, Pin_nRF51822_to_Arduino(D8)); | ||
994 | MAKE_PIN(P9, Pin_nRF51822_to_Arduino(D9)); // INT | ||
995 | MAKE_PIN(P10, Pin_nRF51822_to_Arduino(D10)); // SS | ||
996 | MAKE_PIN(P11, Pin_nRF51822_to_Arduino(D11)); | ||
997 | MAKE_PIN(P12, Pin_nRF51822_to_Arduino(D12)); | ||
998 | MAKE_PIN(P13, Pin_nRF51822_to_Arduino(D13)); | ||
999 | MAKE_PIN(P14, Pin_nRF51822_to_Arduino(D14)); | ||
1000 | MAKE_PIN(P15, Pin_nRF51822_to_Arduino(D15)); | ||
1001 | MAKE_PIN(P17, Pin_nRF51822_to_Arduino(D17)); // MISO | ||
1002 | MAKE_PIN(P18, Pin_nRF51822_to_Arduino(D18)); // MOSI | ||
1003 | MAKE_PIN(P16, Pin_nRF51822_to_Arduino(D16)); // CLK | ||
1004 | MAKE_PIN(P19, Pin_nRF51822_to_Arduino(D19)); | ||
1005 | MAKE_PIN(P20, Pin_nRF51822_to_Arduino(D20)); | ||
1006 | MAKE_PIN(P21, Pin_nRF51822_to_Arduino(D21)); | ||
1007 | MAKE_PIN(P22, Pin_nRF51822_to_Arduino(D22)); | ||
1008 | MAKE_PIN(P23, Pin_nRF51822_to_Arduino(D23)); | ||
1009 | MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24)); | ||
1010 | |||
1011 | #undef MAKE_PIN | ||
1012 | |||
1013 | #else | ||
1014 | #error "Please define board in avrpins.h" | ||
1015 | |||
1016 | #endif | ||
1017 | |||
1018 | #elif defined(__ARDUINO_X86__) // Intel Galileo, Intel Galileo 2 and Intel Edison | ||
1019 | |||
1020 | #include <avr/pgmspace.h> | ||
1021 | |||
1022 | // Pointers are 32 bits on x86 | ||
1023 | #define pgm_read_pointer(p) pgm_read_dword(p) | ||
1024 | |||
1025 | #if PLATFORM_ID == 0xE1 // Edison platform id | ||
1026 | #define pinToFastPin(pin) 1 // As far as I can tell all pins can be used as fast pins | ||
1027 | #endif | ||
1028 | |||
1029 | // Pin 2 and 3 on the Intel Galileo supports a higher rate, | ||
1030 | // so it is recommended to use one of these as the SS pin. | ||
1031 | |||
1032 | #define MAKE_PIN(className, pin) \ | ||
1033 | class className { \ | ||
1034 | public: \ | ||
1035 | static void Set() { \ | ||
1036 | fastDigitalWrite(pin, HIGH); \ | ||
1037 | } \ | ||
1038 | static void Clear() { \ | ||
1039 | fastDigitalWrite(pin, LOW); \ | ||
1040 | } \ | ||
1041 | static void SetDirRead() { \ | ||
1042 | if (pinToFastPin(pin)) \ | ||
1043 | pinMode(pin, INPUT_FAST); \ | ||
1044 | else \ | ||
1045 | pinMode(pin, INPUT); \ | ||
1046 | } \ | ||
1047 | static void SetDirWrite() { \ | ||
1048 | if (pinToFastPin(pin)) \ | ||
1049 | pinMode(pin, OUTPUT_FAST); \ | ||
1050 | else \ | ||
1051 | pinMode(pin, OUTPUT); \ | ||
1052 | } \ | ||
1053 | static uint8_t IsSet() { \ | ||
1054 | return fastDigitalRead(pin); \ | ||
1055 | } \ | ||
1056 | }; | ||
1057 | |||
1058 | MAKE_PIN(P0, 0); | ||
1059 | MAKE_PIN(P1, 1); | ||
1060 | MAKE_PIN(P2, 2); | ||
1061 | MAKE_PIN(P3, 3); | ||
1062 | MAKE_PIN(P4, 4); | ||
1063 | MAKE_PIN(P5, 5); | ||
1064 | MAKE_PIN(P6, 6); | ||
1065 | MAKE_PIN(P7, 7); | ||
1066 | MAKE_PIN(P8, 8); | ||
1067 | MAKE_PIN(P9, 9); | ||
1068 | MAKE_PIN(P10, 10); | ||
1069 | MAKE_PIN(P11, 11); | ||
1070 | MAKE_PIN(P12, 12); | ||
1071 | MAKE_PIN(P13, 13); | ||
1072 | MAKE_PIN(P14, 14); // A0 | ||
1073 | MAKE_PIN(P15, 15); // A1 | ||
1074 | MAKE_PIN(P16, 16); // A2 | ||
1075 | MAKE_PIN(P17, 17); // A3 | ||
1076 | MAKE_PIN(P18, 18); // A4 | ||
1077 | MAKE_PIN(P19, 19); // A5 | ||
1078 | |||
1079 | #undef MAKE_PIN | ||
1080 | |||
1081 | #elif defined(__MIPSEL__) | ||
1082 | // MIPSEL (MIPS architecture using a little endian byte order) | ||
1083 | |||
1084 | // MIPS size_t = 4 | ||
1085 | #define pgm_read_pointer(p) pgm_read_dword(p) | ||
1086 | |||
1087 | #define MAKE_PIN(className, pin) \ | ||
1088 | class className { \ | ||
1089 | public: \ | ||
1090 | static void Set() { \ | ||
1091 | digitalWrite(pin, HIGH);\ | ||
1092 | } \ | ||
1093 | static void Clear() { \ | ||
1094 | digitalWrite(pin, LOW); \ | ||
1095 | } \ | ||
1096 | static void SetDirRead() { \ | ||
1097 | pinMode(pin, INPUT); \ | ||
1098 | } \ | ||
1099 | static void SetDirWrite() { \ | ||
1100 | pinMode(pin, OUTPUT); \ | ||
1101 | } \ | ||
1102 | static uint8_t IsSet() { \ | ||
1103 | return digitalRead(pin); \ | ||
1104 | } \ | ||
1105 | }; | ||
1106 | |||
1107 | // 0 .. 13 - Digital pins | ||
1108 | MAKE_PIN(P0, 0); // RX | ||
1109 | MAKE_PIN(P1, 1); // TX | ||
1110 | MAKE_PIN(P2, 2); // | ||
1111 | MAKE_PIN(P3, 3); // | ||
1112 | MAKE_PIN(P4, 4); // | ||
1113 | MAKE_PIN(P5, 5); // | ||
1114 | MAKE_PIN(P6, 6); // | ||
1115 | MAKE_PIN(P7, 7); // | ||
1116 | MAKE_PIN(P8, 8); // | ||
1117 | MAKE_PIN(P9, 9); // | ||
1118 | MAKE_PIN(P10, 10); // | ||
1119 | MAKE_PIN(P11, 11); // | ||
1120 | MAKE_PIN(P12, 12); // | ||
1121 | MAKE_PIN(P13, 13); // | ||
1122 | |||
1123 | #undef MAKE_PIN | ||
1124 | |||
1125 | #else | ||
1126 | #error "Please define board in avrpins.h" | ||
1127 | |||
1128 | #endif | ||
1129 | |||
1130 | #endif //_avrpins_h_ | ||