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(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) 807 #error "Please define board in avrpins.h" 809 #endif // Arduino pin definitions 811 #elif defined(__arm__) 814 #define pgm_read_pointer(p) pgm_read_dword(p) 816 #if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)) 819 #include "core_pins.h" 820 #include "avr_emulation.h" 822 #define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000) 823 #define GPIO_BITBAND_PTR(reg, bit) ((uint8_t *)GPIO_BITBAND_ADDR((reg), (bit))) 825 #define MAKE_PIN(className, baseReg, pinNum, configReg) \ 828 static void Set() { \ 829 *GPIO_BITBAND_PTR(baseReg, pinNum) = 1; \ 831 static void Clear() { \ 832 *GPIO_BITBAND_PTR(baseReg, pinNum) = 0; \ 834 static void SetDirRead() { \ 835 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \ 836 *(GPIO_BITBAND_PTR(baseReg, pinNum) + 640) = 0; \ 838 static void SetDirWrite() { \ 839 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \ 840 *(GPIO_BITBAND_PTR(baseReg, pinNum) + 640) = 1; \ 842 static uint8_t IsSet() { \ 843 return *(GPIO_BITBAND_PTR(baseReg, pinNum) + 512); \ 847 MAKE_PIN(P0, CORE_PIN0_PORTREG, CORE_PIN0_BIT, CORE_PIN0_CONFIG);
848 MAKE_PIN(P1, CORE_PIN1_PORTREG, CORE_PIN1_BIT, CORE_PIN1_CONFIG);
849 MAKE_PIN(P2, CORE_PIN2_PORTREG, CORE_PIN2_BIT, CORE_PIN2_CONFIG);
850 MAKE_PIN(P3, CORE_PIN3_PORTREG, CORE_PIN3_BIT, CORE_PIN3_CONFIG);
851 MAKE_PIN(P4, CORE_PIN4_PORTREG, CORE_PIN4_BIT, CORE_PIN4_CONFIG);
852 MAKE_PIN(P5, CORE_PIN5_PORTREG, CORE_PIN5_BIT, CORE_PIN5_CONFIG);
853 MAKE_PIN(P6, CORE_PIN6_PORTREG, CORE_PIN6_BIT, CORE_PIN6_CONFIG);
854 MAKE_PIN(P7, CORE_PIN7_PORTREG, CORE_PIN7_BIT, CORE_PIN7_CONFIG);
855 MAKE_PIN(P8, CORE_PIN8_PORTREG, CORE_PIN8_BIT, CORE_PIN8_CONFIG);
856 MAKE_PIN(P9, CORE_PIN9_PORTREG, CORE_PIN9_BIT, CORE_PIN9_CONFIG);
857 MAKE_PIN(P10, CORE_PIN10_PORTREG, CORE_PIN10_BIT, CORE_PIN10_CONFIG);
858 MAKE_PIN(P11, CORE_PIN11_PORTREG, CORE_PIN11_BIT, CORE_PIN11_CONFIG);
859 MAKE_PIN(P12, CORE_PIN12_PORTREG, CORE_PIN12_BIT, CORE_PIN12_CONFIG);
860 MAKE_PIN(P13, CORE_PIN13_PORTREG, CORE_PIN13_BIT, CORE_PIN13_CONFIG);
861 MAKE_PIN(P14, CORE_PIN14_PORTREG, CORE_PIN14_BIT, CORE_PIN14_CONFIG);
862 MAKE_PIN(P15, CORE_PIN15_PORTREG, CORE_PIN15_BIT, CORE_PIN15_CONFIG);
863 MAKE_PIN(P16, CORE_PIN16_PORTREG, CORE_PIN16_BIT, CORE_PIN16_CONFIG);
864 MAKE_PIN(P17, CORE_PIN17_PORTREG, CORE_PIN17_BIT, CORE_PIN17_CONFIG);
865 MAKE_PIN(P18, CORE_PIN18_PORTREG, CORE_PIN18_BIT, CORE_PIN18_CONFIG);
866 MAKE_PIN(P19, CORE_PIN19_PORTREG, CORE_PIN19_BIT, CORE_PIN19_CONFIG);
867 MAKE_PIN(P20, CORE_PIN20_PORTREG, CORE_PIN20_BIT, CORE_PIN20_CONFIG);
868 MAKE_PIN(P21, CORE_PIN21_PORTREG, CORE_PIN21_BIT, CORE_PIN21_CONFIG);
869 MAKE_PIN(P22, CORE_PIN22_PORTREG, CORE_PIN22_BIT, CORE_PIN22_CONFIG);
870 MAKE_PIN(P23, CORE_PIN23_PORTREG, CORE_PIN23_BIT, CORE_PIN23_CONFIG);
871 MAKE_PIN(P24, CORE_PIN24_PORTREG, CORE_PIN24_BIT, CORE_PIN24_CONFIG);
872 MAKE_PIN(P25, CORE_PIN25_PORTREG, CORE_PIN25_BIT, CORE_PIN25_CONFIG);
873 MAKE_PIN(P26, CORE_PIN26_PORTREG, CORE_PIN26_BIT, CORE_PIN26_CONFIG);
874 MAKE_PIN(P27, CORE_PIN27_PORTREG, CORE_PIN27_BIT, CORE_PIN27_CONFIG);
875 MAKE_PIN(P28, CORE_PIN28_PORTREG, CORE_PIN28_BIT, CORE_PIN28_CONFIG);
876 MAKE_PIN(P29, CORE_PIN29_PORTREG, CORE_PIN29_BIT, CORE_PIN29_CONFIG);
877 MAKE_PIN(P30, CORE_PIN30_PORTREG, CORE_PIN30_BIT, CORE_PIN30_CONFIG);
878 MAKE_PIN(P31, CORE_PIN31_PORTREG, CORE_PIN31_BIT, CORE_PIN31_CONFIG);
879 MAKE_PIN(P32, CORE_PIN32_PORTREG, CORE_PIN32_BIT, CORE_PIN32_CONFIG);
880 MAKE_PIN(P33, CORE_PIN33_PORTREG, CORE_PIN33_BIT, CORE_PIN33_CONFIG);
881 #if defined(__MK64FX512__) || defined(__MK66FX1M0__) 882 MAKE_PIN(P34, CORE_PIN34_PORTREG, CORE_PIN34_BIT, CORE_PIN34_CONFIG);
883 MAKE_PIN(P35, CORE_PIN35_PORTREG, CORE_PIN35_BIT, CORE_PIN35_CONFIG);
884 MAKE_PIN(P36, CORE_PIN36_PORTREG, CORE_PIN36_BIT, CORE_PIN36_CONFIG);
885 MAKE_PIN(P37, CORE_PIN37_PORTREG, CORE_PIN37_BIT, CORE_PIN37_CONFIG);
886 MAKE_PIN(P38, CORE_PIN38_PORTREG, CORE_PIN38_BIT, CORE_PIN38_CONFIG);
887 MAKE_PIN(P39, CORE_PIN39_PORTREG, CORE_PIN39_BIT, CORE_PIN39_CONFIG);
888 MAKE_PIN(P40, CORE_PIN40_PORTREG, CORE_PIN40_BIT, CORE_PIN40_CONFIG);
889 MAKE_PIN(P41, CORE_PIN41_PORTREG, CORE_PIN41_BIT, CORE_PIN41_CONFIG);
890 MAKE_PIN(P42, CORE_PIN42_PORTREG, CORE_PIN42_BIT, CORE_PIN42_CONFIG);
891 MAKE_PIN(P43, CORE_PIN43_PORTREG, CORE_PIN43_BIT, CORE_PIN43_CONFIG);
892 MAKE_PIN(P44, CORE_PIN44_PORTREG, CORE_PIN44_BIT, CORE_PIN44_CONFIG);
893 MAKE_PIN(P45, CORE_PIN45_PORTREG, CORE_PIN45_BIT, CORE_PIN45_CONFIG);
894 MAKE_PIN(P46, CORE_PIN46_PORTREG, CORE_PIN46_BIT, CORE_PIN46_CONFIG);
895 MAKE_PIN(P47, CORE_PIN47_PORTREG, CORE_PIN47_BIT, CORE_PIN47_CONFIG);
896 MAKE_PIN(P48, CORE_PIN48_PORTREG, CORE_PIN48_BIT, CORE_PIN48_CONFIG);
897 MAKE_PIN(P49, CORE_PIN49_PORTREG, CORE_PIN49_BIT, CORE_PIN49_CONFIG);
898 MAKE_PIN(P50, CORE_PIN50_PORTREG, CORE_PIN50_BIT, CORE_PIN50_CONFIG);
899 MAKE_PIN(P51, CORE_PIN51_PORTREG, CORE_PIN51_BIT, CORE_PIN51_CONFIG);
900 MAKE_PIN(P52, CORE_PIN52_PORTREG, CORE_PIN52_BIT, CORE_PIN52_CONFIG);
901 MAKE_PIN(P53, CORE_PIN53_PORTREG, CORE_PIN53_BIT, CORE_PIN53_CONFIG);
902 MAKE_PIN(P54, CORE_PIN54_PORTREG, CORE_PIN54_BIT, CORE_PIN54_CONFIG);
903 MAKE_PIN(P55, CORE_PIN55_PORTREG, CORE_PIN55_BIT, CORE_PIN55_CONFIG);
904 MAKE_PIN(P56, CORE_PIN56_PORTREG, CORE_PIN56_BIT, CORE_PIN56_CONFIG);
905 MAKE_PIN(P57, CORE_PIN57_PORTREG, CORE_PIN57_BIT, CORE_PIN57_CONFIG);
906 MAKE_PIN(P58, CORE_PIN58_PORTREG, CORE_PIN58_BIT, CORE_PIN58_CONFIG);
907 MAKE_PIN(P59, CORE_PIN59_PORTREG, CORE_PIN59_BIT, CORE_PIN59_CONFIG);
908 MAKE_PIN(P60, CORE_PIN60_PORTREG, CORE_PIN60_BIT, CORE_PIN60_CONFIG);
909 MAKE_PIN(P61, CORE_PIN61_PORTREG, CORE_PIN61_BIT, CORE_PIN61_CONFIG);
910 MAKE_PIN(P62, CORE_PIN62_PORTREG, CORE_PIN62_BIT, CORE_PIN62_CONFIG);
911 MAKE_PIN(P63, CORE_PIN63_PORTREG, CORE_PIN63_BIT, CORE_PIN63_CONFIG);
916 #elif defined(CORE_TEENSY) && (defined(__MKL26Z64__)) 926 #include "core_pins.h" 927 #include "avr_emulation.h" 929 #define MAKE_PIN(className, baseReg, pinNum, configReg) \ 932 static void Set() { \ 933 *portSetRegister(pinNum) = digitalPinToBitMask(pinNum); \ 935 static void Clear() { \ 936 *portClearRegister(pinNum) = digitalPinToBitMask(pinNum); \ 938 static void SetDirRead() { \ 939 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \ 940 *portModeRegister(pinNum) &= ~digitalPinToBitMask(pinNum); \ 942 static void SetDirWrite() { \ 943 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \ 944 *portModeRegister(pinNum) |= digitalPinToBitMask(pinNum); \ 946 static uint8_t IsSet() { \ 947 return (*portInputRegister(pinNum) & digitalPinToBitMask(pinNum)) ? 1 : 0; \ 951 MAKE_PIN(P0, CORE_PIN0_PORTREG, 0, CORE_PIN0_CONFIG);
952 MAKE_PIN(P1, CORE_PIN1_PORTREG, 1, CORE_PIN1_CONFIG);
953 MAKE_PIN(P2, CORE_PIN2_PORTREG, 2, CORE_PIN2_CONFIG);
954 MAKE_PIN(P3, CORE_PIN3_PORTREG, 3, CORE_PIN3_CONFIG);
955 MAKE_PIN(P4, CORE_PIN4_PORTREG, 4, CORE_PIN4_CONFIG);
956 MAKE_PIN(P5, CORE_PIN5_PORTREG, 5, CORE_PIN5_CONFIG);
957 MAKE_PIN(P6, CORE_PIN6_PORTREG, 6, CORE_PIN6_CONFIG);
958 MAKE_PIN(P7, CORE_PIN7_PORTREG, 7, CORE_PIN7_CONFIG);
959 MAKE_PIN(P8, CORE_PIN8_PORTREG, 8, CORE_PIN8_CONFIG);
960 MAKE_PIN(P9, CORE_PIN9_PORTREG, 9, CORE_PIN9_CONFIG);
961 MAKE_PIN(P10, CORE_PIN10_PORTREG, 10, CORE_PIN10_CONFIG);
962 MAKE_PIN(P11, CORE_PIN11_PORTREG, 11, CORE_PIN11_CONFIG);
963 MAKE_PIN(P12, CORE_PIN12_PORTREG, 12, CORE_PIN12_CONFIG);
964 MAKE_PIN(P13, CORE_PIN13_PORTREG, 13, CORE_PIN13_CONFIG);
965 MAKE_PIN(P14, CORE_PIN14_PORTREG, 14, CORE_PIN14_CONFIG);
966 MAKE_PIN(P15, CORE_PIN15_PORTREG, 15, CORE_PIN15_CONFIG);
967 MAKE_PIN(P16, CORE_PIN16_PORTREG, 16, CORE_PIN16_CONFIG);
968 MAKE_PIN(P17, CORE_PIN17_PORTREG, 17, CORE_PIN17_CONFIG);
969 MAKE_PIN(P18, CORE_PIN18_PORTREG, 18, CORE_PIN18_CONFIG);
970 MAKE_PIN(P19, CORE_PIN19_PORTREG, 19, CORE_PIN19_CONFIG);
971 MAKE_PIN(P20, CORE_PIN20_PORTREG, 20, CORE_PIN20_CONFIG);
972 MAKE_PIN(P21, CORE_PIN21_PORTREG, 21, CORE_PIN21_CONFIG);
973 MAKE_PIN(P22, CORE_PIN22_PORTREG, 22, CORE_PIN22_CONFIG);
974 MAKE_PIN(P23, CORE_PIN23_PORTREG, 23, CORE_PIN23_CONFIG);
975 MAKE_PIN(P24, CORE_PIN24_PORTREG, 24, CORE_PIN24_CONFIG);
976 MAKE_PIN(P25, CORE_PIN25_PORTREG, 25, CORE_PIN25_CONFIG);
977 MAKE_PIN(P26, CORE_PIN26_PORTREG, 26, CORE_PIN26_CONFIG);
981 #elif defined(__IMXRT1062__) && (defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41)) 984 #include "core_pins.h" 986 #define MAKE_PIN(className, pin) \ 989 static void Set() { \ 990 digitalWriteFast(pin, HIGH);\ 992 static void Clear() { \ 993 digitalWriteFast(pin, LOW); \ 995 static void SetDirRead() { \ 996 pinMode(pin, INPUT); \ 998 static void SetDirWrite() { \ 999 pinMode(pin, OUTPUT); \ 1001 static uint8_t IsSet() { \ 1002 return digitalReadFast(pin); \ 1046 #ifdef ARDUINO_TEENSY41 1066 #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) 1080 #define MAKE_PIN(className, pio, pinMask) \ 1083 static void Set() { \ 1084 pio->PIO_SODR = pinMask; \ 1086 static void Clear() { \ 1087 pio->PIO_CODR = pinMask; \ 1089 static void SetDirRead() { \ 1090 pio->PIO_IDR = pinMask ; \ 1091 pio->PIO_PUDR = pinMask; \ 1092 pio->PIO_ODR = pinMask; \ 1093 pio->PIO_PER = pinMask; \ 1095 static void SetDirWrite() { \ 1096 pio->PIO_IDR = pinMask ; \ 1097 pio->PIO_PUDR = pinMask; \ 1098 pio->PIO_OER = pinMask; \ 1099 pio->PIO_PER = pinMask; \ 1101 static uint8_t IsSet() { \ 1102 return pio->PIO_PDSR & pinMask; \ 1108 MAKE_PIN(P0, PIOA, PIO_PA8);
1109 MAKE_PIN(P1, PIOA, PIO_PA9);
1110 MAKE_PIN(P2, PIOB, PIO_PB25);
1111 MAKE_PIN(P3, PIOC, PIO_PC28);
1112 MAKE_PIN(P4, PIOC, PIO_PC26);
1113 MAKE_PIN(P5, PIOC, PIO_PC25);
1114 MAKE_PIN(P6, PIOC, PIO_PC24);
1115 MAKE_PIN(P7, PIOC, PIO_PC23);
1116 MAKE_PIN(P8, PIOC, PIO_PC22);
1117 MAKE_PIN(P9, PIOC, PIO_PC21);
1118 MAKE_PIN(P10, PIOC, PIO_PC29);
1119 MAKE_PIN(P11, PIOD, PIO_PD7);
1120 MAKE_PIN(P12, PIOD, PIO_PD8);
1121 MAKE_PIN(P13, PIOB, PIO_PB27);
1122 MAKE_PIN(P14, PIOD, PIO_PD4);
1123 MAKE_PIN(P15, PIOD, PIO_PD5);
1124 MAKE_PIN(P16, PIOA, PIO_PA13);
1125 MAKE_PIN(P17, PIOA, PIO_PA12);
1126 MAKE_PIN(P18, PIOA, PIO_PA11);
1127 MAKE_PIN(P19, PIOA, PIO_PA10);
1128 MAKE_PIN(P20, PIOB, PIO_PB12);
1129 MAKE_PIN(P21, PIOB, PIO_PB13);
1130 MAKE_PIN(P22, PIOB, PIO_PB26);
1131 MAKE_PIN(P23, PIOA, PIO_PA14);
1132 MAKE_PIN(P24, PIOA, PIO_PA15);
1133 MAKE_PIN(P25, PIOD, PIO_PD0);
1134 MAKE_PIN(P26, PIOD, PIO_PD1);
1135 MAKE_PIN(P27, PIOD, PIO_PD2);
1136 MAKE_PIN(P28, PIOD, PIO_PD3);
1137 MAKE_PIN(P29, PIOD, PIO_PD6);
1138 MAKE_PIN(P30, PIOD, PIO_PD9);
1139 MAKE_PIN(P31, PIOA, PIO_PA7);
1140 MAKE_PIN(P32, PIOD, PIO_PD10);
1141 MAKE_PIN(P33, PIOC, PIO_PC1);
1142 MAKE_PIN(P34, PIOC, PIO_PC2);
1143 MAKE_PIN(P35, PIOC, PIO_PC3);
1144 MAKE_PIN(P36, PIOC, PIO_PC4);
1145 MAKE_PIN(P37, PIOC, PIO_PC5);
1146 MAKE_PIN(P38, PIOC, PIO_PC6);
1147 MAKE_PIN(P39, PIOC, PIO_PC7);
1148 MAKE_PIN(P40, PIOC, PIO_PC8);
1149 MAKE_PIN(P41, PIOC, PIO_PC9);
1150 MAKE_PIN(P42, PIOA, PIO_PA19);
1151 MAKE_PIN(P43, PIOA, PIO_PA20);
1152 MAKE_PIN(P44, PIOC, PIO_PC19);
1153 MAKE_PIN(P45, PIOC, PIO_PC18);
1154 MAKE_PIN(P46, PIOC, PIO_PC17);
1155 MAKE_PIN(P47, PIOC, PIO_PC16);
1156 MAKE_PIN(P48, PIOC, PIO_PC15);
1157 MAKE_PIN(P49, PIOC, PIO_PC14);
1158 MAKE_PIN(P50, PIOC, PIO_PC13);
1159 MAKE_PIN(P51, PIOC, PIO_PC12);
1160 MAKE_PIN(P52, PIOB, PIO_PB21);
1161 MAKE_PIN(P53, PIOB, PIO_PB14);
1162 MAKE_PIN(P54, PIOA, PIO_PA16);
1163 MAKE_PIN(P55, PIOA, PIO_PA24);
1164 MAKE_PIN(P56, PIOA, PIO_PA23);
1165 MAKE_PIN(P57, PIOA, PIO_PA22);
1166 MAKE_PIN(P58, PIOA, PIO_PA6);
1167 MAKE_PIN(P59, PIOA, PIO_PA4);
1168 MAKE_PIN(P60, PIOA, PIO_PA3);
1169 MAKE_PIN(P61, PIOA, PIO_PA2);
1170 MAKE_PIN(P62, PIOB, PIO_PB17);
1171 MAKE_PIN(P63, PIOB, PIO_PB18);
1172 MAKE_PIN(P64, PIOB, PIO_PB19);
1173 MAKE_PIN(P65, PIOB, PIO_PB20);
1174 MAKE_PIN(P66, PIOB, PIO_PB15);
1175 MAKE_PIN(P67, PIOB, PIO_PB16);
1176 MAKE_PIN(P68, PIOA, PIO_PA1);
1177 MAKE_PIN(P69, PIOA, PIO_PA0);
1178 MAKE_PIN(P70, PIOA, PIO_PA17);
1179 MAKE_PIN(P71, PIOA, PIO_PA18);
1180 MAKE_PIN(P72, PIOC, PIO_PC30);
1181 MAKE_PIN(P73, PIOA, PIO_PA21);
1182 MAKE_PIN(P74, PIOA, PIO_PA25);
1183 MAKE_PIN(P75, PIOA, PIO_PA26);
1184 MAKE_PIN(P76, PIOA, PIO_PA27);
1185 MAKE_PIN(P77, PIOA, PIO_PA28);
1186 MAKE_PIN(P78, PIOB, PIO_PB23);
1190 #elif defined(RBL_NRF51822) 1192 #define MAKE_PIN(className, pin) \ 1195 static void Set() { \ 1196 nrf_gpio_pin_set(pin); \ 1198 static void Clear() { \ 1199 nrf_gpio_pin_clear(pin); \ 1201 static void SetDirRead() { \ 1202 nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL); \ 1204 static void SetDirWrite() { \ 1205 nrf_gpio_cfg_output(pin); \ 1207 static uint8_t IsSet() { \ 1208 return (uint8_t)nrf_gpio_pin_read(pin); \ 1213 MAKE_PIN(P0, Pin_nRF51822_to_Arduino(D0));
1214 MAKE_PIN(P1, Pin_nRF51822_to_Arduino(D1));
1215 MAKE_PIN(P2, Pin_nRF51822_to_Arduino(D2));
1216 MAKE_PIN(P3, Pin_nRF51822_to_Arduino(D3));
1217 MAKE_PIN(P4, Pin_nRF51822_to_Arduino(D4));
1218 MAKE_PIN(P5, Pin_nRF51822_to_Arduino(D5));
1219 MAKE_PIN(P6, Pin_nRF51822_to_Arduino(D6));
1220 MAKE_PIN(P7, Pin_nRF51822_to_Arduino(D7));
1221 MAKE_PIN(P8, Pin_nRF51822_to_Arduino(D8));
1222 MAKE_PIN(P9, Pin_nRF51822_to_Arduino(D9));
1223 MAKE_PIN(P10, Pin_nRF51822_to_Arduino(D10));
1224 MAKE_PIN(P11, Pin_nRF51822_to_Arduino(D11));
1225 MAKE_PIN(P12, Pin_nRF51822_to_Arduino(D12));
1226 MAKE_PIN(P13, Pin_nRF51822_to_Arduino(D13));
1227 MAKE_PIN(P14, Pin_nRF51822_to_Arduino(D14));
1228 MAKE_PIN(P15, Pin_nRF51822_to_Arduino(D15));
1229 MAKE_PIN(P17, Pin_nRF51822_to_Arduino(D17));
1230 MAKE_PIN(P18, Pin_nRF51822_to_Arduino(D18));
1231 MAKE_PIN(P16, Pin_nRF51822_to_Arduino(D16));
1232 MAKE_PIN(P19, Pin_nRF51822_to_Arduino(D19));
1233 MAKE_PIN(P20, Pin_nRF51822_to_Arduino(D20));
1234 MAKE_PIN(P21, Pin_nRF51822_to_Arduino(D21));
1235 MAKE_PIN(P22, Pin_nRF51822_to_Arduino(D22));
1236 MAKE_PIN(P23, Pin_nRF51822_to_Arduino(D23));
1237 MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24));
1241 #elif defined(STM32F446xx) 1244 #define MAKE_PIN(className, port, pin) \ 1247 static void Set() { \ 1248 HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET); \ 1250 static void Clear() { \ 1251 HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET); \ 1253 static void SetDirRead() { \ 1254 static GPIO_InitTypeDef GPIO_InitStruct; \ 1255 GPIO_InitStruct.Pin = pin; \ 1256 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; \ 1257 GPIO_InitStruct.Pull = GPIO_NOPULL; \ 1258 HAL_GPIO_Init(port, &GPIO_InitStruct); \ 1260 static void SetDirWrite() { \ 1261 static GPIO_InitTypeDef GPIO_InitStruct; \ 1262 GPIO_InitStruct.Pin = pin; \ 1263 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; \ 1264 GPIO_InitStruct.Pull = GPIO_NOPULL; \ 1265 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; \ 1266 HAL_GPIO_Init(port, &GPIO_InitStruct); \ 1268 static GPIO_PinState IsSet() { \ 1269 return HAL_GPIO_ReadPin(port, pin); \ 1273 MAKE_PIN(P0, GPIOA, GPIO_PIN_3);
1274 MAKE_PIN(P1, GPIOA, GPIO_PIN_2);
1275 MAKE_PIN(P2, GPIOA, GPIO_PIN_10);
1276 MAKE_PIN(P3, GPIOB, GPIO_PIN_3);
1277 MAKE_PIN(P4, GPIOB, GPIO_PIN_5);
1278 MAKE_PIN(P5, GPIOB, GPIO_PIN_4);
1279 MAKE_PIN(P6, GPIOB, GPIO_PIN_10);
1280 MAKE_PIN(P7, GPIOA, GPIO_PIN_8);
1281 MAKE_PIN(P8, GPIOA, GPIO_PIN_9);
1282 MAKE_PIN(P9, GPIOC, GPIO_PIN_7);
1283 MAKE_PIN(P10, GPIOB, GPIO_PIN_6);
1284 MAKE_PIN(P11, GPIOA, GPIO_PIN_7);
1285 MAKE_PIN(P12, GPIOA, GPIO_PIN_6);
1286 MAKE_PIN(P13, GPIOA, GPIO_PIN_5);
1288 MAKE_PIN(P14, GPIOA, GPIO_PIN_0);
1289 MAKE_PIN(P15, GPIOA, GPIO_PIN_1);
1290 MAKE_PIN(P16, GPIOA, GPIO_PIN_4);
1291 MAKE_PIN(P17, GPIOB, GPIO_PIN_0);
1292 MAKE_PIN(P18, GPIOC, GPIO_PIN_1);
1293 MAKE_PIN(P19, GPIOC, GPIO_PIN_0);
1298 #error "Please define board in avrpins.h" 1302 #elif defined(__ARDUINO_ARC__) 1304 #include <avr/pgmspace.h> 1306 #define pgm_read_pointer(p) pgm_read_dword(p) 1308 #define MAKE_PIN(className, pin) \ 1311 static void Set() { \ 1312 digitalWrite(pin, HIGH);\ 1314 static void Clear() { \ 1315 digitalWrite(pin, LOW); \ 1317 static void SetDirRead() { \ 1318 pinMode(pin, INPUT); \ 1320 static void SetDirWrite() { \ 1321 pinMode(pin, OUTPUT); \ 1323 static uint8_t IsSet() { \ 1324 return digitalRead(pin); \ 1354 #elif defined(__ARDUINO_X86__) // Intel Galileo, Intel Galileo 2 and Intel Edison 1356 #include <avr/pgmspace.h> 1359 #define pgm_read_pointer(p) pgm_read_dword(p) 1361 #if PLATFORM_ID == 0xE1 // Edison platform id 1362 #define pinToFastPin(pin) 1 // As far as I can tell all pins can be used as fast pins 1368 #define MAKE_PIN(className, pin) \ 1371 static void Set() { \ 1372 fastDigitalWrite(pin, HIGH); \ 1374 static void Clear() { \ 1375 fastDigitalWrite(pin, LOW); \ 1377 static void SetDirRead() { \ 1378 if (pinToFastPin(pin)) \ 1379 pinMode(pin, INPUT_FAST); \ 1381 pinMode(pin, INPUT); \ 1383 static void SetDirWrite() { \ 1384 if (pinToFastPin(pin)) \ 1385 pinMode(pin, OUTPUT_FAST); \ 1387 pinMode(pin, OUTPUT); \ 1389 static uint8_t IsSet() { \ 1390 return fastDigitalRead(pin); \ 1417 #elif defined(__MIPSEL__) 1421 #define pgm_read_pointer(p) pgm_read_dword(p) 1423 #define MAKE_PIN(className, pin) \ 1426 static void Set() { \ 1427 digitalWrite(pin, HIGH);\ 1429 static void Clear() { \ 1430 digitalWrite(pin, LOW); \ 1432 static void SetDirRead() { \ 1433 pinMode(pin, INPUT); \ 1435 static void SetDirWrite() { \ 1436 pinMode(pin, OUTPUT); \ 1438 static uint8_t IsSet() { \ 1439 return digitalRead(pin); \ 1461 #elif defined(ESP8266) || defined(ESP32) 1463 #define MAKE_PIN(className, pin) \ 1466 static void Set() { \ 1467 digitalWrite(pin, HIGH);\ 1469 static void Clear() { \ 1470 digitalWrite(pin, LOW); \ 1472 static void SetDirRead() { \ 1473 pinMode(pin, INPUT); \ 1475 static void SetDirWrite() { \ 1476 pinMode(pin, OUTPUT); \ 1478 static uint8_t IsSet() { \ 1479 return digitalRead(pin); \ 1483 #if defined(ESP8266) 1486 #undef pgm_read_ptr_aligned 1488 #define pgm_read_ptr_aligned(addr) (*reinterpret_cast<const void* const*>(addr)) 1490 #define pgm_read_ptr_aligned(addr) (*(const void* const*)(addr)) 1494 #if PGM_READ_UNALIGNED 1495 #define pgm_read_ptr(p) pgm_read_ptr_unaligned(p) 1497 #define pgm_read_ptr(p) pgm_read_ptr_aligned(p) 1500 #ifdef pgm_read_pointer 1501 #undef pgm_read_pointer 1503 #define pgm_read_pointer(p) pgm_read_ptr(p) 1520 #elif defined(ESP32) 1523 #ifdef pgm_read_word 1524 #undef pgm_read_word 1526 #ifdef pgm_read_dword 1527 #undef pgm_read_dword 1529 #ifdef pgm_read_float 1530 #undef pgm_read_float 1536 #define pgm_read_word(addr) ({ \ 1537 typeof(addr) _addr = (addr); \ 1538 *(const unsigned short *)(_addr); \ 1540 #define pgm_read_dword(addr) ({ \ 1541 typeof(addr) _addr = (addr); \ 1542 *(const unsigned long *)(_addr); \ 1544 #define pgm_read_float(addr) ({ \ 1545 typeof(addr) _addr = (addr); \ 1546 *(const float *)(_addr); \ 1548 #define pgm_read_ptr(addr) ({ \ 1549 typeof(addr) _addr = (addr); \ 1550 *(void * const *)(_addr); \ 1572 #ifdef pgm_read_pointer 1573 #undef pgm_read_pointer 1575 #define pgm_read_pointer(p) pgm_read_ptr(p) 1578 #error "Please define board in avrpins.h" 1582 #endif //_avrpins_h_