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.

pins_arduino.h 10KB

8 年之前
8 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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__) || defined(__MK66FX1M0__)
  160. // TODO analogInputToDigitalPin needs update...
  161. #define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) >= 12 && (p) <= 20) ? (p) + 19 : -1))
  162. #define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 10) || (p) == 14 || ((p) >= 20 && (p) <= 23) || (p) == 29 || (p) == 30 || ((p) >= 35 && (p) <= 38))
  163. #define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
  164. #endif
  165. #define digitalPinToPCICR(p) ((volatile uint8_t *)0)
  166. #define digitalPinToPCICRbit(p) (0)
  167. #define digitalPinToPCIFR(p) ((volatile uint8_t *)0)
  168. #define digitalPinToPCIFRbit(p) (0)
  169. #define digitalPinToPCMSK(p) ((volatile uint8_t *)0)
  170. #define digitalPinToPCMSKbit(p) (0)
  171. #if defined(KINETISK)
  172. struct digital_pin_bitband_and_config_table_struct {
  173. volatile uint32_t *reg;
  174. volatile uint32_t *config;
  175. };
  176. extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[];
  177. // compatibility macros
  178. #define digitalPinToPort(pin) (pin)
  179. #define digitalPinToBitMask(pin) (1)
  180. #define portOutputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 0))
  181. #define portSetRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 32))
  182. #define portClearRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 64))
  183. #define portToggleRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 96))
  184. #define portInputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 128))
  185. #define portModeRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 160))
  186. #define portConfigRegister(pin) ((volatile uint32_t *)(digital_pin_to_info_PGM[(pin)].config))
  187. #define digitalPinToPortReg(pin) (portOutputRegister(pin))
  188. #define digitalPinToBit(pin) (1)
  189. #elif defined(KINETISL)
  190. struct digital_pin_bitband_and_config_table_struct {
  191. volatile uint8_t *reg;
  192. volatile uint32_t *config;
  193. uint8_t mask;
  194. };
  195. extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[];
  196. // compatibility macros
  197. #define digitalPinToPort(pin) (pin)
  198. #define digitalPinToBitMask(pin) (digital_pin_to_info_PGM[(pin)].mask)
  199. #define portOutputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 0))
  200. #define portSetRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 4))
  201. #define portClearRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 8))
  202. #define portToggleRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 12))
  203. #define portInputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 16))
  204. #define portModeRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 20))
  205. #define portConfigRegister(pin) ((digital_pin_to_info_PGM[(pin)].config))
  206. #define digitalPinToPortReg(pin) (portOutputRegister(pin))
  207. //#define digitalPinToBit(pin) (1)
  208. #endif
  209. #define NOT_ON_TIMER 0
  210. static inline uint8_t digitalPinToTimer(uint8_t) __attribute__((always_inline, unused));
  211. static inline uint8_t digitalPinToTimer(uint8_t pin)
  212. {
  213. if (pin >= 3 && pin <= 6) return pin - 2;
  214. if (pin >= 9 && pin <= 10) return pin - 4;
  215. if (pin >= 20 && pin <= 23) return pin - 13;
  216. return NOT_ON_TIMER;
  217. }
  218. // These serial port names are intended to allow libraries and architecture-neutral
  219. // sketches to automatically default to the correct port name for a particular type
  220. // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
  221. // the first hardware serial port whose RX/TX pins are not dedicated to another use.
  222. //
  223. // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
  224. //
  225. // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
  226. //
  227. // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
  228. //
  229. // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
  230. //
  231. // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
  232. // pins are NOT connected to anything by default.
  233. //
  234. #if F_CPU >= 20000000 && !defined(USB_DISABLED)
  235. #define SERIAL_PORT_MONITOR Serial
  236. #else
  237. #define SERIAL_PORT_MONITOR Serial1
  238. #endif
  239. #define SERIAL_PORT_USBVIRTUAL Serial
  240. #define SERIAL_PORT_HARDWARE Serial1
  241. #define SERIAL_PORT_HARDWARE1 Serial2
  242. #define SERIAL_PORT_HARDWARE2 Serial3
  243. #define SERIAL_PORT_HARDWARE_OPEN Serial1
  244. #define SERIAL_PORT_HARDWARE_OPEN1 Serial2
  245. #define SERIAL_PORT_HARDWARE_OPEN2 Serial3
  246. #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
  247. #define SERIAL_PORT_HARDWARE3 Serial4
  248. #define SERIAL_PORT_HARDWARE4 Serial5
  249. #define SERIAL_PORT_HARDWARE5 Serial6
  250. #define SERIAL_PORT_HARDWARE_OPEN3 Serial4
  251. #define SERIAL_PORT_HARDWARE_OPEN4 Serial5
  252. #define SERIAL_PORT_HARDWARE_OPEN5 Serial6
  253. #endif
  254. #define SerialUSB Serial
  255. #endif