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.

267 lines
9.6KB

  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. #define PIN_A0 (14)
  35. #define PIN_A1 (15)
  36. #define PIN_A2 (16)
  37. #define PIN_A3 (17)
  38. #define PIN_A4 (18)
  39. #define PIN_A5 (19)
  40. #define PIN_A6 (20)
  41. #define PIN_A7 (21)
  42. #define PIN_A8 (22)
  43. #define PIN_A9 (23)
  44. const static uint8_t A0 = 14;
  45. const static uint8_t A1 = 15;
  46. const static uint8_t A2 = 16;
  47. const static uint8_t A3 = 17;
  48. const static uint8_t A4 = 18;
  49. const static uint8_t A5 = 19;
  50. const static uint8_t A6 = 20;
  51. const static uint8_t A7 = 21;
  52. const static uint8_t A8 = 22;
  53. const static uint8_t A9 = 23;
  54. #if defined(__MK20DX128__)
  55. #define PIN_A10 (34)
  56. #define PIN_A11 (35)
  57. #define PIN_A12 (36)
  58. #define PIN_A13 (37)
  59. const static uint8_t A10 = 34;
  60. const static uint8_t A11 = 35;
  61. const static uint8_t A12 = 36;
  62. const static uint8_t A13 = 37;
  63. #elif defined(__MK20DX256__)
  64. #define PIN_A10 (34)
  65. #define PIN_A11 (35)
  66. #define PIN_A12 (36)
  67. #define PIN_A13 (37)
  68. #define PIN_A14 (40)
  69. #define PIN_A15 (26)
  70. #define PIN_A16 (27)
  71. #define PIN_A17 (28)
  72. #define PIN_A18 (29)
  73. #define PIN_A19 (30)
  74. #define PIN_A20 (31)
  75. const static uint8_t A10 = 34;
  76. const static uint8_t A11 = 35;
  77. const static uint8_t A12 = 36;
  78. const static uint8_t A13 = 37;
  79. const static uint8_t A14 = 40;
  80. const static uint8_t A15 = 26;
  81. const static uint8_t A16 = 27;
  82. const static uint8_t A17 = 28;
  83. const static uint8_t A18 = 29;
  84. const static uint8_t A19 = 30;
  85. const static uint8_t A20 = 31;
  86. #elif defined(__MKL26Z64__)
  87. #define PIN_A10 (24)
  88. #define PIN_A11 (25)
  89. #define PIN_A12 (26)
  90. const static uint8_t A10 = 24;
  91. const static uint8_t A11 = 25;
  92. const static uint8_t A12 = 26;
  93. #elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
  94. #define PIN_A10 (40)
  95. #define PIN_A11 (41)
  96. #define PIN_A12 (31)
  97. #define PIN_A13 (32)
  98. #define PIN_A14 (33)
  99. #define PIN_A15 (34)
  100. #define PIN_A16 (35)
  101. #define PIN_A17 (36)
  102. #define PIN_A18 (37)
  103. #define PIN_A19 (38)
  104. #define PIN_A20 (39)
  105. #define PIN_A21 (42)
  106. #define PIN_A22 (43)
  107. const static uint8_t A10 = 40;
  108. const static uint8_t A11 = 41;
  109. const static uint8_t A12 = 31;
  110. const static uint8_t A13 = 32;
  111. const static uint8_t A14 = 33;
  112. const static uint8_t A15 = 34;
  113. const static uint8_t A16 = 35;
  114. const static uint8_t A17 = 36;
  115. const static uint8_t A18 = 37;
  116. const static uint8_t A19 = 38;
  117. const static uint8_t A20 = 39;
  118. const static uint8_t A21 = 42;
  119. const static uint8_t A22 = 43;
  120. #endif
  121. #define LED_BUILTIN (13)
  122. #define PIN_SPI_SS (10)
  123. #define PIN_SPI_MOSI (11)
  124. #define PIN_SPI_MISO (12)
  125. #define PIN_SPI_SCK (13)
  126. const static uint8_t SS = 10;
  127. const static uint8_t MOSI = 11;
  128. const static uint8_t MISO = 12;
  129. const static uint8_t SCK = 13;
  130. #define PIN_WIRE_SDA (18)
  131. #define PIN_WIRE_SCL (19)
  132. const static uint8_t SDA = 18;
  133. const static uint8_t SCL = 19;
  134. #define PIN_SERIAL_RX (0)
  135. #define PIN_SERIAL_TX (1)
  136. #define NUM_DIGITAL_PINS CORE_NUM_DIGITAL
  137. #define NUM_ANALOG_INPUTS CORE_NUM_ANALOG
  138. #define NOT_AN_INTERRUPT -1
  139. #if defined(__MK20DX128__)
  140. #define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) <= 13) ? (p) + 24 : -1))
  141. #define digitalPinHasPWM(p) (((p) >= 3 && (p) <= 6) || (p) == 9 || (p) == 10 || ((p) >= 20 && (p) <= 23))
  142. #define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
  143. #elif defined(__MK20DX256__)
  144. #define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) <= 13) ? (p) + 24 : (((p) == 14) ? 40 : (((p) <= 20) ? (p) + 11 : -1))))
  145. #define digitalPinHasPWM(p) (((p) >= 3 && (p) <= 6) || (p) == 9 || (p) == 10 || ((p) >= 20 && (p) <= 23) || (p) == 25 || (p) == 32)
  146. #define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
  147. #elif defined(__MKL26Z64__)
  148. #define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) <= 12) ? (p) + 14 : -1))
  149. #define digitalPinHasPWM(p) ((p) == 3 || (p) == 4 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 16 || (p) == 17 || (p) == 20 || (p) == 22 || (p) == 23)
  150. #define digitalPinToInterrupt(p) ((((p) >= 2 && (p) <= 15) || ((p) >= 20 && (p) <= 23)) ? (p) : -1)
  151. #elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
  152. #define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) >= 12 && (p) <= 20) ? (p) + 19 : -1))
  153. #define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 10) || (p) == 14 || ((p) >= 20 && (p) <= 23) || (p) == 29 || (p) == 30 || ((p) >= 35 && (p) <= 38))
  154. #define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
  155. #endif
  156. #define digitalPinToPCICR(p) ((volatile uint8_t *)0)
  157. #define digitalPinToPCICRbit(p) (0)
  158. #define digitalPinToPCIFR(p) ((volatile uint8_t *)0)
  159. #define digitalPinToPCIFRbit(p) (0)
  160. #define digitalPinToPCMSK(p) ((volatile uint8_t *)0)
  161. #define digitalPinToPCMSKbit(p) (0)
  162. #if defined(KINETISK)
  163. struct digital_pin_bitband_and_config_table_struct {
  164. volatile uint32_t *reg;
  165. volatile uint32_t *config;
  166. };
  167. extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[];
  168. // compatibility macros
  169. #define digitalPinToPort(pin) (pin)
  170. #define digitalPinToBitMask(pin) (1)
  171. #define portOutputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 0))
  172. #define portSetRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 32))
  173. #define portClearRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 64))
  174. #define portToggleRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 96))
  175. #define portInputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 128))
  176. #define portModeRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 160))
  177. #define portConfigRegister(pin) ((volatile uint32_t *)(digital_pin_to_info_PGM[(pin)].config))
  178. #define digitalPinToPortReg(pin) (portOutputRegister(pin))
  179. #define digitalPinToBit(pin) (1)
  180. #elif defined(KINETISL)
  181. struct digital_pin_bitband_and_config_table_struct {
  182. volatile uint8_t *reg;
  183. volatile uint32_t *config;
  184. uint8_t mask;
  185. };
  186. extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[];
  187. // compatibility macros
  188. #define digitalPinToPort(pin) (pin)
  189. #define digitalPinToBitMask(pin) (digital_pin_to_info_PGM[(pin)].mask)
  190. #define portOutputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 0))
  191. #define portSetRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 4))
  192. #define portClearRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 8))
  193. #define portToggleRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 12))
  194. #define portInputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 16))
  195. #define portModeRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 20))
  196. #define portConfigRegister(pin) ((digital_pin_to_info_PGM[(pin)].config))
  197. #define digitalPinToPortReg(pin) (portOutputRegister(pin))
  198. //#define digitalPinToBit(pin) (1)
  199. #endif
  200. #define NOT_ON_TIMER 0
  201. static inline uint8_t digitalPinToTimer(uint8_t) __attribute__((always_inline, unused));
  202. static inline uint8_t digitalPinToTimer(uint8_t pin)
  203. {
  204. if (pin >= 3 && pin <= 6) return pin - 2;
  205. if (pin >= 9 && pin <= 10) return pin - 4;
  206. if (pin >= 20 && pin <= 23) return pin - 13;
  207. return NOT_ON_TIMER;
  208. }
  209. // These serial port names are intended to allow libraries and architecture-neutral
  210. // sketches to automatically default to the correct port name for a particular type
  211. // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
  212. // the first hardware serial port whose RX/TX pins are not dedicated to another use.
  213. //
  214. // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
  215. //
  216. // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
  217. //
  218. // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
  219. //
  220. // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
  221. //
  222. // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
  223. // pins are NOT connected to anything by default.
  224. //
  225. #if F_CPU >= 20000000 && !defined(USB_DISABLED)
  226. #define SERIAL_PORT_MONITOR Serial
  227. #else
  228. #define SERIAL_PORT_MONITOR Serial1
  229. #endif
  230. #define SERIAL_PORT_USBVIRTUAL Serial
  231. #define SERIAL_PORT_HARDWARE Serial1
  232. #define SERIAL_PORT_HARDWARE1 Serial2
  233. #define SERIAL_PORT_HARDWARE2 Serial3
  234. #define SERIAL_PORT_HARDWARE_OPEN Serial1
  235. #define SERIAL_PORT_HARDWARE_OPEN1 Serial2
  236. #define SERIAL_PORT_HARDWARE_OPEN2 Serial3
  237. #define SerialUSB Serial
  238. #endif