USB Host Shield 2.0
Loading...
Searching...
No Matches
avrpins.h
Go to the documentation of this file.
1/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License as published by
5the Free Software Foundation; either version 2 of the License, or
6(at your option) any later version.
7
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License
14along with this program; if not, write to the Free Software
15Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17Contact information
18-------------------
19
20Circuits At Home, LTD
21Web : http://www.circuitsathome.com
22e-mail : support@circuitsathome.com
23 */
24
25/* derived from Konstantin Chizhov's AVR port templates */
26
27#if !defined(_usb_h_) || defined(_avrpins_h_)
28#error "Never include avrpins.h directly; include Usb.h instead"
29#else
30#define _avrpins_h_
31
32#if defined(__AVR__)
33
34// pointers are 16 bits on AVR
35#define pgm_read_pointer(p) pgm_read_word(p)
36
37// Support for these boards needs to be manually activated in settings.h or in a makefile
38#if !defined(BOARD_MEGA_ADK) && defined(__AVR_ATmega2560__) && (USE_UHS_MEGA_ADK || defined(ARDUINO_AVR_ADK))
39#define BOARD_MEGA_ADK
40#elif !defined(BOARD_BLACK_WIDDOW) && USE_UHS_BLACK_WIDDOW
41#define BOARD_BLACK_WIDDOW
42#endif
43
44#ifdef PORTA
45#define USE_PORTA
46#endif
47#ifdef PORTB
48#define USE_PORTB
49#endif
50#ifdef PORTC
51#define USE_PORTC
52#endif
53#ifdef PORTD
54#define USE_PORTD
55#endif
56#ifdef PORTE
57#define USE_PORTE
58#endif
59#ifdef PORTF
60#define USE_PORTF
61#endif
62#ifdef PORTG
63#define USE_PORTG
64#endif
65#ifdef PORTH
66#define USE_PORTH
67#endif
68#ifdef PORTJ
69#define USE_PORTJ
70#endif
71#ifdef PORTK
72#define USE_PORTK
73#endif
74#ifdef PORTL
75#define USE_PORTL
76#endif
77#ifdef PORTQ
78#define USE_PORTQ
79#endif
80#ifdef PORTR
81#define USE_PORTR
82#endif
83
84#ifdef TCCR0A
85#define USE_TCCR0A
86#endif
87#ifdef TCCR1A
88#define USE_TCCR1A
89#endif
90#ifdef TCCR2A
91#define USE_TCCR2A
92#endif
93
94//Port definitions for AtTiny, AtMega families.
95
96#define MAKE_PORT(portName, ddrName, pinName, className, ID) \
97 class className{\
98 public:\
99 typedef uint8_t DataT;\
100 public:\
101 static void Write(DataT value){portName = value;}\
102 static void ClearAndSet(DataT clearMask, DataT value){portName = (portName & ~clearMask) | value;}\
103 static DataT Read(){return portName;}\
104 static void DirWrite(DataT value){ddrName = value;}\
105 static DataT DirRead(){return ddrName;}\
106 static void Set(DataT value){portName |= value;}\
107 static void Clear(DataT value){portName &= ~value;}\
108 static void Toggle(DataT value){portName ^= value;}\
109 static void DirSet(DataT value){ddrName |= value;}\
110 static void DirClear(DataT value){ddrName &= ~value;}\
111 static void DirToggle(DataT value){ddrName ^= value;}\
112 static DataT PinRead(){return pinName;}\
113 enum{Id = ID};\
114 enum{Width=sizeof(DataT)*8};\
115 };
116
117// TCCR registers to set/clear Arduino PWM
118#define MAKE_TCCR(TccrName, className) \
119 class className{\
120 public:\
121 typedef uint8_t DataT;\
122 public:\
123 static void Write(DataT value){TccrName = value;}\
124 static void ClearAndSet(DataT clearMask, DataT value){TccrName = (TccrName & ~clearMask) | value;}\
125 static DataT Read(){return TccrName;}\
126 static void Set(DataT value){TccrName |= value;}\
127 static void Clear(DataT value){TccrName &= ~value;}\
128 static void Toggle(DataT value){TccrName ^= value;}\
129 enum{Width=sizeof(DataT)*8};\
130 };
131
132#ifdef USE_PORTA
133
135#endif
136#ifdef USE_PORTB
138#endif
139#ifdef USE_PORTC
141#endif
142#ifdef USE_PORTD
144#endif
145#ifdef USE_PORTE
147#endif
148#ifdef USE_PORTF
150#endif
151#ifdef USE_PORTG
153#endif
154#ifdef USE_PORTH
156#endif
157#ifdef USE_PORTJ
159#endif
160#ifdef USE_PORTK
162#endif
163#ifdef USE_PORTL
165#endif
166#ifdef USE_PORTQ
168#endif
169#ifdef USE_PORTR
171#endif
172
173#ifdef USE_TCCR0A
175#endif
176#ifdef USE_TCCR1A
178#endif
179#ifdef USE_TCCR2A
181#endif
182
183// this class represents one pin in a IO port.
184// It is fully static.
185template<typename PORT, uint8_t PIN>
186class TPin {
187 // BOOST_STATIC_ASSERT(PIN < PORT::Width);
188public:
189 typedef PORT Port;
190
191 enum {
192 Number = PIN
193 };
194
195 static void Set() {
196 PORT::Set(1 << PIN);
197 }
198
199 static void Set(uint8_t val) {
200 if(val)
201 Set();
202 else Clear();
203 }
204
205 static void SetDir(uint8_t val) {
206 if(val)
207 SetDirWrite();
208 else SetDirRead();
209 }
210
211 static void Clear() {
212 PORT::Clear(1 << PIN);
213 }
214
215 static void Toggle() {
216 PORT::Toggle(1 << PIN);
217 }
218
219 static void SetDirRead() {
220 PORT::DirClear(1 << PIN);
221 }
222
223 static void SetDirWrite() {
224 PORT::DirSet(1 << PIN);
225 }
226
227 static uint8_t IsSet() {
228 return PORT::PinRead() & (uint8_t)(1 << PIN);
229 }
230
231 static void WaiteForSet() {
232 while(IsSet() == 0) {
233 }
234 }
235
236 static void WaiteForClear() {
237 while(IsSet()) {
238 }
239 }
240}; //class TPin...
241
242// this class represents one bit in TCCR port.
243// used to set/clear TCCRx bits
244// It is fully static.
245
246template<typename TCCR, uint8_t COM>
247class TCom {
248 // BOOST_STATIC_ASSERT(PIN < PORT::Width);
249public:
250 typedef TCCR Tccr;
251
252 enum {
253 Com = COM
254 };
255
256 static void Set() {
257 TCCR::Set(1 << COM);
258 }
259
260 static void Clear() {
261 TCCR::Clear(1 << COM);
262 }
263
264 static void Toggle() {
265 TCCR::Toggle(1 << COM);
266 }
267}; //class TCom...
268
269//Short pin definitions
270#ifdef USE_PORTA
271typedef TPin<Porta, 0 > Pa0;
272typedef TPin<Porta, 1 > Pa1;
273typedef TPin<Porta, 2 > Pa2;
274typedef TPin<Porta, 3 > Pa3;
275typedef TPin<Porta, 4 > Pa4;
276typedef TPin<Porta, 5 > Pa5;
277typedef TPin<Porta, 6 > Pa6;
278typedef TPin<Porta, 7 > Pa7;
279#endif
280
281#ifdef USE_PORTB
282typedef TPin<Portb, 0 > Pb0;
283typedef TPin<Portb, 1 > Pb1;
284typedef TPin<Portb, 2 > Pb2;
285typedef TPin<Portb, 3 > Pb3;
286typedef TPin<Portb, 4 > Pb4;
287typedef TPin<Portb, 5 > Pb5;
288typedef TPin<Portb, 6 > Pb6;
289typedef TPin<Portb, 7 > Pb7;
290#endif
291
292#ifdef USE_PORTC
293typedef TPin<Portc, 0 > Pc0;
294typedef TPin<Portc, 1 > Pc1;
295typedef TPin<Portc, 2 > Pc2;
296typedef TPin<Portc, 3 > Pc3;
297typedef TPin<Portc, 4 > Pc4;
298typedef TPin<Portc, 5 > Pc5;
299typedef TPin<Portc, 6 > Pc6;
300typedef TPin<Portc, 7 > Pc7;
301#endif
302
303#ifdef USE_PORTD
304typedef TPin<Portd, 0 > Pd0;
305typedef TPin<Portd, 1 > Pd1;
306typedef TPin<Portd, 2 > Pd2;
307typedef TPin<Portd, 3 > Pd3;
308typedef TPin<Portd, 4 > Pd4;
309typedef TPin<Portd, 5 > Pd5;
310typedef TPin<Portd, 6 > Pd6;
311typedef TPin<Portd, 7 > Pd7;
312#endif
313
314#ifdef USE_PORTE
315typedef TPin<Porte, 0 > Pe0;
316typedef TPin<Porte, 1 > Pe1;
317typedef TPin<Porte, 2 > Pe2;
318typedef TPin<Porte, 3 > Pe3;
319typedef TPin<Porte, 4 > Pe4;
320typedef TPin<Porte, 5 > Pe5;
321typedef TPin<Porte, 6 > Pe6;
322typedef TPin<Porte, 7 > Pe7;
323#endif
324
325#ifdef USE_PORTF
326typedef TPin<Portf, 0 > Pf0;
327typedef TPin<Portf, 1 > Pf1;
328typedef TPin<Portf, 2 > Pf2;
329typedef TPin<Portf, 3 > Pf3;
330typedef TPin<Portf, 4 > Pf4;
331typedef TPin<Portf, 5 > Pf5;
332typedef TPin<Portf, 6 > Pf6;
333typedef TPin<Portf, 7 > Pf7;
334#endif
335
336#ifdef USE_PORTG
337typedef TPin<Portg, 0 > Pg0;
338typedef TPin<Portg, 1 > Pg1;
339typedef TPin<Portg, 2 > Pg2;
340typedef TPin<Portg, 3 > Pg3;
341typedef TPin<Portg, 4 > Pg4;
342typedef TPin<Portg, 5 > Pg5;
343typedef TPin<Portg, 6 > Pg6;
344typedef TPin<Portg, 7 > Pg7;
345#endif
346
347#ifdef USE_PORTH
348typedef TPin<Porth, 0 > Ph0;
349typedef TPin<Porth, 1 > Ph1;
350typedef TPin<Porth, 2 > Ph2;
351typedef TPin<Porth, 3 > Ph3;
352typedef TPin<Porth, 4 > Ph4;
353typedef TPin<Porth, 5 > Ph5;
354typedef TPin<Porth, 6 > Ph6;
355typedef TPin<Porth, 7 > Ph7;
356#endif
357
358#ifdef USE_PORTJ
359typedef TPin<Portj, 0 > Pj0;
360typedef TPin<Portj, 1 > Pj1;
361typedef TPin<Portj, 2 > Pj2;
362typedef TPin<Portj, 3 > Pj3;
363typedef TPin<Portj, 4 > Pj4;
364typedef TPin<Portj, 5 > Pj5;
365typedef TPin<Portj, 6 > Pj6;
366typedef TPin<Portj, 7 > Pj7;
367#endif
368
369#ifdef USE_PORTK
370typedef TPin<Portk, 0 > Pk0;
371typedef TPin<Portk, 1 > Pk1;
372typedef TPin<Portk, 2 > Pk2;
373typedef TPin<Portk, 3 > Pk3;
374typedef TPin<Portk, 4 > Pk4;
375typedef TPin<Portk, 5 > Pk5;
376typedef TPin<Portk, 6 > Pk6;
377typedef TPin<Portk, 7 > Pk7;
378#endif
379
380#ifdef USE_PORTL
381typedef TPin<Portl, 0 > Pl0;
382typedef TPin<Portl, 1 > Pl1;
383typedef TPin<Portl, 2 > Pl2;
384typedef TPin<Portl, 3 > Pl3;
385typedef TPin<Portl, 4 > Pl4;
386typedef TPin<Portl, 5 > Pl5;
387typedef TPin<Portl, 6 > Pl6;
388typedef TPin<Portl, 7 > Pl7;
389#endif
390
391#ifdef USE_PORTQ
392typedef TPin<Portq, 0 > Pq0;
393typedef TPin<Portq, 1 > Pq1;
394typedef TPin<Portq, 2 > Pq2;
395typedef TPin<Portq, 3 > Pq3;
396typedef TPin<Portq, 4 > Pq4;
397typedef TPin<Portq, 5 > Pq5;
398typedef TPin<Portq, 6 > Pq6;
399typedef TPin<Portq, 7 > Pq7;
400#endif
401
402#ifdef USE_PORTR
403typedef TPin<Portr, 0 > Pr0;
404typedef TPin<Portr, 1 > Pr1;
405typedef TPin<Portr, 2 > Pr2;
406typedef TPin<Portr, 3 > Pr3;
407typedef TPin<Portr, 4 > Pr4;
408typedef TPin<Portr, 5 > Pr5;
409typedef TPin<Portr, 6 > Pr6;
410typedef TPin<Portr, 7 > Pr7;
411#endif
412
413#ifdef USE_TCCR0A
414typedef TCom<Tccr0a, COM0A1> Tc0a; //P6
415typedef TCom<Tccr0a, COM0B1> Tc0b; //P5
416#endif
417
418#ifdef USE_TCCR1A
419typedef TCom<Tccr1a, COM1A1> Tc1a; //P9
420typedef TCom<Tccr1a, COM1B1> Tc1b; //P10
421#endif
422
423#ifdef USE_TCCR2A
424typedef TCom<Tccr2a, COM2A1> Tc2a; //P11
425typedef TCom<Tccr2a, COM2B1> Tc2b; //P3
426#endif
427
428template<typename Tp_pin, typename Tc_bit>
429class Tp_Tc {
430public:
431
432 static void SetDir(uint8_t val) {
433 if(val)
434 SetDirWrite();
435 else SetDirRead();
436 }
437
438 static void SetDirRead() {
439 Tp_pin::SetDirRead(); //set pin direction
440 Tc_bit::Clear(); //disconnect pin from PWM
441 }
442
443 static void SetDirWrite() {
446 }
447};
448
449/* pin definitions for cases where it's necessary to clear compare output mode bits */
450
451//typedef Tp_Tc<Pd3, Tc2b> P3; //Arduino pin 3
452//typedef Tp_Tc<Pd5, Tc0b> P5; //Arduino pin 5
453//typedef Tp_Tc<Pd6, Tc0a> P6; //Arduino pin 6
454//typedef Tp_Tc<Pb1, Tc1a> P9; //Arduino pin 9
455//typedef Tp_Tc<Pb2, Tc1b> P10; //Arduino pin 10
456//typedef Tp_Tc<Pb3, Tc2a> P11; //Arduino pin 11
457
458/* Arduino pin definitions */
459#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
460// "Mega" Arduino pin numbers
461
462#define P0 Pe0
463#define P1 Pe1
464#define P2 Pe4
465#define P3 Pe5
466#define P4 Pg5
467#define P5 Pe3
468#define P6 Ph3
469#define P7 Ph4
470
471#define P8 Ph5
472#define P9 Ph6
473#define P10 Pb4
474#define P11 Pb5
475#define P12 Pb6
476#define P13 Pb7
477
478#define P14 Pj1
479#define P15 Pj0
480#define P16 Ph1
481#define P17 Ph0
482#define P18 Pd3
483#define P19 Pd2
484#define P20 Pd1
485#define P21 Pd0
486
487#define P22 Pa0
488#define P23 Pa1
489#define P24 Pa2
490#define P25 Pa3
491#define P26 Pa4
492#define P27 Pa5
493#define P28 Pa6
494#define P29 Pa7
495#define P30 Pc7
496#define P31 Pc6
497#define P32 Pc5
498#define P33 Pc4
499#define P34 Pc3
500#define P35 Pc2
501#define P36 Pc1
502#define P37 Pc0
503
504#define P38 Pd7
505#define P39 Pg2
506#define P40 Pg1
507#define P41 Pg0
508#define P42 Pl7
509#define P43 Pl6
510#define P44 Pl5
511#define P45 Pl4
512#define P46 Pl3
513#define P47 Pl2
514#define P48 Pl1
515#define P49 Pl0
516#define P50 Pb3
517#define P51 Pb2
518#define P52 Pb1
519#define P53 Pb0
520
521#ifdef BOARD_MEGA_ADK // These pins are not broken out on the Arduino ADK
522#define P54 Pe6 // INT on Arduino ADK
523#define P55 Pj2 // MAX_RESET on Arduino ADK
524#endif
525
526// "Mega" pin numbers
527
528#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
529// "Classic" Arduino pin numbers
530
531#define P0 Pd0
532#define P1 Pd1
533#define P2 Pd2
534#define P3 Pd3
535#define P4 Pd4
536#define P5 Pd5
537#define P6 Pd6
538#define P7 Pd7
539
540#define P8 Pb0
541#define P9 Pb1
542#define P10 Pb2
543#define P11 Pb3
544#define P12 Pb4
545#define P13 Pb5
546
547#define P14 Pc0
548#define P15 Pc1
549#define P16 Pc2
550#define P17 Pc3
551#define P18 Pc4
552#define P19 Pc5
553
554// "Classic" Arduino pin numbers
555
556#elif defined(CORE_TEENSY) && defined(__AVR_ATmega32U4__)
557// Teensy 2.0 pin numbers
558// http://www.pjrc.com/teensy/pinout.html
559#define P0 Pb0
560#define P1 Pb1
561#define P2 Pb2
562#define P3 Pb3
563#define P4 Pb7
564#define P5 Pd0
565#define P6 Pd1
566#define P7 Pd2
567#define P8 Pd3
568#define P9 Pc6
569#define P10 Pc7
570#define P11 Pd6
571#define P12 Pd7
572#define P13 Pb4
573#define P14 Pb5
574#define P15 Pb6
575#define P16 Pf7
576#define P17 Pf6
577#define P18 Pf5
578#define P19 Pf4
579#define P20 Pf1
580#define P21 Pf0
581#define P22 Pd4
582#define P23 Pd5
583#define P24 Pe6
584// Teensy 2.0
585
586#elif defined(__AVR_ATmega32U4__)
587// Arduino Leonardo pin numbers
588
589#define P0 Pd2 // D0 - PD2
590#define P1 Pd3 // D1 - PD3
591#define P2 Pd1 // D2 - PD1
592#define P3 Pd0 // D3 - PD0
593#define P4 Pd4 // D4 - PD4
594#define P5 Pc6 // D5 - PC6
595#define P6 Pd7 // D6 - PD7
596#define P7 Pe6 // D7 - PE6
597
598#define P8 Pb4 // D8 - PB4
599#define P9 Pb5 // D9 - PB5
600#define P10 Pb6 // D10 - PB6
601#define P11 Pb7 // D11 - PB7
602#define P12 Pd6 // D12 - PD6
603#define P13 Pc7 // D13 - PC7
604
605#define P14 Pb3 // D14 - MISO - PB3
606#define P15 Pb1 // D15 - SCK - PB1
607#define P16 Pb2 // D16 - MOSI - PB2
608#define P17 Pb0 // D17 - SS - PB0
609
610#define P18 Pf7 // D18 - A0 - PF7
611#define P19 Pf6 // D19 - A1 - PF6
612#define P20 Pf5 // D20 - A2 - PF5
613#define P21 Pf4 // D21 - A3 - PF4
614#define P22 Pf1 // D22 - A4 - PF1
615#define P23 Pf0 // D23 - A5 - PF0
616
617#define P24 Pd4 // D24 / D4 - A6 - PD4
618#define P25 Pd7 // D25 / D6 - A7 - PD7
619#define P26 Pb4 // D26 / D8 - A8 - PB4
620#define P27 Pb5 // D27 / D9 - A9 - PB5
621#define P28 Pb6 // D28 / D10 - A10 - PB6
622#define P29 Pd6 // D29 / D12 - A11 - PD6
623
624// Arduino Leonardo pin numbers
625
626#elif defined(CORE_TEENSY) && (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__))
627// Teensy++ 1.0 and 2.0 pin numbers
628// http://www.pjrc.com/teensy/pinout.html
629#define P0 Pd0
630#define P1 Pd1
631#define P2 Pd2
632#define P3 Pd3
633#define P4 Pd4
634#define P5 Pd5
635#define P6 Pd6
636#define P7 Pd7
637#define P8 Pe0
638#define P9 Pe1
639#define P10 Pc0
640#define P11 Pc1
641#define P12 Pc2
642#define P13 Pc3
643#define P14 Pc4
644#define P15 Pc5
645#define P16 Pc6
646#define P17 Pc7
647#define P18 Pe6
648#define P19 Pe7
649#define P20 Pb0
650#define P21 Pb1
651#define P22 Pb2
652#define P23 Pb3
653#define P24 Pb4
654#define P25 Pb5
655#define P26 Pb6
656#define P27 Pb7
657#define P28 Pa0
658#define P29 Pa1
659#define P30 Pa2
660#define P31 Pa3
661#define P32 Pa4
662#define P33 Pa5
663#define P34 Pa6
664#define P35 Pa7
665#define P36 Pe4
666#define P37 Pe5
667#define P38 Pf0
668#define P39 Pf1
669#define P40 Pf2
670#define P41 Pf3
671#define P42 Pf4
672#define P43 Pf5
673#define P44 Pf6
674#define P45 Pf7
675// Teensy++ 1.0 and 2.0
676
677#elif defined(ARDUINO_AVR_BALANDUINO) && (defined(__AVR_ATmega644__) || defined(__AVR_ATmega1284P__))
678// Balanduino pin numbers
679// http://balanduino.net/
680#define P0 Pd0 /* 0 - PD0 */
681#define P1 Pd1 /* 1 - PD1 */
682
683#if BALANDUINO_REVISION < 13
684 #define P2 Pb2 /* 2 - PB2 */
685 #define P3 Pd6 /* 3 - PD6 */
686 #define P4 Pd7 /* 4 - PD7 */
687 #define P5 Pb3 /* 5 - PB3 */
688#else
689 #define P2 Pd2 /* 2 - PD2 */
690 #define P3 Pd3 /* 3 - PD3 */
691 #define P4 Pd6 /* 4 - PD6 */
692 #define P5 Pd7 /* 5 - PD7 */
693#endif
694
695#define P6 Pb4 /* 6 - PB4 */
696#define P7 Pa0 /* 7 - PA0 */
697#define P8 Pa1 /* 8 - PA1 */
698#define P9 Pa2 /* 9 - PA2 */
699#define P10 Pa3 /* 10 - PA3 */
700#define P11 Pa4 /* 11 - PA4 */
701#define P12 Pa5 /* 12 - PA5 */
702#define P13 Pc1 /* 13 - PC1 */
703#define P14 Pc0 /* 14 - PC0 */
704
705#if BALANDUINO_REVISION < 13
706 #define P15 Pd2 /* 15 - PD2 */
707 #define P16 Pd3 /* 16 - PD3 */
708#else
709 #define P15 Pb2 /* 15 - PB2 */
710 #define P16 Pb3 /* 16 - PB2 */
711#endif
712
713#define P17 Pd4 /* 17 - PD4 */
714#define P18 Pd5 /* 18 - PD5 */
715#define P19 Pc2 /* 19 - PC2 */
716#define P20 Pc3 /* 20 - PC3 */
717#define P21 Pc4 /* 21 - PC4 */
718#define P22 Pc5 /* 22 - PC5 */
719#define P23 Pc6 /* 23 - PC6 */
720#define P24 Pc7 /* 24 - PC7 */
721#define P25 Pb0 /* 25 - PB0 */
722#define P26 Pb1 /* 26 - PB1 */
723#define P27 Pb5 /* 27 - PB5 */
724#define P28 Pb6 /* 28 - PB6 */
725#define P29 Pb7 /* 29 - PB7 */
726#define P30 Pa6 /* 30 - PA6 */
727#define P31 Pa7 /* 31 - PA7 */
728// Balanduino
729
730#elif defined(ARDUINO_AVR_UNO_PRO) && defined(__AVR_ATmega1284P__)
731// UNO*Pro pin numbers
732// Homepage: http://www.hobbytronics.co.uk/arduino-uno-pro
733// Pin Reference: http://www.hobbytronics.co.uk/download/uno_pro/pins_arduino.h
734#define P0 Pd0
735#define P1 Pd1
736#define P2 Pb2
737#define P3 Pb3
738#define P4 Pb0
739#define P5 Pb1
740#define P6 Pd2
741#define P7 Pd3
742#define P8 Pd5
743#define P9 Pd6
744#define P10 Pb4
745#define P11 Pb5
746#define P12 Pb6
747#define P13 Pb7
748#define P14 Pa7
749#define P15 Pa6
750#define P16 Pa5
751#define P17 Pa4
752#define P18 Pa3
753#define P19 Pa2
754#define P20 Pa1
755#define P21 Pa0
756#define P22 Pc0
757#define P23 Pc1
758#define P24 Pc2
759#define P25 Pc3
760#define P26 Pc4
761#define P27 Pc5
762#define P28 Pc6
763#define P29 Pc7
764#define P30 Pd4
765#define P31 Pd7
766// UNO*Pro
767
768#elif defined(MIGHTYCORE)
769// https://github.com/MCUdude/MightyCore
770#if defined(BOBUINO_PINOUT)
771 #define P0 Pd0
772 #define P1 Pd1
773 #define P2 Pd2
774 #define P3 Pd3
775 #define P4 Pb0
776 #define P5 Pb1
777 #define P6 Pb2
778 #define P7 Pb3
779 #define P8 Pd5
780 #define P9 Pd6
781 #define P10 Pb4
782 #define P11 Pb5
783 #define P12 Pb6
784 #define P13 Pb7
785 #define P14 Pa7
786 #define P15 Pa6
787 #define P16 Pa5
788 #define P17 Pa4
789 #define P18 Pa3
790 #define P19 Pa2
791 #define P20 Pa1
792 #define P21 Pa0
793 #define P22 Pc0
794 #define P23 Pc1
795 #define P24 Pc2
796 #define P25 Pc3
797 #define P26 Pc4
798 #define P27 Pc5
799 #define P28 Pc6
800 #define P29 Pc7
801 #define P30 Pd4
802 #define P31 Pd7
803#else
804 #define P0 Pb0
805 #define P1 Pb1
806 #define P2 Pb2
807 #define P3 Pb3
808 #define P4 Pb4
809 #define P5 Pb5
810 #define P6 Pb6
811 #define P7 Pb7
812 #define P8 Pd0
813 #define P9 Pd1
814 #define P10 Pd2
815 #define P11 Pd3
816 #define P12 Pd4
817 #define P13 Pd5
818 #define P14 Pd6
819 #define P15 Pd7
820 #define P16 Pc0
821 #define P17 Pc1
822 #define P18 Pc2
823 #define P19 Pc3
824 #define P20 Pc4
825 #define P21 Pc5
826 #define P22 Pc6
827 #define P23 Pc7
828 #if defined(SANGUINO_PINOUT)
829 #define P24 Pa7
830 #define P25 Pa6
831 #define P26 Pa5
832 #define P27 Pa4
833 #define P28 Pa3
834 #define P29 Pa2
835 #define P30 Pa1
836 #define P31 Pa0
837 #else
838 #define P24 Pa0
839 #define P25 Pa1
840 #define P26 Pa2
841 #define P27 Pa3
842 #define P28 Pa4
843 #define P29 Pa5
844 #define P30 Pa6
845 #define P31 Pa7
846 #endif
847#endif
848// MightyCore
849
850#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
851// Sanguino pin numbers
852// Homepage: http://sanguino.cc/hardware
853// Hardware add-on: https://github.com/Lauszus/Sanguino
854#define P0 Pb0
855#define P1 Pb1
856#define P2 Pb2
857#define P3 Pb3
858#define P4 Pb4
859#define P5 Pb5
860#define P6 Pb6
861#define P7 Pb7
862#define P8 Pd0
863#define P9 Pd1
864#define P10 Pd2
865#define P11 Pd3
866#define P12 Pd4
867#define P13 Pd5
868#define P14 Pd6
869#define P15 Pd7
870#define P16 Pc0
871#define P17 Pc1
872#define P18 Pc2
873#define P19 Pc3
874#define P20 Pc4
875#define P21 Pc5
876#define P22 Pc6
877#define P23 Pc7
878#define P24 Pa0
879#define P25 Pa1
880#define P26 Pa2
881#define P27 Pa3
882#define P28 Pa4
883#define P29 Pa5
884#define P30 Pa6
885#define P31 Pa7
886// Sanguino
887
888#else
889#error "Please define board in avrpins.h"
890
891#endif // Arduino pin definitions
892
893#elif defined(__arm__)
894
895// pointers are 32 bits on ARM
896#define pgm_read_pointer(p) pgm_read_dword(p)
897
898#if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__))
899// Teensy 3.x
900
901#include "core_pins.h"
902#include "avr_emulation.h"
903
904#define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000)
905#define GPIO_BITBAND_PTR(reg, bit) ((uint8_t *)GPIO_BITBAND_ADDR((reg), (bit)))
906
907#define MAKE_PIN(className, baseReg, pinNum, configReg) \
908class className { \
909public: \
910 static void Set() { \
911 *GPIO_BITBAND_PTR(baseReg, pinNum) = 1; \
912 } \
913 static void Clear() { \
914 *GPIO_BITBAND_PTR(baseReg, pinNum) = 0; \
915 } \
916 static void SetDirRead() { \
917 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \
918 *(GPIO_BITBAND_PTR(baseReg, pinNum) + 640) = 0; \
919 } \
920 static void SetDirWrite() { \
921 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \
922 *(GPIO_BITBAND_PTR(baseReg, pinNum) + 640) = 1; \
923 } \
924 static uint8_t IsSet() { \
925 return *(GPIO_BITBAND_PTR(baseReg, pinNum) + 512); \
926 } \
927};
928
963#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
994#endif
995
996#undef MAKE_PIN
997
998#elif defined(CORE_TEENSY) && (defined(__MKL26Z64__))
999// Teensy-LC
1000
1001// we could get lower level by making these macros work properly.
1002// for now just use the semi optimised version, it costs a lookup in the pin pgm table per op
1003// but for now it will do.
1004//#define GPIO_BITBAND_ADDR(reg, bit) (((volatile uint8_t *)&(reg) + ((bit) >> 3)))
1005//#define GPIO_BITBAND_MASK(reg, bit) (1<<((bit) & 7))
1006//#define GPIO_BITBAND_PTR(reg, bit) ((volatile uint8_t *)GPIO_BITBAND_ADDR((reg), (bit)))
1007
1008#include "core_pins.h"
1009#include "avr_emulation.h"
1010
1011#define MAKE_PIN(className, baseReg, pinNum, configReg) \
1012class className { \
1013public: \
1014 static void Set() { \
1015 *portSetRegister(pinNum) = digitalPinToBitMask(pinNum); \
1016 } \
1017 static void Clear() { \
1018 *portClearRegister(pinNum) = digitalPinToBitMask(pinNum); \
1019 } \
1020 static void SetDirRead() { \
1021 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \
1022 *portModeRegister(pinNum) &= ~digitalPinToBitMask(pinNum); \
1023 } \
1024 static void SetDirWrite() { \
1025 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \
1026 *portModeRegister(pinNum) |= digitalPinToBitMask(pinNum); \
1027 } \
1028 static uint8_t IsSet() { \
1029 return (*portInputRegister(pinNum) & digitalPinToBitMask(pinNum)) ? 1 : 0; \
1030 } \
1031};
1032
1060
1061#undef MAKE_PIN
1062
1063#elif defined(__IMXRT1062__) && (defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41))
1064// Teensy 4.x
1065
1066#include "core_pins.h"
1067
1068#define MAKE_PIN(className, pin) \
1069class className { \
1070public: \
1071 static void Set() { \
1072 digitalWriteFast(pin, HIGH);\
1073 } \
1074 static void Clear() { \
1075 digitalWriteFast(pin, LOW); \
1076 } \
1077 static void SetDirRead() { \
1078 pinMode(pin, INPUT); \
1079 } \
1080 static void SetDirWrite() { \
1081 pinMode(pin, OUTPUT); \
1082 } \
1083 static uint8_t IsSet() { \
1084 return digitalReadFast(pin); \
1085 } \
1086};
1087
1088MAKE_PIN(P0, 0);
1089MAKE_PIN(P1, 1);
1090MAKE_PIN(P2, 2);
1091MAKE_PIN(P3, 3);
1092MAKE_PIN(P4, 4);
1093MAKE_PIN(P5, 5);
1094MAKE_PIN(P6, 6);
1095MAKE_PIN(P7, 7);
1096MAKE_PIN(P8, 8);
1097MAKE_PIN(P9, 9);
1098MAKE_PIN(P10, 10);
1099MAKE_PIN(P11, 11);
1100MAKE_PIN(P12, 12);
1101MAKE_PIN(P13, 13);
1102MAKE_PIN(P14, 14);
1103MAKE_PIN(P15, 15);
1104MAKE_PIN(P16, 16);
1105MAKE_PIN(P17, 17);
1106MAKE_PIN(P18, 18);
1107MAKE_PIN(P19, 19);
1108MAKE_PIN(P20, 20);
1109MAKE_PIN(P21, 21);
1110MAKE_PIN(P22, 22);
1111MAKE_PIN(P23, 23);
1112MAKE_PIN(P24, 24);
1113MAKE_PIN(P25, 25);
1114MAKE_PIN(P26, 26);
1115MAKE_PIN(P27, 27);
1116MAKE_PIN(P28, 28);
1117MAKE_PIN(P29, 29);
1118MAKE_PIN(P30, 30);
1119MAKE_PIN(P31, 31);
1120MAKE_PIN(P32, 35);
1121MAKE_PIN(P33, 33);
1122MAKE_PIN(P34, 34);
1123MAKE_PIN(P35, 35);
1124MAKE_PIN(P36, 36);
1125MAKE_PIN(P37, 37);
1126MAKE_PIN(P38, 38);
1127MAKE_PIN(P39, 39);
1128#ifdef ARDUINO_TEENSY41
1129MAKE_PIN(P40, 40);
1130MAKE_PIN(P41, 41);
1131MAKE_PIN(P42, 42);
1132MAKE_PIN(P43, 43);
1133MAKE_PIN(P44, 44);
1134MAKE_PIN(P45, 45);
1135MAKE_PIN(P46, 46);
1136MAKE_PIN(P47, 47);
1137MAKE_PIN(P48, 48);
1138MAKE_PIN(P49, 49);
1139MAKE_PIN(P50, 50);
1140MAKE_PIN(P51, 51);
1141MAKE_PIN(P52, 52);
1142MAKE_PIN(P53, 53);
1143MAKE_PIN(P54, 54);
1144#endif
1145
1146#undef MAKE_PIN
1147
1148#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
1149
1150// SetDirRead:
1151// Disable interrupts
1152// Disable the pull up resistor
1153// Set to INPUT
1154// Enable PIO
1155
1156// SetDirWrite:
1157// Disable interrupts
1158// Disable the pull up resistor
1159// Set to OUTPUT
1160// Enable PIO
1161
1162#define MAKE_PIN(className, pio, pinMask) \
1163class className { \
1164public: \
1165 static void Set() { \
1166 pio->PIO_SODR = pinMask; \
1167 } \
1168 static void Clear() { \
1169 pio->PIO_CODR = pinMask; \
1170 } \
1171 static void SetDirRead() { \
1172 pio->PIO_IDR = pinMask ; \
1173 pio->PIO_PUDR = pinMask; \
1174 pio->PIO_ODR = pinMask; \
1175 pio->PIO_PER = pinMask; \
1176 } \
1177 static void SetDirWrite() { \
1178 pio->PIO_IDR = pinMask ; \
1179 pio->PIO_PUDR = pinMask; \
1180 pio->PIO_OER = pinMask; \
1181 pio->PIO_PER = pinMask; \
1182 } \
1183 static uint8_t IsSet() { \
1184 return pio->PIO_PDSR & pinMask; \
1185 } \
1186};
1187
1188// See: http://arduino.cc/en/Hacking/PinMappingSAM3X and variant.cpp
1189
1264MAKE_PIN(P74, PIOA, PIO_PA25); // MISO
1265MAKE_PIN(P75, PIOA, PIO_PA26); // MOSI
1266MAKE_PIN(P76, PIOA, PIO_PA27); // CLK
1268MAKE_PIN(P78, PIOB, PIO_PB23); // Unconnected
1269
1270#undef MAKE_PIN
1271
1272#elif defined(RBL_NRF51822)
1273
1274#define MAKE_PIN(className, pin) \
1275class className { \
1276public: \
1277 static void Set() { \
1278 nrf_gpio_pin_set(pin); \
1279 } \
1280 static void Clear() { \
1281 nrf_gpio_pin_clear(pin); \
1282 } \
1283 static void SetDirRead() { \
1284 nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL); \
1285 } \
1286 static void SetDirWrite() { \
1287 nrf_gpio_cfg_output(pin); \
1288 } \
1289 static uint8_t IsSet() { \
1290 return (uint8_t)nrf_gpio_pin_read(pin); \
1291 } \
1292};
1293
1294// See: pin_transform.c in RBL nRF51822 SDK
1320
1321#undef MAKE_PIN
1322
1323#elif defined(__IMXRT1062__) && (defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41))
1324// Teensy 4.x
1325
1326#include "core_pins.h"
1327
1328#define MAKE_PIN(className, pin) \
1329class className { \
1330public: \
1331 static void Set() { \
1332 digitalWriteFast(pin, HIGH);\
1333 } \
1334 static void Clear() { \
1335 digitalWriteFast(pin, LOW); \
1336 } \
1337 static void SetDirRead() { \
1338 pinMode(pin, INPUT); \
1339 } \
1340 static void SetDirWrite() { \
1341 pinMode(pin, OUTPUT); \
1342 } \
1343 static uint8_t IsSet() { \
1344 return digitalReadFast(pin); \
1345 } \
1346};
1347
1348MAKE_PIN(P0, 0);
1349MAKE_PIN(P1, 1);
1350MAKE_PIN(P2, 2);
1351MAKE_PIN(P3, 3);
1352MAKE_PIN(P4, 4);
1353MAKE_PIN(P5, 5);
1354MAKE_PIN(P6, 6);
1355MAKE_PIN(P7, 7);
1356MAKE_PIN(P8, 8);
1357MAKE_PIN(P9, 9);
1358MAKE_PIN(P10, 10);
1359MAKE_PIN(P11, 11);
1360MAKE_PIN(P12, 12);
1361MAKE_PIN(P13, 13);
1362MAKE_PIN(P14, 14);
1363MAKE_PIN(P15, 15);
1364MAKE_PIN(P16, 16);
1365MAKE_PIN(P17, 17);
1366MAKE_PIN(P18, 18);
1367MAKE_PIN(P19, 19);
1368MAKE_PIN(P20, 20);
1369MAKE_PIN(P21, 21);
1370MAKE_PIN(P22, 22);
1371MAKE_PIN(P23, 23);
1372MAKE_PIN(P24, 24);
1373MAKE_PIN(P25, 25);
1374MAKE_PIN(P26, 26);
1375MAKE_PIN(P27, 27);
1376MAKE_PIN(P28, 28);
1377MAKE_PIN(P29, 29);
1378MAKE_PIN(P30, 30);
1379MAKE_PIN(P31, 31);
1380MAKE_PIN(P32, 35);
1381MAKE_PIN(P33, 33);
1382MAKE_PIN(P34, 34);
1383MAKE_PIN(P35, 35);
1384MAKE_PIN(P36, 36);
1385MAKE_PIN(P37, 37);
1386MAKE_PIN(P38, 38);
1387MAKE_PIN(P39, 39);
1388#ifdef ARDUINO_TEENSY41
1389MAKE_PIN(P40, 40);
1390MAKE_PIN(P41, 41);
1391MAKE_PIN(P42, 42);
1392MAKE_PIN(P43, 43);
1393MAKE_PIN(P44, 44);
1394MAKE_PIN(P45, 45);
1395MAKE_PIN(P46, 46);
1396MAKE_PIN(P47, 47);
1397MAKE_PIN(P48, 48);
1398MAKE_PIN(P49, 49);
1399MAKE_PIN(P50, 50);
1400MAKE_PIN(P51, 51);
1401MAKE_PIN(P52, 52);
1402MAKE_PIN(P53, 53);
1403MAKE_PIN(P54, 54);
1404#endif
1405
1406#undef MAKE_PIN
1407
1408#elif defined(ARDUINO_ARCH_RENESAS_UNO)
1409#define MAKE_PIN(className, pin) \
1410class className { \
1411public: \
1412 static void Set() { \
1413 digitalWrite(pin, HIGH); \
1414 } \
1415 static void Clear() { \
1416 digitalWrite(pin, LOW); \
1417 } \
1418 static void SetDirRead() { \
1419 pinMode(pin, INPUT); \
1420 } \
1421 static void SetDirWrite() { \
1422 pinMode(pin, OUTPUT); \
1423 } \
1424 static uint8_t IsSet() { \
1425 return digitalRead(pin); \
1426 } \
1427};
1428
1429MAKE_PIN(P0, 0);
1430MAKE_PIN(P1, 1);
1431MAKE_PIN(P2, 2);
1432MAKE_PIN(P3, 3);
1433MAKE_PIN(P4, 4);
1434MAKE_PIN(P5, 5);
1435MAKE_PIN(P6, 6);
1436MAKE_PIN(P7, 7);
1437MAKE_PIN(P8, 8);
1438MAKE_PIN(P9, 9);
1439MAKE_PIN(P10, 10);
1440MAKE_PIN(P11, 11);
1441MAKE_PIN(P12, 12);
1442MAKE_PIN(P13, 13);
1443MAKE_PIN(P14, 14); // A0
1444MAKE_PIN(P15, 15); // A1
1445MAKE_PIN(P16, 16); // A2
1446MAKE_PIN(P17, 17); // A3
1447MAKE_PIN(P18, 18); // A4
1448MAKE_PIN(P19, 19); // A5
1449
1450#undef MAKE_PIN
1451
1452#elif defined(STM32F446xx)
1453// NUCLEO-F446RE
1454
1455#define MAKE_PIN(className, port, pin) \
1456class className { \
1457public: \
1458 static void Set() { \
1459 HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET); \
1460 } \
1461 static void Clear() { \
1462 HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET); \
1463 } \
1464 static void SetDirRead() { \
1465 static GPIO_InitTypeDef GPIO_InitStruct; \
1466 GPIO_InitStruct.Pin = pin; \
1467 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; \
1468 GPIO_InitStruct.Pull = GPIO_NOPULL; \
1469 HAL_GPIO_Init(port, &GPIO_InitStruct); \
1470 } \
1471 static void SetDirWrite() { \
1472 static GPIO_InitTypeDef GPIO_InitStruct; \
1473 GPIO_InitStruct.Pin = pin; \
1474 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; \
1475 GPIO_InitStruct.Pull = GPIO_NOPULL; \
1476 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; \
1477 HAL_GPIO_Init(port, &GPIO_InitStruct); \
1478 } \
1479 static GPIO_PinState IsSet() { \
1480 return HAL_GPIO_ReadPin(port, pin); \
1481 } \
1482};
1483
1484MAKE_PIN(P0, GPIOA, GPIO_PIN_3); // D0
1485MAKE_PIN(P1, GPIOA, GPIO_PIN_2); // D1
1486MAKE_PIN(P2, GPIOA, GPIO_PIN_10); // D2
1487MAKE_PIN(P3, GPIOB, GPIO_PIN_3); // D3
1488MAKE_PIN(P4, GPIOB, GPIO_PIN_5); // D4
1489MAKE_PIN(P5, GPIOB, GPIO_PIN_4); // D5
1490MAKE_PIN(P6, GPIOB, GPIO_PIN_10); // D6
1491MAKE_PIN(P7, GPIOA, GPIO_PIN_8); // D7
1492MAKE_PIN(P8, GPIOA, GPIO_PIN_9); // D8
1493MAKE_PIN(P9, GPIOC, GPIO_PIN_7); // D9
1494MAKE_PIN(P10, GPIOB, GPIO_PIN_6); // D10
1495MAKE_PIN(P11, GPIOA, GPIO_PIN_7); // D11
1496MAKE_PIN(P12, GPIOA, GPIO_PIN_6); // D12
1497MAKE_PIN(P13, GPIOA, GPIO_PIN_5); // D13
1498
1499MAKE_PIN(P14, GPIOA, GPIO_PIN_0); // A0
1500MAKE_PIN(P15, GPIOA, GPIO_PIN_1); // A1
1501MAKE_PIN(P16, GPIOA, GPIO_PIN_4); // A2
1502MAKE_PIN(P17, GPIOB, GPIO_PIN_0); // A3
1503MAKE_PIN(P18, GPIOC, GPIO_PIN_1); // A4
1504MAKE_PIN(P19, GPIOC, GPIO_PIN_0); // A5
1505
1506#undef MAKE_PIN
1507
1508
1509#elif defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
1510
1511#define MAKE_PIN(className, pin) \
1512class className { \
1513public: \
1514 static void Set() { \
1515 nrf_gpio_pin_set(pin); \
1516 } \
1517 static void Clear() { \
1518 nrf_gpio_pin_clear(pin); \
1519 } \
1520 static void SetDirRead() { \
1521 nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL); \
1522 } \
1523 static void SetDirWrite() { \
1524 nrf_gpio_cfg_output(pin); \
1525 } \
1526 static uint8_t IsSet() { \
1527 return (uint8_t)nrf_gpio_pin_read(pin); \
1528 } \
1529};
1530
1531// Based on variants/feather_nrf52840_express/variant.cpp
1532// g_ADigitalPinMap could be used directly, but it would be slower
1533MAKE_PIN(P0, (25));
1534MAKE_PIN(P1, (24));
1535MAKE_PIN(P2, (10));
1536MAKE_PIN(P3, (47));
1537MAKE_PIN(P4, (42));
1538MAKE_PIN(P5, (40));
1539MAKE_PIN(P6, (7));
1540MAKE_PIN(P7, (34));
1541MAKE_PIN(P8, (16));
1542MAKE_PIN(P9, (26));
1543MAKE_PIN(P10, (27));
1544MAKE_PIN(P11, (6));
1545MAKE_PIN(P12, (8));
1546MAKE_PIN(P13, (41));
1547MAKE_PIN(P14, (4));
1548MAKE_PIN(P15, (5));
1549MAKE_PIN(P17, (30));
1550MAKE_PIN(P18, (28));
1551MAKE_PIN(P16, (2));
1552MAKE_PIN(P19, (3));
1553MAKE_PIN(P20, (29));
1554MAKE_PIN(P21, (31));
1555MAKE_PIN(P22, (12));
1556MAKE_PIN(P23, (11));
1557MAKE_PIN(P24, (15));
1558MAKE_PIN(P25, (13));
1559MAKE_PIN(P26, (14));
1560MAKE_PIN(P27, (19));
1561MAKE_PIN(P28, (20));
1562MAKE_PIN(P29, (17));
1563MAKE_PIN(P30, (22));
1564MAKE_PIN(P31, (23));
1565MAKE_PIN(P32, (21));
1566MAKE_PIN(P33, (9));
1567
1568#undef MAKE_PIN
1569
1570
1571
1572#elif defined(ARDUINO_Seeed_XIAO_nRF52840_Sense)
1573
1574#define MAKE_PIN(className, pin) \
1575class className { \
1576public: \
1577 static void Set() { \
1578 nrf_gpio_pin_set(pin); \
1579 } \
1580 static void Clear() { \
1581 nrf_gpio_pin_clear(pin); \
1582 } \
1583 static void SetDirRead() { \
1584 nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL); \
1585 } \
1586 static void SetDirWrite() { \
1587 nrf_gpio_cfg_output(pin); \
1588 } \
1589 static uint8_t IsSet() { \
1590 return (uint8_t)nrf_gpio_pin_read(pin); \
1591 } \
1592};
1593
1594// Based on variants/feather_nrf52840_express/variant.cpp
1595// g_ADigitalPinMap could be used directly, but it would be slower
1596MAKE_PIN(P0, (2));
1597MAKE_PIN(P1, (3));
1598MAKE_PIN(P2, (28));
1599MAKE_PIN(P3, (29));
1600MAKE_PIN(P4, (4));
1601MAKE_PIN(P5, (5));
1602MAKE_PIN(P6, (43));
1603MAKE_PIN(P7, (44));
1604MAKE_PIN(P8, (45));
1605MAKE_PIN(P9, (46));
1606MAKE_PIN(P10, (47));
1607MAKE_PIN(P11, (26));
1608MAKE_PIN(P12, (6));
1609MAKE_PIN(P13, (30));
1610MAKE_PIN(P14, (14));
1611MAKE_PIN(P15, (40));
1612MAKE_PIN(P17, (27));
1613MAKE_PIN(P18, (7));
1614MAKE_PIN(P16, (11));
1615MAKE_PIN(P19, (42));
1616MAKE_PIN(P20, (32));
1617MAKE_PIN(P21, (16));
1618MAKE_PIN(P22, (13));
1619MAKE_PIN(P23, (17));
1620MAKE_PIN(P24, (21));
1621MAKE_PIN(P25, (25));
1622MAKE_PIN(P26, (20));
1623MAKE_PIN(P27, (24));
1624MAKE_PIN(P28, (22));
1625MAKE_PIN(P29, (23));
1626MAKE_PIN(P30, (9));
1627MAKE_PIN(P31, (10));
1628MAKE_PIN(P32, (31));
1629
1630#undef MAKE_PIN
1631
1632#else
1633#error "Please define board in avrpins.h"
1634
1635#endif
1636
1637#elif defined(__ARDUINO_ARC__)
1638
1639#include <avr/pgmspace.h>
1640// Pointers are 32 bits on arc
1641#define pgm_read_pointer(p) pgm_read_dword(p)
1642
1643#define MAKE_PIN(className, pin) \
1644class className { \
1645public: \
1646 static void Set() { \
1647 digitalWrite(pin, HIGH);\
1648 } \
1649 static void Clear() { \
1650 digitalWrite(pin, LOW); \
1651 } \
1652 static void SetDirRead() { \
1653 pinMode(pin, INPUT); \
1654 } \
1655 static void SetDirWrite() { \
1656 pinMode(pin, OUTPUT); \
1657 } \
1658 static uint8_t IsSet() { \
1659 return digitalRead(pin); \
1660 } \
1661};
1662
1663MAKE_PIN(P0, 0);
1664MAKE_PIN(P1, 1);
1665MAKE_PIN(P2, 2);
1666MAKE_PIN(P3, 3); //PWM
1667MAKE_PIN(P4, 4);
1668MAKE_PIN(P5, 5); //PWM
1669MAKE_PIN(P6, 6); //PWM
1670MAKE_PIN(P7, 7);
1671MAKE_PIN(P8, 8);
1672MAKE_PIN(P9, 9); //PWM
1673
1674MAKE_PIN(P10, 10); //SPI SS
1675MAKE_PIN(P11, 11); //SPI MOSI
1676MAKE_PIN(P12, 12); //SPI MISO
1677MAKE_PIN(P13, 13); //SPI SCK / BUILTIN LED
1678
1679MAKE_PIN(P14, 14); // A0
1680MAKE_PIN(P15, 15); // A1
1681MAKE_PIN(P16, 16); // A2
1682MAKE_PIN(P17, 17); // A3
1683MAKE_PIN(P18, 18); // A4 SDA
1684MAKE_PIN(P19, 19); // A5 SCL
1685MAKE_PIN(P20, 20); // ATN
1686
1687#undef MAKE_PIN
1688
1689#elif defined(__ARDUINO_X86__) // Intel Galileo, Intel Galileo 2 and Intel Edison
1690
1691#include <avr/pgmspace.h>
1692
1693// Pointers are 32 bits on x86
1694#define pgm_read_pointer(p) pgm_read_dword(p)
1695
1696#if PLATFORM_ID == 0xE1 // Edison platform id
1697#define pinToFastPin(pin) 1 // As far as I can tell all pins can be used as fast pins
1698#endif
1699
1700// Pin 2 and 3 on the Intel Galileo supports a higher rate,
1701// so it is recommended to use one of these as the SS pin.
1702
1703#define MAKE_PIN(className, pin) \
1704class className { \
1705public: \
1706 static void Set() { \
1707 fastDigitalWrite(pin, HIGH); \
1708 } \
1709 static void Clear() { \
1710 fastDigitalWrite(pin, LOW); \
1711 } \
1712 static void SetDirRead() { \
1713 if (pinToFastPin(pin)) \
1714 pinMode(pin, INPUT_FAST); \
1715 else \
1716 pinMode(pin, INPUT); \
1717 } \
1718 static void SetDirWrite() { \
1719 if (pinToFastPin(pin)) \
1720 pinMode(pin, OUTPUT_FAST); \
1721 else \
1722 pinMode(pin, OUTPUT); \
1723 } \
1724 static uint8_t IsSet() { \
1725 return fastDigitalRead(pin); \
1726 } \
1727};
1728
1729MAKE_PIN(P0, 0);
1730MAKE_PIN(P1, 1);
1731MAKE_PIN(P2, 2);
1732MAKE_PIN(P3, 3);
1733MAKE_PIN(P4, 4);
1734MAKE_PIN(P5, 5);
1735MAKE_PIN(P6, 6);
1736MAKE_PIN(P7, 7);
1737MAKE_PIN(P8, 8);
1738MAKE_PIN(P9, 9);
1739MAKE_PIN(P10, 10);
1740MAKE_PIN(P11, 11);
1741MAKE_PIN(P12, 12);
1742MAKE_PIN(P13, 13);
1743MAKE_PIN(P14, 14); // A0
1744MAKE_PIN(P15, 15); // A1
1745MAKE_PIN(P16, 16); // A2
1746MAKE_PIN(P17, 17); // A3
1747MAKE_PIN(P18, 18); // A4
1748MAKE_PIN(P19, 19); // A5
1749
1750#undef MAKE_PIN
1751
1752#elif defined(__MIPSEL__)
1753// MIPSEL (MIPS architecture using a little endian byte order)
1754
1755// MIPS size_t = 4
1756#define pgm_read_pointer(p) pgm_read_dword(p)
1757
1758#define MAKE_PIN(className, pin) \
1759class className { \
1760public: \
1761 static void Set() { \
1762 digitalWrite(pin, HIGH);\
1763 } \
1764 static void Clear() { \
1765 digitalWrite(pin, LOW); \
1766 } \
1767 static void SetDirRead() { \
1768 pinMode(pin, INPUT); \
1769 } \
1770 static void SetDirWrite() { \
1771 pinMode(pin, OUTPUT); \
1772 } \
1773 static uint8_t IsSet() { \
1774 return digitalRead(pin); \
1775 } \
1776};
1777
1778// 0 .. 13 - Digital pins
1779MAKE_PIN(P0, 0); // RX
1780MAKE_PIN(P1, 1); // TX
1781MAKE_PIN(P2, 2); //
1782MAKE_PIN(P3, 3); //
1783MAKE_PIN(P4, 4); //
1784MAKE_PIN(P5, 5); //
1785MAKE_PIN(P6, 6); //
1786MAKE_PIN(P7, 7); //
1787MAKE_PIN(P8, 8); //
1788MAKE_PIN(P9, 9); //
1789MAKE_PIN(P10, 10); //
1790MAKE_PIN(P11, 11); //
1791MAKE_PIN(P12, 12); //
1792MAKE_PIN(P13, 13); //
1793
1794#undef MAKE_PIN
1795
1796#elif defined(ESP8266) || defined(ESP32)
1797
1798#define MAKE_PIN(className, pin) \
1799class className { \
1800public: \
1801 static void Set() { \
1802 digitalWrite(pin, HIGH);\
1803 } \
1804 static void Clear() { \
1805 digitalWrite(pin, LOW); \
1806 } \
1807 static void SetDirRead() { \
1808 pinMode(pin, INPUT); \
1809 } \
1810 static void SetDirWrite() { \
1811 pinMode(pin, OUTPUT); \
1812 } \
1813 static uint8_t IsSet() { \
1814 return digitalRead(pin); \
1815 } \
1816};
1817
1818#if defined(ESP8266)
1819
1820// Workaround the following issue: https://github.com/esp8266/Arduino/pull/5735
1821#undef pgm_read_ptr_aligned
1822#ifdef __cplusplus
1823#define pgm_read_ptr_aligned(addr) (*reinterpret_cast<const void* const*>(addr))
1824#else
1825#define pgm_read_ptr_aligned(addr) (*(const void* const*)(addr))
1826#endif
1827
1828#undef pgm_read_ptr
1829#if PGM_READ_UNALIGNED
1830#define pgm_read_ptr(p) pgm_read_ptr_unaligned(p)
1831#else
1832#define pgm_read_ptr(p) pgm_read_ptr_aligned(p)
1833#endif
1834
1835#ifdef pgm_read_pointer
1836#undef pgm_read_pointer
1837#endif
1838#define pgm_read_pointer(p) pgm_read_ptr(p)
1839
1840// Pinout for ESP-12 module
1841// 0 .. 16 - Digital pins
1842// GPIO 6 to 11 and 16 are not usable in this library.
1843
1844MAKE_PIN(P0, 0);
1845MAKE_PIN(P1, 1); // TX0
1846MAKE_PIN(P2, 2); // TX1
1847MAKE_PIN(P3, 3); // RX0
1848MAKE_PIN(P4, 4); // SDA
1849MAKE_PIN(P5, 5); // SCL
1850MAKE_PIN(P12, 12); // MISO
1851MAKE_PIN(P13, 13); // MOSI
1852MAKE_PIN(P14, 14); // SCK
1853MAKE_PIN(P15, 15); // SS
1854
1855#elif defined(ARDUINO_M5STACK_CORES3)
1856
1857// Workaround strict-aliasing warnings
1858#ifdef pgm_read_word
1859#undef pgm_read_word
1860#endif
1861#ifdef pgm_read_dword
1862#undef pgm_read_dword
1863#endif
1864#ifdef pgm_read_float
1865#undef pgm_read_float
1866#endif
1867#ifdef pgm_read_ptr
1868#undef pgm_read_ptr
1869#endif
1870
1871#define pgm_read_word(addr) ({ \
1872 typeof(addr) _addr = (addr); \
1873 *(const unsigned short *)(_addr); \
1874})
1875#define pgm_read_dword(addr) ({ \
1876 typeof(addr) _addr = (addr); \
1877 *(const unsigned long *)(_addr); \
1878})
1879#define pgm_read_float(addr) ({ \
1880 typeof(addr) _addr = (addr); \
1881 *(const float *)(_addr); \
1882})
1883#define pgm_read_ptr(addr) ({ \
1884 typeof(addr) _addr = (addr); \
1885 *(void * const *)(_addr); \
1886})
1887
1888// Pinout for ESP32 dev module
1889
1890MAKE_PIN(P35, 35); // MISO
1891MAKE_PIN(P37, 37); // MOSI
1892MAKE_PIN(P36, 36); // SCK
1893MAKE_PIN(P1, 1); // SS
1894MAKE_PIN(P14, 14); // INT
1895
1896#elif defined(ARDUINO_XIAO_ESP32S3)
1897
1898// Workaround strict-aliasing warnings
1899#ifdef pgm_read_word
1900#undef pgm_read_word
1901#endif
1902#ifdef pgm_read_dword
1903#undef pgm_read_dword
1904#endif
1905#ifdef pgm_read_float
1906#undef pgm_read_float
1907#endif
1908#ifdef pgm_read_ptr
1909#undef pgm_read_ptr
1910#endif
1911
1912#define pgm_read_word(addr) ({ \
1913 typeof(addr) _addr = (addr); \
1914 *(const unsigned short *)(_addr); \
1915})
1916#define pgm_read_dword(addr) ({ \
1917 typeof(addr) _addr = (addr); \
1918 *(const unsigned long *)(_addr); \
1919})
1920#define pgm_read_float(addr) ({ \
1921 typeof(addr) _addr = (addr); \
1922 *(const float *)(_addr); \
1923})
1924#define pgm_read_ptr(addr) ({ \
1925 typeof(addr) _addr = (addr); \
1926 *(void * const *)(_addr); \
1927})
1928
1929// Pinout for ESP32 dev module
1930
1931MAKE_PIN(P8, 8); // MISO
1932MAKE_PIN(P9, 9); // MOSI
1933MAKE_PIN(P7, 7); // SCK
1934MAKE_PIN(P44, 44); // SS
1935MAKE_PIN(P4, 4); // INT
1936
1937#elif defined(ESP32)
1938
1939// Workaround strict-aliasing warnings
1940#ifdef pgm_read_word
1941#undef pgm_read_word
1942#endif
1943#ifdef pgm_read_dword
1944#undef pgm_read_dword
1945#endif
1946#ifdef pgm_read_float
1947#undef pgm_read_float
1948#endif
1949#ifdef pgm_read_ptr
1950#undef pgm_read_ptr
1951#endif
1952
1953#define pgm_read_word(addr) ({ \
1954 typeof(addr) _addr = (addr); \
1955 *(const unsigned short *)(_addr); \
1956})
1957#define pgm_read_dword(addr) ({ \
1958 typeof(addr) _addr = (addr); \
1959 *(const unsigned long *)(_addr); \
1960})
1961#define pgm_read_float(addr) ({ \
1962 typeof(addr) _addr = (addr); \
1963 *(const float *)(_addr); \
1964})
1965#define pgm_read_ptr(addr) ({ \
1966 typeof(addr) _addr = (addr); \
1967 *(void * const *)(_addr); \
1968})
1969
1970// Pinout for ESP32 dev module
1971
1972MAKE_PIN(P0, 0);
1973MAKE_PIN(P1, 1); // TX0
1974MAKE_PIN(P10, 10); // TX1
1975MAKE_PIN(P3, 3); // RX0
1976MAKE_PIN(P21, 21); // SDA
1977MAKE_PIN(P22, 22); // SCL
1978MAKE_PIN(P19, 19); // MISO
1979MAKE_PIN(P23, 23); // MOSI
1980MAKE_PIN(P18, 18); // SCK
1981MAKE_PIN(P5, 5); // SS
1982MAKE_PIN(P17, 17); // INT
1983
1984#endif
1985
1986#undef MAKE_PIN
1987
1988// pgm_read_ptr is not defined in the ESP32, so we have to undef the diffinition from version_helper.h
1989#ifdef pgm_read_pointer
1990#undef pgm_read_pointer
1991#endif
1992#define pgm_read_pointer(p) pgm_read_ptr(p)
1993
1994#else
1995#error "Please define board in avrpins.h"
1996
1997#endif
1998
1999#endif //_avrpins_h_
ConfigDescParser(UsbConfigXtracter *xtractor)