27 #if !defined(_usb_h_) || defined(_avrpins_h_)
28 #error "Never include avrpins.h directly; include Usb.h instead"
35 #define pgm_read_pointer(p) pgm_read_word(p)
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
96 #define MAKE_PORT(portName, ddrName, pinName, className, ID) \
99 typedef uint8_t DataT;\
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;}\
114 enum{Width=sizeof(DataT)*8};\
118 #define MAKE_TCCR(TccrName, className) \
121 typedef uint8_t DataT;\
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};\
134 MAKE_PORT(PORTA, DDRA, PINA, Porta,
'A')
137 MAKE_PORT(PORTB, DDRB, PINB, Portb,
'B')
140 MAKE_PORT(PORTC, DDRC, PINC, Portc,
'C')
143 MAKE_PORT(PORTD, DDRD, PIND, Portd,
'D')
146 MAKE_PORT(PORTE, DDRE, PINE, Porte,
'E')
149 MAKE_PORT(PORTF, DDRF, PINF, Portf,
'F')
152 MAKE_PORT(PORTG, DDRG, PING, Portg,
'G')
155 MAKE_PORT(PORTH, DDRH, PINH, Porth,
'H')
158 MAKE_PORT(PORTJ, DDRJ, PINJ, Portj,
'J')
161 MAKE_PORT(PORTK, DDRK, PINK, Portk,
'K')
164 MAKE_PORT(PORTL, DDRL, PINL, Portl,
'L')
167 MAKE_PORT(PORTQ, DDRQ, PINQ, Portq,
'Q')
170 MAKE_PORT(PORTR, DDRR, PINR, Portr,
'R')
174 MAKE_TCCR(TCCR0A, Tccr0a)
177 MAKE_TCCR(TCCR1A, Tccr1a)
180 MAKE_TCCR(TCCR2A, Tccr2a)
185 template<
typename PORT, u
int8_t PIN>
199 static void Set(uint8_t val) {
205 static void SetDir(uint8_t val) {
211 static void Clear() {
212 PORT::Clear(1 << PIN);
215 static void Toggle() {
216 PORT::Toggle(1 << PIN);
219 static void SetDirRead() {
220 PORT::DirClear(1 << PIN);
223 static void SetDirWrite() {
224 PORT::DirSet(1 << PIN);
227 static uint8_t IsSet() {
228 return PORT::PinRead() & (uint8_t)(1 << PIN);
231 static void WaiteForSet() {
232 while(IsSet() == 0) {
236 static void WaiteForClear() {
246 template<
typename TCCR, u
int8_t COM>
260 static void Clear() {
261 TCCR::Clear(1 << COM);
264 static void Toggle() {
265 TCCR::Toggle(1 << COM);
271 typedef TPin<Porta, 0 > Pa0;
272 typedef TPin<Porta, 1 > Pa1;
273 typedef TPin<Porta, 2 > Pa2;
274 typedef TPin<Porta, 3 > Pa3;
275 typedef TPin<Porta, 4 > Pa4;
276 typedef TPin<Porta, 5 > Pa5;
277 typedef TPin<Porta, 6 > Pa6;
278 typedef TPin<Porta, 7 > Pa7;
282 typedef TPin<Portb, 0 > Pb0;
283 typedef TPin<Portb, 1 > Pb1;
284 typedef TPin<Portb, 2 > Pb2;
285 typedef TPin<Portb, 3 > Pb3;
286 typedef TPin<Portb, 4 > Pb4;
287 typedef TPin<Portb, 5 > Pb5;
288 typedef TPin<Portb, 6 > Pb6;
289 typedef TPin<Portb, 7 > Pb7;
293 typedef TPin<Portc, 0 > Pc0;
294 typedef TPin<Portc, 1 > Pc1;
295 typedef TPin<Portc, 2 > Pc2;
296 typedef TPin<Portc, 3 > Pc3;
297 typedef TPin<Portc, 4 > Pc4;
298 typedef TPin<Portc, 5 > Pc5;
299 typedef TPin<Portc, 6 > Pc6;
300 typedef TPin<Portc, 7 > Pc7;
304 typedef TPin<Portd, 0 > Pd0;
305 typedef TPin<Portd, 1 > Pd1;
306 typedef TPin<Portd, 2 > Pd2;
307 typedef TPin<Portd, 3 > Pd3;
308 typedef TPin<Portd, 4 > Pd4;
309 typedef TPin<Portd, 5 > Pd5;
310 typedef TPin<Portd, 6 > Pd6;
311 typedef TPin<Portd, 7 > Pd7;
315 typedef TPin<Porte, 0 > Pe0;
316 typedef TPin<Porte, 1 > Pe1;
317 typedef TPin<Porte, 2 > Pe2;
318 typedef TPin<Porte, 3 > Pe3;
319 typedef TPin<Porte, 4 > Pe4;
320 typedef TPin<Porte, 5 > Pe5;
321 typedef TPin<Porte, 6 > Pe6;
322 typedef TPin<Porte, 7 > Pe7;
326 typedef TPin<Portf, 0 > Pf0;
327 typedef TPin<Portf, 1 > Pf1;
328 typedef TPin<Portf, 2 > Pf2;
329 typedef TPin<Portf, 3 > Pf3;
330 typedef TPin<Portf, 4 > Pf4;
331 typedef TPin<Portf, 5 > Pf5;
332 typedef TPin<Portf, 6 > Pf6;
333 typedef TPin<Portf, 7 > Pf7;
337 typedef TPin<Portg, 0 > Pg0;
338 typedef TPin<Portg, 1 > Pg1;
339 typedef TPin<Portg, 2 > Pg2;
340 typedef TPin<Portg, 3 > Pg3;
341 typedef TPin<Portg, 4 > Pg4;
342 typedef TPin<Portg, 5 > Pg5;
343 typedef TPin<Portg, 6 > Pg6;
344 typedef TPin<Portg, 7 > Pg7;
348 typedef TPin<Porth, 0 > Ph0;
349 typedef TPin<Porth, 1 > Ph1;
350 typedef TPin<Porth, 2 > Ph2;
351 typedef TPin<Porth, 3 > Ph3;
352 typedef TPin<Porth, 4 > Ph4;
353 typedef TPin<Porth, 5 > Ph5;
354 typedef TPin<Porth, 6 > Ph6;
355 typedef TPin<Porth, 7 > Ph7;
359 typedef TPin<Portj, 0 > Pj0;
360 typedef TPin<Portj, 1 > Pj1;
361 typedef TPin<Portj, 2 > Pj2;
362 typedef TPin<Portj, 3 > Pj3;
363 typedef TPin<Portj, 4 > Pj4;
364 typedef TPin<Portj, 5 > Pj5;
365 typedef TPin<Portj, 6 > Pj6;
366 typedef TPin<Portj, 7 > Pj7;
370 typedef TPin<Portk, 0 > Pk0;
371 typedef TPin<Portk, 1 > Pk1;
372 typedef TPin<Portk, 2 > Pk2;
373 typedef TPin<Portk, 3 > Pk3;
374 typedef TPin<Portk, 4 > Pk4;
375 typedef TPin<Portk, 5 > Pk5;
376 typedef TPin<Portk, 6 > Pk6;
377 typedef TPin<Portk, 7 > Pk7;
381 typedef TPin<Portl, 0 > Pl0;
382 typedef TPin<Portl, 1 > Pl1;
383 typedef TPin<Portl, 2 > Pl2;
384 typedef TPin<Portl, 3 > Pl3;
385 typedef TPin<Portl, 4 > Pl4;
386 typedef TPin<Portl, 5 > Pl5;
387 typedef TPin<Portl, 6 > Pl6;
388 typedef TPin<Portl, 7 > Pl7;
392 typedef TPin<Portq, 0 > Pq0;
393 typedef TPin<Portq, 1 > Pq1;
394 typedef TPin<Portq, 2 > Pq2;
395 typedef TPin<Portq, 3 > Pq3;
396 typedef TPin<Portq, 4 > Pq4;
397 typedef TPin<Portq, 5 > Pq5;
398 typedef TPin<Portq, 6 > Pq6;
399 typedef TPin<Portq, 7 > Pq7;
403 typedef TPin<Portr, 0 > Pr0;
404 typedef TPin<Portr, 1 > Pr1;
405 typedef TPin<Portr, 2 > Pr2;
406 typedef TPin<Portr, 3 > Pr3;
407 typedef TPin<Portr, 4 > Pr4;
408 typedef TPin<Portr, 5 > Pr5;
409 typedef TPin<Portr, 6 > Pr6;
410 typedef TPin<Portr, 7 > Pr7;
414 typedef TCom<Tccr0a, COM0A1> Tc0a;
415 typedef TCom<Tccr0a, COM0B1> Tc0b;
419 typedef TCom<Tccr1a, COM1A1> Tc1a;
420 typedef TCom<Tccr1a, COM1B1> Tc1b;
424 typedef TCom<Tccr2a, COM2A1> Tc2a;
425 typedef TCom<Tccr2a, COM2B1> Tc2b;
428 template<
typename Tp_pin,
typename Tc_bit>
432 static void SetDir(uint8_t val) {
438 static void SetDirRead() {
439 Tp_pin::SetDirRead();
443 static void SetDirWrite() {
444 Tp_pin::SetDirWrite();
459 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
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
528 #elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
556 #elif defined(CORE_TEENSY) && defined(__AVR_ATmega32U4__)
586 #elif defined(__AVR_ATmega32U4__)
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
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
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
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
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
626 #elif defined(CORE_TEENSY) && (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__))
677 #elif defined(ARDUINO_AVR_BALANDUINO) && (defined(__AVR_ATmega644__) || defined(__AVR_ATmega1284P__))
683 #if BALANDUINO_REVISION < 13
705 #if BALANDUINO_REVISION < 13
730 #elif defined(ARDUINO_AVR_UNO_PRO) && defined(__AVR_ATmega1284P__)
768 #elif defined(MIGHTYCORE)
770 #if defined(BOBUINO_PINOUT)
828 #if defined(SANGUINO_PINOUT)
850 #elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
889 #error "Please define board in avrpins.h"
891 #endif // Arduino pin definitions
893 #elif defined(__arm__)
896 #define pgm_read_pointer(p) pgm_read_dword(p)
898 #if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__))
901 #include "core_pins.h"
902 #include "avr_emulation.h"
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)))
907 #define MAKE_PIN(className, baseReg, pinNum, configReg) \
910 static void Set() { \
911 *GPIO_BITBAND_PTR(baseReg, pinNum) = 1; \
913 static void Clear() { \
914 *GPIO_BITBAND_PTR(baseReg, pinNum) = 0; \
916 static void SetDirRead() { \
917 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \
918 *(GPIO_BITBAND_PTR(baseReg, pinNum) + 640) = 0; \
920 static void SetDirWrite() { \
921 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \
922 *(GPIO_BITBAND_PTR(baseReg, pinNum) + 640) = 1; \
924 static uint8_t IsSet() { \
925 return *(GPIO_BITBAND_PTR(baseReg, pinNum) + 512); \
929 MAKE_PIN(P0, CORE_PIN0_PORTREG, CORE_PIN0_BIT, CORE_PIN0_CONFIG);
930 MAKE_PIN(P1, CORE_PIN1_PORTREG, CORE_PIN1_BIT, CORE_PIN1_CONFIG);
931 MAKE_PIN(P2, CORE_PIN2_PORTREG, CORE_PIN2_BIT, CORE_PIN2_CONFIG);
932 MAKE_PIN(P3, CORE_PIN3_PORTREG, CORE_PIN3_BIT, CORE_PIN3_CONFIG);
933 MAKE_PIN(P4, CORE_PIN4_PORTREG, CORE_PIN4_BIT, CORE_PIN4_CONFIG);
934 MAKE_PIN(P5, CORE_PIN5_PORTREG, CORE_PIN5_BIT, CORE_PIN5_CONFIG);
935 MAKE_PIN(P6, CORE_PIN6_PORTREG, CORE_PIN6_BIT, CORE_PIN6_CONFIG);
936 MAKE_PIN(P7, CORE_PIN7_PORTREG, CORE_PIN7_BIT, CORE_PIN7_CONFIG);
937 MAKE_PIN(P8, CORE_PIN8_PORTREG, CORE_PIN8_BIT, CORE_PIN8_CONFIG);
938 MAKE_PIN(P9, CORE_PIN9_PORTREG, CORE_PIN9_BIT, CORE_PIN9_CONFIG);
939 MAKE_PIN(P10, CORE_PIN10_PORTREG, CORE_PIN10_BIT, CORE_PIN10_CONFIG);
940 MAKE_PIN(P11, CORE_PIN11_PORTREG, CORE_PIN11_BIT, CORE_PIN11_CONFIG);
941 MAKE_PIN(P12, CORE_PIN12_PORTREG, CORE_PIN12_BIT, CORE_PIN12_CONFIG);
942 MAKE_PIN(P13, CORE_PIN13_PORTREG, CORE_PIN13_BIT, CORE_PIN13_CONFIG);
943 MAKE_PIN(P14, CORE_PIN14_PORTREG, CORE_PIN14_BIT, CORE_PIN14_CONFIG);
944 MAKE_PIN(P15, CORE_PIN15_PORTREG, CORE_PIN15_BIT, CORE_PIN15_CONFIG);
945 MAKE_PIN(P16, CORE_PIN16_PORTREG, CORE_PIN16_BIT, CORE_PIN16_CONFIG);
946 MAKE_PIN(P17, CORE_PIN17_PORTREG, CORE_PIN17_BIT, CORE_PIN17_CONFIG);
947 MAKE_PIN(P18, CORE_PIN18_PORTREG, CORE_PIN18_BIT, CORE_PIN18_CONFIG);
948 MAKE_PIN(P19, CORE_PIN19_PORTREG, CORE_PIN19_BIT, CORE_PIN19_CONFIG);
949 MAKE_PIN(P20, CORE_PIN20_PORTREG, CORE_PIN20_BIT, CORE_PIN20_CONFIG);
950 MAKE_PIN(P21, CORE_PIN21_PORTREG, CORE_PIN21_BIT, CORE_PIN21_CONFIG);
951 MAKE_PIN(P22, CORE_PIN22_PORTREG, CORE_PIN22_BIT, CORE_PIN22_CONFIG);
952 MAKE_PIN(P23, CORE_PIN23_PORTREG, CORE_PIN23_BIT, CORE_PIN23_CONFIG);
953 MAKE_PIN(P24, CORE_PIN24_PORTREG, CORE_PIN24_BIT, CORE_PIN24_CONFIG);
954 MAKE_PIN(P25, CORE_PIN25_PORTREG, CORE_PIN25_BIT, CORE_PIN25_CONFIG);
955 MAKE_PIN(P26, CORE_PIN26_PORTREG, CORE_PIN26_BIT, CORE_PIN26_CONFIG);
956 MAKE_PIN(P27, CORE_PIN27_PORTREG, CORE_PIN27_BIT, CORE_PIN27_CONFIG);
957 MAKE_PIN(P28, CORE_PIN28_PORTREG, CORE_PIN28_BIT, CORE_PIN28_CONFIG);
958 MAKE_PIN(P29, CORE_PIN29_PORTREG, CORE_PIN29_BIT, CORE_PIN29_CONFIG);
959 MAKE_PIN(P30, CORE_PIN30_PORTREG, CORE_PIN30_BIT, CORE_PIN30_CONFIG);
960 MAKE_PIN(P31, CORE_PIN31_PORTREG, CORE_PIN31_BIT, CORE_PIN31_CONFIG);
961 MAKE_PIN(P32, CORE_PIN32_PORTREG, CORE_PIN32_BIT, CORE_PIN32_CONFIG);
962 MAKE_PIN(P33, CORE_PIN33_PORTREG, CORE_PIN33_BIT, CORE_PIN33_CONFIG);
963 #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
964 MAKE_PIN(P34, CORE_PIN34_PORTREG, CORE_PIN34_BIT, CORE_PIN34_CONFIG);
965 MAKE_PIN(P35, CORE_PIN35_PORTREG, CORE_PIN35_BIT, CORE_PIN35_CONFIG);
966 MAKE_PIN(P36, CORE_PIN36_PORTREG, CORE_PIN36_BIT, CORE_PIN36_CONFIG);
967 MAKE_PIN(P37, CORE_PIN37_PORTREG, CORE_PIN37_BIT, CORE_PIN37_CONFIG);
968 MAKE_PIN(P38, CORE_PIN38_PORTREG, CORE_PIN38_BIT, CORE_PIN38_CONFIG);
969 MAKE_PIN(P39, CORE_PIN39_PORTREG, CORE_PIN39_BIT, CORE_PIN39_CONFIG);
970 MAKE_PIN(P40, CORE_PIN40_PORTREG, CORE_PIN40_BIT, CORE_PIN40_CONFIG);
971 MAKE_PIN(P41, CORE_PIN41_PORTREG, CORE_PIN41_BIT, CORE_PIN41_CONFIG);
972 MAKE_PIN(P42, CORE_PIN42_PORTREG, CORE_PIN42_BIT, CORE_PIN42_CONFIG);
973 MAKE_PIN(P43, CORE_PIN43_PORTREG, CORE_PIN43_BIT, CORE_PIN43_CONFIG);
974 MAKE_PIN(P44, CORE_PIN44_PORTREG, CORE_PIN44_BIT, CORE_PIN44_CONFIG);
975 MAKE_PIN(P45, CORE_PIN45_PORTREG, CORE_PIN45_BIT, CORE_PIN45_CONFIG);
976 MAKE_PIN(P46, CORE_PIN46_PORTREG, CORE_PIN46_BIT, CORE_PIN46_CONFIG);
977 MAKE_PIN(P47, CORE_PIN47_PORTREG, CORE_PIN47_BIT, CORE_PIN47_CONFIG);
978 MAKE_PIN(P48, CORE_PIN48_PORTREG, CORE_PIN48_BIT, CORE_PIN48_CONFIG);
979 MAKE_PIN(P49, CORE_PIN49_PORTREG, CORE_PIN49_BIT, CORE_PIN49_CONFIG);
980 MAKE_PIN(P50, CORE_PIN50_PORTREG, CORE_PIN50_BIT, CORE_PIN50_CONFIG);
981 MAKE_PIN(P51, CORE_PIN51_PORTREG, CORE_PIN51_BIT, CORE_PIN51_CONFIG);
982 MAKE_PIN(P52, CORE_PIN52_PORTREG, CORE_PIN52_BIT, CORE_PIN52_CONFIG);
983 MAKE_PIN(P53, CORE_PIN53_PORTREG, CORE_PIN53_BIT, CORE_PIN53_CONFIG);
984 MAKE_PIN(P54, CORE_PIN54_PORTREG, CORE_PIN54_BIT, CORE_PIN54_CONFIG);
985 MAKE_PIN(P55, CORE_PIN55_PORTREG, CORE_PIN55_BIT, CORE_PIN55_CONFIG);
986 MAKE_PIN(P56, CORE_PIN56_PORTREG, CORE_PIN56_BIT, CORE_PIN56_CONFIG);
987 MAKE_PIN(P57, CORE_PIN57_PORTREG, CORE_PIN57_BIT, CORE_PIN57_CONFIG);
988 MAKE_PIN(P58, CORE_PIN58_PORTREG, CORE_PIN58_BIT, CORE_PIN58_CONFIG);
989 MAKE_PIN(P59, CORE_PIN59_PORTREG, CORE_PIN59_BIT, CORE_PIN59_CONFIG);
990 MAKE_PIN(P60, CORE_PIN60_PORTREG, CORE_PIN60_BIT, CORE_PIN60_CONFIG);
991 MAKE_PIN(P61, CORE_PIN61_PORTREG, CORE_PIN61_BIT, CORE_PIN61_CONFIG);
992 MAKE_PIN(P62, CORE_PIN62_PORTREG, CORE_PIN62_BIT, CORE_PIN62_CONFIG);
993 MAKE_PIN(P63, CORE_PIN63_PORTREG, CORE_PIN63_BIT, CORE_PIN63_CONFIG);
998 #elif defined(CORE_TEENSY) && (defined(__MKL26Z64__))
1008 #include "core_pins.h"
1009 #include "avr_emulation.h"
1011 #define MAKE_PIN(className, baseReg, pinNum, configReg) \
1014 static void Set() { \
1015 *portSetRegister(pinNum) = digitalPinToBitMask(pinNum); \
1017 static void Clear() { \
1018 *portClearRegister(pinNum) = digitalPinToBitMask(pinNum); \
1020 static void SetDirRead() { \
1021 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \
1022 *portModeRegister(pinNum) &= ~digitalPinToBitMask(pinNum); \
1024 static void SetDirWrite() { \
1025 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \
1026 *portModeRegister(pinNum) |= digitalPinToBitMask(pinNum); \
1028 static uint8_t IsSet() { \
1029 return (*portInputRegister(pinNum) & digitalPinToBitMask(pinNum)) ? 1 : 0; \
1033 MAKE_PIN(P0, CORE_PIN0_PORTREG, 0, CORE_PIN0_CONFIG);
1034 MAKE_PIN(P1, CORE_PIN1_PORTREG, 1, CORE_PIN1_CONFIG);
1035 MAKE_PIN(P2, CORE_PIN2_PORTREG, 2, CORE_PIN2_CONFIG);
1036 MAKE_PIN(P3, CORE_PIN3_PORTREG, 3, CORE_PIN3_CONFIG);
1037 MAKE_PIN(P4, CORE_PIN4_PORTREG, 4, CORE_PIN4_CONFIG);
1038 MAKE_PIN(P5, CORE_PIN5_PORTREG, 5, CORE_PIN5_CONFIG);
1039 MAKE_PIN(P6, CORE_PIN6_PORTREG, 6, CORE_PIN6_CONFIG);
1040 MAKE_PIN(P7, CORE_PIN7_PORTREG, 7, CORE_PIN7_CONFIG);
1041 MAKE_PIN(P8, CORE_PIN8_PORTREG, 8, CORE_PIN8_CONFIG);
1042 MAKE_PIN(P9, CORE_PIN9_PORTREG, 9, CORE_PIN9_CONFIG);
1043 MAKE_PIN(P10, CORE_PIN10_PORTREG, 10, CORE_PIN10_CONFIG);
1044 MAKE_PIN(P11, CORE_PIN11_PORTREG, 11, CORE_PIN11_CONFIG);
1045 MAKE_PIN(P12, CORE_PIN12_PORTREG, 12, CORE_PIN12_CONFIG);
1046 MAKE_PIN(P13, CORE_PIN13_PORTREG, 13, CORE_PIN13_CONFIG);
1047 MAKE_PIN(P14, CORE_PIN14_PORTREG, 14, CORE_PIN14_CONFIG);
1048 MAKE_PIN(P15, CORE_PIN15_PORTREG, 15, CORE_PIN15_CONFIG);
1049 MAKE_PIN(P16, CORE_PIN16_PORTREG, 16, CORE_PIN16_CONFIG);
1050 MAKE_PIN(P17, CORE_PIN17_PORTREG, 17, CORE_PIN17_CONFIG);
1051 MAKE_PIN(P18, CORE_PIN18_PORTREG, 18, CORE_PIN18_CONFIG);
1052 MAKE_PIN(P19, CORE_PIN19_PORTREG, 19, CORE_PIN19_CONFIG);
1053 MAKE_PIN(P20, CORE_PIN20_PORTREG, 20, CORE_PIN20_CONFIG);
1054 MAKE_PIN(P21, CORE_PIN21_PORTREG, 21, CORE_PIN21_CONFIG);
1055 MAKE_PIN(P22, CORE_PIN22_PORTREG, 22, CORE_PIN22_CONFIG);
1056 MAKE_PIN(P23, CORE_PIN23_PORTREG, 23, CORE_PIN23_CONFIG);
1057 MAKE_PIN(P24, CORE_PIN24_PORTREG, 24, CORE_PIN24_CONFIG);
1058 MAKE_PIN(P25, CORE_PIN25_PORTREG, 25, CORE_PIN25_CONFIG);
1059 MAKE_PIN(P26, CORE_PIN26_PORTREG, 26, CORE_PIN26_CONFIG);
1063 #elif defined(__IMXRT1062__) && (defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41))
1066 #include "core_pins.h"
1068 #define MAKE_PIN(className, pin) \
1071 static void Set() { \
1072 digitalWriteFast(pin, HIGH);\
1074 static void Clear() { \
1075 digitalWriteFast(pin, LOW); \
1077 static void SetDirRead() { \
1078 pinMode(pin, INPUT); \
1080 static void SetDirWrite() { \
1081 pinMode(pin, OUTPUT); \
1083 static uint8_t IsSet() { \
1084 return digitalReadFast(pin); \
1128 #ifdef ARDUINO_TEENSY41
1148 #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
1162 #define MAKE_PIN(className, pio, pinMask) \
1165 static void Set() { \
1166 pio->PIO_SODR = pinMask; \
1168 static void Clear() { \
1169 pio->PIO_CODR = pinMask; \
1171 static void SetDirRead() { \
1172 pio->PIO_IDR = pinMask ; \
1173 pio->PIO_PUDR = pinMask; \
1174 pio->PIO_ODR = pinMask; \
1175 pio->PIO_PER = pinMask; \
1177 static void SetDirWrite() { \
1178 pio->PIO_IDR = pinMask ; \
1179 pio->PIO_PUDR = pinMask; \
1180 pio->PIO_OER = pinMask; \
1181 pio->PIO_PER = pinMask; \
1183 static uint8_t IsSet() { \
1184 return pio->PIO_PDSR & pinMask; \
1190 MAKE_PIN(P0, PIOA, PIO_PA8);
1191 MAKE_PIN(P1, PIOA, PIO_PA9);
1192 MAKE_PIN(P2, PIOB, PIO_PB25);
1193 MAKE_PIN(P3, PIOC, PIO_PC28);
1194 MAKE_PIN(P4, PIOC, PIO_PC26);
1195 MAKE_PIN(P5, PIOC, PIO_PC25);
1196 MAKE_PIN(P6, PIOC, PIO_PC24);
1197 MAKE_PIN(P7, PIOC, PIO_PC23);
1198 MAKE_PIN(P8, PIOC, PIO_PC22);
1199 MAKE_PIN(P9, PIOC, PIO_PC21);
1200 MAKE_PIN(P10, PIOC, PIO_PC29);
1201 MAKE_PIN(P11, PIOD, PIO_PD7);
1202 MAKE_PIN(P12, PIOD, PIO_PD8);
1203 MAKE_PIN(P13, PIOB, PIO_PB27);
1204 MAKE_PIN(P14, PIOD, PIO_PD4);
1205 MAKE_PIN(P15, PIOD, PIO_PD5);
1206 MAKE_PIN(P16, PIOA, PIO_PA13);
1207 MAKE_PIN(P17, PIOA, PIO_PA12);
1208 MAKE_PIN(P18, PIOA, PIO_PA11);
1209 MAKE_PIN(P19, PIOA, PIO_PA10);
1210 MAKE_PIN(P20, PIOB, PIO_PB12);
1211 MAKE_PIN(P21, PIOB, PIO_PB13);
1212 MAKE_PIN(P22, PIOB, PIO_PB26);
1213 MAKE_PIN(P23, PIOA, PIO_PA14);
1214 MAKE_PIN(P24, PIOA, PIO_PA15);
1215 MAKE_PIN(P25, PIOD, PIO_PD0);
1216 MAKE_PIN(P26, PIOD, PIO_PD1);
1217 MAKE_PIN(P27, PIOD, PIO_PD2);
1218 MAKE_PIN(P28, PIOD, PIO_PD3);
1219 MAKE_PIN(P29, PIOD, PIO_PD6);
1220 MAKE_PIN(P30, PIOD, PIO_PD9);
1221 MAKE_PIN(P31, PIOA, PIO_PA7);
1222 MAKE_PIN(P32, PIOD, PIO_PD10);
1223 MAKE_PIN(P33, PIOC, PIO_PC1);
1224 MAKE_PIN(P34, PIOC, PIO_PC2);
1225 MAKE_PIN(P35, PIOC, PIO_PC3);
1226 MAKE_PIN(P36, PIOC, PIO_PC4);
1227 MAKE_PIN(P37, PIOC, PIO_PC5);
1228 MAKE_PIN(P38, PIOC, PIO_PC6);
1229 MAKE_PIN(P39, PIOC, PIO_PC7);
1230 MAKE_PIN(P40, PIOC, PIO_PC8);
1231 MAKE_PIN(P41, PIOC, PIO_PC9);
1232 MAKE_PIN(P42, PIOA, PIO_PA19);
1233 MAKE_PIN(P43, PIOA, PIO_PA20);
1234 MAKE_PIN(P44, PIOC, PIO_PC19);
1235 MAKE_PIN(P45, PIOC, PIO_PC18);
1236 MAKE_PIN(P46, PIOC, PIO_PC17);
1237 MAKE_PIN(P47, PIOC, PIO_PC16);
1238 MAKE_PIN(P48, PIOC, PIO_PC15);
1239 MAKE_PIN(P49, PIOC, PIO_PC14);
1240 MAKE_PIN(P50, PIOC, PIO_PC13);
1241 MAKE_PIN(P51, PIOC, PIO_PC12);
1242 MAKE_PIN(P52, PIOB, PIO_PB21);
1243 MAKE_PIN(P53, PIOB, PIO_PB14);
1244 MAKE_PIN(P54, PIOA, PIO_PA16);
1245 MAKE_PIN(P55, PIOA, PIO_PA24);
1246 MAKE_PIN(P56, PIOA, PIO_PA23);
1247 MAKE_PIN(P57, PIOA, PIO_PA22);
1248 MAKE_PIN(P58, PIOA, PIO_PA6);
1249 MAKE_PIN(P59, PIOA, PIO_PA4);
1250 MAKE_PIN(P60, PIOA, PIO_PA3);
1251 MAKE_PIN(P61, PIOA, PIO_PA2);
1252 MAKE_PIN(P62, PIOB, PIO_PB17);
1253 MAKE_PIN(P63, PIOB, PIO_PB18);
1254 MAKE_PIN(P64, PIOB, PIO_PB19);
1255 MAKE_PIN(P65, PIOB, PIO_PB20);
1256 MAKE_PIN(P66, PIOB, PIO_PB15);
1257 MAKE_PIN(P67, PIOB, PIO_PB16);
1258 MAKE_PIN(P68, PIOA, PIO_PA1);
1259 MAKE_PIN(P69, PIOA, PIO_PA0);
1260 MAKE_PIN(P70, PIOA, PIO_PA17);
1261 MAKE_PIN(P71, PIOA, PIO_PA18);
1262 MAKE_PIN(P72, PIOC, PIO_PC30);
1263 MAKE_PIN(P73, PIOA, PIO_PA21);
1264 MAKE_PIN(P74, PIOA, PIO_PA25);
1265 MAKE_PIN(P75, PIOA, PIO_PA26);
1266 MAKE_PIN(P76, PIOA, PIO_PA27);
1267 MAKE_PIN(P77, PIOA, PIO_PA28);
1268 MAKE_PIN(P78, PIOB, PIO_PB23);
1272 #elif defined(RBL_NRF51822)
1274 #define MAKE_PIN(className, pin) \
1277 static void Set() { \
1278 nrf_gpio_pin_set(pin); \
1280 static void Clear() { \
1281 nrf_gpio_pin_clear(pin); \
1283 static void SetDirRead() { \
1284 nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL); \
1286 static void SetDirWrite() { \
1287 nrf_gpio_cfg_output(pin); \
1289 static uint8_t IsSet() { \
1290 return (uint8_t)nrf_gpio_pin_read(pin); \
1295 MAKE_PIN(P0, Pin_nRF51822_to_Arduino(D0));
1296 MAKE_PIN(P1, Pin_nRF51822_to_Arduino(D1));
1297 MAKE_PIN(P2, Pin_nRF51822_to_Arduino(D2));
1298 MAKE_PIN(P3, Pin_nRF51822_to_Arduino(D3));
1299 MAKE_PIN(P4, Pin_nRF51822_to_Arduino(D4));
1300 MAKE_PIN(P5, Pin_nRF51822_to_Arduino(D5));
1301 MAKE_PIN(P6, Pin_nRF51822_to_Arduino(D6));
1302 MAKE_PIN(P7, Pin_nRF51822_to_Arduino(D7));
1303 MAKE_PIN(P8, Pin_nRF51822_to_Arduino(D8));
1304 MAKE_PIN(P9, Pin_nRF51822_to_Arduino(D9));
1305 MAKE_PIN(P10, Pin_nRF51822_to_Arduino(D10));
1306 MAKE_PIN(P11, Pin_nRF51822_to_Arduino(D11));
1307 MAKE_PIN(P12, Pin_nRF51822_to_Arduino(D12));
1308 MAKE_PIN(P13, Pin_nRF51822_to_Arduino(D13));
1309 MAKE_PIN(P14, Pin_nRF51822_to_Arduino(D14));
1310 MAKE_PIN(P15, Pin_nRF51822_to_Arduino(D15));
1311 MAKE_PIN(P17, Pin_nRF51822_to_Arduino(D17));
1312 MAKE_PIN(P18, Pin_nRF51822_to_Arduino(D18));
1313 MAKE_PIN(P16, Pin_nRF51822_to_Arduino(D16));
1314 MAKE_PIN(P19, Pin_nRF51822_to_Arduino(D19));
1315 MAKE_PIN(P20, Pin_nRF51822_to_Arduino(D20));
1316 MAKE_PIN(P21, Pin_nRF51822_to_Arduino(D21));
1317 MAKE_PIN(P22, Pin_nRF51822_to_Arduino(D22));
1318 MAKE_PIN(P23, Pin_nRF51822_to_Arduino(D23));
1319 MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24));
1323 #elif defined(STM32F446xx)
1326 #define MAKE_PIN(className, port, pin) \
1329 static void Set() { \
1330 HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET); \
1332 static void Clear() { \
1333 HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET); \
1335 static void SetDirRead() { \
1336 static GPIO_InitTypeDef GPIO_InitStruct; \
1337 GPIO_InitStruct.Pin = pin; \
1338 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; \
1339 GPIO_InitStruct.Pull = GPIO_NOPULL; \
1340 HAL_GPIO_Init(port, &GPIO_InitStruct); \
1342 static void SetDirWrite() { \
1343 static GPIO_InitTypeDef GPIO_InitStruct; \
1344 GPIO_InitStruct.Pin = pin; \
1345 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; \
1346 GPIO_InitStruct.Pull = GPIO_NOPULL; \
1347 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; \
1348 HAL_GPIO_Init(port, &GPIO_InitStruct); \
1350 static GPIO_PinState IsSet() { \
1351 return HAL_GPIO_ReadPin(port, pin); \
1355 MAKE_PIN(P0, GPIOA, GPIO_PIN_3);
1356 MAKE_PIN(P1, GPIOA, GPIO_PIN_2);
1357 MAKE_PIN(P2, GPIOA, GPIO_PIN_10);
1358 MAKE_PIN(P3, GPIOB, GPIO_PIN_3);
1359 MAKE_PIN(P4, GPIOB, GPIO_PIN_5);
1360 MAKE_PIN(P5, GPIOB, GPIO_PIN_4);
1361 MAKE_PIN(P6, GPIOB, GPIO_PIN_10);
1362 MAKE_PIN(P7, GPIOA, GPIO_PIN_8);
1363 MAKE_PIN(P8, GPIOA, GPIO_PIN_9);
1364 MAKE_PIN(P9, GPIOC, GPIO_PIN_7);
1365 MAKE_PIN(P10, GPIOB, GPIO_PIN_6);
1366 MAKE_PIN(P11, GPIOA, GPIO_PIN_7);
1367 MAKE_PIN(P12, GPIOA, GPIO_PIN_6);
1368 MAKE_PIN(P13, GPIOA, GPIO_PIN_5);
1370 MAKE_PIN(P14, GPIOA, GPIO_PIN_0);
1371 MAKE_PIN(P15, GPIOA, GPIO_PIN_1);
1372 MAKE_PIN(P16, GPIOA, GPIO_PIN_4);
1373 MAKE_PIN(P17, GPIOB, GPIO_PIN_0);
1374 MAKE_PIN(P18, GPIOC, GPIO_PIN_1);
1375 MAKE_PIN(P19, GPIOC, GPIO_PIN_0);
1380 #elif defined(ARDUINO_NRF52840_FEATHER)
1382 #define MAKE_PIN(className, pin) \
1385 static void Set() { \
1386 nrf_gpio_pin_set(pin); \
1388 static void Clear() { \
1389 nrf_gpio_pin_clear(pin); \
1391 static void SetDirRead() { \
1392 nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL); \
1394 static void SetDirWrite() { \
1395 nrf_gpio_cfg_output(pin); \
1397 static uint8_t IsSet() { \
1398 return (uint8_t)nrf_gpio_pin_read(pin); \
1414 MAKE_PIN(P10, (27));
1417 MAKE_PIN(P13, (41));
1420 MAKE_PIN(P17, (30));
1421 MAKE_PIN(P18, (28));
1424 MAKE_PIN(P20, (29));
1425 MAKE_PIN(P21, (31));
1426 MAKE_PIN(P22, (12));
1427 MAKE_PIN(P23, (11));
1428 MAKE_PIN(P24, (15));
1429 MAKE_PIN(P25, (13));
1430 MAKE_PIN(P26, (14));
1431 MAKE_PIN(P27, (19));
1432 MAKE_PIN(P28, (20));
1433 MAKE_PIN(P29, (17));
1434 MAKE_PIN(P30, (22));
1435 MAKE_PIN(P31, (23));
1436 MAKE_PIN(P32, (21));
1442 #error "Please define board in avrpins.h"
1446 #elif defined(__ARDUINO_ARC__)
1448 #include <avr/pgmspace.h>
1450 #define pgm_read_pointer(p) pgm_read_dword(p)
1452 #define MAKE_PIN(className, pin) \
1455 static void Set() { \
1456 digitalWrite(pin, HIGH);\
1458 static void Clear() { \
1459 digitalWrite(pin, LOW); \
1461 static void SetDirRead() { \
1462 pinMode(pin, INPUT); \
1464 static void SetDirWrite() { \
1465 pinMode(pin, OUTPUT); \
1467 static uint8_t IsSet() { \
1468 return digitalRead(pin); \
1498 #elif defined(__ARDUINO_X86__) // Intel Galileo, Intel Galileo 2 and Intel Edison
1500 #include <avr/pgmspace.h>
1503 #define pgm_read_pointer(p) pgm_read_dword(p)
1505 #if PLATFORM_ID == 0xE1 // Edison platform id
1506 #define pinToFastPin(pin) 1 // As far as I can tell all pins can be used as fast pins
1512 #define MAKE_PIN(className, pin) \
1515 static void Set() { \
1516 fastDigitalWrite(pin, HIGH); \
1518 static void Clear() { \
1519 fastDigitalWrite(pin, LOW); \
1521 static void SetDirRead() { \
1522 if (pinToFastPin(pin)) \
1523 pinMode(pin, INPUT_FAST); \
1525 pinMode(pin, INPUT); \
1527 static void SetDirWrite() { \
1528 if (pinToFastPin(pin)) \
1529 pinMode(pin, OUTPUT_FAST); \
1531 pinMode(pin, OUTPUT); \
1533 static uint8_t IsSet() { \
1534 return fastDigitalRead(pin); \
1561 #elif defined(__MIPSEL__)
1565 #define pgm_read_pointer(p) pgm_read_dword(p)
1567 #define MAKE_PIN(className, pin) \
1570 static void Set() { \
1571 digitalWrite(pin, HIGH);\
1573 static void Clear() { \
1574 digitalWrite(pin, LOW); \
1576 static void SetDirRead() { \
1577 pinMode(pin, INPUT); \
1579 static void SetDirWrite() { \
1580 pinMode(pin, OUTPUT); \
1582 static uint8_t IsSet() { \
1583 return digitalRead(pin); \
1605 #elif defined(ESP8266) || defined(ESP32)
1607 #define MAKE_PIN(className, pin) \
1610 static void Set() { \
1611 digitalWrite(pin, HIGH);\
1613 static void Clear() { \
1614 digitalWrite(pin, LOW); \
1616 static void SetDirRead() { \
1617 pinMode(pin, INPUT); \
1619 static void SetDirWrite() { \
1620 pinMode(pin, OUTPUT); \
1622 static uint8_t IsSet() { \
1623 return digitalRead(pin); \
1627 #if defined(ESP8266)
1630 #undef pgm_read_ptr_aligned
1632 #define pgm_read_ptr_aligned(addr) (*reinterpret_cast<const void* const*>(addr))
1634 #define pgm_read_ptr_aligned(addr) (*(const void* const*)(addr))
1638 #if PGM_READ_UNALIGNED
1639 #define pgm_read_ptr(p) pgm_read_ptr_unaligned(p)
1641 #define pgm_read_ptr(p) pgm_read_ptr_aligned(p)
1644 #ifdef pgm_read_pointer
1645 #undef pgm_read_pointer
1647 #define pgm_read_pointer(p) pgm_read_ptr(p)
1664 #elif defined(ESP32)
1667 #ifdef pgm_read_word
1668 #undef pgm_read_word
1670 #ifdef pgm_read_dword
1671 #undef pgm_read_dword
1673 #ifdef pgm_read_float
1674 #undef pgm_read_float
1680 #define pgm_read_word(addr) ({ \
1681 typeof(addr) _addr = (addr); \
1682 *(const unsigned short *)(_addr); \
1684 #define pgm_read_dword(addr) ({ \
1685 typeof(addr) _addr = (addr); \
1686 *(const unsigned long *)(_addr); \
1688 #define pgm_read_float(addr) ({ \
1689 typeof(addr) _addr = (addr); \
1690 *(const float *)(_addr); \
1692 #define pgm_read_ptr(addr) ({ \
1693 typeof(addr) _addr = (addr); \
1694 *(void * const *)(_addr); \
1716 #ifdef pgm_read_pointer
1717 #undef pgm_read_pointer
1719 #define pgm_read_pointer(p) pgm_read_ptr(p)
1722 #error "Please define board in avrpins.h"
1726 #endif //_avrpins_h_