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__)) 818 #include "core_pins.h" 819 #include "avr_emulation.h" 821 #define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000) 822 #define GPIO_BITBAND_PTR(reg, bit) ((uint8_t *)GPIO_BITBAND_ADDR((reg), (bit))) 824 #define MAKE_PIN(className, baseReg, pinNum, configReg) \ 827 static void Set() { \ 828 *GPIO_BITBAND_PTR(baseReg, pinNum) = 1; \ 830 static void Clear() { \ 831 *GPIO_BITBAND_PTR(baseReg, pinNum) = 0; \ 833 static void SetDirRead() { \ 834 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \ 835 *(GPIO_BITBAND_PTR(baseReg, pinNum) + 640) = 0; \ 837 static void SetDirWrite() { \ 838 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \ 839 *(GPIO_BITBAND_PTR(baseReg, pinNum) + 640) = 1; \ 841 static uint8_t IsSet() { \ 842 return *(GPIO_BITBAND_PTR(baseReg, pinNum) + 512); \ 846 MAKE_PIN(P0, CORE_PIN0_PORTREG, CORE_PIN0_BIT, CORE_PIN0_CONFIG);
847 MAKE_PIN(P1, CORE_PIN1_PORTREG, CORE_PIN1_BIT, CORE_PIN1_CONFIG);
848 MAKE_PIN(P2, CORE_PIN2_PORTREG, CORE_PIN2_BIT, CORE_PIN2_CONFIG);
849 MAKE_PIN(P3, CORE_PIN3_PORTREG, CORE_PIN3_BIT, CORE_PIN3_CONFIG);
850 MAKE_PIN(P4, CORE_PIN4_PORTREG, CORE_PIN4_BIT, CORE_PIN4_CONFIG);
851 MAKE_PIN(P5, CORE_PIN5_PORTREG, CORE_PIN5_BIT, CORE_PIN5_CONFIG);
852 MAKE_PIN(P6, CORE_PIN6_PORTREG, CORE_PIN6_BIT, CORE_PIN6_CONFIG);
853 MAKE_PIN(P7, CORE_PIN7_PORTREG, CORE_PIN7_BIT, CORE_PIN7_CONFIG);
854 MAKE_PIN(P8, CORE_PIN8_PORTREG, CORE_PIN8_BIT, CORE_PIN8_CONFIG);
855 MAKE_PIN(P9, CORE_PIN9_PORTREG, CORE_PIN9_BIT, CORE_PIN9_CONFIG);
856 MAKE_PIN(P10, CORE_PIN10_PORTREG, CORE_PIN10_BIT, CORE_PIN10_CONFIG);
857 MAKE_PIN(P11, CORE_PIN11_PORTREG, CORE_PIN11_BIT, CORE_PIN11_CONFIG);
858 MAKE_PIN(P12, CORE_PIN12_PORTREG, CORE_PIN12_BIT, CORE_PIN12_CONFIG);
859 MAKE_PIN(P13, CORE_PIN13_PORTREG, CORE_PIN13_BIT, CORE_PIN13_CONFIG);
860 MAKE_PIN(P14, CORE_PIN14_PORTREG, CORE_PIN14_BIT, CORE_PIN14_CONFIG);
861 MAKE_PIN(P15, CORE_PIN15_PORTREG, CORE_PIN15_BIT, CORE_PIN15_CONFIG);
862 MAKE_PIN(P16, CORE_PIN16_PORTREG, CORE_PIN16_BIT, CORE_PIN16_CONFIG);
863 MAKE_PIN(P17, CORE_PIN17_PORTREG, CORE_PIN17_BIT, CORE_PIN17_CONFIG);
864 MAKE_PIN(P18, CORE_PIN18_PORTREG, CORE_PIN18_BIT, CORE_PIN18_CONFIG);
865 MAKE_PIN(P19, CORE_PIN19_PORTREG, CORE_PIN19_BIT, CORE_PIN19_CONFIG);
866 MAKE_PIN(P20, CORE_PIN20_PORTREG, CORE_PIN20_BIT, CORE_PIN20_CONFIG);
867 MAKE_PIN(P21, CORE_PIN21_PORTREG, CORE_PIN21_BIT, CORE_PIN21_CONFIG);
868 MAKE_PIN(P22, CORE_PIN22_PORTREG, CORE_PIN22_BIT, CORE_PIN22_CONFIG);
869 MAKE_PIN(P23, CORE_PIN23_PORTREG, CORE_PIN23_BIT, CORE_PIN23_CONFIG);
870 MAKE_PIN(P24, CORE_PIN24_PORTREG, CORE_PIN24_BIT, CORE_PIN24_CONFIG);
871 MAKE_PIN(P25, CORE_PIN25_PORTREG, CORE_PIN25_BIT, CORE_PIN25_CONFIG);
872 MAKE_PIN(P26, CORE_PIN26_PORTREG, CORE_PIN26_BIT, CORE_PIN26_CONFIG);
873 MAKE_PIN(P27, CORE_PIN27_PORTREG, CORE_PIN27_BIT, CORE_PIN27_CONFIG);
874 MAKE_PIN(P28, CORE_PIN28_PORTREG, CORE_PIN28_BIT, CORE_PIN28_CONFIG);
875 MAKE_PIN(P29, CORE_PIN29_PORTREG, CORE_PIN29_BIT, CORE_PIN29_CONFIG);
876 MAKE_PIN(P30, CORE_PIN30_PORTREG, CORE_PIN30_BIT, CORE_PIN30_CONFIG);
877 MAKE_PIN(P31, CORE_PIN31_PORTREG, CORE_PIN31_BIT, CORE_PIN31_CONFIG);
878 MAKE_PIN(P32, CORE_PIN32_PORTREG, CORE_PIN32_BIT, CORE_PIN32_CONFIG);
879 MAKE_PIN(P33, CORE_PIN33_PORTREG, CORE_PIN33_BIT, CORE_PIN33_CONFIG);
880 #if defined(__MK64FX512__) || defined(__MK66FX1M0__) 881 MAKE_PIN(P34, CORE_PIN34_PORTREG, CORE_PIN34_BIT, CORE_PIN34_CONFIG);
882 MAKE_PIN(P35, CORE_PIN35_PORTREG, CORE_PIN35_BIT, CORE_PIN35_CONFIG);
883 MAKE_PIN(P36, CORE_PIN36_PORTREG, CORE_PIN36_BIT, CORE_PIN36_CONFIG);
884 MAKE_PIN(P37, CORE_PIN37_PORTREG, CORE_PIN37_BIT, CORE_PIN37_CONFIG);
885 MAKE_PIN(P38, CORE_PIN38_PORTREG, CORE_PIN38_BIT, CORE_PIN38_CONFIG);
886 MAKE_PIN(P39, CORE_PIN39_PORTREG, CORE_PIN39_BIT, CORE_PIN39_CONFIG);
887 MAKE_PIN(P40, CORE_PIN40_PORTREG, CORE_PIN40_BIT, CORE_PIN40_CONFIG);
888 MAKE_PIN(P41, CORE_PIN41_PORTREG, CORE_PIN41_BIT, CORE_PIN41_CONFIG);
889 MAKE_PIN(P42, CORE_PIN42_PORTREG, CORE_PIN42_BIT, CORE_PIN42_CONFIG);
890 MAKE_PIN(P43, CORE_PIN43_PORTREG, CORE_PIN43_BIT, CORE_PIN43_CONFIG);
891 MAKE_PIN(P44, CORE_PIN44_PORTREG, CORE_PIN44_BIT, CORE_PIN44_CONFIG);
892 MAKE_PIN(P45, CORE_PIN45_PORTREG, CORE_PIN45_BIT, CORE_PIN45_CONFIG);
893 MAKE_PIN(P46, CORE_PIN46_PORTREG, CORE_PIN46_BIT, CORE_PIN46_CONFIG);
894 MAKE_PIN(P47, CORE_PIN47_PORTREG, CORE_PIN47_BIT, CORE_PIN47_CONFIG);
895 MAKE_PIN(P48, CORE_PIN48_PORTREG, CORE_PIN48_BIT, CORE_PIN48_CONFIG);
896 MAKE_PIN(P49, CORE_PIN49_PORTREG, CORE_PIN49_BIT, CORE_PIN49_CONFIG);
897 MAKE_PIN(P50, CORE_PIN50_PORTREG, CORE_PIN50_BIT, CORE_PIN50_CONFIG);
898 MAKE_PIN(P51, CORE_PIN51_PORTREG, CORE_PIN51_BIT, CORE_PIN51_CONFIG);
899 MAKE_PIN(P52, CORE_PIN52_PORTREG, CORE_PIN52_BIT, CORE_PIN52_CONFIG);
900 MAKE_PIN(P53, CORE_PIN53_PORTREG, CORE_PIN53_BIT, CORE_PIN53_CONFIG);
901 MAKE_PIN(P54, CORE_PIN54_PORTREG, CORE_PIN54_BIT, CORE_PIN54_CONFIG);
902 MAKE_PIN(P55, CORE_PIN55_PORTREG, CORE_PIN55_BIT, CORE_PIN55_CONFIG);
903 MAKE_PIN(P56, CORE_PIN56_PORTREG, CORE_PIN56_BIT, CORE_PIN56_CONFIG);
904 MAKE_PIN(P57, CORE_PIN57_PORTREG, CORE_PIN57_BIT, CORE_PIN57_CONFIG);
905 MAKE_PIN(P58, CORE_PIN58_PORTREG, CORE_PIN58_BIT, CORE_PIN58_CONFIG);
906 MAKE_PIN(P59, CORE_PIN59_PORTREG, CORE_PIN59_BIT, CORE_PIN59_CONFIG);
907 MAKE_PIN(P60, CORE_PIN60_PORTREG, CORE_PIN60_BIT, CORE_PIN60_CONFIG);
908 MAKE_PIN(P61, CORE_PIN61_PORTREG, CORE_PIN61_BIT, CORE_PIN61_CONFIG);
909 MAKE_PIN(P62, CORE_PIN62_PORTREG, CORE_PIN62_BIT, CORE_PIN62_CONFIG);
910 MAKE_PIN(P63, CORE_PIN63_PORTREG, CORE_PIN63_BIT, CORE_PIN63_CONFIG);
915 #elif defined(CORE_TEENSY) && (defined(__MKL26Z64__)) 924 #include "core_pins.h" 925 #include "avr_emulation.h" 927 #define MAKE_PIN(className, baseReg, pinNum, configReg) \ 930 static void Set() { \ 931 *portSetRegister(pinNum) = digitalPinToBitMask(pinNum); \ 933 static void Clear() { \ 934 *portClearRegister(pinNum) = digitalPinToBitMask(pinNum); \ 936 static void SetDirRead() { \ 937 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \ 938 *portModeRegister(pinNum) &= ~digitalPinToBitMask(pinNum); \ 940 static void SetDirWrite() { \ 941 configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \ 942 *portModeRegister(pinNum) |= digitalPinToBitMask(pinNum); \ 944 static uint8_t IsSet() { \ 945 return (*portInputRegister(pinNum) & digitalPinToBitMask(pinNum)) ? 1 : 0; \ 949 MAKE_PIN(P0, CORE_PIN0_PORTREG, 0, CORE_PIN0_CONFIG);
950 MAKE_PIN(P1, CORE_PIN1_PORTREG, 1, CORE_PIN1_CONFIG);
951 MAKE_PIN(P2, CORE_PIN2_PORTREG, 2, CORE_PIN2_CONFIG);
952 MAKE_PIN(P3, CORE_PIN3_PORTREG, 3, CORE_PIN3_CONFIG);
953 MAKE_PIN(P4, CORE_PIN4_PORTREG, 4, CORE_PIN4_CONFIG);
954 MAKE_PIN(P5, CORE_PIN5_PORTREG, 5, CORE_PIN5_CONFIG);
955 MAKE_PIN(P6, CORE_PIN6_PORTREG, 6, CORE_PIN6_CONFIG);
956 MAKE_PIN(P7, CORE_PIN7_PORTREG, 7, CORE_PIN7_CONFIG);
957 MAKE_PIN(P8, CORE_PIN8_PORTREG, 8, CORE_PIN8_CONFIG);
958 MAKE_PIN(P9, CORE_PIN9_PORTREG, 9, CORE_PIN9_CONFIG);
959 MAKE_PIN(P10, CORE_PIN10_PORTREG, 10, CORE_PIN10_CONFIG);
960 MAKE_PIN(P11, CORE_PIN11_PORTREG, 11, CORE_PIN11_CONFIG);
961 MAKE_PIN(P12, CORE_PIN12_PORTREG, 12, CORE_PIN12_CONFIG);
962 MAKE_PIN(P13, CORE_PIN13_PORTREG, 13, CORE_PIN13_CONFIG);
963 MAKE_PIN(P14, CORE_PIN14_PORTREG, 14, CORE_PIN14_CONFIG);
964 MAKE_PIN(P15, CORE_PIN15_PORTREG, 15, CORE_PIN15_CONFIG);
965 MAKE_PIN(P16, CORE_PIN16_PORTREG, 16, CORE_PIN16_CONFIG);
966 MAKE_PIN(P17, CORE_PIN17_PORTREG, 17, CORE_PIN17_CONFIG);
967 MAKE_PIN(P18, CORE_PIN18_PORTREG, 18, CORE_PIN18_CONFIG);
968 MAKE_PIN(P19, CORE_PIN19_PORTREG, 19, CORE_PIN19_CONFIG);
969 MAKE_PIN(P20, CORE_PIN20_PORTREG, 20, CORE_PIN20_CONFIG);
970 MAKE_PIN(P21, CORE_PIN21_PORTREG, 21, CORE_PIN21_CONFIG);
971 MAKE_PIN(P22, CORE_PIN22_PORTREG, 22, CORE_PIN22_CONFIG);
972 MAKE_PIN(P23, CORE_PIN23_PORTREG, 23, CORE_PIN23_CONFIG);
973 MAKE_PIN(P24, CORE_PIN24_PORTREG, 24, CORE_PIN24_CONFIG);
974 MAKE_PIN(P25, CORE_PIN25_PORTREG, 25, CORE_PIN25_CONFIG);
975 MAKE_PIN(P26, CORE_PIN26_PORTREG, 26, CORE_PIN26_CONFIG);
979 #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) 993 #define MAKE_PIN(className, pio, pinMask) \ 996 static void Set() { \ 997 pio->PIO_SODR = pinMask; \ 999 static void Clear() { \ 1000 pio->PIO_CODR = pinMask; \ 1002 static void SetDirRead() { \ 1003 pio->PIO_IDR = pinMask ; \ 1004 pio->PIO_PUDR = pinMask; \ 1005 pio->PIO_ODR = pinMask; \ 1006 pio->PIO_PER = pinMask; \ 1008 static void SetDirWrite() { \ 1009 pio->PIO_IDR = pinMask ; \ 1010 pio->PIO_PUDR = pinMask; \ 1011 pio->PIO_OER = pinMask; \ 1012 pio->PIO_PER = pinMask; \ 1014 static uint8_t IsSet() { \ 1015 return pio->PIO_PDSR & pinMask; \ 1021 MAKE_PIN(P0, PIOA, PIO_PA8);
1022 MAKE_PIN(P1, PIOA, PIO_PA9);
1023 MAKE_PIN(P2, PIOB, PIO_PB25);
1024 MAKE_PIN(P3, PIOC, PIO_PC28);
1025 MAKE_PIN(P4, PIOC, PIO_PC26);
1026 MAKE_PIN(P5, PIOC, PIO_PC25);
1027 MAKE_PIN(P6, PIOC, PIO_PC24);
1028 MAKE_PIN(P7, PIOC, PIO_PC23);
1029 MAKE_PIN(P8, PIOC, PIO_PC22);
1030 MAKE_PIN(P9, PIOC, PIO_PC21);
1031 MAKE_PIN(P10, PIOC, PIO_PC29);
1032 MAKE_PIN(P11, PIOD, PIO_PD7);
1033 MAKE_PIN(P12, PIOD, PIO_PD8);
1034 MAKE_PIN(P13, PIOB, PIO_PB27);
1035 MAKE_PIN(P14, PIOD, PIO_PD4);
1036 MAKE_PIN(P15, PIOD, PIO_PD5);
1037 MAKE_PIN(P16, PIOA, PIO_PA13);
1038 MAKE_PIN(P17, PIOA, PIO_PA12);
1039 MAKE_PIN(P18, PIOA, PIO_PA11);
1040 MAKE_PIN(P19, PIOA, PIO_PA10);
1041 MAKE_PIN(P20, PIOB, PIO_PB12);
1042 MAKE_PIN(P21, PIOB, PIO_PB13);
1043 MAKE_PIN(P22, PIOB, PIO_PB26);
1044 MAKE_PIN(P23, PIOA, PIO_PA14);
1045 MAKE_PIN(P24, PIOA, PIO_PA15);
1046 MAKE_PIN(P25, PIOD, PIO_PD0);
1047 MAKE_PIN(P26, PIOD, PIO_PD1);
1048 MAKE_PIN(P27, PIOD, PIO_PD2);
1049 MAKE_PIN(P28, PIOD, PIO_PD3);
1050 MAKE_PIN(P29, PIOD, PIO_PD6);
1051 MAKE_PIN(P30, PIOD, PIO_PD9);
1052 MAKE_PIN(P31, PIOA, PIO_PA7);
1053 MAKE_PIN(P32, PIOD, PIO_PD10);
1054 MAKE_PIN(P33, PIOC, PIO_PC1);
1055 MAKE_PIN(P34, PIOC, PIO_PC2);
1056 MAKE_PIN(P35, PIOC, PIO_PC3);
1057 MAKE_PIN(P36, PIOC, PIO_PC4);
1058 MAKE_PIN(P37, PIOC, PIO_PC5);
1059 MAKE_PIN(P38, PIOC, PIO_PC6);
1060 MAKE_PIN(P39, PIOC, PIO_PC7);
1061 MAKE_PIN(P40, PIOC, PIO_PC8);
1062 MAKE_PIN(P41, PIOC, PIO_PC9);
1063 MAKE_PIN(P42, PIOA, PIO_PA19);
1064 MAKE_PIN(P43, PIOA, PIO_PA20);
1065 MAKE_PIN(P44, PIOC, PIO_PC19);
1066 MAKE_PIN(P45, PIOC, PIO_PC18);
1067 MAKE_PIN(P46, PIOC, PIO_PC17);
1068 MAKE_PIN(P47, PIOC, PIO_PC16);
1069 MAKE_PIN(P48, PIOC, PIO_PC15);
1070 MAKE_PIN(P49, PIOC, PIO_PC14);
1071 MAKE_PIN(P50, PIOC, PIO_PC13);
1072 MAKE_PIN(P51, PIOC, PIO_PC12);
1073 MAKE_PIN(P52, PIOB, PIO_PB21);
1074 MAKE_PIN(P53, PIOB, PIO_PB14);
1075 MAKE_PIN(P54, PIOA, PIO_PA16);
1076 MAKE_PIN(P55, PIOA, PIO_PA24);
1077 MAKE_PIN(P56, PIOA, PIO_PA23);
1078 MAKE_PIN(P57, PIOA, PIO_PA22);
1079 MAKE_PIN(P58, PIOA, PIO_PA6);
1080 MAKE_PIN(P59, PIOA, PIO_PA4);
1081 MAKE_PIN(P60, PIOA, PIO_PA3);
1082 MAKE_PIN(P61, PIOA, PIO_PA2);
1083 MAKE_PIN(P62, PIOB, PIO_PB17);
1084 MAKE_PIN(P63, PIOB, PIO_PB18);
1085 MAKE_PIN(P64, PIOB, PIO_PB19);
1086 MAKE_PIN(P65, PIOB, PIO_PB20);
1087 MAKE_PIN(P66, PIOB, PIO_PB15);
1088 MAKE_PIN(P67, PIOB, PIO_PB16);
1089 MAKE_PIN(P68, PIOA, PIO_PA1);
1090 MAKE_PIN(P69, PIOA, PIO_PA0);
1091 MAKE_PIN(P70, PIOA, PIO_PA17);
1092 MAKE_PIN(P71, PIOA, PIO_PA18);
1093 MAKE_PIN(P72, PIOC, PIO_PC30);
1094 MAKE_PIN(P73, PIOA, PIO_PA21);
1095 MAKE_PIN(P74, PIOA, PIO_PA25);
1096 MAKE_PIN(P75, PIOA, PIO_PA26);
1097 MAKE_PIN(P76, PIOA, PIO_PA27);
1098 MAKE_PIN(P77, PIOA, PIO_PA28);
1099 MAKE_PIN(P78, PIOB, PIO_PB23);
1103 #elif defined(RBL_NRF51822) 1105 #define MAKE_PIN(className, pin) \ 1108 static void Set() { \ 1109 nrf_gpio_pin_set(pin); \ 1111 static void Clear() { \ 1112 nrf_gpio_pin_clear(pin); \ 1114 static void SetDirRead() { \ 1115 nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL); \ 1117 static void SetDirWrite() { \ 1118 nrf_gpio_cfg_output(pin); \ 1120 static uint8_t IsSet() { \ 1121 return (uint8_t)nrf_gpio_pin_read(pin); \ 1126 MAKE_PIN(P0, Pin_nRF51822_to_Arduino(D0));
1127 MAKE_PIN(P1, Pin_nRF51822_to_Arduino(D1));
1128 MAKE_PIN(P2, Pin_nRF51822_to_Arduino(D2));
1129 MAKE_PIN(P3, Pin_nRF51822_to_Arduino(D3));
1130 MAKE_PIN(P4, Pin_nRF51822_to_Arduino(D4));
1131 MAKE_PIN(P5, Pin_nRF51822_to_Arduino(D5));
1132 MAKE_PIN(P6, Pin_nRF51822_to_Arduino(D6));
1133 MAKE_PIN(P7, Pin_nRF51822_to_Arduino(D7));
1134 MAKE_PIN(P8, Pin_nRF51822_to_Arduino(D8));
1135 MAKE_PIN(P9, Pin_nRF51822_to_Arduino(D9));
1136 MAKE_PIN(P10, Pin_nRF51822_to_Arduino(D10));
1137 MAKE_PIN(P11, Pin_nRF51822_to_Arduino(D11));
1138 MAKE_PIN(P12, Pin_nRF51822_to_Arduino(D12));
1139 MAKE_PIN(P13, Pin_nRF51822_to_Arduino(D13));
1140 MAKE_PIN(P14, Pin_nRF51822_to_Arduino(D14));
1141 MAKE_PIN(P15, Pin_nRF51822_to_Arduino(D15));
1142 MAKE_PIN(P17, Pin_nRF51822_to_Arduino(D17));
1143 MAKE_PIN(P18, Pin_nRF51822_to_Arduino(D18));
1144 MAKE_PIN(P16, Pin_nRF51822_to_Arduino(D16));
1145 MAKE_PIN(P19, Pin_nRF51822_to_Arduino(D19));
1146 MAKE_PIN(P20, Pin_nRF51822_to_Arduino(D20));
1147 MAKE_PIN(P21, Pin_nRF51822_to_Arduino(D21));
1148 MAKE_PIN(P22, Pin_nRF51822_to_Arduino(D22));
1149 MAKE_PIN(P23, Pin_nRF51822_to_Arduino(D23));
1150 MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24));
1154 #elif defined(STM32F446xx) 1157 #define MAKE_PIN(className, port, pin) \ 1160 static void Set() { \ 1161 HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET); \ 1163 static void Clear() { \ 1164 HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET); \ 1166 static void SetDirRead() { \ 1167 static GPIO_InitTypeDef GPIO_InitStruct; \ 1168 GPIO_InitStruct.Pin = pin; \ 1169 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; \ 1170 GPIO_InitStruct.Pull = GPIO_NOPULL; \ 1171 HAL_GPIO_Init(port, &GPIO_InitStruct); \ 1173 static void SetDirWrite() { \ 1174 static GPIO_InitTypeDef GPIO_InitStruct; \ 1175 GPIO_InitStruct.Pin = pin; \ 1176 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; \ 1177 GPIO_InitStruct.Pull = GPIO_NOPULL; \ 1178 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; \ 1179 HAL_GPIO_Init(port, &GPIO_InitStruct); \ 1181 static GPIO_PinState IsSet() { \ 1182 return HAL_GPIO_ReadPin(port, pin); \ 1186 MAKE_PIN(P0, GPIOA, GPIO_PIN_3);
1187 MAKE_PIN(P1, GPIOA, GPIO_PIN_2);
1188 MAKE_PIN(P2, GPIOA, GPIO_PIN_10);
1189 MAKE_PIN(P3, GPIOB, GPIO_PIN_3);
1190 MAKE_PIN(P4, GPIOB, GPIO_PIN_5);
1191 MAKE_PIN(P5, GPIOB, GPIO_PIN_4);
1192 MAKE_PIN(P6, GPIOB, GPIO_PIN_10);
1193 MAKE_PIN(P7, GPIOA, GPIO_PIN_8);
1194 MAKE_PIN(P8, GPIOA, GPIO_PIN_9);
1195 MAKE_PIN(P9, GPIOC, GPIO_PIN_7);
1196 MAKE_PIN(P10, GPIOB, GPIO_PIN_6);
1197 MAKE_PIN(P11, GPIOA, GPIO_PIN_7);
1198 MAKE_PIN(P12, GPIOA, GPIO_PIN_6);
1199 MAKE_PIN(P13, GPIOA, GPIO_PIN_5);
1201 MAKE_PIN(P14, GPIOA, GPIO_PIN_0);
1202 MAKE_PIN(P15, GPIOA, GPIO_PIN_1);
1203 MAKE_PIN(P16, GPIOA, GPIO_PIN_4);
1204 MAKE_PIN(P17, GPIOB, GPIO_PIN_0);
1205 MAKE_PIN(P18, GPIOC, GPIO_PIN_1);
1206 MAKE_PIN(P19, GPIOC, GPIO_PIN_0);
1211 #error "Please define board in avrpins.h" 1215 #elif defined(__ARDUINO_ARC__) 1217 #include <avr/pgmspace.h> 1219 #define pgm_read_pointer(p) pgm_read_dword(p) 1221 #define MAKE_PIN(className, pin) \ 1224 static void Set() { \ 1225 digitalWrite(pin, HIGH);\ 1227 static void Clear() { \ 1228 digitalWrite(pin, LOW); \ 1230 static void SetDirRead() { \ 1231 pinMode(pin, INPUT); \ 1233 static void SetDirWrite() { \ 1234 pinMode(pin, OUTPUT); \ 1236 static uint8_t IsSet() { \ 1237 return digitalRead(pin); \ 1267 #elif defined(__ARDUINO_X86__) // Intel Galileo, Intel Galileo 2 and Intel Edison 1269 #include <avr/pgmspace.h> 1272 #define pgm_read_pointer(p) pgm_read_dword(p) 1274 #if PLATFORM_ID == 0xE1 // Edison platform id 1275 #define pinToFastPin(pin) 1 // As far as I can tell all pins can be used as fast pins 1281 #define MAKE_PIN(className, pin) \ 1284 static void Set() { \ 1285 fastDigitalWrite(pin, HIGH); \ 1287 static void Clear() { \ 1288 fastDigitalWrite(pin, LOW); \ 1290 static void SetDirRead() { \ 1291 if (pinToFastPin(pin)) \ 1292 pinMode(pin, INPUT_FAST); \ 1294 pinMode(pin, INPUT); \ 1296 static void SetDirWrite() { \ 1297 if (pinToFastPin(pin)) \ 1298 pinMode(pin, OUTPUT_FAST); \ 1300 pinMode(pin, OUTPUT); \ 1302 static uint8_t IsSet() { \ 1303 return fastDigitalRead(pin); \ 1330 #elif defined(__MIPSEL__) 1334 #define pgm_read_pointer(p) pgm_read_dword(p) 1336 #define MAKE_PIN(className, pin) \ 1339 static void Set() { \ 1340 digitalWrite(pin, HIGH);\ 1342 static void Clear() { \ 1343 digitalWrite(pin, LOW); \ 1345 static void SetDirRead() { \ 1346 pinMode(pin, INPUT); \ 1348 static void SetDirWrite() { \ 1349 pinMode(pin, OUTPUT); \ 1351 static uint8_t IsSet() { \ 1352 return digitalRead(pin); \ 1374 #elif defined(ESP8266) || defined(ESP32) 1376 #define MAKE_PIN(className, pin) \ 1379 static void Set() { \ 1380 digitalWrite(pin, HIGH);\ 1382 static void Clear() { \ 1383 digitalWrite(pin, LOW); \ 1385 static void SetDirRead() { \ 1386 pinMode(pin, INPUT); \ 1388 static void SetDirWrite() { \ 1389 pinMode(pin, OUTPUT); \ 1391 static uint8_t IsSet() { \ 1392 return digitalRead(pin); \ 1396 #if defined(ESP8266) 1399 #undef pgm_read_ptr_aligned 1401 #define pgm_read_ptr_aligned(addr) (*reinterpret_cast<const void* const*>(addr)) 1403 #define pgm_read_ptr_aligned(addr) (*(const void* const*)(addr)) 1407 #if PGM_READ_UNALIGNED 1408 #define pgm_read_ptr(p) pgm_read_ptr_unaligned(p) 1410 #define pgm_read_ptr(p) pgm_read_ptr_aligned(p) 1413 #ifdef pgm_read_pointer 1414 #undef pgm_read_pointer 1416 #define pgm_read_pointer(p) pgm_read_ptr(p) 1433 #elif defined(ESP32) 1436 #ifdef pgm_read_word 1437 #undef pgm_read_word 1439 #ifdef pgm_read_dword 1440 #undef pgm_read_dword 1442 #ifdef pgm_read_float 1443 #undef pgm_read_float 1449 #define pgm_read_word(addr) ({ \ 1450 typeof(addr) _addr = (addr); \ 1451 *(const unsigned short *)(_addr); \ 1453 #define pgm_read_dword(addr) ({ \ 1454 typeof(addr) _addr = (addr); \ 1455 *(const unsigned long *)(_addr); \ 1457 #define pgm_read_float(addr) ({ \ 1458 typeof(addr) _addr = (addr); \ 1459 *(const float *)(_addr); \ 1461 #define pgm_read_ptr(addr) ({ \ 1462 typeof(addr) _addr = (addr); \ 1463 *(void * const *)(_addr); \ 1485 #ifdef pgm_read_pointer 1486 #undef pgm_read_pointer 1488 #define pgm_read_pointer(p) pgm_read_ptr(p) 1491 #error "Please define board in avrpins.h" 1495 #endif //_avrpins_h_