Teensy 4.1 core updated for C++20
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

181 rinda
7.4KB

  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2013 PJRC.COM, LLC.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * 1. The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * 2. If the Software is incorporated into a build system that allows
  17. * selection among a list of target devices, then similar target
  18. * devices manufactured by PJRC.COM must be included in the list of
  19. * target devices and selectable in the same manner.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  25. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  26. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  27. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  28. * SOFTWARE.
  29. */
  30. #ifndef pins_macros_for_arduino_compatibility_h
  31. #define pins_macros_for_arduino_compatibility_h
  32. #include <stdint.h>
  33. // A0-A9 are always digital 14-23, for Arduino compatibility
  34. const static uint8_t A0 = 14;
  35. const static uint8_t A1 = 15;
  36. const static uint8_t A2 = 16;
  37. const static uint8_t A3 = 17;
  38. const static uint8_t A4 = 18;
  39. const static uint8_t A5 = 19;
  40. const static uint8_t A6 = 20;
  41. const static uint8_t A7 = 21;
  42. const static uint8_t A8 = 22;
  43. const static uint8_t A9 = 23;
  44. #if defined(__MK20DX128__)
  45. const static uint8_t A10 = 34;
  46. const static uint8_t A11 = 35;
  47. const static uint8_t A12 = 36;
  48. const static uint8_t A13 = 37;
  49. #elif defined(__MK20DX256__)
  50. const static uint8_t A10 = 34;
  51. const static uint8_t A11 = 35;
  52. const static uint8_t A12 = 36;
  53. const static uint8_t A13 = 37;
  54. const static uint8_t A14 = 40;
  55. const static uint8_t A15 = 26;
  56. const static uint8_t A16 = 27;
  57. const static uint8_t A17 = 28;
  58. const static uint8_t A18 = 29;
  59. const static uint8_t A19 = 30;
  60. const static uint8_t A20 = 31;
  61. #elif defined(__MKL26Z64__)
  62. const static uint8_t A10 = 24;
  63. const static uint8_t A11 = 25;
  64. const static uint8_t A12 = 26;
  65. #endif
  66. const static uint8_t SS = 10;
  67. const static uint8_t MOSI = 11;
  68. const static uint8_t MISO = 12;
  69. const static uint8_t SCK = 13;
  70. const static uint8_t LED_BUILTIN = 13;
  71. const static uint8_t SDA = 18;
  72. const static uint8_t SCL = 19;
  73. #define NUM_DIGITAL_PINS CORE_NUM_DIGITAL
  74. #define NUM_ANALOG_INPUTS CORE_NUM_ANALOG
  75. #define NOT_AN_INTERRUPT -1
  76. #if defined(__MK20DX128__)
  77. #define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) <= 13) ? (p) + 24 : -1))
  78. #define digitalPinHasPWM(p) (((p) >= 3 && (p) <= 6) || (p) == 9 || (p) == 10 || ((p) >= 20 && (p) <= 23))
  79. #define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
  80. #elif defined(__MK20DX256__)
  81. #define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) <= 13) ? (p) + 24 : (((p) == 14) ? 40 : (((p) <= 20) ? (p) + 11 : -1))))
  82. #define digitalPinHasPWM(p) (((p) >= 3 && (p) <= 6) || (p) == 9 || (p) == 10 || ((p) >= 20 && (p) <= 23) || (p) == 25 || (p) == 32)
  83. #define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
  84. #elif defined(__MKL26Z64__)
  85. #define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) <= 12) ? (p) + 14 : -1))
  86. #define digitalPinHasPWM(p) ((p) == 3 || (p) == 4 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 16 || (p) == 17 || (p) == 20 || (p) == 22 || (p) == 23)
  87. #define digitalPinToInterrupt(p) ((((p) >= 2 && (p) <= 15) || ((p) >= 20 && (p) <= 23)) ? (p) : -1)
  88. #endif
  89. #if defined(KINETISK)
  90. struct digital_pin_bitband_and_config_table_struct {
  91. volatile uint32_t *reg;
  92. volatile uint32_t *config;
  93. };
  94. extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[];
  95. // compatibility macros
  96. #define digitalPinToPort(pin) (pin)
  97. #define digitalPinToBitMask(pin) (1)
  98. #define portOutputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 0))
  99. #define portSetRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 32))
  100. #define portClearRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 64))
  101. #define portToggleRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 96))
  102. #define portInputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 128))
  103. #define portModeRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 160))
  104. #define portConfigRegister(pin) ((volatile uint32_t *)(digital_pin_to_info_PGM[(pin)].config))
  105. #define digitalPinToPortReg(pin) (portOutputRegister(pin))
  106. #define digitalPinToBit(pin) (1)
  107. #elif defined(KINETISL)
  108. struct digital_pin_bitband_and_config_table_struct {
  109. volatile uint8_t *reg;
  110. volatile uint32_t *config;
  111. uint8_t mask;
  112. };
  113. extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[];
  114. // compatibility macros
  115. #define digitalPinToPort(pin) (pin)
  116. #define digitalPinToBitMask(pin) (digital_pin_to_info_PGM[(pin)].mask)
  117. #define portOutputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 0))
  118. #define portSetRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 4))
  119. #define portClearRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 8))
  120. #define portToggleRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 12))
  121. #define portInputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 16))
  122. #define portModeRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 20))
  123. #define portConfigRegister(pin) ((digital_pin_to_info_PGM[(pin)].config))
  124. #define digitalPinToPortReg(pin) (portOutputRegister(pin))
  125. //#define digitalPinToBit(pin) (1)
  126. #endif
  127. #define NOT_ON_TIMER 0
  128. static inline uint8_t digitalPinToTimer(uint8_t) __attribute__((always_inline, unused));
  129. static inline uint8_t digitalPinToTimer(uint8_t pin)
  130. {
  131. if (pin >= 3 && pin <= 6) return pin - 2;
  132. if (pin >= 9 && pin <= 10) return pin - 4;
  133. if (pin >= 20 && pin <= 23) return pin - 13;
  134. return NOT_ON_TIMER;
  135. }
  136. // These serial port names are intended to allow libraries and architecture-neutral
  137. // sketches to automatically default to the correct port name for a particular type
  138. // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
  139. // the first hardware serial port whose RX/TX pins are not dedicated to another use.
  140. //
  141. // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
  142. //
  143. // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
  144. //
  145. // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
  146. //
  147. // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
  148. //
  149. // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
  150. // pins are NOT connected to anything by default.
  151. //
  152. #define SERIAL_PORT_MONITOR Serial
  153. #define SERIAL_PORT_USBVIRTUAL Serial
  154. #define SERIAL_PORT_HARDWARE Serial1
  155. #define SERIAL_PORT_HARDWARE1 Serial2
  156. #define SERIAL_PORT_HARDWARE2 Serial3
  157. #define SERIAL_PORT_HARDWARE_OPEN Serial1
  158. #define SERIAL_PORT_HARDWARE_OPEN1 Serial2
  159. #define SERIAL_PORT_HARDWARE_OPEN2 Serial3
  160. #endif