Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

287 Zeilen
11KB

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