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.

core_pins.h 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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. #if defined(__IMXRT1062__)
  48. #define CORE_NUM_TOTAL_PINS 40
  49. #define CORE_NUM_DIGITAL 40
  50. #define CORE_NUM_INTERRUPT 40
  51. #define CORE_NUM_ANALOG 14
  52. #define CORE_NUM_PWM 27
  53. #define CORE_PIN0_BIT 3
  54. #define CORE_PIN1_BIT 2
  55. #define CORE_PIN2_BIT 4
  56. #define CORE_PIN3_BIT 5
  57. #define CORE_PIN4_BIT 6
  58. #define CORE_PIN5_BIT 8
  59. #define CORE_PIN6_BIT 10
  60. #define CORE_PIN7_BIT 17
  61. #define CORE_PIN8_BIT 16
  62. #define CORE_PIN9_BIT 11
  63. #define CORE_PIN10_BIT 0
  64. #define CORE_PIN11_BIT 2
  65. #define CORE_PIN12_BIT 1
  66. #define CORE_PIN13_BIT 3
  67. #define CORE_PIN14_BIT 18
  68. #define CORE_PIN15_BIT 19
  69. #define CORE_PIN16_BIT 23
  70. #define CORE_PIN17_BIT 22
  71. #define CORE_PIN18_BIT 17
  72. #define CORE_PIN19_BIT 16
  73. #define CORE_PIN20_BIT 26
  74. #define CORE_PIN21_BIT 27
  75. #define CORE_PIN22_BIT 24
  76. #define CORE_PIN23_BIT 25
  77. #define CORE_PIN24_BIT 12
  78. #define CORE_PIN25_BIT 13
  79. #define CORE_PIN26_BIT 30
  80. #define CORE_PIN27_BIT 31
  81. #define CORE_PIN28_BIT 18
  82. #define CORE_PIN29_BIT 31
  83. #define CORE_PIN30_BIT 23
  84. #define CORE_PIN31_BIT 22
  85. #define CORE_PIN32_BIT 12
  86. #define CORE_PIN33_BIT 7
  87. #define CORE_PIN34_BIT 15
  88. #define CORE_PIN35_BIT 14
  89. #define CORE_PIN36_BIT 13
  90. #define CORE_PIN37_BIT 12
  91. #define CORE_PIN38_BIT 17
  92. #define CORE_PIN39_BIT 16
  93. #define CORE_PIN0_BITMASK (1<<(CORE_PIN0_BIT))
  94. #define CORE_PIN1_BITMASK (1<<(CORE_PIN1_BIT))
  95. #define CORE_PIN2_BITMASK (1<<(CORE_PIN2_BIT))
  96. #define CORE_PIN3_BITMASK (1<<(CORE_PIN3_BIT))
  97. #define CORE_PIN4_BITMASK (1<<(CORE_PIN4_BIT))
  98. #define CORE_PIN5_BITMASK (1<<(CORE_PIN5_BIT))
  99. #define CORE_PIN6_BITMASK (1<<(CORE_PIN6_BIT))
  100. #define CORE_PIN7_BITMASK (1<<(CORE_PIN7_BIT))
  101. #define CORE_PIN8_BITMASK (1<<(CORE_PIN8_BIT))
  102. #define CORE_PIN9_BITMASK (1<<(CORE_PIN9_BIT))
  103. #define CORE_PIN10_BITMASK (1<<(CORE_PIN10_BIT))
  104. #define CORE_PIN11_BITMASK (1<<(CORE_PIN11_BIT))
  105. #define CORE_PIN12_BITMASK (1<<(CORE_PIN12_BIT))
  106. #define CORE_PIN13_BITMASK (1<<(CORE_PIN13_BIT))
  107. #define CORE_PIN14_BITMASK (1<<(CORE_PIN14_BIT))
  108. #define CORE_PIN15_BITMASK (1<<(CORE_PIN15_BIT))
  109. #define CORE_PIN16_BITMASK (1<<(CORE_PIN16_BIT))
  110. #define CORE_PIN17_BITMASK (1<<(CORE_PIN17_BIT))
  111. #define CORE_PIN18_BITMASK (1<<(CORE_PIN18_BIT))
  112. #define CORE_PIN19_BITMASK (1<<(CORE_PIN19_BIT))
  113. #define CORE_PIN20_BITMASK (1<<(CORE_PIN20_BIT))
  114. #define CORE_PIN21_BITMASK (1<<(CORE_PIN21_BIT))
  115. #define CORE_PIN22_BITMASK (1<<(CORE_PIN22_BIT))
  116. #define CORE_PIN23_BITMASK (1<<(CORE_PIN23_BIT))
  117. #define CORE_PIN24_BITMASK (1<<(CORE_PIN24_BIT))
  118. #define CORE_PIN25_BITMASK (1<<(CORE_PIN25_BIT))
  119. #define CORE_PIN26_BITMASK (1<<(CORE_PIN26_BIT))
  120. #define CORE_PIN27_BITMASK (1<<(CORE_PIN27_BIT))
  121. #define CORE_PIN28_BITMASK (1<<(CORE_PIN28_BIT))
  122. #define CORE_PIN29_BITMASK (1<<(CORE_PIN29_BIT))
  123. #define CORE_PIN30_BITMASK (1<<(CORE_PIN30_BIT))
  124. #define CORE_PIN31_BITMASK (1<<(CORE_PIN31_BIT))
  125. #define CORE_PIN32_BITMASK (1<<(CORE_PIN32_BIT))
  126. #define CORE_PIN33_BITMASK (1<<(CORE_PIN33_BIT))
  127. #define CORE_PIN34_BITMASK (1<<(CORE_PIN34_BIT))
  128. #define CORE_PIN35_BITMASK (1<<(CORE_PIN35_BIT))
  129. #define CORE_PIN36_BITMASK (1<<(CORE_PIN36_BIT))
  130. #define CORE_PIN37_BITMASK (1<<(CORE_PIN37_BIT))
  131. #define CORE_PIN38_BITMASK (1<<(CORE_PIN38_BIT))
  132. #define CORE_PIN39_BITMASK (1<<(CORE_PIN39_BIT))
  133. // Fast GPIO
  134. #define CORE_PIN0_PORTREG GPIO6_DR
  135. #define CORE_PIN1_PORTREG GPIO6_DR
  136. #define CORE_PIN2_PORTREG GPIO9_DR
  137. #define CORE_PIN3_PORTREG GPIO9_DR
  138. #define CORE_PIN4_PORTREG GPIO9_DR
  139. #define CORE_PIN5_PORTREG GPIO9_DR
  140. #define CORE_PIN6_PORTREG GPIO7_DR
  141. #define CORE_PIN7_PORTREG GPIO7_DR
  142. #define CORE_PIN8_PORTREG GPIO7_DR
  143. #define CORE_PIN9_PORTREG GPIO7_DR
  144. #define CORE_PIN10_PORTREG GPIO7_DR
  145. #define CORE_PIN11_PORTREG GPIO7_DR
  146. #define CORE_PIN12_PORTREG GPIO7_DR
  147. #define CORE_PIN13_PORTREG GPIO7_DR
  148. #define CORE_PIN14_PORTREG GPIO6_DR
  149. #define CORE_PIN15_PORTREG GPIO6_DR
  150. #define CORE_PIN16_PORTREG GPIO6_DR
  151. #define CORE_PIN17_PORTREG GPIO6_DR
  152. #define CORE_PIN18_PORTREG GPIO6_DR
  153. #define CORE_PIN19_PORTREG GPIO6_DR
  154. #define CORE_PIN20_PORTREG GPIO6_DR
  155. #define CORE_PIN21_PORTREG GPIO6_DR
  156. #define CORE_PIN22_PORTREG GPIO6_DR
  157. #define CORE_PIN23_PORTREG GPIO6_DR
  158. #define CORE_PIN24_PORTREG GPIO6_DR
  159. #define CORE_PIN25_PORTREG GPIO6_DR
  160. #define CORE_PIN26_PORTREG GPIO6_DR
  161. #define CORE_PIN27_PORTREG GPIO6_DR
  162. #define CORE_PIN28_PORTREG GPIO8_DR
  163. #define CORE_PIN29_PORTREG GPIO9_DR
  164. #define CORE_PIN30_PORTREG GPIO8_DR
  165. #define CORE_PIN31_PORTREG GPIO8_DR
  166. #define CORE_PIN32_PORTREG GPIO7_DR
  167. #define CORE_PIN33_PORTREG GPIO9_DR
  168. #define CORE_PIN34_PORTREG GPIO8_DR
  169. #define CORE_PIN35_PORTREG GPIO8_DR
  170. #define CORE_PIN36_PORTREG GPIO8_DR
  171. #define CORE_PIN37_PORTREG GPIO8_DR
  172. #define CORE_PIN38_PORTREG GPIO8_DR
  173. #define CORE_PIN39_PORTREG GPIO8_DR
  174. #define CORE_PIN0_PORTSET GPIO6_DR_SET
  175. #define CORE_PIN1_PORTSET GPIO6_DR_SET
  176. #define CORE_PIN2_PORTSET GPIO9_DR_SET
  177. #define CORE_PIN3_PORTSET GPIO9_DR_SET
  178. #define CORE_PIN4_PORTSET GPIO9_DR_SET
  179. #define CORE_PIN5_PORTSET GPIO9_DR_SET
  180. #define CORE_PIN6_PORTSET GPIO7_DR_SET
  181. #define CORE_PIN7_PORTSET GPIO7_DR_SET
  182. #define CORE_PIN8_PORTSET GPIO7_DR_SET
  183. #define CORE_PIN9_PORTSET GPIO7_DR_SET
  184. #define CORE_PIN10_PORTSET GPIO7_DR_SET
  185. #define CORE_PIN11_PORTSET GPIO7_DR_SET
  186. #define CORE_PIN12_PORTSET GPIO7_DR_SET
  187. #define CORE_PIN13_PORTSET GPIO7_DR_SET
  188. #define CORE_PIN14_PORTSET GPIO6_DR_SET
  189. #define CORE_PIN15_PORTSET GPIO6_DR_SET
  190. #define CORE_PIN16_PORTSET GPIO6_DR_SET
  191. #define CORE_PIN17_PORTSET GPIO6_DR_SET
  192. #define CORE_PIN18_PORTSET GPIO6_DR_SET
  193. #define CORE_PIN19_PORTSET GPIO6_DR_SET
  194. #define CORE_PIN20_PORTSET GPIO6_DR_SET
  195. #define CORE_PIN21_PORTSET GPIO6_DR_SET
  196. #define CORE_PIN22_PORTSET GPIO6_DR_SET
  197. #define CORE_PIN23_PORTSET GPIO6_DR_SET
  198. #define CORE_PIN24_PORTSET GPIO6_DR_SET
  199. #define CORE_PIN25_PORTSET GPIO6_DR_SET
  200. #define CORE_PIN26_PORTSET GPIO6_DR_SET
  201. #define CORE_PIN27_PORTSET GPIO6_DR_SET
  202. #define CORE_PIN28_PORTSET GPIO8_DR_SET
  203. #define CORE_PIN29_PORTSET GPIO9_DR_SET
  204. #define CORE_PIN30_PORTSET GPIO8_DR_SET
  205. #define CORE_PIN31_PORTSET GPIO8_DR_SET
  206. #define CORE_PIN32_PORTSET GPIO7_DR_SET
  207. #define CORE_PIN33_PORTSET GPIO9_DR_SET
  208. #define CORE_PIN34_PORTSET GPIO8_DR_SET
  209. #define CORE_PIN35_PORTSET GPIO8_DR_SET
  210. #define CORE_PIN36_PORTSET GPIO8_DR_SET
  211. #define CORE_PIN37_PORTSET GPIO8_DR_SET
  212. #define CORE_PIN38_PORTSET GPIO8_DR_SET
  213. #define CORE_PIN39_PORTSET GPIO8_DR_SET
  214. #define CORE_PIN0_PORTCLEAR GPIO6_DR_CLEAR
  215. #define CORE_PIN1_PORTCLEAR GPIO6_DR_CLEAR
  216. #define CORE_PIN2_PORTCLEAR GPIO9_DR_CLEAR
  217. #define CORE_PIN3_PORTCLEAR GPIO9_DR_CLEAR
  218. #define CORE_PIN4_PORTCLEAR GPIO9_DR_CLEAR
  219. #define CORE_PIN5_PORTCLEAR GPIO9_DR_CLEAR
  220. #define CORE_PIN6_PORTCLEAR GPIO7_DR_CLEAR
  221. #define CORE_PIN7_PORTCLEAR GPIO7_DR_CLEAR
  222. #define CORE_PIN8_PORTCLEAR GPIO7_DR_CLEAR
  223. #define CORE_PIN9_PORTCLEAR GPIO7_DR_CLEAR
  224. #define CORE_PIN10_PORTCLEAR GPIO7_DR_CLEAR
  225. #define CORE_PIN11_PORTCLEAR GPIO7_DR_CLEAR
  226. #define CORE_PIN12_PORTCLEAR GPIO7_DR_CLEAR
  227. #define CORE_PIN13_PORTCLEAR GPIO7_DR_CLEAR
  228. #define CORE_PIN14_PORTCLEAR GPIO6_DR_CLEAR
  229. #define CORE_PIN15_PORTCLEAR GPIO6_DR_CLEAR
  230. #define CORE_PIN16_PORTCLEAR GPIO6_DR_CLEAR
  231. #define CORE_PIN17_PORTCLEAR GPIO6_DR_CLEAR
  232. #define CORE_PIN18_PORTCLEAR GPIO6_DR_CLEAR
  233. #define CORE_PIN19_PORTCLEAR GPIO6_DR_CLEAR
  234. #define CORE_PIN20_PORTCLEAR GPIO6_DR_CLEAR
  235. #define CORE_PIN21_PORTCLEAR GPIO6_DR_CLEAR
  236. #define CORE_PIN22_PORTCLEAR GPIO6_DR_CLEAR
  237. #define CORE_PIN23_PORTCLEAR GPIO6_DR_CLEAR
  238. #define CORE_PIN24_PORTCLEAR GPIO6_DR_CLEAR
  239. #define CORE_PIN25_PORTCLEAR GPIO6_DR_CLEAR
  240. #define CORE_PIN26_PORTCLEAR GPIO6_DR_CLEAR
  241. #define CORE_PIN27_PORTCLEAR GPIO6_DR_CLEAR
  242. #define CORE_PIN28_PORTCLEAR GPIO8_DR_CLEAR
  243. #define CORE_PIN29_PORTCLEAR GPIO9_DR_CLEAR
  244. #define CORE_PIN30_PORTCLEAR GPIO8_DR_CLEAR
  245. #define CORE_PIN31_PORTCLEAR GPIO8_DR_CLEAR
  246. #define CORE_PIN32_PORTCLEAR GPIO7_DR_CLEAR
  247. #define CORE_PIN33_PORTCLEAR GPIO9_DR_CLEAR
  248. #define CORE_PIN34_PORTCLEAR GPIO8_DR_CLEAR
  249. #define CORE_PIN35_PORTCLEAR GPIO8_DR_CLEAR
  250. #define CORE_PIN36_PORTCLEAR GPIO8_DR_CLEAR
  251. #define CORE_PIN37_PORTCLEAR GPIO8_DR_CLEAR
  252. #define CORE_PIN38_PORTCLEAR GPIO8_DR_CLEAR
  253. #define CORE_PIN39_PORTCLEAR GPIO8_DR_CLEAR
  254. #define CORE_PIN0_DDRREG GPIO6_GDIR
  255. #define CORE_PIN1_DDRREG GPIO6_GDIR
  256. #define CORE_PIN2_DDRREG GPIO9_GDIR
  257. #define CORE_PIN3_DDRREG GPIO9_GDIR
  258. #define CORE_PIN4_DDRREG GPIO9_GDIR
  259. #define CORE_PIN5_DDRREG GPIO9_GDIR
  260. #define CORE_PIN6_DDRREG GPIO7_GDIR
  261. #define CORE_PIN7_DDRREG GPIO7_GDIR
  262. #define CORE_PIN8_DDRREG GPIO7_GDIR
  263. #define CORE_PIN9_DDRREG GPIO7_GDIR
  264. #define CORE_PIN10_DDRREG GPIO7_GDIR
  265. #define CORE_PIN11_DDRREG GPIO7_GDIR
  266. #define CORE_PIN12_DDRREG GPIO7_GDIR
  267. #define CORE_PIN13_DDRREG GPIO7_GDIR
  268. #define CORE_PIN14_DDRREG GPIO6_GDIR
  269. #define CORE_PIN15_DDRREG GPIO6_GDIR
  270. #define CORE_PIN16_DDRREG GPIO6_GDIR
  271. #define CORE_PIN17_DDRREG GPIO6_GDIR
  272. #define CORE_PIN18_DDRREG GPIO6_GDIR
  273. #define CORE_PIN19_DDRREG GPIO6_GDIR
  274. #define CORE_PIN20_DDRREG GPIO6_GDIR
  275. #define CORE_PIN21_DDRREG GPIO6_GDIR
  276. #define CORE_PIN22_DDRREG GPIO6_GDIR
  277. #define CORE_PIN23_DDRREG GPIO6_GDIR
  278. #define CORE_PIN24_DDRREG GPIO6_GDIR
  279. #define CORE_PIN25_DDRREG GPIO6_GDIR
  280. #define CORE_PIN26_DDRREG GPIO6_GDIR
  281. #define CORE_PIN27_DDRREG GPIO6_GDIR
  282. #define CORE_PIN28_DDRREG GPIO8_GDIR
  283. #define CORE_PIN29_DDRREG GPIO9_GDIR
  284. #define CORE_PIN30_DDRREG GPIO8_GDIR
  285. #define CORE_PIN31_DDRREG GPIO8_GDIR
  286. #define CORE_PIN32_DDRREG GPIO7_GDIR
  287. #define CORE_PIN33_DDRREG GPIO9_GDIR
  288. #define CORE_PIN34_DDRREG GPIO8_GDIR
  289. #define CORE_PIN35_DDRREG GPIO8_GDIR
  290. #define CORE_PIN36_DDRREG GPIO8_GDIR
  291. #define CORE_PIN37_DDRREG GPIO8_GDIR
  292. #define CORE_PIN38_DDRREG GPIO8_GDIR
  293. #define CORE_PIN39_DDRREG GPIO8_GDIR
  294. #define CORE_PIN0_PINREG GPIO6_PSR
  295. #define CORE_PIN1_PINREG GPIO6_PSR
  296. #define CORE_PIN2_PINREG GPIO9_PSR
  297. #define CORE_PIN3_PINREG GPIO9_PSR
  298. #define CORE_PIN4_PINREG GPIO9_PSR
  299. #define CORE_PIN5_PINREG GPIO9_PSR
  300. #define CORE_PIN6_PINREG GPIO7_PSR
  301. #define CORE_PIN7_PINREG GPIO7_PSR
  302. #define CORE_PIN8_PINREG GPIO7_PSR
  303. #define CORE_PIN9_PINREG GPIO7_PSR
  304. #define CORE_PIN10_PINREG GPIO7_PSR
  305. #define CORE_PIN11_PINREG GPIO7_PSR
  306. #define CORE_PIN12_PINREG GPIO7_PSR
  307. #define CORE_PIN13_PINREG GPIO7_PSR
  308. #define CORE_PIN14_PINREG GPIO6_PSR
  309. #define CORE_PIN15_PINREG GPIO6_PSR
  310. #define CORE_PIN16_PINREG GPIO6_PSR
  311. #define CORE_PIN17_PINREG GPIO6_PSR
  312. #define CORE_PIN18_PINREG GPIO6_PSR
  313. #define CORE_PIN19_PINREG GPIO6_PSR
  314. #define CORE_PIN20_PINREG GPIO6_PSR
  315. #define CORE_PIN21_PINREG GPIO6_PSR
  316. #define CORE_PIN22_PINREG GPIO6_PSR
  317. #define CORE_PIN23_PINREG GPIO6_PSR
  318. #define CORE_PIN24_PINREG GPIO6_PSR
  319. #define CORE_PIN25_PINREG GPIO6_PSR
  320. #define CORE_PIN26_PINREG GPIO6_PSR
  321. #define CORE_PIN27_PINREG GPIO6_PSR
  322. #define CORE_PIN28_PINREG GPIO8_PSR
  323. #define CORE_PIN29_PINREG GPIO9_PSR
  324. #define CORE_PIN30_PINREG GPIO8_PSR
  325. #define CORE_PIN31_PINREG GPIO8_PSR
  326. #define CORE_PIN32_PINREG GPIO7_PSR
  327. #define CORE_PIN33_PINREG GPIO9_PSR
  328. #define CORE_PIN34_PINREG GPIO8_PSR
  329. #define CORE_PIN35_PINREG GPIO8_PSR
  330. #define CORE_PIN36_PINREG GPIO8_PSR
  331. #define CORE_PIN37_PINREG GPIO8_PSR
  332. #define CORE_PIN38_PINREG GPIO8_PSR
  333. #define CORE_PIN39_PINREG GPIO8_PSR
  334. // mux config registers control which peripheral uses the pin
  335. #define CORE_PIN0_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_03
  336. #define CORE_PIN1_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_02
  337. #define CORE_PIN2_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_04
  338. #define CORE_PIN3_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_05
  339. #define CORE_PIN4_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_06
  340. #define CORE_PIN5_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_08
  341. #define CORE_PIN6_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_10
  342. #define CORE_PIN7_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B1_01
  343. #define CORE_PIN8_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B1_00
  344. #define CORE_PIN9_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_11
  345. #define CORE_PIN10_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_00
  346. #define CORE_PIN11_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_02
  347. #define CORE_PIN12_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_01
  348. #define CORE_PIN13_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_03
  349. #define CORE_PIN14_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_02
  350. #define CORE_PIN15_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_03
  351. #define CORE_PIN16_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_07
  352. #define CORE_PIN17_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_06
  353. #define CORE_PIN18_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_01
  354. #define CORE_PIN19_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_00
  355. #define CORE_PIN20_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_10
  356. #define CORE_PIN21_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_11
  357. #define CORE_PIN22_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_08
  358. #define CORE_PIN23_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_09
  359. #define CORE_PIN24_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_12
  360. #define CORE_PIN25_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_13
  361. #define CORE_PIN26_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_14
  362. #define CORE_PIN27_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_15
  363. #define CORE_PIN28_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_32
  364. #define CORE_PIN29_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_31
  365. #define CORE_PIN30_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_37
  366. #define CORE_PIN31_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_36
  367. #define CORE_PIN32_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_12
  368. #define CORE_PIN33_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_07
  369. #define CORE_PIN34_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_SD_B0_03
  370. #define CORE_PIN35_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_SD_B0_02
  371. #define CORE_PIN36_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_SD_B0_01
  372. #define CORE_PIN37_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_SD_B0_00
  373. #define CORE_PIN38_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_SD_B0_05
  374. #define CORE_PIN39_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_SD_B0_04
  375. // pad config registers control pullup/pulldown/keeper, drive strength, etc
  376. #define CORE_PIN0_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_03
  377. #define CORE_PIN1_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_02
  378. #define CORE_PIN2_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_04
  379. #define CORE_PIN3_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_05
  380. #define CORE_PIN4_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_06
  381. #define CORE_PIN5_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_08
  382. #define CORE_PIN6_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_10
  383. #define CORE_PIN7_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B1_01
  384. #define CORE_PIN8_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B1_00
  385. #define CORE_PIN9_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_11
  386. #define CORE_PIN10_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_00
  387. #define CORE_PIN11_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_02
  388. #define CORE_PIN12_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_01
  389. #define CORE_PIN13_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_03
  390. #define CORE_PIN14_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_02
  391. #define CORE_PIN15_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_03
  392. #define CORE_PIN16_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_07
  393. #define CORE_PIN17_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_06
  394. #define CORE_PIN18_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_01
  395. #define CORE_PIN19_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_00
  396. #define CORE_PIN20_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_10
  397. #define CORE_PIN21_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_11
  398. #define CORE_PIN22_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_08
  399. #define CORE_PIN23_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_09
  400. #define CORE_PIN24_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_12
  401. #define CORE_PIN25_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_13
  402. #define CORE_PIN26_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_14
  403. #define CORE_PIN27_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_15
  404. #define CORE_PIN28_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_32
  405. #define CORE_PIN29_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_31
  406. #define CORE_PIN30_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_37
  407. #define CORE_PIN31_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_36
  408. #define CORE_PIN32_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_12
  409. #define CORE_PIN33_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_07
  410. #define CORE_PIN34_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_SD_B0_03
  411. #define CORE_PIN35_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_SD_B0_02
  412. #define CORE_PIN36_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_SD_B0_01
  413. #define CORE_PIN37_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_SD_B0_00
  414. #define CORE_PIN38_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_SD_B0_05
  415. #define CORE_PIN39_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_SD_B0_04
  416. #define CORE_LED0_PIN 13
  417. #define CORE_ADC0_PIN 14
  418. #define CORE_ADC1_PIN 15
  419. #define CORE_ADC2_PIN 16
  420. #define CORE_ADC3_PIN 17
  421. #define CORE_ADC4_PIN 18
  422. #define CORE_ADC5_PIN 19
  423. #define CORE_ADC6_PIN 20
  424. #define CORE_ADC7_PIN 21
  425. #define CORE_ADC8_PIN 22
  426. #define CORE_ADC9_PIN 23
  427. #define CORE_RXD0_PIN 0
  428. #define CORE_TXD0_PIN 1
  429. #define CORE_RXD1_PIN 7
  430. #define CORE_TXD1_PIN 8
  431. #define CORE_RXD2_PIN 15
  432. #define CORE_TXD2_PIN 14
  433. #define CORE_RXD3_PIN 16
  434. #define CORE_TXD3_PIN 17
  435. #define CORE_RXD4_PIN 21
  436. #define CORE_TXD4_PIN 20
  437. #define CORE_RXD5_PIN 25
  438. #define CORE_TXD5_PIN 24
  439. #define CORE_RXD6_PIN 28
  440. #define CORE_TXD6_PIN 29
  441. #define CORE_INT0_PIN 0
  442. #define CORE_INT1_PIN 1
  443. #define CORE_INT2_PIN 2
  444. #define CORE_INT3_PIN 3
  445. #define CORE_INT4_PIN 4
  446. #define CORE_INT5_PIN 5
  447. #define CORE_INT6_PIN 6
  448. #define CORE_INT7_PIN 7
  449. #define CORE_INT8_PIN 8
  450. #define CORE_INT9_PIN 9
  451. #define CORE_INT10_PIN 10
  452. #define CORE_INT11_PIN 11
  453. #define CORE_INT12_PIN 12
  454. #define CORE_INT13_PIN 13
  455. #define CORE_INT14_PIN 14
  456. #define CORE_INT15_PIN 15
  457. #define CORE_INT16_PIN 16
  458. #define CORE_INT17_PIN 17
  459. #define CORE_INT18_PIN 18
  460. #define CORE_INT19_PIN 19
  461. #define CORE_INT20_PIN 20
  462. #define CORE_INT21_PIN 21
  463. #define CORE_INT22_PIN 22
  464. #define CORE_INT23_PIN 23
  465. #define CORE_INT24_PIN 24
  466. #define CORE_INT25_PIN 25
  467. #define CORE_INT26_PIN 26
  468. #define CORE_INT27_PIN 27
  469. #define CORE_INT28_PIN 28
  470. #define CORE_INT29_PIN 29
  471. #define CORE_INT30_PIN 30
  472. #define CORE_INT31_PIN 31
  473. #define CORE_INT32_PIN 32
  474. #define CORE_INT33_PIN 33
  475. #define CORE_INT34_PIN 34
  476. #define CORE_INT35_PIN 35
  477. #define CORE_INT36_PIN 36
  478. #define CORE_INT37_PIN 37
  479. #define CORE_INT38_PIN 38
  480. #define CORE_INT39_PIN 39
  481. #define CORE_INT_EVERY_PIN 1
  482. #endif // __IMXRT1062__
  483. #ifdef __cplusplus
  484. extern "C" {
  485. #endif
  486. //TODO:
  487. //#define analogInputToDigitalPin(p)
  488. //#define digitalPinHasPWM(p)
  489. #define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
  490. void digitalWrite(uint8_t pin, uint8_t val);
  491. static inline void digitalWriteFast(uint8_t pin, uint8_t val) __attribute__((always_inline, unused));
  492. static inline void digitalWriteFast(uint8_t pin, uint8_t val)
  493. {
  494. if (__builtin_constant_p(pin)) {
  495. if (val) {
  496. if (pin == 0) {
  497. CORE_PIN0_PORTSET = CORE_PIN0_BITMASK;
  498. } else if (pin == 1) {
  499. CORE_PIN1_PORTSET = CORE_PIN1_BITMASK;
  500. } else if (pin == 2) {
  501. CORE_PIN2_PORTSET = CORE_PIN2_BITMASK;
  502. } else if (pin == 3) {
  503. CORE_PIN3_PORTSET = CORE_PIN3_BITMASK;
  504. } else if (pin == 4) {
  505. CORE_PIN4_PORTSET = CORE_PIN4_BITMASK;
  506. } else if (pin == 5) {
  507. CORE_PIN5_PORTSET = CORE_PIN5_BITMASK;
  508. } else if (pin == 6) {
  509. CORE_PIN6_PORTSET = CORE_PIN6_BITMASK;
  510. } else if (pin == 7) {
  511. CORE_PIN7_PORTSET = CORE_PIN7_BITMASK;
  512. } else if (pin == 8) {
  513. CORE_PIN8_PORTSET = CORE_PIN8_BITMASK;
  514. } else if (pin == 9) {
  515. CORE_PIN9_PORTSET = CORE_PIN9_BITMASK;
  516. } else if (pin == 10) {
  517. CORE_PIN10_PORTSET = CORE_PIN10_BITMASK;
  518. } else if (pin == 11) {
  519. CORE_PIN11_PORTSET = CORE_PIN11_BITMASK;
  520. } else if (pin == 12) {
  521. CORE_PIN12_PORTSET = CORE_PIN12_BITMASK;
  522. } else if (pin == 13) {
  523. CORE_PIN13_PORTSET = CORE_PIN13_BITMASK;
  524. } else if (pin == 14) {
  525. CORE_PIN14_PORTSET = CORE_PIN14_BITMASK;
  526. } else if (pin == 15) {
  527. CORE_PIN15_PORTSET = CORE_PIN15_BITMASK;
  528. } else if (pin == 16) {
  529. CORE_PIN16_PORTSET = CORE_PIN16_BITMASK;
  530. } else if (pin == 17) {
  531. CORE_PIN17_PORTSET = CORE_PIN17_BITMASK;
  532. } else if (pin == 18) {
  533. CORE_PIN18_PORTSET = CORE_PIN18_BITMASK;
  534. } else if (pin == 19) {
  535. CORE_PIN19_PORTSET = CORE_PIN19_BITMASK;
  536. } else if (pin == 20) {
  537. CORE_PIN20_PORTSET = CORE_PIN20_BITMASK;
  538. } else if (pin == 21) {
  539. CORE_PIN21_PORTSET = CORE_PIN21_BITMASK;
  540. } else if (pin == 22) {
  541. CORE_PIN22_PORTSET = CORE_PIN22_BITMASK;
  542. } else if (pin == 23) {
  543. CORE_PIN23_PORTSET = CORE_PIN23_BITMASK;
  544. } else if (pin == 24) {
  545. CORE_PIN24_PORTSET = CORE_PIN24_BITMASK;
  546. } else if (pin == 25) {
  547. CORE_PIN25_PORTSET = CORE_PIN25_BITMASK;
  548. } else if (pin == 26) {
  549. CORE_PIN26_PORTSET = CORE_PIN26_BITMASK;
  550. } else if (pin == 27) {
  551. CORE_PIN27_PORTSET = CORE_PIN27_BITMASK;
  552. } else if (pin == 28) {
  553. CORE_PIN28_PORTSET = CORE_PIN28_BITMASK;
  554. } else if (pin == 29) {
  555. CORE_PIN29_PORTSET = CORE_PIN29_BITMASK;
  556. } else if (pin == 30) {
  557. CORE_PIN30_PORTSET = CORE_PIN30_BITMASK;
  558. } else if (pin == 31) {
  559. CORE_PIN31_PORTSET = CORE_PIN31_BITMASK;
  560. } else if (pin == 32) {
  561. CORE_PIN32_PORTSET = CORE_PIN32_BITMASK;
  562. } else if (pin == 33) {
  563. CORE_PIN33_PORTSET = CORE_PIN33_BITMASK;
  564. #if defined(__IMXRT1062__)
  565. } else if (pin == 34) {
  566. CORE_PIN34_PORTSET = CORE_PIN34_BITMASK;
  567. } else if (pin == 35) {
  568. CORE_PIN35_PORTSET = CORE_PIN35_BITMASK;
  569. } else if (pin == 36) {
  570. CORE_PIN36_PORTSET = CORE_PIN36_BITMASK;
  571. } else if (pin == 37) {
  572. CORE_PIN37_PORTSET = CORE_PIN37_BITMASK;
  573. } else if (pin == 38) {
  574. CORE_PIN38_PORTSET = CORE_PIN38_BITMASK;
  575. } else if (pin == 39) {
  576. CORE_PIN39_PORTSET = CORE_PIN39_BITMASK;
  577. #endif
  578. }
  579. } else {
  580. if (pin == 0) {
  581. CORE_PIN0_PORTCLEAR = CORE_PIN0_BITMASK;
  582. } else if (pin == 1) {
  583. CORE_PIN1_PORTCLEAR = CORE_PIN1_BITMASK;
  584. } else if (pin == 2) {
  585. CORE_PIN2_PORTCLEAR = CORE_PIN2_BITMASK;
  586. } else if (pin == 3) {
  587. CORE_PIN3_PORTCLEAR = CORE_PIN3_BITMASK;
  588. } else if (pin == 4) {
  589. CORE_PIN4_PORTCLEAR = CORE_PIN4_BITMASK;
  590. } else if (pin == 5) {
  591. CORE_PIN5_PORTCLEAR = CORE_PIN5_BITMASK;
  592. } else if (pin == 6) {
  593. CORE_PIN6_PORTCLEAR = CORE_PIN6_BITMASK;
  594. } else if (pin == 7) {
  595. CORE_PIN7_PORTCLEAR = CORE_PIN7_BITMASK;
  596. } else if (pin == 8) {
  597. CORE_PIN8_PORTCLEAR = CORE_PIN8_BITMASK;
  598. } else if (pin == 9) {
  599. CORE_PIN9_PORTCLEAR = CORE_PIN9_BITMASK;
  600. } else if (pin == 10) {
  601. CORE_PIN10_PORTCLEAR = CORE_PIN10_BITMASK;
  602. } else if (pin == 11) {
  603. CORE_PIN11_PORTCLEAR = CORE_PIN11_BITMASK;
  604. } else if (pin == 12) {
  605. CORE_PIN12_PORTCLEAR = CORE_PIN12_BITMASK;
  606. } else if (pin == 13) {
  607. CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK;
  608. } else if (pin == 14) {
  609. CORE_PIN14_PORTCLEAR = CORE_PIN14_BITMASK;
  610. } else if (pin == 15) {
  611. CORE_PIN15_PORTCLEAR = CORE_PIN15_BITMASK;
  612. } else if (pin == 16) {
  613. CORE_PIN16_PORTCLEAR = CORE_PIN16_BITMASK;
  614. } else if (pin == 17) {
  615. CORE_PIN17_PORTCLEAR = CORE_PIN17_BITMASK;
  616. } else if (pin == 18) {
  617. CORE_PIN18_PORTCLEAR = CORE_PIN18_BITMASK;
  618. } else if (pin == 19) {
  619. CORE_PIN19_PORTCLEAR = CORE_PIN19_BITMASK;
  620. } else if (pin == 20) {
  621. CORE_PIN20_PORTCLEAR = CORE_PIN20_BITMASK;
  622. } else if (pin == 21) {
  623. CORE_PIN21_PORTCLEAR = CORE_PIN21_BITMASK;
  624. } else if (pin == 22) {
  625. CORE_PIN22_PORTCLEAR = CORE_PIN22_BITMASK;
  626. } else if (pin == 23) {
  627. CORE_PIN23_PORTCLEAR = CORE_PIN23_BITMASK;
  628. } else if (pin == 24) {
  629. CORE_PIN24_PORTCLEAR = CORE_PIN24_BITMASK;
  630. } else if (pin == 25) {
  631. CORE_PIN25_PORTCLEAR = CORE_PIN25_BITMASK;
  632. } else if (pin == 26) {
  633. CORE_PIN26_PORTCLEAR = CORE_PIN26_BITMASK;
  634. } else if (pin == 27) {
  635. CORE_PIN27_PORTCLEAR = CORE_PIN27_BITMASK;
  636. } else if (pin == 28) {
  637. CORE_PIN28_PORTCLEAR = CORE_PIN28_BITMASK;
  638. } else if (pin == 29) {
  639. CORE_PIN29_PORTCLEAR = CORE_PIN29_BITMASK;
  640. } else if (pin == 30) {
  641. CORE_PIN30_PORTCLEAR = CORE_PIN30_BITMASK;
  642. } else if (pin == 31) {
  643. CORE_PIN31_PORTCLEAR = CORE_PIN31_BITMASK;
  644. } else if (pin == 32) {
  645. CORE_PIN32_PORTCLEAR = CORE_PIN32_BITMASK;
  646. } else if (pin == 33) {
  647. CORE_PIN33_PORTCLEAR = CORE_PIN33_BITMASK;
  648. #if defined(__IMXRT1062__)
  649. } else if (pin == 34) {
  650. CORE_PIN34_PORTCLEAR = CORE_PIN34_BITMASK;
  651. } else if (pin == 35) {
  652. CORE_PIN35_PORTCLEAR = CORE_PIN35_BITMASK;
  653. } else if (pin == 36) {
  654. CORE_PIN36_PORTCLEAR = CORE_PIN36_BITMASK;
  655. } else if (pin == 37) {
  656. CORE_PIN37_PORTCLEAR = CORE_PIN37_BITMASK;
  657. } else if (pin == 38) {
  658. CORE_PIN38_PORTCLEAR = CORE_PIN38_BITMASK;
  659. } else if (pin == 39) {
  660. CORE_PIN39_PORTCLEAR = CORE_PIN39_BITMASK;
  661. #endif
  662. }
  663. }
  664. } else {
  665. if(val) *portSetRegister(pin) = digitalPinToBitMask(pin);
  666. else *portClearRegister(pin) = digitalPinToBitMask(pin);
  667. }
  668. }
  669. uint8_t digitalRead(uint8_t pin);
  670. static inline uint8_t digitalReadFast(uint8_t pin) __attribute__((always_inline, unused));
  671. static inline uint8_t digitalReadFast(uint8_t pin)
  672. {
  673. if (__builtin_constant_p(pin)) {
  674. if (pin == 0) {
  675. return (CORE_PIN0_PINREG & CORE_PIN0_BITMASK) ? 1 : 0;
  676. } else if (pin == 1) {
  677. return (CORE_PIN1_PINREG & CORE_PIN1_BITMASK) ? 1 : 0;
  678. } else if (pin == 2) {
  679. return (CORE_PIN2_PINREG & CORE_PIN2_BITMASK) ? 1 : 0;
  680. } else if (pin == 3) {
  681. return (CORE_PIN3_PINREG & CORE_PIN3_BITMASK) ? 1 : 0;
  682. } else if (pin == 4) {
  683. return (CORE_PIN4_PINREG & CORE_PIN4_BITMASK) ? 1 : 0;
  684. } else if (pin == 5) {
  685. return (CORE_PIN5_PINREG & CORE_PIN5_BITMASK) ? 1 : 0;
  686. } else if (pin == 6) {
  687. return (CORE_PIN6_PINREG & CORE_PIN6_BITMASK) ? 1 : 0;
  688. } else if (pin == 7) {
  689. return (CORE_PIN7_PINREG & CORE_PIN7_BITMASK) ? 1 : 0;
  690. } else if (pin == 8) {
  691. return (CORE_PIN8_PINREG & CORE_PIN8_BITMASK) ? 1 : 0;
  692. } else if (pin == 9) {
  693. return (CORE_PIN9_PINREG & CORE_PIN9_BITMASK) ? 1 : 0;
  694. } else if (pin == 10) {
  695. return (CORE_PIN10_PINREG & CORE_PIN10_BITMASK) ? 1 : 0;
  696. } else if (pin == 11) {
  697. return (CORE_PIN11_PINREG & CORE_PIN11_BITMASK) ? 1 : 0;
  698. } else if (pin == 12) {
  699. return (CORE_PIN12_PINREG & CORE_PIN12_BITMASK) ? 1 : 0;
  700. } else if (pin == 13) {
  701. return (CORE_PIN13_PINREG & CORE_PIN13_BITMASK) ? 1 : 0;
  702. } else if (pin == 14) {
  703. return (CORE_PIN14_PINREG & CORE_PIN14_BITMASK) ? 1 : 0;
  704. } else if (pin == 15) {
  705. return (CORE_PIN15_PINREG & CORE_PIN15_BITMASK) ? 1 : 0;
  706. } else if (pin == 16) {
  707. return (CORE_PIN16_PINREG & CORE_PIN16_BITMASK) ? 1 : 0;
  708. } else if (pin == 17) {
  709. return (CORE_PIN17_PINREG & CORE_PIN17_BITMASK) ? 1 : 0;
  710. } else if (pin == 18) {
  711. return (CORE_PIN18_PINREG & CORE_PIN18_BITMASK) ? 1 : 0;
  712. } else if (pin == 19) {
  713. return (CORE_PIN19_PINREG & CORE_PIN19_BITMASK) ? 1 : 0;
  714. } else if (pin == 20) {
  715. return (CORE_PIN20_PINREG & CORE_PIN20_BITMASK) ? 1 : 0;
  716. } else if (pin == 21) {
  717. return (CORE_PIN21_PINREG & CORE_PIN21_BITMASK) ? 1 : 0;
  718. } else if (pin == 22) {
  719. return (CORE_PIN22_PINREG & CORE_PIN22_BITMASK) ? 1 : 0;
  720. } else if (pin == 23) {
  721. return (CORE_PIN23_PINREG & CORE_PIN23_BITMASK) ? 1 : 0;
  722. } else if (pin == 24) {
  723. return (CORE_PIN24_PINREG & CORE_PIN24_BITMASK) ? 1 : 0;
  724. } else if (pin == 25) {
  725. return (CORE_PIN25_PINREG & CORE_PIN25_BITMASK) ? 1 : 0;
  726. } else if (pin == 26) {
  727. return (CORE_PIN26_PINREG & CORE_PIN26_BITMASK) ? 1 : 0;
  728. } else if (pin == 27) {
  729. return (CORE_PIN27_PINREG & CORE_PIN27_BITMASK) ? 1 : 0;
  730. } else if (pin == 28) {
  731. return (CORE_PIN28_PINREG & CORE_PIN28_BITMASK) ? 1 : 0;
  732. } else if (pin == 29) {
  733. return (CORE_PIN29_PINREG & CORE_PIN29_BITMASK) ? 1 : 0;
  734. } else if (pin == 30) {
  735. return (CORE_PIN30_PINREG & CORE_PIN30_BITMASK) ? 1 : 0;
  736. } else if (pin == 31) {
  737. return (CORE_PIN31_PINREG & CORE_PIN31_BITMASK) ? 1 : 0;
  738. } else if (pin == 32) {
  739. return (CORE_PIN32_PINREG & CORE_PIN32_BITMASK) ? 1 : 0;
  740. } else if (pin == 33) {
  741. return (CORE_PIN33_PINREG & CORE_PIN33_BITMASK) ? 1 : 0;
  742. } else {
  743. return 0;
  744. }
  745. } else {
  746. return (*portInputRegister(pin) & digitalPinToBitMask(pin)) ? 1 : 0;
  747. }
  748. }
  749. void pinMode(uint8_t pin, uint8_t mode);
  750. void init_pins(void);
  751. void analogWrite(uint8_t pin, int val);
  752. uint32_t analogWriteRes(uint32_t bits);
  753. static inline uint32_t analogWriteResolution(uint32_t bits) { return analogWriteRes(bits); }
  754. void analogWriteFrequency(uint8_t pin, float frequency);
  755. void attachInterrupt(uint8_t pin, void (*function)(void), int mode);
  756. void detachInterrupt(uint8_t pin);
  757. void _init_Teensyduino_internal_(void);
  758. int analogRead(uint8_t pin);
  759. void analogReference(uint8_t type);
  760. void analogReadRes(unsigned int bits);
  761. static inline void analogReadResolution(unsigned int bits) { analogReadRes(bits); }
  762. void analogReadAveraging(unsigned int num);
  763. void analog_init(void);
  764. int touchRead(uint8_t pin);
  765. static inline void shiftOut(uint8_t, uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
  766. extern void _shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value) __attribute__((noinline));
  767. extern void shiftOut_lsbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
  768. extern void shiftOut_msbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
  769. static inline void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value)
  770. {
  771. if (__builtin_constant_p(bitOrder)) {
  772. if (bitOrder == LSBFIRST) {
  773. shiftOut_lsbFirst(dataPin, clockPin, value);
  774. } else {
  775. shiftOut_msbFirst(dataPin, clockPin, value);
  776. }
  777. } else {
  778. _shiftOut(dataPin, clockPin, bitOrder, value);
  779. }
  780. }
  781. static inline uint8_t shiftIn(uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
  782. extern uint8_t _shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) __attribute__((noinline));
  783. extern uint8_t shiftIn_lsbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
  784. extern uint8_t shiftIn_msbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
  785. static inline uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
  786. {
  787. if (__builtin_constant_p(bitOrder)) {
  788. if (bitOrder == LSBFIRST) {
  789. return shiftIn_lsbFirst(dataPin, clockPin);
  790. } else {
  791. return shiftIn_msbFirst(dataPin, clockPin);
  792. }
  793. } else {
  794. return _shiftIn(dataPin, clockPin, bitOrder);
  795. }
  796. }
  797. void _reboot_Teensyduino_(void) __attribute__((noreturn));
  798. void _restart_Teensyduino_(void) __attribute__((noreturn));
  799. void yield(void);
  800. void delay(uint32_t msec);
  801. extern volatile uint32_t F_CPU_ACTUAL;
  802. extern volatile uint32_t F_BUS_ACTUAL;
  803. extern volatile uint32_t scale_cpu_cycles_to_microseconds;
  804. extern volatile uint32_t systick_millis_count;
  805. static inline uint32_t millis(void) __attribute__((always_inline, unused));
  806. static inline uint32_t millis(void)
  807. {
  808. return systick_millis_count;
  809. }
  810. uint32_t micros(void);
  811. static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused));
  812. static inline void delayMicroseconds(uint32_t usec)
  813. {
  814. uint32_t begin = ARM_DWT_CYCCNT;
  815. uint32_t cycles = F_CPU_ACTUAL / 1000000 * usec;
  816. // TODO: check if cycles is large, do a wait with yield calls until it's smaller
  817. while (ARM_DWT_CYCCNT - begin < cycles) ; // wait
  818. }
  819. static inline void delayNanoseconds(uint32_t) __attribute__((always_inline, unused));
  820. static inline void delayNanoseconds(uint32_t nsec)
  821. {
  822. uint32_t begin = ARM_DWT_CYCCNT;
  823. uint32_t cycles = ((F_CPU_ACTUAL>>16) * nsec) / (1000000000UL>>16);
  824. while (ARM_DWT_CYCCNT - begin < cycles) ; // wait
  825. }
  826. unsigned long rtc_get(void);
  827. void rtc_set(unsigned long t);
  828. void rtc_compensate(int adjust);
  829. void tempmon_init(void);
  830. float tempmonGetTemp(void);
  831. void tempmon_Start();
  832. void tempmon_Stop();
  833. void tempmon_PwrDwn();
  834. #ifdef __cplusplus
  835. }
  836. class teensy3_clock_class
  837. {
  838. public:
  839. static unsigned long get(void) __attribute__((always_inline)) { return rtc_get(); }
  840. static void set(unsigned long t) __attribute__((always_inline)) { rtc_set(t); }
  841. static void compensate(int adj) __attribute__((always_inline)) { rtc_compensate(adj); }
  842. };
  843. extern teensy3_clock_class Teensy3Clock;
  844. #endif // __cplusplus