You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef pins_macros_for_arduino_compatibility_h
  2. #define pins_macros_for_arduino_compatibility_h
  3. #include <avr/pgmspace.h>
  4. #include "core_pins.h"
  5. #if defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  6. const static uint8_t A0 = CORE_ANALOG0_PIN;
  7. const static uint8_t A1 = CORE_ANALOG1_PIN;
  8. const static uint8_t A2 = CORE_ANALOG2_PIN;
  9. const static uint8_t A3 = CORE_ANALOG3_PIN;
  10. const static uint8_t A4 = CORE_ANALOG4_PIN;
  11. const static uint8_t A5 = CORE_ANALOG5_PIN;
  12. const static uint8_t A6 = CORE_ANALOG6_PIN;
  13. const static uint8_t A7 = CORE_ANALOG7_PIN;
  14. #if defined(__AVR_ATmega32U4__)
  15. const static uint8_t A8 = CORE_ANALOG8_PIN;
  16. const static uint8_t A9 = CORE_ANALOG9_PIN;
  17. const static uint8_t A10 = 10;
  18. const static uint8_t A11 = CORE_ANALOG11_PIN;
  19. #endif
  20. #endif
  21. const static uint8_t SS = CORE_SS0_PIN;
  22. const static uint8_t MOSI = CORE_MOSI0_PIN;
  23. const static uint8_t MISO = CORE_MISO0_PIN;
  24. const static uint8_t SCK = CORE_SCLK0_PIN;
  25. const static uint8_t LED_BUILTIN = CORE_LED0_PIN;
  26. #if defined(CORE_SDA0_PIN)
  27. const static uint8_t SDA = CORE_SDA0_PIN;
  28. #endif
  29. #if defined(CORE_SCL0_PIN)
  30. const static uint8_t SCL = CORE_SCL0_PIN;
  31. #endif
  32. #define NUM_DIGITAL_PINS CORE_NUM_TOTAL_PINS
  33. #define NUM_ANALOG_INPUTS CORE_NUM_ANALOG
  34. // default CS pin to use for Ethernet library
  35. #if defined(__AVR_ATmega32U4__)
  36. #define PIN_SPI_SS_ETHERNET_LIB 0
  37. #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  38. #define PIN_SPI_SS_ETHERNET_LIB 20
  39. #endif
  40. // This allows CapSense to work. Do any libraries
  41. // depend on these to be zero?
  42. #define NOT_A_PORT 127
  43. #define NOT_A_PIN 127
  44. #define NOT_AN_INTERRUPT -1
  45. #define digitalPinToPort(P) (P)
  46. #define portInputRegister(P) ((volatile uint8_t *)((int)pgm_read_byte(digital_pin_table_PGM+(P)*2+1)))
  47. #define portModeRegister(P) (portInputRegister(P) + 1)
  48. #define portOutputRegister(P) (portInputRegister(P) + 2)
  49. #define digitalPinToBitMask(P) (pgm_read_byte(digital_pin_table_PGM+(P)*2))
  50. extern const uint8_t PROGMEM digital_pin_table_PGM[];
  51. #if defined(__AVR_AT90USB162__)
  52. #define analogInputToDigitalPin(ch) (-1)
  53. #define digitalPinHasPWM(p) ((p) == 0 || (p) == 15 || (p) == 17 || (p) == 18)
  54. #define digitalPinToInterrupt(p) (((p) <= 3 || (p) == 6 || (p) == 8) ? (p) : ((p) == 4 ? 5 : ((p) == 16 ? 4 : -1)))
  55. #elif defined(__AVR_ATmega32U4__)
  56. #define analogInputToDigitalPin(ch) ((ch) <= 10 ? 21 - (ch) : ((ch) == 11 ? 22 : -1))
  57. #define digitalPinHasPWM(p) ((p) == 4 || (p) == 5 || (p) == 9 || (p) == 10 || (p) == 12 || (p) == 14 || (p) == 15)
  58. #define digitalPinToInterrupt(p) (((p) >= 5 && (p) <= 8) ? (p) - 5 : -1)
  59. #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  60. #define analogInputToDigitalPin(ch) ((ch) <= 7 ? (ch) + 38 : -1)
  61. #define digitalPinHasPWM(p) (((p) >= 14 && (p) <= 16) || ((p) >= 24 && (p) <= 27) || (p) == 0 || (p) == 1)
  62. #define digitalPinToInterrupt(p) ((p) <= 3 ? (p) : (((p) == 36 || (p) == 37) ? (p) - 32 : (((p) == 18 || (p) == 19) ? (p) - 12 : -1)))
  63. #endif
  64. #if defined(__AVR_AT90USB162__)
  65. #define digitalPinToPortReg(p) (((p) <= 7) ? &PORTD : (((p) <= 15) ? &PORTB : &PORTC))
  66. #define digitalPinToBit(p) \
  67. (((p) <= 7) ? (p) : (((p) <= 15) ? (p) - 8 : (((p) <= 19) ? 23 - (p) : 2)))
  68. #define digitalPinToPCICR(p) \
  69. ((((p) >= 8 && (p) <= 15) || ((p) >= 17 && (p) <= 20) || (p) == 5) ? &PCICR : NULL)
  70. #define digitalPinToPCICRbit(p) (((p) >= 8 && (p) <= 15) ? 0 : 1)
  71. #define digitalPinToPCIFR(p) \
  72. ((((p) >= 8 && (p) <= 15) || ((p) >= 17 && (p) <= 20) || (p) == 5) ? &PCIFR : NULL)
  73. #define digitalPinToPCIFRbit(p) (((p) >= 8 && (p) <= 15) ? 0 : 1)
  74. #define digitalPinToPCMSK(p) \
  75. (((p) >= 8 && (p) <= 15) ? &PCMSK0 : ((((p) >= 17 && (p) <= 20) || (p) == 5) ? &PCMSK1 : NULL))
  76. #define digitalPinToPCMSKbit(p) \
  77. (((p) >= 8 && (p) <= 15) ? (p) - 8 : (((p) >= 17 && (p) <= 20) ? (p) - 17 : 4))
  78. #elif defined(__AVR_ATmega32U4__)
  79. #define digitalPinToPortReg(p) \
  80. (((p) <= 4) ? &PORTB : (((p) <= 8) ? &PORTD : (((p) <= 10) ? &PORTC : (((p) <= 12) ? &PORTD : \
  81. (((p) <= 15) ? &PORTB : (((p) <= 21) ? &PORTF : (((p) <= 23) ? &PORTD : &PORTE)))))))
  82. #define digitalPinToBit(p) \
  83. (((p) <= 3) ? (p) : (((p) == 4) ? 7 : (((p) <= 8) ? (p) - 5 : (((p) <= 10) ? (p) - 3 : \
  84. (((p) <= 12) ? (p) - 5 : (((p) <= 15) ? (p) - 9 : (((p) <= 19) ? 23 - (p) : \
  85. (((p) <= 21) ? 21 - (p) : (((p) <= 23) ? (p) - 18 : 6)))))))))
  86. #define digitalPinToPCICR(p) ((((p) >= 0 && (p) <= 4) || ((p) >= 13 && (p) <= 15)) ? &PCICR : NULL)
  87. #define digitalPinToPCICRbit(p) (0)
  88. #define digitalPinToPCIFR(p) ((((p) >= 0 && (p) <= 4) || ((p) >= 13 && (p) <= 15)) ? &PCIFR : NULL)
  89. #define digitalPinToPCIFRbit(p) (0)
  90. #define digitalPinToPCMSK(p) ((((p) >= 0 && (p) <= 4) || ((p) >= 13 && (p) <= 15)) ? &PCMSK0 : NULL)
  91. #define digitalPinToPCMSKbit(p) \
  92. (((p) >= 0 && (p) <= 3) ? (p) : (((p) >= 13 && (p) <= 15) ? (p) - 9 : 7))
  93. #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  94. #define digitalPinToPortReg(p) \
  95. (((p) >= 0 && (p) <= 7) ? &PORTD : (((p) >= 10 && (p) <= 17) ? &PORTC : \
  96. (((p) >= 20 && (p) <= 27) ? &PORTB : (((p) >= 28 && (p) <= 35) ? &PORTA : \
  97. (((p) >= 38 && (p) <= 45) ? &PORTF : &PORTE)))))
  98. #define digitalPinToBit(p) \
  99. (((p) <= 7) ? (p) : (((p) <= 9) ? (p) - 8 : (((p) <= 17) ? (p) - 10 : \
  100. (((p) <= 19) ? (p) - 12 : (((p) <= 27) ? (p) - 20 : (((p) <= 35) ? (p) - 28 : \
  101. (((p) <= 37) ? (p) - 32 : (((p) <= 45) ? (p) - 38 : 2))))))))
  102. #define digitalPinToPCICR(p) (((p) >= 20 && (p) <= 27) ? &PCICR : NULL)
  103. #define digitalPinToPCICRbit(p) (0)
  104. #define digitalPinToPCIFR(p) (((p) >= 20 && (p) <= 27) ? &PCIFR : NULL)
  105. #define digitalPinToPCIFRbit(p) (0)
  106. #define digitalPinToPCMSK(p) (((p) >= 20 && (p) <= 27) ? &PCMSK0 : NULL)
  107. #define digitalPinToPCMSKbit(p) (((p) - 20) & 7)
  108. #endif
  109. #define NOT_ON_TIMER 0
  110. static inline uint8_t digitalPinToTimer(uint8_t) __attribute__((always_inline, unused));
  111. static inline uint8_t digitalPinToTimer(uint8_t pin)
  112. {
  113. switch (pin) {
  114. #ifdef CORE_PWM0_PIN
  115. case CORE_PWM0_PIN: return 1;
  116. #endif
  117. #ifdef CORE_PWM1_PIN
  118. case CORE_PWM1_PIN: return 2;
  119. #endif
  120. #ifdef CORE_PWM2_PIN
  121. case CORE_PWM2_PIN: return 3;
  122. #endif
  123. #ifdef CORE_PWM3_PIN
  124. case CORE_PWM3_PIN: return 4;
  125. #endif
  126. #ifdef CORE_PWM4_PIN
  127. case CORE_PWM4_PIN: return 5;
  128. #endif
  129. #ifdef CORE_PWM5_PIN
  130. case CORE_PWM5_PIN: return 6;
  131. #endif
  132. #ifdef CORE_PWM6_PIN
  133. case CORE_PWM6_PIN: return 7;
  134. #endif
  135. #ifdef CORE_PWM7_PIN
  136. case CORE_PWM7_PIN: return 8;
  137. #endif
  138. #ifdef CORE_PWM8_PIN
  139. case CORE_PWM8_PIN: return 9;
  140. #endif
  141. default: return NOT_ON_TIMER;
  142. }
  143. }
  144. #define SERIAL_PORT_MONITOR Serial
  145. #define SERIAL_PORT_USBVIRTUAL Serial
  146. #define SERIAL_PORT_HARDWARE Serial1
  147. #define SERIAL_PORT_HARDWARE_OPEN Serial1
  148. #define SerialUSB Serial
  149. #endif