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.

198 lines
7.2KB

  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2018 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. #define PIN_A10 (24)
  45. #define PIN_A11 (25)
  46. #define PIN_A12 (26)
  47. #define PIN_A13 (27)
  48. const static uint8_t A0 = PIN_A0;
  49. const static uint8_t A1 = PIN_A1;
  50. const static uint8_t A2 = PIN_A2;
  51. const static uint8_t A3 = PIN_A3;
  52. const static uint8_t A4 = PIN_A4;
  53. const static uint8_t A5 = PIN_A5;
  54. const static uint8_t A6 = PIN_A6;
  55. const static uint8_t A7 = PIN_A7;
  56. const static uint8_t A8 = PIN_A8;
  57. const static uint8_t A9 = PIN_A9;
  58. const static uint8_t A10 = PIN_A10;
  59. const static uint8_t A11 = PIN_A11;
  60. const static uint8_t A12 = PIN_A12;
  61. const static uint8_t A13 = PIN_A13;
  62. #ifdef ARDUINO_TEENSY41
  63. #define PIN_A14 (38)
  64. #define PIN_A15 (39)
  65. #define PIN_A16 (40)
  66. #define PIN_A17 (41)
  67. const static uint8_t A14 = PIN_A14;
  68. const static uint8_t A15 = PIN_A15;
  69. const static uint8_t A16 = PIN_A16;
  70. const static uint8_t A17 = PIN_A17;
  71. #endif
  72. #define LED_BUILTIN (13)
  73. #define PIN_SPI_SS (10)
  74. #define PIN_SPI_MOSI (11)
  75. #define PIN_SPI_MISO (12)
  76. #define PIN_SPI_SCK (13)
  77. const static uint8_t SS = 10;
  78. const static uint8_t MOSI = 11;
  79. const static uint8_t MISO = 12;
  80. const static uint8_t SCK = 13;
  81. #define PIN_WIRE_SDA (18)
  82. #define PIN_WIRE_SCL (19)
  83. const static uint8_t SDA = 18;
  84. const static uint8_t SCL = 19;
  85. #define PIN_SERIAL_RX (0)
  86. #define PIN_SERIAL_TX (1)
  87. #ifdef ARDUINO_TEENSY41
  88. #define NUM_DIGITAL_PINS 55
  89. #define NUM_ANALOG_INPUTS 18
  90. #else
  91. #define NUM_DIGITAL_PINS 40
  92. #define NUM_ANALOG_INPUTS 14
  93. #endif
  94. #define NOT_AN_INTERRUPT -1
  95. #if defined(__IMXRT1062__) && defined(ARDUINO_TEENSY40)
  96. #define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (( ((p) >= 14 && (p) <= 27)) ? (p) : -1))
  97. #define digitalPinHasPWM(p) ((p) <= 15 || (p) == 18 || (p) == 19 || ((p) >= 22 && (p) <= 25) || ((p) >= 28 && (p) <= 31) || (p) == 33)
  98. #elif defined(__IMXRT1062__) && defined(ARDUINO_TEENSY41)
  99. #define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (( ((p) >= 14 && (p) <= 27)) || ((p) >= 38 && (p) <= 41) ? (p) : -1))
  100. #define digitalPinHasPWM(p) ((p) <= 15 || (p) == 18 || (p) == 19 || ((p) >= 22 && (p) <= 25) || ((p) >= 28 && (p) <= 31) || (p) == 33)
  101. #endif
  102. #define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
  103. #define digitalPinToPCICR(p) ((volatile uint8_t *)0)
  104. #define digitalPinToPCICRbit(p) (0)
  105. #define digitalPinToPCIFR(p) ((volatile uint8_t *)0)
  106. #define digitalPinToPCIFRbit(p) (0)
  107. #define digitalPinToPCMSK(p) ((volatile uint8_t *)0)
  108. #define digitalPinToPCMSKbit(p) (0)
  109. struct digital_pin_bitband_and_config_table_struct { // not really bitband, old name from Teensy3
  110. volatile uint32_t *reg;
  111. volatile uint32_t *mux;
  112. volatile uint32_t *pad;
  113. uint32_t mask;
  114. };
  115. extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[];
  116. #define digitalPinToPort(pin) (pin)
  117. #define digitalPinToBitMask(pin) (digital_pin_to_info_PGM[(pin)].mask)
  118. #define portOutputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 0))
  119. #define portSetRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 33))
  120. #define portClearRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 34))
  121. #define portToggleRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 35))
  122. #define portInputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 2))
  123. #define portModeRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 1))
  124. #define portConfigRegister(pin) ((digital_pin_to_info_PGM[(pin)].mux))
  125. #define portControlRegister(pin) ((digital_pin_to_info_PGM[(pin)].pad))
  126. #define digitalPinToPortReg(pin) (portOutputRegister(pin))
  127. #define digitalPinToBit(pin) (__builtin_ctz(digitalPinToBitMask(pin)))
  128. #define NOT_ON_TIMER 0
  129. static inline uint8_t digitalPinToTimer(uint8_t) __attribute__((always_inline, unused));
  130. static inline uint8_t digitalPinToTimer(uint8_t pin)
  131. {
  132. // TODO: does anything meaningful use this?
  133. return NOT_ON_TIMER;
  134. }
  135. // These serial port names are intended to allow libraries and architecture-neutral
  136. // sketches to automatically default to the correct port name for a particular type
  137. // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
  138. // the first hardware serial port whose RX/TX pins are not dedicated to another use.
  139. //
  140. // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
  141. //
  142. // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
  143. //
  144. // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
  145. //
  146. // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
  147. //
  148. // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
  149. // pins are NOT connected to anything by default.
  150. //
  151. #if F_CPU >= 20000000 && !defined(USB_DISABLED)
  152. #define SERIAL_PORT_MONITOR Serial
  153. #else
  154. #define SERIAL_PORT_MONITOR Serial1
  155. #endif
  156. #define SERIAL_PORT_USBVIRTUAL Serial
  157. #define SERIAL_PORT_HARDWARE Serial1
  158. #define SERIAL_PORT_HARDWARE1 Serial2
  159. #define SERIAL_PORT_HARDWARE2 Serial3
  160. #define SERIAL_PORT_HARDWARE_OPEN Serial1
  161. #define SERIAL_PORT_HARDWARE_OPEN1 Serial2
  162. #define SERIAL_PORT_HARDWARE_OPEN2 Serial3
  163. #define SERIAL_PORT_HARDWARE3 Serial4
  164. #define SERIAL_PORT_HARDWARE4 Serial5
  165. #define SERIAL_PORT_HARDWARE5 Serial6
  166. #define SERIAL_PORT_HARDWARE6 Serial7
  167. #define SERIAL_PORT_HARDWARE_OPEN3 Serial4
  168. #define SERIAL_PORT_HARDWARE_OPEN4 Serial5
  169. #define SERIAL_PORT_HARDWARE_OPEN5 Serial6
  170. #define SERIAL_PORT_HARDWARE_OPEN6 Serial7
  171. #if defined(__IMXRT1052__)
  172. #define SERIAL_PORT_HARDWARE7 Serial8
  173. #define SERIAL_PORT_HARDWARE_OPEN7 Serial8
  174. #endif
  175. #define SerialUSB Serial
  176. #endif // pins_macros_for_arduino_compatibility_h