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.

847 lines
27KB

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