No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

148 líneas
5.8KB

  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. // This allows CapSense to work. Do any libraries
  35. // depend on these to be zero?
  36. #define NOT_A_PORT 127
  37. #define NOT_A_PIN 127
  38. #define digitalPinToPort(P) (P)
  39. #define portInputRegister(P) ((volatile uint8_t *)((int)pgm_read_byte(digital_pin_table_PGM+(P)*2+1)))
  40. #define portModeRegister(P) (portInputRegister(P) + 1)
  41. #define portOutputRegister(P) (portInputRegister(P) + 2)
  42. #define digitalPinToBitMask(P) (pgm_read_byte(digital_pin_table_PGM+(P)*2))
  43. extern const uint8_t PROGMEM digital_pin_table_PGM[];
  44. #if defined(__AVR_AT90USB162__)
  45. #define analogInputToDigitalPin(ch) (-1)
  46. #define digitalPinHasPWM(p) ((p) == 0 || (p) == 15 || (p) == 17 || (p) == 18)
  47. #elif defined(__AVR_ATmega32U4__)
  48. #define analogInputToDigitalPin(ch) ((ch) <= 10 ? 21 - (ch) : ((ch) == 11 ? 22 : -1))
  49. #define digitalPinHasPWM(p) ((p) == 4 || (p) == 5 || (p) == 9 || (p) == 10 || (p) == 12 || (p) == 14 || (p) == 15)
  50. #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  51. #define analogInputToDigitalPin(ch) ((ch) <= 7 ? (ch) + 38 : -1)
  52. #define digitalPinHasPWM(p) (((p) >= 14 && (p) <= 16) || ((p) >= 24 && (p) <= 27) || (p) == 0 || (p) == 1)
  53. #endif
  54. #if defined(__AVR_AT90USB162__)
  55. #define digitalPinToPortReg(p) (((p) <= 7) ? &PORTD : (((p) <= 15) ? &PORTB : &PORTC))
  56. #define digitalPinToBit(p) \
  57. (((p) <= 7) ? (p) : (((p) <= 15) ? (p) - 8 : (((p) <= 19) ? 23 - (p) : 2)))
  58. #define digitalPinToPCICR(p) \
  59. ((((p) >= 8 && (p) <= 15) || ((p) >= 17 && (p) <= 20) || (p) == 5) ? &PCICR : NULL)
  60. #define digitalPinToPCICRbit(p) (((p) >= 8 && (p) <= 15) ? 0 : 1)
  61. #define digitalPinToPCIFR(p) \
  62. ((((p) >= 8 && (p) <= 15) || ((p) >= 17 && (p) <= 20) || (p) == 5) ? &PCIFR : NULL)
  63. #define digitalPinToPCIFRbit(p) (((p) >= 8 && (p) <= 15) ? 0 : 1)
  64. #define digitalPinToPCMSK(p) \
  65. (((p) >= 8 && (p) <= 15) ? &PCMSK0 : ((((p) >= 17 && (p) <= 20) || (p) == 5) ? &PCMSK1 : NULL))
  66. #define digitalPinToPCMSKbit(p) \
  67. (((p) >= 8 && (p) <= 15) ? (p) - 8 : (((p) >= 17 && (p) <= 20) ? (p) - 17 : 4))
  68. #elif defined(__AVR_ATmega32U4__)
  69. #define digitalPinToPortReg(p) \
  70. (((p) <= 4) ? &PORTB : (((p) <= 8) ? &PORTD : (((p) <= 10) ? &PORTC : (((p) <= 12) ? &PORTD : \
  71. (((p) <= 15) ? &PORTB : (((p) <= 21) ? &PORTF : (((p) <= 23) ? &PORTD : &PORTE)))))))
  72. #define digitalPinToBit(p) \
  73. (((p) <= 3) ? (p) : (((p) == 4) ? 7 : (((p) <= 8) ? (p) - 5 : (((p) <= 10) ? (p) - 3 : \
  74. (((p) <= 12) ? (p) - 5 : (((p) <= 15) ? (p) - 9 : (((p) <= 19) ? 23 - (p) : \
  75. (((p) <= 21) ? 21 - (p) : (((p) <= 23) ? (p) - 18 : 6)))))))))
  76. #define digitalPinToPCICR(p) ((((p) >= 0 && (p) <= 4) || ((p) >= 13 && (p) <= 15)) ? &PCICR : NULL)
  77. #define digitalPinToPCICRbit(p) (0)
  78. #define digitalPinToPCIFR(p) ((((p) >= 0 && (p) <= 4) || ((p) >= 13 && (p) <= 15)) ? &PCIFR : NULL)
  79. #define digitalPinToPCIFRbit(p) (0)
  80. #define digitalPinToPCMSK(p) ((((p) >= 0 && (p) <= 4) || ((p) >= 13 && (p) <= 15)) ? &PCMSK0 : NULL)
  81. #define digitalPinToPCMSKbit(p) \
  82. (((p) >= 0 && (p) <= 3) ? (p) : (((p) >= 13 && (p) <= 15) ? (p) - 9 : 7))
  83. #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  84. #define digitalPinToPortReg(p) \
  85. (((p) >= 0 && (p) <= 7) ? &PORTD : (((p) >= 10 && (p) <= 17) ? &PORTC : \
  86. (((p) >= 20 && (p) <= 27) ? &PORTB : (((p) >= 28 && (p) <= 35) ? &PORTA : \
  87. (((p) >= 38 && (p) <= 45) ? &PORTF : &PORTE)))))
  88. #define digitalPinToBit(p) \
  89. (((p) <= 7) ? (p) : (((p) <= 9) ? (p) - 8 : (((p) <= 17) ? (p) - 10 : \
  90. (((p) <= 19) ? (p) - 12 : (((p) <= 27) ? (p) - 20 : (((p) <= 35) ? (p) - 28 : \
  91. (((p) <= 37) ? (p) - 32 : (((p) <= 45) ? (p) - 38 : 2))))))))
  92. #define digitalPinToPCICR(p) (((p) >= 20 && (p) <= 27) ? &PCICR : NULL)
  93. #define digitalPinToPCICRbit(p) (0)
  94. #define digitalPinToPCIFR(p) (((p) >= 20 && (p) <= 27) ? &PCIFR : NULL)
  95. #define digitalPinToPCIFRbit(p) (0)
  96. #define digitalPinToPCMSK(p) (((p) >= 20 && (p) <= 27) ? &PCMSK0 : NULL)
  97. #define digitalPinToPCMSKbit(p) (((p) - 20) & 7)
  98. #endif
  99. #define NOT_ON_TIMER 0
  100. static inline uint8_t digitalPinToTimer(uint8_t) __attribute__((always_inline, unused));
  101. static inline uint8_t digitalPinToTimer(uint8_t pin)
  102. {
  103. switch (pin) {
  104. #ifdef CORE_PWM0_PIN
  105. case CORE_PWM0_PIN: return 1;
  106. #endif
  107. #ifdef CORE_PWM1_PIN
  108. case CORE_PWM1_PIN: return 2;
  109. #endif
  110. #ifdef CORE_PWM2_PIN
  111. case CORE_PWM2_PIN: return 3;
  112. #endif
  113. #ifdef CORE_PWM3_PIN
  114. case CORE_PWM3_PIN: return 4;
  115. #endif
  116. #ifdef CORE_PWM4_PIN
  117. case CORE_PWM4_PIN: return 5;
  118. #endif
  119. #ifdef CORE_PWM5_PIN
  120. case CORE_PWM5_PIN: return 6;
  121. #endif
  122. #ifdef CORE_PWM6_PIN
  123. case CORE_PWM6_PIN: return 7;
  124. #endif
  125. #ifdef CORE_PWM7_PIN
  126. case CORE_PWM7_PIN: return 8;
  127. #endif
  128. #ifdef CORE_PWM8_PIN
  129. case CORE_PWM8_PIN: return 9;
  130. #endif
  131. default: return NOT_ON_TIMER;
  132. }
  133. }
  134. #endif