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.

718 lines
27KB

  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. #pragma once
  31. #include "imxrt.h"
  32. #include "pins_arduino.h"
  33. #define HIGH 1
  34. #define LOW 0
  35. #define INPUT 0
  36. #define OUTPUT 1
  37. #define INPUT_PULLUP 2
  38. #define INPUT_PULLDOWN 3
  39. #define OUTPUT_OPENDRAIN 4
  40. #define INPUT_DISABLE 5
  41. #define LSBFIRST 0
  42. #define MSBFIRST 1
  43. #define _BV(n) (1<<(n))
  44. #define CHANGE 4
  45. #define FALLING 2
  46. #define RISING 3
  47. #define CORE_NUM_TOTAL_PINS 34
  48. #define CORE_NUM_DIGITAL 34
  49. #define CORE_NUM_INTERRUPT 34
  50. #define CORE_NUM_ANALOG 14
  51. #define CORE_NUM_PWM 27
  52. #define CORE_PIN0_BIT 3
  53. #define CORE_PIN1_BIT 2
  54. #define CORE_PIN2_BIT 4
  55. #define CORE_PIN3_BIT 5
  56. #define CORE_PIN4_BIT 6
  57. #define CORE_PIN5_BIT 7
  58. #define CORE_PIN6_BIT 17
  59. #define CORE_PIN7_BIT 16
  60. #define CORE_PIN8_BIT 10
  61. #define CORE_PIN9_BIT 11
  62. #define CORE_PIN10_BIT 0
  63. #define CORE_PIN11_BIT 2
  64. #define CORE_PIN12_BIT 1
  65. #define CORE_PIN13_BIT 3
  66. #define CORE_PIN14_BIT 18
  67. #define CORE_PIN15_BIT 19
  68. #define CORE_PIN16_BIT 23
  69. #define CORE_PIN17_BIT 22
  70. #define CORE_PIN18_BIT 17
  71. #define CORE_PIN19_BIT 16
  72. #define CORE_PIN20_BIT 26
  73. #define CORE_PIN21_BIT 27
  74. #define CORE_PIN22_BIT 24
  75. #define CORE_PIN23_BIT 25
  76. #define CORE_PIN24_BIT 12
  77. #define CORE_PIN25_BIT 13
  78. #define CORE_PIN26_BIT 30
  79. #define CORE_PIN27_BIT 31
  80. #define CORE_PIN28_BIT 18
  81. #define CORE_PIN29_BIT 31
  82. #define CORE_PIN30_BIT 24
  83. #define CORE_PIN31_BIT 23
  84. #define CORE_PIN32_BIT 12
  85. #define CORE_PIN33_BIT 8
  86. #define CORE_PIN0_BITMASK (1<<(CORE_PIN0_BIT))
  87. #define CORE_PIN1_BITMASK (1<<(CORE_PIN1_BIT))
  88. #define CORE_PIN2_BITMASK (1<<(CORE_PIN2_BIT))
  89. #define CORE_PIN3_BITMASK (1<<(CORE_PIN3_BIT))
  90. #define CORE_PIN4_BITMASK (1<<(CORE_PIN4_BIT))
  91. #define CORE_PIN5_BITMASK (1<<(CORE_PIN5_BIT))
  92. #define CORE_PIN6_BITMASK (1<<(CORE_PIN6_BIT))
  93. #define CORE_PIN7_BITMASK (1<<(CORE_PIN7_BIT))
  94. #define CORE_PIN8_BITMASK (1<<(CORE_PIN8_BIT))
  95. #define CORE_PIN9_BITMASK (1<<(CORE_PIN9_BIT))
  96. #define CORE_PIN10_BITMASK (1<<(CORE_PIN10_BIT))
  97. #define CORE_PIN11_BITMASK (1<<(CORE_PIN11_BIT))
  98. #define CORE_PIN12_BITMASK (1<<(CORE_PIN12_BIT))
  99. #define CORE_PIN13_BITMASK (1<<(CORE_PIN13_BIT))
  100. #define CORE_PIN14_BITMASK (1<<(CORE_PIN14_BIT))
  101. #define CORE_PIN15_BITMASK (1<<(CORE_PIN15_BIT))
  102. #define CORE_PIN16_BITMASK (1<<(CORE_PIN16_BIT))
  103. #define CORE_PIN17_BITMASK (1<<(CORE_PIN17_BIT))
  104. #define CORE_PIN18_BITMASK (1<<(CORE_PIN18_BIT))
  105. #define CORE_PIN19_BITMASK (1<<(CORE_PIN19_BIT))
  106. #define CORE_PIN20_BITMASK (1<<(CORE_PIN20_BIT))
  107. #define CORE_PIN21_BITMASK (1<<(CORE_PIN21_BIT))
  108. #define CORE_PIN22_BITMASK (1<<(CORE_PIN22_BIT))
  109. #define CORE_PIN23_BITMASK (1<<(CORE_PIN23_BIT))
  110. #define CORE_PIN24_BITMASK (1<<(CORE_PIN24_BIT))
  111. #define CORE_PIN25_BITMASK (1<<(CORE_PIN25_BIT))
  112. #define CORE_PIN26_BITMASK (1<<(CORE_PIN26_BIT))
  113. #define CORE_PIN27_BITMASK (1<<(CORE_PIN27_BIT))
  114. #define CORE_PIN28_BITMASK (1<<(CORE_PIN28_BIT))
  115. #define CORE_PIN29_BITMASK (1<<(CORE_PIN29_BIT))
  116. #define CORE_PIN30_BITMASK (1<<(CORE_PIN30_BIT))
  117. #define CORE_PIN31_BITMASK (1<<(CORE_PIN31_BIT))
  118. #define CORE_PIN32_BITMASK (1<<(CORE_PIN32_BIT))
  119. #define CORE_PIN33_BITMASK (1<<(CORE_PIN33_BIT))
  120. #define CORE_PIN0_PORTREG GPIO1_DR
  121. #define CORE_PIN1_PORTREG GPIO1_DR
  122. #define CORE_PIN2_PORTREG GPIO4_DR
  123. #define CORE_PIN3_PORTREG GPIO4_DR
  124. #define CORE_PIN4_PORTREG GPIO4_DR
  125. #define CORE_PIN5_PORTREG GPIO4_DR
  126. #define CORE_PIN6_PORTREG GPIO2_DR
  127. #define CORE_PIN7_PORTREG GPIO2_DR
  128. #define CORE_PIN8_PORTREG GPIO2_DR
  129. #define CORE_PIN9_PORTREG GPIO2_DR
  130. #define CORE_PIN10_PORTREG GPIO2_DR
  131. #define CORE_PIN11_PORTREG GPIO2_DR
  132. #define CORE_PIN12_PORTREG GPIO2_DR
  133. #define CORE_PIN13_PORTREG GPIO2_DR
  134. #define CORE_PIN14_PORTREG GPIO1_DR
  135. #define CORE_PIN15_PORTREG GPIO1_DR
  136. #define CORE_PIN16_PORTREG GPIO1_DR
  137. #define CORE_PIN17_PORTREG GPIO1_DR
  138. #define CORE_PIN18_PORTREG GPIO1_DR
  139. #define CORE_PIN19_PORTREG GPIO1_DR
  140. #define CORE_PIN20_PORTREG GPIO1_DR
  141. #define CORE_PIN21_PORTREG GPIO1_DR
  142. #define CORE_PIN22_PORTREG GPIO1_DR
  143. #define CORE_PIN23_PORTREG GPIO1_DR
  144. #define CORE_PIN24_PORTREG GPIO1_DR
  145. #define CORE_PIN25_PORTREG GPIO1_DR
  146. #define CORE_PIN26_PORTREG GPIO1_DR
  147. #define CORE_PIN27_PORTREG GPIO1_DR
  148. #define CORE_PIN28_PORTREG GPIO3_DR
  149. #define CORE_PIN29_PORTREG GPIO4_DR
  150. #define CORE_PIN30_PORTREG GPIO4_DR
  151. #define CORE_PIN31_PORTREG GPIO4_DR
  152. #define CORE_PIN32_PORTREG GPIO2_DR
  153. #define CORE_PIN33_PORTREG GPIO4_DR
  154. #define CORE_PIN0_PORTSET GPIO1_DR_SET
  155. #define CORE_PIN1_PORTSET GPIO1_DR_SET
  156. #define CORE_PIN2_PORTSET GPIO4_DR_SET
  157. #define CORE_PIN3_PORTSET GPIO4_DR_SET
  158. #define CORE_PIN4_PORTSET GPIO4_DR_SET
  159. #define CORE_PIN5_PORTSET GPIO4_DR_SET
  160. #define CORE_PIN6_PORTSET GPIO2_DR_SET
  161. #define CORE_PIN7_PORTSET GPIO2_DR_SET
  162. #define CORE_PIN8_PORTSET GPIO2_DR_SET
  163. #define CORE_PIN9_PORTSET GPIO2_DR_SET
  164. #define CORE_PIN10_PORTSET GPIO2_DR_SET
  165. #define CORE_PIN11_PORTSET GPIO2_DR_SET
  166. #define CORE_PIN12_PORTSET GPIO2_DR_SET
  167. #define CORE_PIN13_PORTSET GPIO2_DR_SET
  168. #define CORE_PIN14_PORTSET GPIO1_DR_SET
  169. #define CORE_PIN15_PORTSET GPIO1_DR_SET
  170. #define CORE_PIN16_PORTSET GPIO1_DR_SET
  171. #define CORE_PIN17_PORTSET GPIO1_DR_SET
  172. #define CORE_PIN18_PORTSET GPIO1_DR_SET
  173. #define CORE_PIN19_PORTSET GPIO1_DR_SET
  174. #define CORE_PIN20_PORTSET GPIO1_DR_SET
  175. #define CORE_PIN21_PORTSET GPIO1_DR_SET
  176. #define CORE_PIN22_PORTSET GPIO1_DR_SET
  177. #define CORE_PIN23_PORTSET GPIO1_DR_SET
  178. #define CORE_PIN24_PORTSET GPIO1_DR_SET
  179. #define CORE_PIN25_PORTSET GPIO1_DR_SET
  180. #define CORE_PIN26_PORTSET GPIO1_DR_SET
  181. #define CORE_PIN27_PORTSET GPIO1_DR_SET
  182. #define CORE_PIN28_PORTSET GPIO3_DR_SET
  183. #define CORE_PIN29_PORTSET GPIO4_DR_SET
  184. #define CORE_PIN30_PORTSET GPIO4_DR_SET
  185. #define CORE_PIN31_PORTSET GPIO4_DR_SET
  186. #define CORE_PIN32_PORTSET GPIO2_DR_SET
  187. #define CORE_PIN33_PORTSET GPIO4_DR_SET
  188. #define CORE_PIN0_PORTCLEAR GPIO1_DR_CLEAR
  189. #define CORE_PIN1_PORTCLEAR GPIO1_DR_CLEAR
  190. #define CORE_PIN2_PORTCLEAR GPIO4_DR_CLEAR
  191. #define CORE_PIN3_PORTCLEAR GPIO4_DR_CLEAR
  192. #define CORE_PIN4_PORTCLEAR GPIO4_DR_CLEAR
  193. #define CORE_PIN5_PORTCLEAR GPIO4_DR_CLEAR
  194. #define CORE_PIN6_PORTCLEAR GPIO2_DR_CLEAR
  195. #define CORE_PIN7_PORTCLEAR GPIO2_DR_CLEAR
  196. #define CORE_PIN8_PORTCLEAR GPIO2_DR_CLEAR
  197. #define CORE_PIN9_PORTCLEAR GPIO2_DR_CLEAR
  198. #define CORE_PIN10_PORTCLEAR GPIO2_DR_CLEAR
  199. #define CORE_PIN11_PORTCLEAR GPIO2_DR_CLEAR
  200. #define CORE_PIN12_PORTCLEAR GPIO2_DR_CLEAR
  201. #define CORE_PIN13_PORTCLEAR GPIO2_DR_CLEAR
  202. #define CORE_PIN14_PORTCLEAR GPIO1_DR_CLEAR
  203. #define CORE_PIN15_PORTCLEAR GPIO1_DR_CLEAR
  204. #define CORE_PIN16_PORTCLEAR GPIO1_DR_CLEAR
  205. #define CORE_PIN17_PORTCLEAR GPIO1_DR_CLEAR
  206. #define CORE_PIN18_PORTCLEAR GPIO1_DR_CLEAR
  207. #define CORE_PIN19_PORTCLEAR GPIO1_DR_CLEAR
  208. #define CORE_PIN20_PORTCLEAR GPIO1_DR_CLEAR
  209. #define CORE_PIN21_PORTCLEAR GPIO1_DR_CLEAR
  210. #define CORE_PIN22_PORTCLEAR GPIO1_DR_CLEAR
  211. #define CORE_PIN23_PORTCLEAR GPIO1_DR_CLEAR
  212. #define CORE_PIN24_PORTCLEAR GPIO1_DR_CLEAR
  213. #define CORE_PIN25_PORTCLEAR GPIO1_DR_CLEAR
  214. #define CORE_PIN26_PORTCLEAR GPIO1_DR_CLEAR
  215. #define CORE_PIN27_PORTCLEAR GPIO1_DR_CLEAR
  216. #define CORE_PIN28_PORTCLEAR GPIO3_DR_CLEAR
  217. #define CORE_PIN29_PORTCLEAR GPIO4_DR_CLEAR
  218. #define CORE_PIN30_PORTCLEAR GPIO4_DR_CLEAR
  219. #define CORE_PIN31_PORTCLEAR GPIO4_DR_CLEAR
  220. #define CORE_PIN32_PORTCLEAR GPIO2_DR_CLEAR
  221. #define CORE_PIN33_PORTCLEAR GPIO4_DR_CLEAR
  222. #define CORE_PIN0_DDRREG GPIO1_GDIR
  223. #define CORE_PIN1_DDRREG GPIO1_GDIR
  224. #define CORE_PIN2_DDRREG GPIO4_GDIR
  225. #define CORE_PIN3_DDRREG GPIO4_GDIR
  226. #define CORE_PIN4_DDRREG GPIO4_GDIR
  227. #define CORE_PIN5_DDRREG GPIO4_GDIR
  228. #define CORE_PIN6_DDRREG GPIO2_GDIR
  229. #define CORE_PIN7_DDRREG GPIO2_GDIR
  230. #define CORE_PIN8_DDRREG GPIO2_GDIR
  231. #define CORE_PIN9_DDRREG GPIO2_GDIR
  232. #define CORE_PIN10_DDRREG GPIO2_GDIR
  233. #define CORE_PIN11_DDRREG GPIO2_GDIR
  234. #define CORE_PIN12_DDRREG GPIO2_GDIR
  235. #define CORE_PIN13_DDRREG GPIO2_GDIR
  236. #define CORE_PIN14_DDRREG GPIO1_GDIR
  237. #define CORE_PIN15_DDRREG GPIO1_GDIR
  238. #define CORE_PIN16_DDRREG GPIO1_GDIR
  239. #define CORE_PIN17_DDRREG GPIO1_GDIR
  240. #define CORE_PIN18_DDRREG GPIO1_GDIR
  241. #define CORE_PIN19_DDRREG GPIO1_GDIR
  242. #define CORE_PIN20_DDRREG GPIO1_GDIR
  243. #define CORE_PIN21_DDRREG GPIO1_GDIR
  244. #define CORE_PIN22_DDRREG GPIO1_GDIR
  245. #define CORE_PIN23_DDRREG GPIO1_GDIR
  246. #define CORE_PIN24_DDRREG GPIO1_GDIR
  247. #define CORE_PIN25_DDRREG GPIO1_GDIR
  248. #define CORE_PIN26_DDRREG GPIO1_GDIR
  249. #define CORE_PIN27_DDRREG GPIO1_GDIR
  250. #define CORE_PIN28_DDRREG GPIO3_GDIR
  251. #define CORE_PIN29_DDRREG GPIO4_GDIR
  252. #define CORE_PIN30_DDRREG GPIO4_GDIR
  253. #define CORE_PIN31_DDRREG GPIO4_GDIR
  254. #define CORE_PIN32_DDRREG GPIO2_GDIR
  255. #define CORE_PIN33_DDRREG GPIO4_GDIR
  256. #define CORE_PIN0_PINREG GPIO1_PSR
  257. #define CORE_PIN1_PINREG GPIO1_PSR
  258. #define CORE_PIN2_PINREG GPIO4_PSR
  259. #define CORE_PIN3_PINREG GPIO4_PSR
  260. #define CORE_PIN4_PINREG GPIO4_PSR
  261. #define CORE_PIN5_PINREG GPIO4_PSR
  262. #define CORE_PIN6_PINREG GPIO2_PSR
  263. #define CORE_PIN7_PINREG GPIO2_PSR
  264. #define CORE_PIN8_PINREG GPIO2_PSR
  265. #define CORE_PIN9_PINREG GPIO2_PSR
  266. #define CORE_PIN10_PINREG GPIO2_PSR
  267. #define CORE_PIN11_PINREG GPIO2_PSR
  268. #define CORE_PIN12_PINREG GPIO2_PSR
  269. #define CORE_PIN13_PINREG GPIO2_PSR
  270. #define CORE_PIN14_PINREG GPIO1_PSR
  271. #define CORE_PIN15_PINREG GPIO1_PSR
  272. #define CORE_PIN16_PINREG GPIO1_PSR
  273. #define CORE_PIN17_PINREG GPIO1_PSR
  274. #define CORE_PIN18_PINREG GPIO1_PSR
  275. #define CORE_PIN19_PINREG GPIO1_PSR
  276. #define CORE_PIN20_PINREG GPIO1_PSR
  277. #define CORE_PIN21_PINREG GPIO1_PSR
  278. #define CORE_PIN22_PINREG GPIO1_PSR
  279. #define CORE_PIN23_PINREG GPIO1_PSR
  280. #define CORE_PIN24_PINREG GPIO1_PSR
  281. #define CORE_PIN25_PINREG GPIO1_PSR
  282. #define CORE_PIN26_PINREG GPIO1_PSR
  283. #define CORE_PIN27_PINREG GPIO1_PSR
  284. #define CORE_PIN28_PINREG GPIO3_PSR
  285. #define CORE_PIN29_PINREG GPIO4_PSR
  286. #define CORE_PIN30_PINREG GPIO4_PSR
  287. #define CORE_PIN31_PINREG GPIO4_PSR
  288. #define CORE_PIN32_PINREG GPIO2_PSR
  289. #define CORE_PIN33_PINREG GPIO4_PSR
  290. // mux config registers control which peripheral uses the pin
  291. #define CORE_PIN0_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_03
  292. #define CORE_PIN1_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_02
  293. #define CORE_PIN2_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_04
  294. #define CORE_PIN3_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_05
  295. #define CORE_PIN4_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_06
  296. #define CORE_PIN5_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_07
  297. #define CORE_PIN6_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B1_01
  298. #define CORE_PIN7_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B1_00
  299. #define CORE_PIN8_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_10
  300. #define CORE_PIN9_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_11
  301. #define CORE_PIN10_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_00
  302. #define CORE_PIN11_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_02
  303. #define CORE_PIN12_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_01
  304. #define CORE_PIN13_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_03
  305. #define CORE_PIN14_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_02
  306. #define CORE_PIN15_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_03
  307. #define CORE_PIN16_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_07
  308. #define CORE_PIN17_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_06
  309. #define CORE_PIN18_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_01
  310. #define CORE_PIN19_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_00
  311. #define CORE_PIN20_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_10
  312. #define CORE_PIN21_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_11
  313. #define CORE_PIN22_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_08
  314. #define CORE_PIN23_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_09
  315. #define CORE_PIN24_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_12
  316. #define CORE_PIN25_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_13
  317. #define CORE_PIN26_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_14
  318. #define CORE_PIN27_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_15
  319. #define CORE_PIN28_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_32
  320. #define CORE_PIN29_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_31
  321. #define CORE_PIN30_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_24
  322. #define CORE_PIN31_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_23
  323. #define CORE_PIN32_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_12
  324. #define CORE_PIN33_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_08
  325. // pad config registers control pullup/pulldown/keeper, drive strength, etc
  326. #define CORE_PIN0_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_02
  327. #define CORE_PIN1_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_03
  328. #define CORE_PIN2_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_04
  329. #define CORE_PIN3_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_05
  330. #define CORE_PIN4_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_06
  331. #define CORE_PIN5_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_07
  332. #define CORE_PIN6_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B1_01
  333. #define CORE_PIN7_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B1_00
  334. #define CORE_PIN8_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_10
  335. #define CORE_PIN9_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_11
  336. #define CORE_PIN10_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_00
  337. #define CORE_PIN11_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_02
  338. #define CORE_PIN12_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_01
  339. #define CORE_PIN13_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_03
  340. #define CORE_PIN14_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_02
  341. #define CORE_PIN15_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_03
  342. #define CORE_PIN16_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_07
  343. #define CORE_PIN17_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_06
  344. #define CORE_PIN18_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_01
  345. #define CORE_PIN19_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_00
  346. #define CORE_PIN20_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_10
  347. #define CORE_PIN21_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_11
  348. #define CORE_PIN22_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_08
  349. #define CORE_PIN23_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_09
  350. #define CORE_PIN24_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_12
  351. #define CORE_PIN25_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_13
  352. #define CORE_PIN26_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_14
  353. #define CORE_PIN27_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_15
  354. #define CORE_PIN28_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_32
  355. #define CORE_PIN29_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_31
  356. #define CORE_PIN30_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_24
  357. #define CORE_PIN31_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_23
  358. #define CORE_PIN32_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_12
  359. #define CORE_PIN33_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_08
  360. #ifdef __cplusplus
  361. extern "C" {
  362. #endif
  363. void digitalWrite(uint8_t pin, uint8_t val);
  364. static inline void digitalWriteFast(uint8_t pin, uint8_t val) __attribute__((always_inline, unused));
  365. static inline void digitalWriteFast(uint8_t pin, uint8_t val)
  366. {
  367. if (__builtin_constant_p(pin)) {
  368. if (val) {
  369. if (pin == 0) {
  370. CORE_PIN0_PORTSET = CORE_PIN0_BITMASK;
  371. } else if (pin == 1) {
  372. CORE_PIN1_PORTSET = CORE_PIN1_BITMASK;
  373. } else if (pin == 2) {
  374. CORE_PIN2_PORTSET = CORE_PIN2_BITMASK;
  375. } else if (pin == 3) {
  376. CORE_PIN3_PORTSET = CORE_PIN3_BITMASK;
  377. } else if (pin == 4) {
  378. CORE_PIN4_PORTSET = CORE_PIN4_BITMASK;
  379. } else if (pin == 5) {
  380. CORE_PIN5_PORTSET = CORE_PIN5_BITMASK;
  381. } else if (pin == 6) {
  382. CORE_PIN6_PORTSET = CORE_PIN6_BITMASK;
  383. } else if (pin == 7) {
  384. CORE_PIN7_PORTSET = CORE_PIN7_BITMASK;
  385. } else if (pin == 8) {
  386. CORE_PIN8_PORTSET = CORE_PIN8_BITMASK;
  387. } else if (pin == 9) {
  388. CORE_PIN9_PORTSET = CORE_PIN9_BITMASK;
  389. } else if (pin == 10) {
  390. CORE_PIN10_PORTSET = CORE_PIN10_BITMASK;
  391. } else if (pin == 11) {
  392. CORE_PIN11_PORTSET = CORE_PIN11_BITMASK;
  393. } else if (pin == 12) {
  394. CORE_PIN12_PORTSET = CORE_PIN12_BITMASK;
  395. } else if (pin == 13) {
  396. CORE_PIN13_PORTSET = CORE_PIN13_BITMASK;
  397. } else if (pin == 14) {
  398. CORE_PIN14_PORTSET = CORE_PIN14_BITMASK;
  399. } else if (pin == 15) {
  400. CORE_PIN15_PORTSET = CORE_PIN15_BITMASK;
  401. } else if (pin == 16) {
  402. CORE_PIN16_PORTSET = CORE_PIN16_BITMASK;
  403. } else if (pin == 17) {
  404. CORE_PIN17_PORTSET = CORE_PIN17_BITMASK;
  405. } else if (pin == 18) {
  406. CORE_PIN18_PORTSET = CORE_PIN18_BITMASK;
  407. } else if (pin == 19) {
  408. CORE_PIN19_PORTSET = CORE_PIN19_BITMASK;
  409. } else if (pin == 20) {
  410. CORE_PIN20_PORTSET = CORE_PIN20_BITMASK;
  411. } else if (pin == 21) {
  412. CORE_PIN21_PORTSET = CORE_PIN21_BITMASK;
  413. } else if (pin == 22) {
  414. CORE_PIN22_PORTSET = CORE_PIN22_BITMASK;
  415. } else if (pin == 23) {
  416. CORE_PIN23_PORTSET = CORE_PIN23_BITMASK;
  417. } else if (pin == 24) {
  418. CORE_PIN24_PORTSET = CORE_PIN24_BITMASK;
  419. } else if (pin == 25) {
  420. CORE_PIN25_PORTSET = CORE_PIN25_BITMASK;
  421. } else if (pin == 26) {
  422. CORE_PIN26_PORTSET = CORE_PIN26_BITMASK;
  423. } else if (pin == 27) {
  424. CORE_PIN27_PORTSET = CORE_PIN27_BITMASK;
  425. } else if (pin == 28) {
  426. CORE_PIN28_PORTSET = CORE_PIN28_BITMASK;
  427. } else if (pin == 29) {
  428. CORE_PIN29_PORTSET = CORE_PIN29_BITMASK;
  429. } else if (pin == 30) {
  430. CORE_PIN30_PORTSET = CORE_PIN30_BITMASK;
  431. } else if (pin == 31) {
  432. CORE_PIN31_PORTSET = CORE_PIN31_BITMASK;
  433. } else if (pin == 32) {
  434. CORE_PIN32_PORTSET = CORE_PIN32_BITMASK;
  435. } else if (pin == 33) {
  436. CORE_PIN33_PORTSET = CORE_PIN33_BITMASK;
  437. }
  438. } else {
  439. if (pin == 0) {
  440. CORE_PIN0_PORTCLEAR = CORE_PIN0_BITMASK;
  441. } else if (pin == 1) {
  442. CORE_PIN1_PORTCLEAR = CORE_PIN1_BITMASK;
  443. } else if (pin == 2) {
  444. CORE_PIN2_PORTCLEAR = CORE_PIN2_BITMASK;
  445. } else if (pin == 3) {
  446. CORE_PIN3_PORTCLEAR = CORE_PIN3_BITMASK;
  447. } else if (pin == 4) {
  448. CORE_PIN4_PORTCLEAR = CORE_PIN4_BITMASK;
  449. } else if (pin == 5) {
  450. CORE_PIN5_PORTCLEAR = CORE_PIN5_BITMASK;
  451. } else if (pin == 6) {
  452. CORE_PIN6_PORTCLEAR = CORE_PIN6_BITMASK;
  453. } else if (pin == 7) {
  454. CORE_PIN7_PORTCLEAR = CORE_PIN7_BITMASK;
  455. } else if (pin == 8) {
  456. CORE_PIN8_PORTCLEAR = CORE_PIN8_BITMASK;
  457. } else if (pin == 9) {
  458. CORE_PIN9_PORTCLEAR = CORE_PIN9_BITMASK;
  459. } else if (pin == 10) {
  460. CORE_PIN10_PORTCLEAR = CORE_PIN10_BITMASK;
  461. } else if (pin == 11) {
  462. CORE_PIN11_PORTCLEAR = CORE_PIN11_BITMASK;
  463. } else if (pin == 12) {
  464. CORE_PIN12_PORTCLEAR = CORE_PIN12_BITMASK;
  465. } else if (pin == 13) {
  466. CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK;
  467. } else if (pin == 14) {
  468. CORE_PIN14_PORTCLEAR = CORE_PIN14_BITMASK;
  469. } else if (pin == 15) {
  470. CORE_PIN15_PORTCLEAR = CORE_PIN15_BITMASK;
  471. } else if (pin == 16) {
  472. CORE_PIN16_PORTCLEAR = CORE_PIN16_BITMASK;
  473. } else if (pin == 17) {
  474. CORE_PIN17_PORTCLEAR = CORE_PIN17_BITMASK;
  475. } else if (pin == 18) {
  476. CORE_PIN18_PORTCLEAR = CORE_PIN18_BITMASK;
  477. } else if (pin == 19) {
  478. CORE_PIN19_PORTCLEAR = CORE_PIN19_BITMASK;
  479. } else if (pin == 20) {
  480. CORE_PIN20_PORTCLEAR = CORE_PIN20_BITMASK;
  481. } else if (pin == 21) {
  482. CORE_PIN21_PORTCLEAR = CORE_PIN21_BITMASK;
  483. } else if (pin == 22) {
  484. CORE_PIN22_PORTCLEAR = CORE_PIN22_BITMASK;
  485. } else if (pin == 23) {
  486. CORE_PIN23_PORTCLEAR = CORE_PIN23_BITMASK;
  487. } else if (pin == 24) {
  488. CORE_PIN24_PORTCLEAR = CORE_PIN24_BITMASK;
  489. } else if (pin == 25) {
  490. CORE_PIN25_PORTCLEAR = CORE_PIN25_BITMASK;
  491. } else if (pin == 26) {
  492. CORE_PIN26_PORTCLEAR = CORE_PIN26_BITMASK;
  493. } else if (pin == 27) {
  494. CORE_PIN27_PORTCLEAR = CORE_PIN27_BITMASK;
  495. } else if (pin == 28) {
  496. CORE_PIN28_PORTCLEAR = CORE_PIN28_BITMASK;
  497. } else if (pin == 29) {
  498. CORE_PIN29_PORTCLEAR = CORE_PIN29_BITMASK;
  499. } else if (pin == 30) {
  500. CORE_PIN30_PORTCLEAR = CORE_PIN30_BITMASK;
  501. } else if (pin == 31) {
  502. CORE_PIN31_PORTCLEAR = CORE_PIN31_BITMASK;
  503. } else if (pin == 32) {
  504. CORE_PIN32_PORTCLEAR = CORE_PIN32_BITMASK;
  505. } else if (pin == 33) {
  506. CORE_PIN33_PORTCLEAR = CORE_PIN33_BITMASK;
  507. }
  508. }
  509. } else {
  510. *portClearRegister(pin) = digitalPinToBitMask(pin);
  511. }
  512. }
  513. uint8_t digitalRead(uint8_t pin);
  514. static inline uint8_t digitalReadFast(uint8_t pin) __attribute__((always_inline, unused));
  515. static inline uint8_t digitalReadFast(uint8_t pin)
  516. {
  517. if (__builtin_constant_p(pin)) {
  518. if (pin == 0) {
  519. return (CORE_PIN0_PINREG & CORE_PIN0_BITMASK) ? 1 : 0;
  520. } else if (pin == 1) {
  521. return (CORE_PIN1_PINREG & CORE_PIN1_BITMASK) ? 1 : 0;
  522. } else if (pin == 2) {
  523. return (CORE_PIN2_PINREG & CORE_PIN2_BITMASK) ? 1 : 0;
  524. } else if (pin == 3) {
  525. return (CORE_PIN3_PINREG & CORE_PIN3_BITMASK) ? 1 : 0;
  526. } else if (pin == 4) {
  527. return (CORE_PIN4_PINREG & CORE_PIN4_BITMASK) ? 1 : 0;
  528. } else if (pin == 5) {
  529. return (CORE_PIN5_PINREG & CORE_PIN5_BITMASK) ? 1 : 0;
  530. } else if (pin == 6) {
  531. return (CORE_PIN6_PINREG & CORE_PIN6_BITMASK) ? 1 : 0;
  532. } else if (pin == 7) {
  533. return (CORE_PIN7_PINREG & CORE_PIN7_BITMASK) ? 1 : 0;
  534. } else if (pin == 8) {
  535. return (CORE_PIN8_PINREG & CORE_PIN8_BITMASK) ? 1 : 0;
  536. } else if (pin == 9) {
  537. return (CORE_PIN9_PINREG & CORE_PIN9_BITMASK) ? 1 : 0;
  538. } else if (pin == 10) {
  539. return (CORE_PIN10_PINREG & CORE_PIN10_BITMASK) ? 1 : 0;
  540. } else if (pin == 11) {
  541. return (CORE_PIN11_PINREG & CORE_PIN11_BITMASK) ? 1 : 0;
  542. } else if (pin == 12) {
  543. return (CORE_PIN12_PINREG & CORE_PIN12_BITMASK) ? 1 : 0;
  544. } else if (pin == 13) {
  545. return (CORE_PIN13_PINREG & CORE_PIN13_BITMASK) ? 1 : 0;
  546. } else if (pin == 14) {
  547. return (CORE_PIN14_PINREG & CORE_PIN14_BITMASK) ? 1 : 0;
  548. } else if (pin == 15) {
  549. return (CORE_PIN15_PINREG & CORE_PIN15_BITMASK) ? 1 : 0;
  550. } else if (pin == 16) {
  551. return (CORE_PIN16_PINREG & CORE_PIN16_BITMASK) ? 1 : 0;
  552. } else if (pin == 17) {
  553. return (CORE_PIN17_PINREG & CORE_PIN17_BITMASK) ? 1 : 0;
  554. } else if (pin == 18) {
  555. return (CORE_PIN18_PINREG & CORE_PIN18_BITMASK) ? 1 : 0;
  556. } else if (pin == 19) {
  557. return (CORE_PIN19_PINREG & CORE_PIN19_BITMASK) ? 1 : 0;
  558. } else if (pin == 20) {
  559. return (CORE_PIN20_PINREG & CORE_PIN20_BITMASK) ? 1 : 0;
  560. } else if (pin == 21) {
  561. return (CORE_PIN21_PINREG & CORE_PIN21_BITMASK) ? 1 : 0;
  562. } else if (pin == 22) {
  563. return (CORE_PIN22_PINREG & CORE_PIN22_BITMASK) ? 1 : 0;
  564. } else if (pin == 23) {
  565. return (CORE_PIN23_PINREG & CORE_PIN23_BITMASK) ? 1 : 0;
  566. } else if (pin == 24) {
  567. return (CORE_PIN24_PINREG & CORE_PIN24_BITMASK) ? 1 : 0;
  568. } else if (pin == 25) {
  569. return (CORE_PIN25_PINREG & CORE_PIN25_BITMASK) ? 1 : 0;
  570. } else if (pin == 26) {
  571. return (CORE_PIN26_PINREG & CORE_PIN26_BITMASK) ? 1 : 0;
  572. } else if (pin == 27) {
  573. return (CORE_PIN27_PINREG & CORE_PIN27_BITMASK) ? 1 : 0;
  574. } else if (pin == 28) {
  575. return (CORE_PIN28_PINREG & CORE_PIN28_BITMASK) ? 1 : 0;
  576. } else if (pin == 29) {
  577. return (CORE_PIN29_PINREG & CORE_PIN29_BITMASK) ? 1 : 0;
  578. } else if (pin == 30) {
  579. return (CORE_PIN30_PINREG & CORE_PIN30_BITMASK) ? 1 : 0;
  580. } else if (pin == 31) {
  581. return (CORE_PIN31_PINREG & CORE_PIN31_BITMASK) ? 1 : 0;
  582. } else if (pin == 32) {
  583. return (CORE_PIN32_PINREG & CORE_PIN32_BITMASK) ? 1 : 0;
  584. } else if (pin == 33) {
  585. return (CORE_PIN33_PINREG & CORE_PIN33_BITMASK) ? 1 : 0;
  586. } else {
  587. return 0;
  588. }
  589. } else {
  590. return (*portInputRegister(pin) & digitalPinToBitMask(pin)) ? 1 : 0;
  591. }
  592. }
  593. void pinMode(uint8_t pin, uint8_t mode);
  594. void init_pins(void);
  595. void analogWrite(uint8_t pin, int val);
  596. uint32_t analogWriteRes(uint32_t bits);
  597. static inline uint32_t analogWriteResolution(uint32_t bits) { return analogWriteRes(bits); }
  598. void analogWriteFrequency(uint8_t pin, float frequency);
  599. void attachInterrupt(uint8_t pin, void (*function)(void), int mode);
  600. void detachInterrupt(uint8_t pin);
  601. void _init_Teensyduino_internal_(void);
  602. int analogRead(uint8_t pin);
  603. void analogReference(uint8_t type);
  604. void analogReadRes(unsigned int bits);
  605. static inline void analogReadResolution(unsigned int bits) { analogReadRes(bits); }
  606. void analogReadAveraging(unsigned int num);
  607. void analog_init(void);
  608. int touchRead(uint8_t pin);
  609. static inline void shiftOut(uint8_t, uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
  610. extern void _shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value) __attribute__((noinline));
  611. extern void shiftOut_lsbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
  612. extern void shiftOut_msbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
  613. static inline void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value)
  614. {
  615. if (__builtin_constant_p(bitOrder)) {
  616. if (bitOrder == LSBFIRST) {
  617. shiftOut_lsbFirst(dataPin, clockPin, value);
  618. } else {
  619. shiftOut_msbFirst(dataPin, clockPin, value);
  620. }
  621. } else {
  622. _shiftOut(dataPin, clockPin, bitOrder, value);
  623. }
  624. }
  625. static inline uint8_t shiftIn(uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
  626. extern uint8_t _shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) __attribute__((noinline));
  627. extern uint8_t shiftIn_lsbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
  628. extern uint8_t shiftIn_msbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
  629. static inline uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
  630. {
  631. if (__builtin_constant_p(bitOrder)) {
  632. if (bitOrder == LSBFIRST) {
  633. return shiftIn_lsbFirst(dataPin, clockPin);
  634. } else {
  635. return shiftIn_msbFirst(dataPin, clockPin);
  636. }
  637. } else {
  638. return _shiftIn(dataPin, clockPin, bitOrder);
  639. }
  640. }
  641. void _reboot_Teensyduino_(void) __attribute__((noreturn));
  642. void _restart_Teensyduino_(void) __attribute__((noreturn));
  643. void yield(void);
  644. void delay(uint32_t msec);
  645. extern volatile uint32_t F_CPU_ACTUAL;
  646. extern volatile uint32_t F_BUS_ACTUAL;
  647. extern volatile uint32_t systick_millis_count;
  648. static inline uint32_t millis(void) __attribute__((always_inline, unused));
  649. static inline uint32_t millis(void)
  650. {
  651. return systick_millis_count;
  652. }
  653. uint32_t micros(void);
  654. static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused));
  655. static inline void delayMicroseconds(uint32_t usec)
  656. {
  657. uint32_t begin = ARM_DWT_CYCCNT;
  658. uint32_t cycles = F_CPU_ACTUAL / 1000000 * usec;
  659. // TODO: check if cycles is large, do a wait with yield calls until it's smaller
  660. while (ARM_DWT_CYCCNT - begin < cycles) ; // wait
  661. }
  662. unsigned long rtc_get(void);
  663. void rtc_set(unsigned long t);
  664. void rtc_compensate(int adjust);
  665. #ifdef __cplusplus
  666. }
  667. class teensy3_clock_class
  668. {
  669. public:
  670. static unsigned long get(void) __attribute__((always_inline)) { return rtc_get(); }
  671. static void set(unsigned long t) __attribute__((always_inline)) { rtc_set(t); }
  672. static void compensate(int adj) __attribute__((always_inline)) { rtc_compensate(adj); }
  673. };
  674. extern teensy3_clock_class Teensy3Clock;
  675. #endif // __cplusplus