Teensy 4.1 core updated for C++20
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.

152 satır
6.1KB

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