Teensy 4.1 core updated for C++20
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 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2013 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 _core_pins_h_
  31. #define _core_pins_h_
  32. #include "mk20dx128.h"
  33. #include "pins_arduino.h"
  34. #define HIGH 1
  35. #define LOW 0
  36. #define INPUT 0
  37. #define OUTPUT 1
  38. #define INPUT_PULLUP 2
  39. #define LSBFIRST 0
  40. #define MSBFIRST 1
  41. #define _BV(n) (1<<(n))
  42. #define CHANGE 4
  43. #define FALLING 2
  44. #define RISING 3
  45. // Pin Arduino
  46. // 0 B16 RXD
  47. // 1 B17 TXD
  48. // 2 D0
  49. // 3 A12 FTM1_CH0
  50. // 4 A13 FTM1_CH1
  51. // 5 D7 FTM0_CH7 OC0B/T1
  52. // 6 D4 FTM0_CH4 OC0A
  53. // 7 D2
  54. // 8 D3 ICP1
  55. // 9 C3 FTM0_CH2 OC1A
  56. // 10 C4 FTM0_CH3 SS/OC1B
  57. // 11 C6 MOSI/OC2A
  58. // 12 C7 MISO
  59. // 13 C5 SCK
  60. // 14 D1
  61. // 15 C0
  62. // 16 B0 (FTM1_CH0)
  63. // 17 B1 (FTM1_CH1)
  64. // 18 B3 SDA
  65. // 19 B2 SCL
  66. // 20 D5 FTM0_CH5
  67. // 21 D6 FTM0_CH6
  68. // 22 C1 FTM0_CH0
  69. // 23 C2 FTM0_CH1
  70. // 24 A5 (FTM0_CH2)
  71. // 25 B19
  72. // 26 E1
  73. // 27 C9
  74. // 28 C8
  75. // 29 C10
  76. // 30 C11
  77. // 31 E0
  78. // 32 B18
  79. // 33 A4 (FTM0_CH1)
  80. // (34) analog only
  81. // (35) analog only
  82. // (36) analog only
  83. // (37) analog only
  84. // not available to user:
  85. // A0 FTM0_CH5 SWD Clock
  86. // A1 FTM0_CH6 USB ID
  87. // A2 FTM0_CH7 SWD Trace
  88. // A3 FTM0_CH0 SWD Data
  89. #define CORE_NUM_TOTAL_PINS 34
  90. #define CORE_NUM_DIGITAL 34
  91. #define CORE_NUM_ANALOG 14
  92. #define CORE_NUM_PWM 10
  93. #define CORE_NUM_INTERRUPT 34
  94. #define CORE_PIN0_BIT 16
  95. #define CORE_PIN1_BIT 17
  96. #define CORE_PIN2_BIT 0
  97. #define CORE_PIN3_BIT 12
  98. #define CORE_PIN4_BIT 13
  99. #define CORE_PIN5_BIT 7
  100. #define CORE_PIN6_BIT 4
  101. #define CORE_PIN7_BIT 2
  102. #define CORE_PIN8_BIT 3
  103. #define CORE_PIN9_BIT 3
  104. #define CORE_PIN10_BIT 4
  105. #define CORE_PIN11_BIT 6
  106. #define CORE_PIN12_BIT 7
  107. #define CORE_PIN13_BIT 5
  108. #define CORE_PIN14_BIT 1
  109. #define CORE_PIN15_BIT 0
  110. #define CORE_PIN16_BIT 0
  111. #define CORE_PIN17_BIT 1
  112. #define CORE_PIN18_BIT 3
  113. #define CORE_PIN19_BIT 2
  114. #define CORE_PIN20_BIT 5
  115. #define CORE_PIN21_BIT 6
  116. #define CORE_PIN22_BIT 1
  117. #define CORE_PIN23_BIT 2
  118. #define CORE_PIN24_BIT 5
  119. #define CORE_PIN25_BIT 19
  120. #define CORE_PIN26_BIT 1
  121. #define CORE_PIN27_BIT 9
  122. #define CORE_PIN28_BIT 8
  123. #define CORE_PIN29_BIT 10
  124. #define CORE_PIN30_BIT 11
  125. #define CORE_PIN31_BIT 0
  126. #define CORE_PIN32_BIT 18
  127. #define CORE_PIN33_BIT 4
  128. #define CORE_PIN0_BITMASK (1<<(CORE_PIN0_BIT))
  129. #define CORE_PIN1_BITMASK (1<<(CORE_PIN1_BIT))
  130. #define CORE_PIN2_BITMASK (1<<(CORE_PIN2_BIT))
  131. #define CORE_PIN3_BITMASK (1<<(CORE_PIN3_BIT))
  132. #define CORE_PIN4_BITMASK (1<<(CORE_PIN4_BIT))
  133. #define CORE_PIN5_BITMASK (1<<(CORE_PIN5_BIT))
  134. #define CORE_PIN6_BITMASK (1<<(CORE_PIN6_BIT))
  135. #define CORE_PIN7_BITMASK (1<<(CORE_PIN7_BIT))
  136. #define CORE_PIN8_BITMASK (1<<(CORE_PIN8_BIT))
  137. #define CORE_PIN9_BITMASK (1<<(CORE_PIN9_BIT))
  138. #define CORE_PIN10_BITMASK (1<<(CORE_PIN10_BIT))
  139. #define CORE_PIN11_BITMASK (1<<(CORE_PIN11_BIT))
  140. #define CORE_PIN12_BITMASK (1<<(CORE_PIN12_BIT))
  141. #define CORE_PIN13_BITMASK (1<<(CORE_PIN13_BIT))
  142. #define CORE_PIN14_BITMASK (1<<(CORE_PIN14_BIT))
  143. #define CORE_PIN15_BITMASK (1<<(CORE_PIN15_BIT))
  144. #define CORE_PIN16_BITMASK (1<<(CORE_PIN16_BIT))
  145. #define CORE_PIN17_BITMASK (1<<(CORE_PIN17_BIT))
  146. #define CORE_PIN18_BITMASK (1<<(CORE_PIN18_BIT))
  147. #define CORE_PIN19_BITMASK (1<<(CORE_PIN19_BIT))
  148. #define CORE_PIN20_BITMASK (1<<(CORE_PIN20_BIT))
  149. #define CORE_PIN21_BITMASK (1<<(CORE_PIN21_BIT))
  150. #define CORE_PIN22_BITMASK (1<<(CORE_PIN22_BIT))
  151. #define CORE_PIN23_BITMASK (1<<(CORE_PIN23_BIT))
  152. #define CORE_PIN24_BITMASK (1<<(CORE_PIN24_BIT))
  153. #define CORE_PIN25_BITMASK (1<<(CORE_PIN25_BIT))
  154. #define CORE_PIN26_BITMASK (1<<(CORE_PIN26_BIT))
  155. #define CORE_PIN27_BITMASK (1<<(CORE_PIN27_BIT))
  156. #define CORE_PIN28_BITMASK (1<<(CORE_PIN28_BIT))
  157. #define CORE_PIN29_BITMASK (1<<(CORE_PIN29_BIT))
  158. #define CORE_PIN30_BITMASK (1<<(CORE_PIN30_BIT))
  159. #define CORE_PIN31_BITMASK (1<<(CORE_PIN31_BIT))
  160. #define CORE_PIN32_BITMASK (1<<(CORE_PIN32_BIT))
  161. #define CORE_PIN33_BITMASK (1<<(CORE_PIN33_BIT))
  162. #define CORE_PIN0_PORTREG GPIOB_PDOR
  163. #define CORE_PIN1_PORTREG GPIOB_PDOR
  164. #define CORE_PIN2_PORTREG GPIOD_PDOR
  165. #define CORE_PIN3_PORTREG GPIOA_PDOR
  166. #define CORE_PIN4_PORTREG GPIOA_PDOR
  167. #define CORE_PIN5_PORTREG GPIOD_PDOR
  168. #define CORE_PIN6_PORTREG GPIOD_PDOR
  169. #define CORE_PIN7_PORTREG GPIOD_PDOR
  170. #define CORE_PIN8_PORTREG GPIOD_PDOR
  171. #define CORE_PIN9_PORTREG GPIOC_PDOR
  172. #define CORE_PIN10_PORTREG GPIOC_PDOR
  173. #define CORE_PIN11_PORTREG GPIOC_PDOR
  174. #define CORE_PIN12_PORTREG GPIOC_PDOR
  175. #define CORE_PIN13_PORTREG GPIOC_PDOR
  176. #define CORE_PIN14_PORTREG GPIOD_PDOR
  177. #define CORE_PIN15_PORTREG GPIOC_PDOR
  178. #define CORE_PIN16_PORTREG GPIOB_PDOR
  179. #define CORE_PIN17_PORTREG GPIOB_PDOR
  180. #define CORE_PIN18_PORTREG GPIOB_PDOR
  181. #define CORE_PIN19_PORTREG GPIOB_PDOR
  182. #define CORE_PIN20_PORTREG GPIOD_PDOR
  183. #define CORE_PIN21_PORTREG GPIOD_PDOR
  184. #define CORE_PIN22_PORTREG GPIOC_PDOR
  185. #define CORE_PIN23_PORTREG GPIOC_PDOR
  186. #define CORE_PIN24_PORTREG GPIOA_PDOR
  187. #define CORE_PIN25_PORTREG GPIOB_PDOR
  188. #define CORE_PIN26_PORTREG GPIOE_PDOR
  189. #define CORE_PIN27_PORTREG GPIOC_PDOR
  190. #define CORE_PIN28_PORTREG GPIOC_PDOR
  191. #define CORE_PIN29_PORTREG GPIOC_PDOR
  192. #define CORE_PIN30_PORTREG GPIOC_PDOR
  193. #define CORE_PIN31_PORTREG GPIOE_PDOR
  194. #define CORE_PIN32_PORTREG GPIOB_PDOR
  195. #define CORE_PIN33_PORTREG GPIOA_PDOR
  196. #define CORE_PIN0_PORTSET GPIOB_PSOR
  197. #define CORE_PIN1_PORTSET GPIOB_PSOR
  198. #define CORE_PIN2_PORTSET GPIOD_PSOR
  199. #define CORE_PIN3_PORTSET GPIOA_PSOR
  200. #define CORE_PIN4_PORTSET GPIOA_PSOR
  201. #define CORE_PIN5_PORTSET GPIOD_PSOR
  202. #define CORE_PIN6_PORTSET GPIOD_PSOR
  203. #define CORE_PIN7_PORTSET GPIOD_PSOR
  204. #define CORE_PIN8_PORTSET GPIOD_PSOR
  205. #define CORE_PIN9_PORTSET GPIOC_PSOR
  206. #define CORE_PIN10_PORTSET GPIOC_PSOR
  207. #define CORE_PIN11_PORTSET GPIOC_PSOR
  208. #define CORE_PIN12_PORTSET GPIOC_PSOR
  209. #define CORE_PIN13_PORTSET GPIOC_PSOR
  210. #define CORE_PIN14_PORTSET GPIOD_PSOR
  211. #define CORE_PIN15_PORTSET GPIOC_PSOR
  212. #define CORE_PIN16_PORTSET GPIOB_PSOR
  213. #define CORE_PIN17_PORTSET GPIOB_PSOR
  214. #define CORE_PIN18_PORTSET GPIOB_PSOR
  215. #define CORE_PIN19_PORTSET GPIOB_PSOR
  216. #define CORE_PIN20_PORTSET GPIOD_PSOR
  217. #define CORE_PIN21_PORTSET GPIOD_PSOR
  218. #define CORE_PIN22_PORTSET GPIOC_PSOR
  219. #define CORE_PIN23_PORTSET GPIOC_PSOR
  220. #define CORE_PIN24_PORTSET GPIOA_PSOR
  221. #define CORE_PIN25_PORTSET GPIOB_PSOR
  222. #define CORE_PIN26_PORTSET GPIOE_PSOR
  223. #define CORE_PIN27_PORTSET GPIOC_PSOR
  224. #define CORE_PIN28_PORTSET GPIOC_PSOR
  225. #define CORE_PIN29_PORTSET GPIOC_PSOR
  226. #define CORE_PIN30_PORTSET GPIOC_PSOR
  227. #define CORE_PIN31_PORTSET GPIOE_PSOR
  228. #define CORE_PIN32_PORTSET GPIOB_PSOR
  229. #define CORE_PIN33_PORTSET GPIOA_PSOR
  230. #define CORE_PIN0_PORTCLEAR GPIOB_PCOR
  231. #define CORE_PIN1_PORTCLEAR GPIOB_PCOR
  232. #define CORE_PIN2_PORTCLEAR GPIOD_PCOR
  233. #define CORE_PIN3_PORTCLEAR GPIOA_PCOR
  234. #define CORE_PIN4_PORTCLEAR GPIOA_PCOR
  235. #define CORE_PIN5_PORTCLEAR GPIOD_PCOR
  236. #define CORE_PIN6_PORTCLEAR GPIOD_PCOR
  237. #define CORE_PIN7_PORTCLEAR GPIOD_PCOR
  238. #define CORE_PIN8_PORTCLEAR GPIOD_PCOR
  239. #define CORE_PIN9_PORTCLEAR GPIOC_PCOR
  240. #define CORE_PIN10_PORTCLEAR GPIOC_PCOR
  241. #define CORE_PIN11_PORTCLEAR GPIOC_PCOR
  242. #define CORE_PIN12_PORTCLEAR GPIOC_PCOR
  243. #define CORE_PIN13_PORTCLEAR GPIOC_PCOR
  244. #define CORE_PIN14_PORTCLEAR GPIOD_PCOR
  245. #define CORE_PIN15_PORTCLEAR GPIOC_PCOR
  246. #define CORE_PIN16_PORTCLEAR GPIOB_PCOR
  247. #define CORE_PIN17_PORTCLEAR GPIOB_PCOR
  248. #define CORE_PIN18_PORTCLEAR GPIOB_PCOR
  249. #define CORE_PIN19_PORTCLEAR GPIOB_PCOR
  250. #define CORE_PIN20_PORTCLEAR GPIOD_PCOR
  251. #define CORE_PIN21_PORTCLEAR GPIOD_PCOR
  252. #define CORE_PIN22_PORTCLEAR GPIOC_PCOR
  253. #define CORE_PIN23_PORTCLEAR GPIOC_PCOR
  254. #define CORE_PIN24_PORTCLEAR GPIOA_PCOR
  255. #define CORE_PIN25_PORTCLEAR GPIOB_PCOR
  256. #define CORE_PIN26_PORTCLEAR GPIOE_PCOR
  257. #define CORE_PIN27_PORTCLEAR GPIOC_PCOR
  258. #define CORE_PIN28_PORTCLEAR GPIOC_PCOR
  259. #define CORE_PIN29_PORTCLEAR GPIOC_PCOR
  260. #define CORE_PIN30_PORTCLEAR GPIOC_PCOR
  261. #define CORE_PIN31_PORTCLEAR GPIOE_PCOR
  262. #define CORE_PIN32_PORTCLEAR GPIOB_PCOR
  263. #define CORE_PIN33_PORTCLEAR GPIOA_PCOR
  264. #define CORE_PIN0_DDRREG GPIOB_PDDR
  265. #define CORE_PIN1_DDRREG GPIOB_PDDR
  266. #define CORE_PIN2_DDRREG GPIOD_PDDR
  267. #define CORE_PIN3_DDRREG GPIOA_PDDR
  268. #define CORE_PIN4_DDRREG GPIOA_PDDR
  269. #define CORE_PIN5_DDRREG GPIOD_PDDR
  270. #define CORE_PIN6_DDRREG GPIOD_PDDR
  271. #define CORE_PIN7_DDRREG GPIOD_PDDR
  272. #define CORE_PIN8_DDRREG GPIOD_PDDR
  273. #define CORE_PIN9_DDRREG GPIOC_PDDR
  274. #define CORE_PIN10_DDRREG GPIOC_PDDR
  275. #define CORE_PIN11_DDRREG GPIOC_PDDR
  276. #define CORE_PIN12_DDRREG GPIOC_PDDR
  277. #define CORE_PIN13_DDRREG GPIOC_PDDR
  278. #define CORE_PIN14_DDRREG GPIOD_PDDR
  279. #define CORE_PIN15_DDRREG GPIOC_PDDR
  280. #define CORE_PIN16_DDRREG GPIOB_PDDR
  281. #define CORE_PIN17_DDRREG GPIOB_PDDR
  282. #define CORE_PIN18_DDRREG GPIOB_PDDR
  283. #define CORE_PIN19_DDRREG GPIOB_PDDR
  284. #define CORE_PIN20_DDRREG GPIOD_PDDR
  285. #define CORE_PIN21_DDRREG GPIOD_PDDR
  286. #define CORE_PIN22_DDRREG GPIOC_PDDR
  287. #define CORE_PIN23_DDRREG GPIOC_PDDR
  288. #define CORE_PIN24_DDRREG GPIOA_PDDR
  289. #define CORE_PIN25_DDRREG GPIOB_PDDR
  290. #define CORE_PIN26_DDRREG GPIOE_PDDR
  291. #define CORE_PIN27_DDRREG GPIOC_PDDR
  292. #define CORE_PIN28_DDRREG GPIOC_PDDR
  293. #define CORE_PIN29_DDRREG GPIOC_PDDR
  294. #define CORE_PIN30_DDRREG GPIOC_PDDR
  295. #define CORE_PIN31_DDRREG GPIOE_PDDR
  296. #define CORE_PIN32_DDRREG GPIOB_PDDR
  297. #define CORE_PIN33_DDRREG GPIOA_PDDR
  298. #define CORE_PIN0_PINREG GPIOB_PDIR
  299. #define CORE_PIN1_PINREG GPIOB_PDIR
  300. #define CORE_PIN2_PINREG GPIOD_PDIR
  301. #define CORE_PIN3_PINREG GPIOA_PDIR
  302. #define CORE_PIN4_PINREG GPIOA_PDIR
  303. #define CORE_PIN5_PINREG GPIOD_PDIR
  304. #define CORE_PIN6_PINREG GPIOD_PDIR
  305. #define CORE_PIN7_PINREG GPIOD_PDIR
  306. #define CORE_PIN8_PINREG GPIOD_PDIR
  307. #define CORE_PIN9_PINREG GPIOC_PDIR
  308. #define CORE_PIN10_PINREG GPIOC_PDIR
  309. #define CORE_PIN11_PINREG GPIOC_PDIR
  310. #define CORE_PIN12_PINREG GPIOC_PDIR
  311. #define CORE_PIN13_PINREG GPIOC_PDIR
  312. #define CORE_PIN14_PINREG GPIOD_PDIR
  313. #define CORE_PIN15_PINREG GPIOC_PDIR
  314. #define CORE_PIN16_PINREG GPIOB_PDIR
  315. #define CORE_PIN17_PINREG GPIOB_PDIR
  316. #define CORE_PIN18_PINREG GPIOB_PDIR
  317. #define CORE_PIN19_PINREG GPIOB_PDIR
  318. #define CORE_PIN20_PINREG GPIOD_PDIR
  319. #define CORE_PIN21_PINREG GPIOD_PDIR
  320. #define CORE_PIN22_PINREG GPIOC_PDIR
  321. #define CORE_PIN23_PINREG GPIOC_PDIR
  322. #define CORE_PIN24_PINREG GPIOA_PDIR
  323. #define CORE_PIN25_PINREG GPIOB_PDIR
  324. #define CORE_PIN26_PINREG GPIOE_PDIR
  325. #define CORE_PIN27_PINREG GPIOC_PDIR
  326. #define CORE_PIN28_PINREG GPIOC_PDIR
  327. #define CORE_PIN29_PINREG GPIOC_PDIR
  328. #define CORE_PIN30_PINREG GPIOC_PDIR
  329. #define CORE_PIN31_PINREG GPIOE_PDIR
  330. #define CORE_PIN32_PINREG GPIOB_PDIR
  331. #define CORE_PIN33_PINREG GPIOA_PDIR
  332. #define CORE_PIN0_CONFIG PORTB_PCR16
  333. #define CORE_PIN1_CONFIG PORTB_PCR17
  334. #define CORE_PIN2_CONFIG PORTD_PCR0
  335. #define CORE_PIN3_CONFIG PORTA_PCR12
  336. #define CORE_PIN4_CONFIG PORTA_PCR13
  337. #define CORE_PIN5_CONFIG PORTD_PCR7
  338. #define CORE_PIN6_CONFIG PORTD_PCR4
  339. #define CORE_PIN7_CONFIG PORTD_PCR2
  340. #define CORE_PIN8_CONFIG PORTD_PCR3
  341. #define CORE_PIN9_CONFIG PORTC_PCR3
  342. #define CORE_PIN10_CONFIG PORTC_PCR4
  343. #define CORE_PIN11_CONFIG PORTC_PCR6
  344. #define CORE_PIN12_CONFIG PORTC_PCR7
  345. #define CORE_PIN13_CONFIG PORTC_PCR5
  346. #define CORE_PIN14_CONFIG PORTD_PCR1
  347. #define CORE_PIN15_CONFIG PORTC_PCR0
  348. #define CORE_PIN16_CONFIG PORTB_PCR0
  349. #define CORE_PIN17_CONFIG PORTB_PCR1
  350. #define CORE_PIN18_CONFIG PORTB_PCR3
  351. #define CORE_PIN19_CONFIG PORTB_PCR2
  352. #define CORE_PIN20_CONFIG PORTD_PCR5
  353. #define CORE_PIN21_CONFIG PORTD_PCR6
  354. #define CORE_PIN22_CONFIG PORTC_PCR1
  355. #define CORE_PIN23_CONFIG PORTC_PCR2
  356. #define CORE_PIN24_CONFIG PORTA_PCR5
  357. #define CORE_PIN25_CONFIG PORTB_PCR19
  358. #define CORE_PIN26_CONFIG PORTE_PCR1
  359. #define CORE_PIN27_CONFIG PORTC_PCR9
  360. #define CORE_PIN28_CONFIG PORTC_PCR8
  361. #define CORE_PIN29_CONFIG PORTC_PCR10
  362. #define CORE_PIN30_CONFIG PORTC_PCR11
  363. #define CORE_PIN31_CONFIG PORTE_PCR0
  364. #define CORE_PIN32_CONFIG PORTB_PCR18
  365. #define CORE_PIN33_CONFIG PORTA_PCR4
  366. #define CORE_ADC0_PIN 14
  367. #define CORE_ADC1_PIN 15
  368. #define CORE_ADC2_PIN 16
  369. #define CORE_ADC3_PIN 17
  370. #define CORE_ADC4_PIN 18
  371. #define CORE_ADC5_PIN 19
  372. #define CORE_ADC6_PIN 20
  373. #define CORE_ADC7_PIN 21
  374. #define CORE_ADC8_PIN 22
  375. #define CORE_ADC9_PIN 23
  376. #define CORE_ADC10_PIN 34
  377. #define CORE_ADC11_PIN 35
  378. #define CORE_ADC12_PIN 36
  379. #define CORE_ADC13_PIN 37
  380. #define CORE_RXD0_PIN 0
  381. #define CORE_TXD0_PIN 1
  382. #define CORE_RXD1_PIN 9
  383. #define CORE_TXD1_PIN 10
  384. #define CORE_RXD2_PIN 7
  385. #define CORE_TXD2_PIN 8
  386. #define CORE_INT0_PIN 0
  387. #define CORE_INT1_PIN 1
  388. #define CORE_INT2_PIN 2
  389. #define CORE_INT3_PIN 3
  390. #define CORE_INT4_PIN 4
  391. #define CORE_INT5_PIN 5
  392. #define CORE_INT6_PIN 6
  393. #define CORE_INT7_PIN 7
  394. #define CORE_INT8_PIN 8
  395. #define CORE_INT9_PIN 9
  396. #define CORE_INT10_PIN 10
  397. #define CORE_INT11_PIN 11
  398. #define CORE_INT12_PIN 12
  399. #define CORE_INT13_PIN 13
  400. #define CORE_INT14_PIN 14
  401. #define CORE_INT15_PIN 15
  402. #define CORE_INT16_PIN 16
  403. #define CORE_INT17_PIN 17
  404. #define CORE_INT18_PIN 18
  405. #define CORE_INT19_PIN 19
  406. #define CORE_INT20_PIN 20
  407. #define CORE_INT21_PIN 21
  408. #define CORE_INT22_PIN 22
  409. #define CORE_INT23_PIN 23
  410. #define CORE_INT24_PIN 24
  411. #define CORE_INT25_PIN 25
  412. #define CORE_INT26_PIN 26
  413. #define CORE_INT27_PIN 27
  414. #define CORE_INT28_PIN 28
  415. #define CORE_INT29_PIN 29
  416. #define CORE_INT30_PIN 30
  417. #define CORE_INT31_PIN 31
  418. #define CORE_INT32_PIN 32
  419. #define CORE_INT33_PIN 33
  420. #define CORE_INT_EVERY_PIN 1
  421. #ifdef __cplusplus
  422. extern "C" {
  423. #endif
  424. void digitalWrite(uint8_t pin, uint8_t val);
  425. static inline void digitalWriteFast(uint8_t pin, uint8_t val) __attribute__((always_inline, unused));
  426. static inline void digitalWriteFast(uint8_t pin, uint8_t val)
  427. {
  428. if (__builtin_constant_p(pin)) {
  429. if (val) {
  430. if (pin == 0) {
  431. CORE_PIN0_PORTSET = CORE_PIN0_BITMASK;
  432. } else if (pin == 1) {
  433. CORE_PIN1_PORTSET = CORE_PIN1_BITMASK;
  434. } else if (pin == 2) {
  435. CORE_PIN2_PORTSET = CORE_PIN2_BITMASK;
  436. } else if (pin == 3) {
  437. CORE_PIN3_PORTSET = CORE_PIN3_BITMASK;
  438. } else if (pin == 4) {
  439. CORE_PIN4_PORTSET = CORE_PIN4_BITMASK;
  440. } else if (pin == 5) {
  441. CORE_PIN5_PORTSET = CORE_PIN5_BITMASK;
  442. } else if (pin == 6) {
  443. CORE_PIN6_PORTSET = CORE_PIN6_BITMASK;
  444. } else if (pin == 7) {
  445. CORE_PIN7_PORTSET = CORE_PIN7_BITMASK;
  446. } else if (pin == 8) {
  447. CORE_PIN8_PORTSET = CORE_PIN8_BITMASK;
  448. } else if (pin == 9) {
  449. CORE_PIN9_PORTSET = CORE_PIN9_BITMASK;
  450. } else if (pin == 10) {
  451. CORE_PIN10_PORTSET = CORE_PIN10_BITMASK;
  452. } else if (pin == 11) {
  453. CORE_PIN11_PORTSET = CORE_PIN11_BITMASK;
  454. } else if (pin == 12) {
  455. CORE_PIN12_PORTSET = CORE_PIN12_BITMASK;
  456. } else if (pin == 13) {
  457. CORE_PIN13_PORTSET = CORE_PIN13_BITMASK;
  458. } else if (pin == 14) {
  459. CORE_PIN14_PORTSET = CORE_PIN14_BITMASK;
  460. } else if (pin == 15) {
  461. CORE_PIN15_PORTSET = CORE_PIN15_BITMASK;
  462. } else if (pin == 16) {
  463. CORE_PIN16_PORTSET = CORE_PIN16_BITMASK;
  464. } else if (pin == 17) {
  465. CORE_PIN17_PORTSET = CORE_PIN17_BITMASK;
  466. } else if (pin == 18) {
  467. CORE_PIN18_PORTSET = CORE_PIN18_BITMASK;
  468. } else if (pin == 19) {
  469. CORE_PIN19_PORTSET = CORE_PIN19_BITMASK;
  470. } else if (pin == 20) {
  471. CORE_PIN20_PORTSET = CORE_PIN20_BITMASK;
  472. } else if (pin == 21) {
  473. CORE_PIN21_PORTSET = CORE_PIN21_BITMASK;
  474. } else if (pin == 22) {
  475. CORE_PIN22_PORTSET = CORE_PIN22_BITMASK;
  476. } else if (pin == 23) {
  477. CORE_PIN23_PORTSET = CORE_PIN23_BITMASK;
  478. } else if (pin == 24) {
  479. CORE_PIN24_PORTSET = CORE_PIN24_BITMASK;
  480. } else if (pin == 25) {
  481. CORE_PIN25_PORTSET = CORE_PIN25_BITMASK;
  482. } else if (pin == 26) {
  483. CORE_PIN26_PORTSET = CORE_PIN26_BITMASK;
  484. } else if (pin == 27) {
  485. CORE_PIN27_PORTSET = CORE_PIN27_BITMASK;
  486. } else if (pin == 28) {
  487. CORE_PIN28_PORTSET = CORE_PIN28_BITMASK;
  488. } else if (pin == 29) {
  489. CORE_PIN29_PORTSET = CORE_PIN29_BITMASK;
  490. } else if (pin == 30) {
  491. CORE_PIN30_PORTSET = CORE_PIN30_BITMASK;
  492. } else if (pin == 31) {
  493. CORE_PIN31_PORTSET = CORE_PIN31_BITMASK;
  494. } else if (pin == 32) {
  495. CORE_PIN32_PORTSET = CORE_PIN32_BITMASK;
  496. } else if (pin == 33) {
  497. CORE_PIN33_PORTSET = CORE_PIN33_BITMASK;
  498. }
  499. } else {
  500. if (pin == 0) {
  501. CORE_PIN0_PORTCLEAR = CORE_PIN0_BITMASK;
  502. } else if (pin == 1) {
  503. CORE_PIN1_PORTCLEAR = CORE_PIN1_BITMASK;
  504. } else if (pin == 2) {
  505. CORE_PIN2_PORTCLEAR = CORE_PIN2_BITMASK;
  506. } else if (pin == 3) {
  507. CORE_PIN3_PORTCLEAR = CORE_PIN3_BITMASK;
  508. } else if (pin == 4) {
  509. CORE_PIN4_PORTCLEAR = CORE_PIN4_BITMASK;
  510. } else if (pin == 5) {
  511. CORE_PIN5_PORTCLEAR = CORE_PIN5_BITMASK;
  512. } else if (pin == 6) {
  513. CORE_PIN6_PORTCLEAR = CORE_PIN6_BITMASK;
  514. } else if (pin == 7) {
  515. CORE_PIN7_PORTCLEAR = CORE_PIN7_BITMASK;
  516. } else if (pin == 8) {
  517. CORE_PIN8_PORTCLEAR = CORE_PIN8_BITMASK;
  518. } else if (pin == 9) {
  519. CORE_PIN9_PORTCLEAR = CORE_PIN9_BITMASK;
  520. } else if (pin == 10) {
  521. CORE_PIN10_PORTCLEAR = CORE_PIN10_BITMASK;
  522. } else if (pin == 11) {
  523. CORE_PIN11_PORTCLEAR = CORE_PIN11_BITMASK;
  524. } else if (pin == 12) {
  525. CORE_PIN12_PORTCLEAR = CORE_PIN12_BITMASK;
  526. } else if (pin == 13) {
  527. CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK;
  528. } else if (pin == 14) {
  529. CORE_PIN14_PORTCLEAR = CORE_PIN14_BITMASK;
  530. } else if (pin == 15) {
  531. CORE_PIN15_PORTCLEAR = CORE_PIN15_BITMASK;
  532. } else if (pin == 16) {
  533. CORE_PIN16_PORTCLEAR = CORE_PIN16_BITMASK;
  534. } else if (pin == 17) {
  535. CORE_PIN17_PORTCLEAR = CORE_PIN17_BITMASK;
  536. } else if (pin == 18) {
  537. CORE_PIN18_PORTCLEAR = CORE_PIN18_BITMASK;
  538. } else if (pin == 19) {
  539. CORE_PIN19_PORTCLEAR = CORE_PIN19_BITMASK;
  540. } else if (pin == 20) {
  541. CORE_PIN20_PORTCLEAR = CORE_PIN20_BITMASK;
  542. } else if (pin == 21) {
  543. CORE_PIN21_PORTCLEAR = CORE_PIN21_BITMASK;
  544. } else if (pin == 22) {
  545. CORE_PIN22_PORTCLEAR = CORE_PIN22_BITMASK;
  546. } else if (pin == 23) {
  547. CORE_PIN23_PORTCLEAR = CORE_PIN23_BITMASK;
  548. } else if (pin == 24) {
  549. CORE_PIN24_PORTCLEAR = CORE_PIN24_BITMASK;
  550. } else if (pin == 25) {
  551. CORE_PIN25_PORTCLEAR = CORE_PIN25_BITMASK;
  552. } else if (pin == 26) {
  553. CORE_PIN26_PORTCLEAR = CORE_PIN26_BITMASK;
  554. } else if (pin == 27) {
  555. CORE_PIN27_PORTCLEAR = CORE_PIN27_BITMASK;
  556. } else if (pin == 28) {
  557. CORE_PIN28_PORTCLEAR = CORE_PIN28_BITMASK;
  558. } else if (pin == 29) {
  559. CORE_PIN29_PORTCLEAR = CORE_PIN29_BITMASK;
  560. } else if (pin == 30) {
  561. CORE_PIN30_PORTCLEAR = CORE_PIN30_BITMASK;
  562. } else if (pin == 31) {
  563. CORE_PIN31_PORTCLEAR = CORE_PIN31_BITMASK;
  564. } else if (pin == 32) {
  565. CORE_PIN32_PORTCLEAR = CORE_PIN32_BITMASK;
  566. } else if (pin == 33) {
  567. CORE_PIN33_PORTCLEAR = CORE_PIN33_BITMASK;
  568. }
  569. }
  570. } else {
  571. if (val) {
  572. *portSetRegister(pin) = 1;
  573. } else {
  574. *portClearRegister(pin) = 1;
  575. }
  576. }
  577. }
  578. uint8_t digitalRead(uint8_t pin);
  579. static inline uint8_t digitalReadFast(uint8_t pin) __attribute__((always_inline, unused));
  580. static inline uint8_t digitalReadFast(uint8_t pin)
  581. {
  582. if (__builtin_constant_p(pin)) {
  583. if (pin == 0) {
  584. return (CORE_PIN0_PINREG & CORE_PIN0_BITMASK) ? 1 : 0;
  585. } else if (pin == 1) {
  586. return (CORE_PIN1_PINREG & CORE_PIN1_BITMASK) ? 1 : 0;
  587. } else if (pin == 2) {
  588. return (CORE_PIN2_PINREG & CORE_PIN2_BITMASK) ? 1 : 0;
  589. } else if (pin == 3) {
  590. return (CORE_PIN3_PINREG & CORE_PIN3_BITMASK) ? 1 : 0;
  591. } else if (pin == 4) {
  592. return (CORE_PIN4_PINREG & CORE_PIN4_BITMASK) ? 1 : 0;
  593. } else if (pin == 5) {
  594. return (CORE_PIN5_PINREG & CORE_PIN5_BITMASK) ? 1 : 0;
  595. } else if (pin == 6) {
  596. return (CORE_PIN6_PINREG & CORE_PIN6_BITMASK) ? 1 : 0;
  597. } else if (pin == 7) {
  598. return (CORE_PIN7_PINREG & CORE_PIN7_BITMASK) ? 1 : 0;
  599. } else if (pin == 8) {
  600. return (CORE_PIN8_PINREG & CORE_PIN8_BITMASK) ? 1 : 0;
  601. } else if (pin == 9) {
  602. return (CORE_PIN9_PINREG & CORE_PIN9_BITMASK) ? 1 : 0;
  603. } else if (pin == 10) {
  604. return (CORE_PIN10_PINREG & CORE_PIN10_BITMASK) ? 1 : 0;
  605. } else if (pin == 11) {
  606. return (CORE_PIN11_PINREG & CORE_PIN11_BITMASK) ? 1 : 0;
  607. } else if (pin == 12) {
  608. return (CORE_PIN12_PINREG & CORE_PIN12_BITMASK) ? 1 : 0;
  609. } else if (pin == 13) {
  610. return (CORE_PIN13_PINREG & CORE_PIN13_BITMASK) ? 1 : 0;
  611. } else if (pin == 14) {
  612. return (CORE_PIN14_PINREG & CORE_PIN14_BITMASK) ? 1 : 0;
  613. } else if (pin == 15) {
  614. return (CORE_PIN15_PINREG & CORE_PIN15_BITMASK) ? 1 : 0;
  615. } else if (pin == 16) {
  616. return (CORE_PIN16_PINREG & CORE_PIN16_BITMASK) ? 1 : 0;
  617. } else if (pin == 17) {
  618. return (CORE_PIN17_PINREG & CORE_PIN17_BITMASK) ? 1 : 0;
  619. } else if (pin == 18) {
  620. return (CORE_PIN18_PINREG & CORE_PIN18_BITMASK) ? 1 : 0;
  621. } else if (pin == 19) {
  622. return (CORE_PIN19_PINREG & CORE_PIN19_BITMASK) ? 1 : 0;
  623. } else if (pin == 20) {
  624. return (CORE_PIN20_PINREG & CORE_PIN20_BITMASK) ? 1 : 0;
  625. } else if (pin == 21) {
  626. return (CORE_PIN21_PINREG & CORE_PIN21_BITMASK) ? 1 : 0;
  627. } else if (pin == 22) {
  628. return (CORE_PIN22_PINREG & CORE_PIN22_BITMASK) ? 1 : 0;
  629. } else if (pin == 23) {
  630. return (CORE_PIN23_PINREG & CORE_PIN23_BITMASK) ? 1 : 0;
  631. } else if (pin == 24) {
  632. return (CORE_PIN24_PINREG & CORE_PIN24_BITMASK) ? 1 : 0;
  633. } else if (pin == 25) {
  634. return (CORE_PIN25_PINREG & CORE_PIN25_BITMASK) ? 1 : 0;
  635. } else if (pin == 26) {
  636. return (CORE_PIN26_PINREG & CORE_PIN26_BITMASK) ? 1 : 0;
  637. } else if (pin == 27) {
  638. return (CORE_PIN27_PINREG & CORE_PIN27_BITMASK) ? 1 : 0;
  639. } else if (pin == 28) {
  640. return (CORE_PIN28_PINREG & CORE_PIN28_BITMASK) ? 1 : 0;
  641. } else if (pin == 29) {
  642. return (CORE_PIN29_PINREG & CORE_PIN29_BITMASK) ? 1 : 0;
  643. } else if (pin == 30) {
  644. return (CORE_PIN30_PINREG & CORE_PIN30_BITMASK) ? 1 : 0;
  645. } else if (pin == 31) {
  646. return (CORE_PIN31_PINREG & CORE_PIN31_BITMASK) ? 1 : 0;
  647. } else if (pin == 32) {
  648. return (CORE_PIN32_PINREG & CORE_PIN32_BITMASK) ? 1 : 0;
  649. } else if (pin == 33) {
  650. return (CORE_PIN33_PINREG & CORE_PIN33_BITMASK) ? 1 : 0;
  651. } else {
  652. return 0;
  653. }
  654. } else {
  655. return *portInputRegister(pin);
  656. }
  657. }
  658. void pinMode(uint8_t pin, uint8_t mode);
  659. void init_pins(void);
  660. void analogWrite(uint8_t pin, int val);
  661. void analogWriteRes(uint32_t bits);
  662. static inline void analogWriteResolution(uint32_t bits) { analogWriteRes(bits); }
  663. void analogWriteFrequency(uint8_t pin, uint32_t frequency);
  664. void attachInterrupt(uint8_t pin, void (*function)(void), int mode);
  665. void detachInterrupt(uint8_t pin);
  666. void _init_Teensyduino_internal_(void);
  667. int analogRead(uint8_t pin);
  668. void analogReference(uint8_t type);
  669. void analogReadRes(unsigned int bits);
  670. static inline void analogReadResolution(unsigned int bits) { analogReadRes(bits); }
  671. void analogReadAveraging(unsigned int num);
  672. void analog_init(void);
  673. #define DEFAULT 0
  674. #define INTERNAL 2
  675. #define INTERNAL1V2 2
  676. #define INTERNAL1V1 2
  677. #define EXTERNAL 0
  678. int touchRead(uint8_t pin);
  679. static inline void shiftOut(uint8_t, uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
  680. extern void _shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value) __attribute__((noinline));
  681. extern void shiftOut_lsbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
  682. extern void shiftOut_msbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
  683. static inline void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value)
  684. {
  685. if (__builtin_constant_p(bitOrder)) {
  686. if (bitOrder == LSBFIRST) {
  687. shiftOut_lsbFirst(dataPin, clockPin, value);
  688. } else {
  689. shiftOut_msbFirst(dataPin, clockPin, value);
  690. }
  691. } else {
  692. _shiftOut(dataPin, clockPin, bitOrder, value);
  693. }
  694. }
  695. static inline uint8_t shiftIn(uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
  696. extern uint8_t _shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) __attribute__((noinline));
  697. extern uint8_t shiftIn_lsbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
  698. extern uint8_t shiftIn_msbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
  699. static inline uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
  700. {
  701. if (__builtin_constant_p(bitOrder)) {
  702. if (bitOrder == LSBFIRST) {
  703. return shiftIn_lsbFirst(dataPin, clockPin);
  704. } else {
  705. return shiftIn_msbFirst(dataPin, clockPin);
  706. }
  707. } else {
  708. return _shiftIn(dataPin, clockPin, bitOrder);
  709. }
  710. }
  711. void _reboot_Teensyduino_(void) __attribute__((noreturn));
  712. void _restart_Teensyduino_(void) __attribute__((noreturn));
  713. void yield(void);
  714. void delay(uint32_t msec);
  715. extern volatile uint32_t systick_millis_count;
  716. static inline uint32_t millis(void) __attribute__((always_inline, unused));
  717. static inline uint32_t millis(void)
  718. {
  719. volatile uint32_t ret = systick_millis_count; // single aligned 32 bit is atomic;
  720. return ret;
  721. }
  722. uint32_t micros(void);
  723. static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused));
  724. static inline void delayMicroseconds(uint32_t usec)
  725. {
  726. #if F_CPU == 96000000
  727. uint32_t n = usec << 5;
  728. #elif F_CPU == 48000000
  729. uint32_t n = usec << 4;
  730. #elif F_CPU == 24000000
  731. uint32_t n = usec << 3;
  732. #endif
  733. if (usec == 0) return;
  734. asm volatile(
  735. "L_%=_delayMicroseconds:" "\n\t"
  736. "subs %0, #1" "\n\t"
  737. "bne L_%=_delayMicroseconds" "\n"
  738. : "+r" (n) :
  739. );
  740. }
  741. #ifdef __cplusplus
  742. }
  743. #endif
  744. #ifdef __cplusplus
  745. extern "C" {
  746. #endif
  747. unsigned long rtc_get(void);
  748. void rtc_set(unsigned long t);
  749. void rtc_compensate(int adjust);
  750. #ifdef __cplusplus
  751. }
  752. class teensy3_clock_class
  753. {
  754. public:
  755. static unsigned long get(void) __attribute__((always_inline)) { return rtc_get(); }
  756. static void set(unsigned long t) __attribute__((always_inline)) { rtc_set(t); }
  757. static void compensate(int adj) __attribute__((always_inline)) { rtc_compensate(adj); }
  758. };
  759. extern teensy3_clock_class Teensy3Clock;
  760. #endif
  761. #endif