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.

1154 lines
37KB

  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. #if defined(__MK20DX128__)
  90. #define CORE_NUM_TOTAL_PINS 34
  91. #define CORE_NUM_DIGITAL 34
  92. #define CORE_NUM_INTERRUPT 34
  93. #define CORE_NUM_ANALOG 14
  94. #define CORE_NUM_PWM 10
  95. #elif defined(__MK20DX256__)
  96. #define CORE_NUM_TOTAL_PINS 34
  97. #define CORE_NUM_DIGITAL 34
  98. #define CORE_NUM_INTERRUPT 34
  99. #define CORE_NUM_ANALOG 21
  100. #define CORE_NUM_PWM 12
  101. #elif defined(__MKL26Z64__)
  102. #define CORE_NUM_TOTAL_PINS 27
  103. #define CORE_NUM_DIGITAL 27
  104. #define CORE_NUM_INTERRUPT 24 // really only 18, but 6 "holes"
  105. #define CORE_NUM_ANALOG 13
  106. #define CORE_NUM_PWM 10
  107. #endif
  108. #if defined(__MK20DX128__) || defined(__MK20DX256__)
  109. #define CORE_PIN0_BIT 16
  110. #define CORE_PIN1_BIT 17
  111. #define CORE_PIN2_BIT 0
  112. #define CORE_PIN3_BIT 12
  113. #define CORE_PIN4_BIT 13
  114. #define CORE_PIN5_BIT 7
  115. #define CORE_PIN6_BIT 4
  116. #define CORE_PIN7_BIT 2
  117. #define CORE_PIN8_BIT 3
  118. #define CORE_PIN9_BIT 3
  119. #define CORE_PIN10_BIT 4
  120. #define CORE_PIN11_BIT 6
  121. #define CORE_PIN12_BIT 7
  122. #define CORE_PIN13_BIT 5
  123. #define CORE_PIN14_BIT 1
  124. #define CORE_PIN15_BIT 0
  125. #define CORE_PIN16_BIT 0
  126. #define CORE_PIN17_BIT 1
  127. #define CORE_PIN18_BIT 3
  128. #define CORE_PIN19_BIT 2
  129. #define CORE_PIN20_BIT 5
  130. #define CORE_PIN21_BIT 6
  131. #define CORE_PIN22_BIT 1
  132. #define CORE_PIN23_BIT 2
  133. #define CORE_PIN24_BIT 5
  134. #define CORE_PIN25_BIT 19
  135. #define CORE_PIN26_BIT 1
  136. #define CORE_PIN27_BIT 9
  137. #define CORE_PIN28_BIT 8
  138. #define CORE_PIN29_BIT 10
  139. #define CORE_PIN30_BIT 11
  140. #define CORE_PIN31_BIT 0
  141. #define CORE_PIN32_BIT 18
  142. #define CORE_PIN33_BIT 4
  143. #define CORE_PIN0_BITMASK (1<<(CORE_PIN0_BIT))
  144. #define CORE_PIN1_BITMASK (1<<(CORE_PIN1_BIT))
  145. #define CORE_PIN2_BITMASK (1<<(CORE_PIN2_BIT))
  146. #define CORE_PIN3_BITMASK (1<<(CORE_PIN3_BIT))
  147. #define CORE_PIN4_BITMASK (1<<(CORE_PIN4_BIT))
  148. #define CORE_PIN5_BITMASK (1<<(CORE_PIN5_BIT))
  149. #define CORE_PIN6_BITMASK (1<<(CORE_PIN6_BIT))
  150. #define CORE_PIN7_BITMASK (1<<(CORE_PIN7_BIT))
  151. #define CORE_PIN8_BITMASK (1<<(CORE_PIN8_BIT))
  152. #define CORE_PIN9_BITMASK (1<<(CORE_PIN9_BIT))
  153. #define CORE_PIN10_BITMASK (1<<(CORE_PIN10_BIT))
  154. #define CORE_PIN11_BITMASK (1<<(CORE_PIN11_BIT))
  155. #define CORE_PIN12_BITMASK (1<<(CORE_PIN12_BIT))
  156. #define CORE_PIN13_BITMASK (1<<(CORE_PIN13_BIT))
  157. #define CORE_PIN14_BITMASK (1<<(CORE_PIN14_BIT))
  158. #define CORE_PIN15_BITMASK (1<<(CORE_PIN15_BIT))
  159. #define CORE_PIN16_BITMASK (1<<(CORE_PIN16_BIT))
  160. #define CORE_PIN17_BITMASK (1<<(CORE_PIN17_BIT))
  161. #define CORE_PIN18_BITMASK (1<<(CORE_PIN18_BIT))
  162. #define CORE_PIN19_BITMASK (1<<(CORE_PIN19_BIT))
  163. #define CORE_PIN20_BITMASK (1<<(CORE_PIN20_BIT))
  164. #define CORE_PIN21_BITMASK (1<<(CORE_PIN21_BIT))
  165. #define CORE_PIN22_BITMASK (1<<(CORE_PIN22_BIT))
  166. #define CORE_PIN23_BITMASK (1<<(CORE_PIN23_BIT))
  167. #define CORE_PIN24_BITMASK (1<<(CORE_PIN24_BIT))
  168. #define CORE_PIN25_BITMASK (1<<(CORE_PIN25_BIT))
  169. #define CORE_PIN26_BITMASK (1<<(CORE_PIN26_BIT))
  170. #define CORE_PIN27_BITMASK (1<<(CORE_PIN27_BIT))
  171. #define CORE_PIN28_BITMASK (1<<(CORE_PIN28_BIT))
  172. #define CORE_PIN29_BITMASK (1<<(CORE_PIN29_BIT))
  173. #define CORE_PIN30_BITMASK (1<<(CORE_PIN30_BIT))
  174. #define CORE_PIN31_BITMASK (1<<(CORE_PIN31_BIT))
  175. #define CORE_PIN32_BITMASK (1<<(CORE_PIN32_BIT))
  176. #define CORE_PIN33_BITMASK (1<<(CORE_PIN33_BIT))
  177. #define CORE_PIN0_PORTREG GPIOB_PDOR
  178. #define CORE_PIN1_PORTREG GPIOB_PDOR
  179. #define CORE_PIN2_PORTREG GPIOD_PDOR
  180. #define CORE_PIN3_PORTREG GPIOA_PDOR
  181. #define CORE_PIN4_PORTREG GPIOA_PDOR
  182. #define CORE_PIN5_PORTREG GPIOD_PDOR
  183. #define CORE_PIN6_PORTREG GPIOD_PDOR
  184. #define CORE_PIN7_PORTREG GPIOD_PDOR
  185. #define CORE_PIN8_PORTREG GPIOD_PDOR
  186. #define CORE_PIN9_PORTREG GPIOC_PDOR
  187. #define CORE_PIN10_PORTREG GPIOC_PDOR
  188. #define CORE_PIN11_PORTREG GPIOC_PDOR
  189. #define CORE_PIN12_PORTREG GPIOC_PDOR
  190. #define CORE_PIN13_PORTREG GPIOC_PDOR
  191. #define CORE_PIN14_PORTREG GPIOD_PDOR
  192. #define CORE_PIN15_PORTREG GPIOC_PDOR
  193. #define CORE_PIN16_PORTREG GPIOB_PDOR
  194. #define CORE_PIN17_PORTREG GPIOB_PDOR
  195. #define CORE_PIN18_PORTREG GPIOB_PDOR
  196. #define CORE_PIN19_PORTREG GPIOB_PDOR
  197. #define CORE_PIN20_PORTREG GPIOD_PDOR
  198. #define CORE_PIN21_PORTREG GPIOD_PDOR
  199. #define CORE_PIN22_PORTREG GPIOC_PDOR
  200. #define CORE_PIN23_PORTREG GPIOC_PDOR
  201. #define CORE_PIN24_PORTREG GPIOA_PDOR
  202. #define CORE_PIN25_PORTREG GPIOB_PDOR
  203. #define CORE_PIN26_PORTREG GPIOE_PDOR
  204. #define CORE_PIN27_PORTREG GPIOC_PDOR
  205. #define CORE_PIN28_PORTREG GPIOC_PDOR
  206. #define CORE_PIN29_PORTREG GPIOC_PDOR
  207. #define CORE_PIN30_PORTREG GPIOC_PDOR
  208. #define CORE_PIN31_PORTREG GPIOE_PDOR
  209. #define CORE_PIN32_PORTREG GPIOB_PDOR
  210. #define CORE_PIN33_PORTREG GPIOA_PDOR
  211. #define CORE_PIN0_PORTSET GPIOB_PSOR
  212. #define CORE_PIN1_PORTSET GPIOB_PSOR
  213. #define CORE_PIN2_PORTSET GPIOD_PSOR
  214. #define CORE_PIN3_PORTSET GPIOA_PSOR
  215. #define CORE_PIN4_PORTSET GPIOA_PSOR
  216. #define CORE_PIN5_PORTSET GPIOD_PSOR
  217. #define CORE_PIN6_PORTSET GPIOD_PSOR
  218. #define CORE_PIN7_PORTSET GPIOD_PSOR
  219. #define CORE_PIN8_PORTSET GPIOD_PSOR
  220. #define CORE_PIN9_PORTSET GPIOC_PSOR
  221. #define CORE_PIN10_PORTSET GPIOC_PSOR
  222. #define CORE_PIN11_PORTSET GPIOC_PSOR
  223. #define CORE_PIN12_PORTSET GPIOC_PSOR
  224. #define CORE_PIN13_PORTSET GPIOC_PSOR
  225. #define CORE_PIN14_PORTSET GPIOD_PSOR
  226. #define CORE_PIN15_PORTSET GPIOC_PSOR
  227. #define CORE_PIN16_PORTSET GPIOB_PSOR
  228. #define CORE_PIN17_PORTSET GPIOB_PSOR
  229. #define CORE_PIN18_PORTSET GPIOB_PSOR
  230. #define CORE_PIN19_PORTSET GPIOB_PSOR
  231. #define CORE_PIN20_PORTSET GPIOD_PSOR
  232. #define CORE_PIN21_PORTSET GPIOD_PSOR
  233. #define CORE_PIN22_PORTSET GPIOC_PSOR
  234. #define CORE_PIN23_PORTSET GPIOC_PSOR
  235. #define CORE_PIN24_PORTSET GPIOA_PSOR
  236. #define CORE_PIN25_PORTSET GPIOB_PSOR
  237. #define CORE_PIN26_PORTSET GPIOE_PSOR
  238. #define CORE_PIN27_PORTSET GPIOC_PSOR
  239. #define CORE_PIN28_PORTSET GPIOC_PSOR
  240. #define CORE_PIN29_PORTSET GPIOC_PSOR
  241. #define CORE_PIN30_PORTSET GPIOC_PSOR
  242. #define CORE_PIN31_PORTSET GPIOE_PSOR
  243. #define CORE_PIN32_PORTSET GPIOB_PSOR
  244. #define CORE_PIN33_PORTSET GPIOA_PSOR
  245. #define CORE_PIN0_PORTCLEAR GPIOB_PCOR
  246. #define CORE_PIN1_PORTCLEAR GPIOB_PCOR
  247. #define CORE_PIN2_PORTCLEAR GPIOD_PCOR
  248. #define CORE_PIN3_PORTCLEAR GPIOA_PCOR
  249. #define CORE_PIN4_PORTCLEAR GPIOA_PCOR
  250. #define CORE_PIN5_PORTCLEAR GPIOD_PCOR
  251. #define CORE_PIN6_PORTCLEAR GPIOD_PCOR
  252. #define CORE_PIN7_PORTCLEAR GPIOD_PCOR
  253. #define CORE_PIN8_PORTCLEAR GPIOD_PCOR
  254. #define CORE_PIN9_PORTCLEAR GPIOC_PCOR
  255. #define CORE_PIN10_PORTCLEAR GPIOC_PCOR
  256. #define CORE_PIN11_PORTCLEAR GPIOC_PCOR
  257. #define CORE_PIN12_PORTCLEAR GPIOC_PCOR
  258. #define CORE_PIN13_PORTCLEAR GPIOC_PCOR
  259. #define CORE_PIN14_PORTCLEAR GPIOD_PCOR
  260. #define CORE_PIN15_PORTCLEAR GPIOC_PCOR
  261. #define CORE_PIN16_PORTCLEAR GPIOB_PCOR
  262. #define CORE_PIN17_PORTCLEAR GPIOB_PCOR
  263. #define CORE_PIN18_PORTCLEAR GPIOB_PCOR
  264. #define CORE_PIN19_PORTCLEAR GPIOB_PCOR
  265. #define CORE_PIN20_PORTCLEAR GPIOD_PCOR
  266. #define CORE_PIN21_PORTCLEAR GPIOD_PCOR
  267. #define CORE_PIN22_PORTCLEAR GPIOC_PCOR
  268. #define CORE_PIN23_PORTCLEAR GPIOC_PCOR
  269. #define CORE_PIN24_PORTCLEAR GPIOA_PCOR
  270. #define CORE_PIN25_PORTCLEAR GPIOB_PCOR
  271. #define CORE_PIN26_PORTCLEAR GPIOE_PCOR
  272. #define CORE_PIN27_PORTCLEAR GPIOC_PCOR
  273. #define CORE_PIN28_PORTCLEAR GPIOC_PCOR
  274. #define CORE_PIN29_PORTCLEAR GPIOC_PCOR
  275. #define CORE_PIN30_PORTCLEAR GPIOC_PCOR
  276. #define CORE_PIN31_PORTCLEAR GPIOE_PCOR
  277. #define CORE_PIN32_PORTCLEAR GPIOB_PCOR
  278. #define CORE_PIN33_PORTCLEAR GPIOA_PCOR
  279. #define CORE_PIN0_DDRREG GPIOB_PDDR
  280. #define CORE_PIN1_DDRREG GPIOB_PDDR
  281. #define CORE_PIN2_DDRREG GPIOD_PDDR
  282. #define CORE_PIN3_DDRREG GPIOA_PDDR
  283. #define CORE_PIN4_DDRREG GPIOA_PDDR
  284. #define CORE_PIN5_DDRREG GPIOD_PDDR
  285. #define CORE_PIN6_DDRREG GPIOD_PDDR
  286. #define CORE_PIN7_DDRREG GPIOD_PDDR
  287. #define CORE_PIN8_DDRREG GPIOD_PDDR
  288. #define CORE_PIN9_DDRREG GPIOC_PDDR
  289. #define CORE_PIN10_DDRREG GPIOC_PDDR
  290. #define CORE_PIN11_DDRREG GPIOC_PDDR
  291. #define CORE_PIN12_DDRREG GPIOC_PDDR
  292. #define CORE_PIN13_DDRREG GPIOC_PDDR
  293. #define CORE_PIN14_DDRREG GPIOD_PDDR
  294. #define CORE_PIN15_DDRREG GPIOC_PDDR
  295. #define CORE_PIN16_DDRREG GPIOB_PDDR
  296. #define CORE_PIN17_DDRREG GPIOB_PDDR
  297. #define CORE_PIN18_DDRREG GPIOB_PDDR
  298. #define CORE_PIN19_DDRREG GPIOB_PDDR
  299. #define CORE_PIN20_DDRREG GPIOD_PDDR
  300. #define CORE_PIN21_DDRREG GPIOD_PDDR
  301. #define CORE_PIN22_DDRREG GPIOC_PDDR
  302. #define CORE_PIN23_DDRREG GPIOC_PDDR
  303. #define CORE_PIN24_DDRREG GPIOA_PDDR
  304. #define CORE_PIN25_DDRREG GPIOB_PDDR
  305. #define CORE_PIN26_DDRREG GPIOE_PDDR
  306. #define CORE_PIN27_DDRREG GPIOC_PDDR
  307. #define CORE_PIN28_DDRREG GPIOC_PDDR
  308. #define CORE_PIN29_DDRREG GPIOC_PDDR
  309. #define CORE_PIN30_DDRREG GPIOC_PDDR
  310. #define CORE_PIN31_DDRREG GPIOE_PDDR
  311. #define CORE_PIN32_DDRREG GPIOB_PDDR
  312. #define CORE_PIN33_DDRREG GPIOA_PDDR
  313. #define CORE_PIN0_PINREG GPIOB_PDIR
  314. #define CORE_PIN1_PINREG GPIOB_PDIR
  315. #define CORE_PIN2_PINREG GPIOD_PDIR
  316. #define CORE_PIN3_PINREG GPIOA_PDIR
  317. #define CORE_PIN4_PINREG GPIOA_PDIR
  318. #define CORE_PIN5_PINREG GPIOD_PDIR
  319. #define CORE_PIN6_PINREG GPIOD_PDIR
  320. #define CORE_PIN7_PINREG GPIOD_PDIR
  321. #define CORE_PIN8_PINREG GPIOD_PDIR
  322. #define CORE_PIN9_PINREG GPIOC_PDIR
  323. #define CORE_PIN10_PINREG GPIOC_PDIR
  324. #define CORE_PIN11_PINREG GPIOC_PDIR
  325. #define CORE_PIN12_PINREG GPIOC_PDIR
  326. #define CORE_PIN13_PINREG GPIOC_PDIR
  327. #define CORE_PIN14_PINREG GPIOD_PDIR
  328. #define CORE_PIN15_PINREG GPIOC_PDIR
  329. #define CORE_PIN16_PINREG GPIOB_PDIR
  330. #define CORE_PIN17_PINREG GPIOB_PDIR
  331. #define CORE_PIN18_PINREG GPIOB_PDIR
  332. #define CORE_PIN19_PINREG GPIOB_PDIR
  333. #define CORE_PIN20_PINREG GPIOD_PDIR
  334. #define CORE_PIN21_PINREG GPIOD_PDIR
  335. #define CORE_PIN22_PINREG GPIOC_PDIR
  336. #define CORE_PIN23_PINREG GPIOC_PDIR
  337. #define CORE_PIN24_PINREG GPIOA_PDIR
  338. #define CORE_PIN25_PINREG GPIOB_PDIR
  339. #define CORE_PIN26_PINREG GPIOE_PDIR
  340. #define CORE_PIN27_PINREG GPIOC_PDIR
  341. #define CORE_PIN28_PINREG GPIOC_PDIR
  342. #define CORE_PIN29_PINREG GPIOC_PDIR
  343. #define CORE_PIN30_PINREG GPIOC_PDIR
  344. #define CORE_PIN31_PINREG GPIOE_PDIR
  345. #define CORE_PIN32_PINREG GPIOB_PDIR
  346. #define CORE_PIN33_PINREG GPIOA_PDIR
  347. #define CORE_PIN0_CONFIG PORTB_PCR16
  348. #define CORE_PIN1_CONFIG PORTB_PCR17
  349. #define CORE_PIN2_CONFIG PORTD_PCR0
  350. #define CORE_PIN3_CONFIG PORTA_PCR12
  351. #define CORE_PIN4_CONFIG PORTA_PCR13
  352. #define CORE_PIN5_CONFIG PORTD_PCR7
  353. #define CORE_PIN6_CONFIG PORTD_PCR4
  354. #define CORE_PIN7_CONFIG PORTD_PCR2
  355. #define CORE_PIN8_CONFIG PORTD_PCR3
  356. #define CORE_PIN9_CONFIG PORTC_PCR3
  357. #define CORE_PIN10_CONFIG PORTC_PCR4
  358. #define CORE_PIN11_CONFIG PORTC_PCR6
  359. #define CORE_PIN12_CONFIG PORTC_PCR7
  360. #define CORE_PIN13_CONFIG PORTC_PCR5
  361. #define CORE_PIN14_CONFIG PORTD_PCR1
  362. #define CORE_PIN15_CONFIG PORTC_PCR0
  363. #define CORE_PIN16_CONFIG PORTB_PCR0
  364. #define CORE_PIN17_CONFIG PORTB_PCR1
  365. #define CORE_PIN18_CONFIG PORTB_PCR3
  366. #define CORE_PIN19_CONFIG PORTB_PCR2
  367. #define CORE_PIN20_CONFIG PORTD_PCR5
  368. #define CORE_PIN21_CONFIG PORTD_PCR6
  369. #define CORE_PIN22_CONFIG PORTC_PCR1
  370. #define CORE_PIN23_CONFIG PORTC_PCR2
  371. #define CORE_PIN24_CONFIG PORTA_PCR5
  372. #define CORE_PIN25_CONFIG PORTB_PCR19
  373. #define CORE_PIN26_CONFIG PORTE_PCR1
  374. #define CORE_PIN27_CONFIG PORTC_PCR9
  375. #define CORE_PIN28_CONFIG PORTC_PCR8
  376. #define CORE_PIN29_CONFIG PORTC_PCR10
  377. #define CORE_PIN30_CONFIG PORTC_PCR11
  378. #define CORE_PIN31_CONFIG PORTE_PCR0
  379. #define CORE_PIN32_CONFIG PORTB_PCR18
  380. #define CORE_PIN33_CONFIG PORTA_PCR4
  381. #define CORE_ADC0_PIN 14
  382. #define CORE_ADC1_PIN 15
  383. #define CORE_ADC2_PIN 16
  384. #define CORE_ADC3_PIN 17
  385. #define CORE_ADC4_PIN 18
  386. #define CORE_ADC5_PIN 19
  387. #define CORE_ADC6_PIN 20
  388. #define CORE_ADC7_PIN 21
  389. #define CORE_ADC8_PIN 22
  390. #define CORE_ADC9_PIN 23
  391. #define CORE_ADC10_PIN 34
  392. #define CORE_ADC11_PIN 35
  393. #define CORE_ADC12_PIN 36
  394. #define CORE_ADC13_PIN 37
  395. #define CORE_RXD0_PIN 0
  396. #define CORE_TXD0_PIN 1
  397. #define CORE_RXD1_PIN 9
  398. #define CORE_TXD1_PIN 10
  399. #define CORE_RXD2_PIN 7
  400. #define CORE_TXD2_PIN 8
  401. #define CORE_INT0_PIN 0
  402. #define CORE_INT1_PIN 1
  403. #define CORE_INT2_PIN 2
  404. #define CORE_INT3_PIN 3
  405. #define CORE_INT4_PIN 4
  406. #define CORE_INT5_PIN 5
  407. #define CORE_INT6_PIN 6
  408. #define CORE_INT7_PIN 7
  409. #define CORE_INT8_PIN 8
  410. #define CORE_INT9_PIN 9
  411. #define CORE_INT10_PIN 10
  412. #define CORE_INT11_PIN 11
  413. #define CORE_INT12_PIN 12
  414. #define CORE_INT13_PIN 13
  415. #define CORE_INT14_PIN 14
  416. #define CORE_INT15_PIN 15
  417. #define CORE_INT16_PIN 16
  418. #define CORE_INT17_PIN 17
  419. #define CORE_INT18_PIN 18
  420. #define CORE_INT19_PIN 19
  421. #define CORE_INT20_PIN 20
  422. #define CORE_INT21_PIN 21
  423. #define CORE_INT22_PIN 22
  424. #define CORE_INT23_PIN 23
  425. #define CORE_INT24_PIN 24
  426. #define CORE_INT25_PIN 25
  427. #define CORE_INT26_PIN 26
  428. #define CORE_INT27_PIN 27
  429. #define CORE_INT28_PIN 28
  430. #define CORE_INT29_PIN 29
  431. #define CORE_INT30_PIN 30
  432. #define CORE_INT31_PIN 31
  433. #define CORE_INT32_PIN 32
  434. #define CORE_INT33_PIN 33
  435. #define CORE_INT_EVERY_PIN 1
  436. #elif defined(__MKL26Z64__)
  437. #define CORE_PIN0_BIT 16
  438. #define CORE_PIN1_BIT 17
  439. #define CORE_PIN2_BIT 0
  440. #define CORE_PIN3_BIT 1
  441. #define CORE_PIN4_BIT 2
  442. #define CORE_PIN5_BIT 7
  443. #define CORE_PIN6_BIT 4
  444. #define CORE_PIN7_BIT 2
  445. #define CORE_PIN8_BIT 3
  446. #define CORE_PIN9_BIT 3
  447. #define CORE_PIN10_BIT 4
  448. #define CORE_PIN11_BIT 6
  449. #define CORE_PIN12_BIT 7
  450. #define CORE_PIN13_BIT 5
  451. #define CORE_PIN14_BIT 1
  452. #define CORE_PIN15_BIT 0
  453. #define CORE_PIN16_BIT 0
  454. #define CORE_PIN17_BIT 1
  455. #define CORE_PIN18_BIT 3
  456. #define CORE_PIN19_BIT 2
  457. #define CORE_PIN20_BIT 5
  458. #define CORE_PIN21_BIT 6
  459. #define CORE_PIN22_BIT 1
  460. #define CORE_PIN23_BIT 2
  461. #define CORE_PIN24_BIT 20
  462. #define CORE_PIN25_BIT 21
  463. #define CORE_PIN26_BIT 30
  464. #define CORE_PIN0_BITMASK (1<<(CORE_PIN0_BIT))
  465. #define CORE_PIN1_BITMASK (1<<(CORE_PIN1_BIT))
  466. #define CORE_PIN2_BITMASK (1<<(CORE_PIN2_BIT))
  467. #define CORE_PIN3_BITMASK (1<<(CORE_PIN3_BIT))
  468. #define CORE_PIN4_BITMASK (1<<(CORE_PIN4_BIT))
  469. #define CORE_PIN5_BITMASK (1<<(CORE_PIN5_BIT))
  470. #define CORE_PIN6_BITMASK (1<<(CORE_PIN6_BIT))
  471. #define CORE_PIN7_BITMASK (1<<(CORE_PIN7_BIT))
  472. #define CORE_PIN8_BITMASK (1<<(CORE_PIN8_BIT))
  473. #define CORE_PIN9_BITMASK (1<<(CORE_PIN9_BIT))
  474. #define CORE_PIN10_BITMASK (1<<(CORE_PIN10_BIT))
  475. #define CORE_PIN11_BITMASK (1<<(CORE_PIN11_BIT))
  476. #define CORE_PIN12_BITMASK (1<<(CORE_PIN12_BIT))
  477. #define CORE_PIN13_BITMASK (1<<(CORE_PIN13_BIT))
  478. #define CORE_PIN14_BITMASK (1<<(CORE_PIN14_BIT))
  479. #define CORE_PIN15_BITMASK (1<<(CORE_PIN15_BIT))
  480. #define CORE_PIN16_BITMASK (1<<(CORE_PIN16_BIT))
  481. #define CORE_PIN17_BITMASK (1<<(CORE_PIN17_BIT))
  482. #define CORE_PIN18_BITMASK (1<<(CORE_PIN18_BIT))
  483. #define CORE_PIN19_BITMASK (1<<(CORE_PIN19_BIT))
  484. #define CORE_PIN20_BITMASK (1<<(CORE_PIN20_BIT))
  485. #define CORE_PIN21_BITMASK (1<<(CORE_PIN21_BIT))
  486. #define CORE_PIN22_BITMASK (1<<(CORE_PIN22_BIT))
  487. #define CORE_PIN23_BITMASK (1<<(CORE_PIN23_BIT))
  488. #define CORE_PIN24_BITMASK (1<<(CORE_PIN24_BIT))
  489. #define CORE_PIN25_BITMASK (1<<(CORE_PIN25_BIT))
  490. #define CORE_PIN26_BITMASK (1<<(CORE_PIN26_BIT))
  491. #define CORE_PIN0_PORTREG FGPIOB_PDOR
  492. #define CORE_PIN1_PORTREG FGPIOB_PDOR
  493. #define CORE_PIN2_PORTREG FGPIOD_PDOR
  494. #define CORE_PIN3_PORTREG FGPIOA_PDOR
  495. #define CORE_PIN4_PORTREG FGPIOA_PDOR
  496. #define CORE_PIN5_PORTREG FGPIOD_PDOR
  497. #define CORE_PIN6_PORTREG FGPIOD_PDOR
  498. #define CORE_PIN7_PORTREG FGPIOD_PDOR
  499. #define CORE_PIN8_PORTREG FGPIOD_PDOR
  500. #define CORE_PIN9_PORTREG FGPIOC_PDOR
  501. #define CORE_PIN10_PORTREG FGPIOC_PDOR
  502. #define CORE_PIN11_PORTREG FGPIOC_PDOR
  503. #define CORE_PIN12_PORTREG FGPIOC_PDOR
  504. #define CORE_PIN13_PORTREG FGPIOC_PDOR
  505. #define CORE_PIN14_PORTREG FGPIOD_PDOR
  506. #define CORE_PIN15_PORTREG FGPIOC_PDOR
  507. #define CORE_PIN16_PORTREG FGPIOB_PDOR
  508. #define CORE_PIN17_PORTREG FGPIOB_PDOR
  509. #define CORE_PIN18_PORTREG FGPIOB_PDOR
  510. #define CORE_PIN19_PORTREG FGPIOB_PDOR
  511. #define CORE_PIN20_PORTREG FGPIOD_PDOR
  512. #define CORE_PIN21_PORTREG FGPIOD_PDOR
  513. #define CORE_PIN22_PORTREG FGPIOC_PDOR
  514. #define CORE_PIN23_PORTREG FGPIOC_PDOR
  515. #define CORE_PIN24_PORTREG FGPIOE_PDOR
  516. #define CORE_PIN25_PORTREG FGPIOE_PDOR
  517. #define CORE_PIN26_PORTREG FGPIOE_PDOR
  518. #define CORE_PIN0_PORTSET FGPIOB_PSOR
  519. #define CORE_PIN1_PORTSET FGPIOB_PSOR
  520. #define CORE_PIN2_PORTSET FGPIOD_PSOR
  521. #define CORE_PIN3_PORTSET FGPIOA_PSOR
  522. #define CORE_PIN4_PORTSET FGPIOA_PSOR
  523. #define CORE_PIN5_PORTSET FGPIOD_PSOR
  524. #define CORE_PIN6_PORTSET FGPIOD_PSOR
  525. #define CORE_PIN7_PORTSET FGPIOD_PSOR
  526. #define CORE_PIN8_PORTSET FGPIOD_PSOR
  527. #define CORE_PIN9_PORTSET FGPIOC_PSOR
  528. #define CORE_PIN10_PORTSET FGPIOC_PSOR
  529. #define CORE_PIN11_PORTSET FGPIOC_PSOR
  530. #define CORE_PIN12_PORTSET FGPIOC_PSOR
  531. #define CORE_PIN13_PORTSET FGPIOC_PSOR
  532. #define CORE_PIN14_PORTSET FGPIOD_PSOR
  533. #define CORE_PIN15_PORTSET FGPIOC_PSOR
  534. #define CORE_PIN16_PORTSET FGPIOB_PSOR
  535. #define CORE_PIN17_PORTSET FGPIOB_PSOR
  536. #define CORE_PIN18_PORTSET FGPIOB_PSOR
  537. #define CORE_PIN19_PORTSET FGPIOB_PSOR
  538. #define CORE_PIN20_PORTSET FGPIOD_PSOR
  539. #define CORE_PIN21_PORTSET FGPIOD_PSOR
  540. #define CORE_PIN22_PORTSET FGPIOC_PSOR
  541. #define CORE_PIN23_PORTSET FGPIOC_PSOR
  542. #define CORE_PIN24_PORTSET FGPIOE_PSOR
  543. #define CORE_PIN25_PORTSET FGPIOE_PSOR
  544. #define CORE_PIN26_PORTSET FGPIOE_PSOR
  545. #define CORE_PIN0_PORTCLEAR FGPIOB_PCOR
  546. #define CORE_PIN1_PORTCLEAR FGPIOB_PCOR
  547. #define CORE_PIN2_PORTCLEAR FGPIOD_PCOR
  548. #define CORE_PIN3_PORTCLEAR FGPIOA_PCOR
  549. #define CORE_PIN4_PORTCLEAR FGPIOA_PCOR
  550. #define CORE_PIN5_PORTCLEAR FGPIOD_PCOR
  551. #define CORE_PIN6_PORTCLEAR FGPIOD_PCOR
  552. #define CORE_PIN7_PORTCLEAR FGPIOD_PCOR
  553. #define CORE_PIN8_PORTCLEAR FGPIOD_PCOR
  554. #define CORE_PIN9_PORTCLEAR FGPIOC_PCOR
  555. #define CORE_PIN10_PORTCLEAR FGPIOC_PCOR
  556. #define CORE_PIN11_PORTCLEAR FGPIOC_PCOR
  557. #define CORE_PIN12_PORTCLEAR FGPIOC_PCOR
  558. #define CORE_PIN13_PORTCLEAR FGPIOC_PCOR
  559. #define CORE_PIN14_PORTCLEAR FGPIOD_PCOR
  560. #define CORE_PIN15_PORTCLEAR FGPIOC_PCOR
  561. #define CORE_PIN16_PORTCLEAR FGPIOB_PCOR
  562. #define CORE_PIN17_PORTCLEAR FGPIOB_PCOR
  563. #define CORE_PIN18_PORTCLEAR FGPIOB_PCOR
  564. #define CORE_PIN19_PORTCLEAR FGPIOB_PCOR
  565. #define CORE_PIN20_PORTCLEAR FGPIOD_PCOR
  566. #define CORE_PIN21_PORTCLEAR FGPIOD_PCOR
  567. #define CORE_PIN22_PORTCLEAR FGPIOC_PCOR
  568. #define CORE_PIN23_PORTCLEAR FGPIOC_PCOR
  569. #define CORE_PIN24_PORTCLEAR FGPIOE_PCOR
  570. #define CORE_PIN25_PORTCLEAR FGPIOE_PCOR
  571. #define CORE_PIN26_PORTCLEAR FGPIOE_PCOR
  572. #define CORE_PIN0_DDRREG FGPIOB_PDDR
  573. #define CORE_PIN1_DDRREG FGPIOB_PDDR
  574. #define CORE_PIN2_DDRREG FGPIOD_PDDR
  575. #define CORE_PIN3_DDRREG FGPIOA_PDDR
  576. #define CORE_PIN4_DDRREG FGPIOA_PDDR
  577. #define CORE_PIN5_DDRREG FGPIOD_PDDR
  578. #define CORE_PIN6_DDRREG FGPIOD_PDDR
  579. #define CORE_PIN7_DDRREG FGPIOD_PDDR
  580. #define CORE_PIN8_DDRREG FGPIOD_PDDR
  581. #define CORE_PIN9_DDRREG FGPIOC_PDDR
  582. #define CORE_PIN10_DDRREG FGPIOC_PDDR
  583. #define CORE_PIN11_DDRREG FGPIOC_PDDR
  584. #define CORE_PIN12_DDRREG FGPIOC_PDDR
  585. #define CORE_PIN13_DDRREG FGPIOC_PDDR
  586. #define CORE_PIN14_DDRREG FGPIOD_PDDR
  587. #define CORE_PIN15_DDRREG FGPIOC_PDDR
  588. #define CORE_PIN16_DDRREG FGPIOB_PDDR
  589. #define CORE_PIN17_DDRREG FGPIOB_PDDR
  590. #define CORE_PIN18_DDRREG FGPIOB_PDDR
  591. #define CORE_PIN19_DDRREG FGPIOB_PDDR
  592. #define CORE_PIN20_DDRREG FGPIOD_PDDR
  593. #define CORE_PIN21_DDRREG FGPIOD_PDDR
  594. #define CORE_PIN22_DDRREG FGPIOC_PDDR
  595. #define CORE_PIN23_DDRREG FGPIOC_PDDR
  596. #define CORE_PIN24_DDRREG FGPIOE_PDDR
  597. #define CORE_PIN25_DDRREG FGPIOE_PDDR
  598. #define CORE_PIN26_DDRREG FGPIOE_PDDR
  599. #define CORE_PIN0_PINREG FGPIOB_PDIR
  600. #define CORE_PIN1_PINREG FGPIOB_PDIR
  601. #define CORE_PIN2_PINREG FGPIOD_PDIR
  602. #define CORE_PIN3_PINREG FGPIOA_PDIR
  603. #define CORE_PIN4_PINREG FGPIOA_PDIR
  604. #define CORE_PIN5_PINREG FGPIOD_PDIR
  605. #define CORE_PIN6_PINREG FGPIOD_PDIR
  606. #define CORE_PIN7_PINREG FGPIOD_PDIR
  607. #define CORE_PIN8_PINREG FGPIOD_PDIR
  608. #define CORE_PIN9_PINREG FGPIOC_PDIR
  609. #define CORE_PIN10_PINREG FGPIOC_PDIR
  610. #define CORE_PIN11_PINREG FGPIOC_PDIR
  611. #define CORE_PIN12_PINREG FGPIOC_PDIR
  612. #define CORE_PIN13_PINREG FGPIOC_PDIR
  613. #define CORE_PIN14_PINREG FGPIOD_PDIR
  614. #define CORE_PIN15_PINREG FGPIOC_PDIR
  615. #define CORE_PIN16_PINREG FGPIOB_PDIR
  616. #define CORE_PIN17_PINREG FGPIOB_PDIR
  617. #define CORE_PIN18_PINREG FGPIOB_PDIR
  618. #define CORE_PIN19_PINREG FGPIOB_PDIR
  619. #define CORE_PIN20_PINREG FGPIOD_PDIR
  620. #define CORE_PIN21_PINREG FGPIOD_PDIR
  621. #define CORE_PIN22_PINREG FGPIOC_PDIR
  622. #define CORE_PIN23_PINREG FGPIOC_PDIR
  623. #define CORE_PIN24_PINREG FGPIOE_PDIR
  624. #define CORE_PIN25_PINREG FGPIOE_PDIR
  625. #define CORE_PIN26_PINREG FGPIOE_PDIR
  626. #define CORE_PIN0_CONFIG PORTB_PCR16
  627. #define CORE_PIN1_CONFIG PORTB_PCR17
  628. #define CORE_PIN2_CONFIG PORTD_PCR0
  629. #define CORE_PIN3_CONFIG PORTA_PCR1
  630. #define CORE_PIN4_CONFIG PORTA_PCR2
  631. #define CORE_PIN5_CONFIG PORTD_PCR7
  632. #define CORE_PIN6_CONFIG PORTD_PCR4
  633. #define CORE_PIN7_CONFIG PORTD_PCR2
  634. #define CORE_PIN8_CONFIG PORTD_PCR3
  635. #define CORE_PIN9_CONFIG PORTC_PCR3
  636. #define CORE_PIN10_CONFIG PORTC_PCR4
  637. #define CORE_PIN11_CONFIG PORTC_PCR6
  638. #define CORE_PIN12_CONFIG PORTC_PCR7
  639. #define CORE_PIN13_CONFIG PORTC_PCR5
  640. #define CORE_PIN14_CONFIG PORTD_PCR1
  641. #define CORE_PIN15_CONFIG PORTC_PCR0
  642. #define CORE_PIN16_CONFIG PORTB_PCR0
  643. #define CORE_PIN17_CONFIG PORTB_PCR1
  644. #define CORE_PIN18_CONFIG PORTB_PCR3
  645. #define CORE_PIN19_CONFIG PORTB_PCR2
  646. #define CORE_PIN20_CONFIG PORTD_PCR5
  647. #define CORE_PIN21_CONFIG PORTD_PCR6
  648. #define CORE_PIN22_CONFIG PORTC_PCR1
  649. #define CORE_PIN23_CONFIG PORTC_PCR2
  650. #define CORE_PIN24_CONFIG PORTE_PCR20
  651. #define CORE_PIN25_CONFIG PORTE_PCR21
  652. #define CORE_PIN26_CONFIG PORTE_PCR30
  653. #define CORE_ADC0_PIN 14
  654. #define CORE_ADC1_PIN 15
  655. #define CORE_ADC2_PIN 16
  656. #define CORE_ADC3_PIN 17
  657. #define CORE_ADC4_PIN 18
  658. #define CORE_ADC5_PIN 19
  659. #define CORE_ADC6_PIN 20
  660. #define CORE_ADC7_PIN 21
  661. #define CORE_ADC8_PIN 22
  662. #define CORE_ADC9_PIN 23
  663. #define CORE_ADC10_PIN 24
  664. #define CORE_ADC11_PIN 25
  665. #define CORE_ADC12_PIN 26
  666. #define CORE_RXD0_PIN 0
  667. #define CORE_TXD0_PIN 1
  668. #define CORE_RXD1_PIN 9
  669. #define CORE_TXD1_PIN 10
  670. #define CORE_RXD2_PIN 7
  671. #define CORE_TXD2_PIN 8
  672. #define CORE_INT2_PIN 2
  673. #define CORE_INT3_PIN 3
  674. #define CORE_INT4_PIN 4
  675. #define CORE_INT5_PIN 5
  676. #define CORE_INT6_PIN 6
  677. #define CORE_INT7_PIN 7
  678. #define CORE_INT8_PIN 8
  679. #define CORE_INT9_PIN 9
  680. #define CORE_INT10_PIN 10
  681. #define CORE_INT11_PIN 11
  682. #define CORE_INT12_PIN 12
  683. #define CORE_INT13_PIN 13
  684. #define CORE_INT14_PIN 14
  685. #define CORE_INT15_PIN 15
  686. #define CORE_INT20_PIN 20
  687. #define CORE_INT21_PIN 21
  688. #define CORE_INT22_PIN 22
  689. #define CORE_INT23_PIN 23
  690. #endif
  691. #ifdef __cplusplus
  692. extern "C" {
  693. #endif
  694. void digitalWrite(uint8_t pin, uint8_t val);
  695. static inline void digitalWriteFast(uint8_t pin, uint8_t val) __attribute__((always_inline, unused));
  696. static inline void digitalWriteFast(uint8_t pin, uint8_t val)
  697. {
  698. if (__builtin_constant_p(pin)) {
  699. if (val) {
  700. if (pin == 0) {
  701. CORE_PIN0_PORTSET = CORE_PIN0_BITMASK;
  702. } else if (pin == 1) {
  703. CORE_PIN1_PORTSET = CORE_PIN1_BITMASK;
  704. } else if (pin == 2) {
  705. CORE_PIN2_PORTSET = CORE_PIN2_BITMASK;
  706. } else if (pin == 3) {
  707. CORE_PIN3_PORTSET = CORE_PIN3_BITMASK;
  708. } else if (pin == 4) {
  709. CORE_PIN4_PORTSET = CORE_PIN4_BITMASK;
  710. } else if (pin == 5) {
  711. CORE_PIN5_PORTSET = CORE_PIN5_BITMASK;
  712. } else if (pin == 6) {
  713. CORE_PIN6_PORTSET = CORE_PIN6_BITMASK;
  714. } else if (pin == 7) {
  715. CORE_PIN7_PORTSET = CORE_PIN7_BITMASK;
  716. } else if (pin == 8) {
  717. CORE_PIN8_PORTSET = CORE_PIN8_BITMASK;
  718. } else if (pin == 9) {
  719. CORE_PIN9_PORTSET = CORE_PIN9_BITMASK;
  720. } else if (pin == 10) {
  721. CORE_PIN10_PORTSET = CORE_PIN10_BITMASK;
  722. } else if (pin == 11) {
  723. CORE_PIN11_PORTSET = CORE_PIN11_BITMASK;
  724. } else if (pin == 12) {
  725. CORE_PIN12_PORTSET = CORE_PIN12_BITMASK;
  726. } else if (pin == 13) {
  727. CORE_PIN13_PORTSET = CORE_PIN13_BITMASK;
  728. } else if (pin == 14) {
  729. CORE_PIN14_PORTSET = CORE_PIN14_BITMASK;
  730. } else if (pin == 15) {
  731. CORE_PIN15_PORTSET = CORE_PIN15_BITMASK;
  732. } else if (pin == 16) {
  733. CORE_PIN16_PORTSET = CORE_PIN16_BITMASK;
  734. } else if (pin == 17) {
  735. CORE_PIN17_PORTSET = CORE_PIN17_BITMASK;
  736. } else if (pin == 18) {
  737. CORE_PIN18_PORTSET = CORE_PIN18_BITMASK;
  738. } else if (pin == 19) {
  739. CORE_PIN19_PORTSET = CORE_PIN19_BITMASK;
  740. } else if (pin == 20) {
  741. CORE_PIN20_PORTSET = CORE_PIN20_BITMASK;
  742. } else if (pin == 21) {
  743. CORE_PIN21_PORTSET = CORE_PIN21_BITMASK;
  744. } else if (pin == 22) {
  745. CORE_PIN22_PORTSET = CORE_PIN22_BITMASK;
  746. } else if (pin == 23) {
  747. CORE_PIN23_PORTSET = CORE_PIN23_BITMASK;
  748. } else if (pin == 24) {
  749. CORE_PIN24_PORTSET = CORE_PIN24_BITMASK;
  750. } else if (pin == 25) {
  751. CORE_PIN25_PORTSET = CORE_PIN25_BITMASK;
  752. } else if (pin == 26) {
  753. CORE_PIN26_PORTSET = CORE_PIN26_BITMASK;
  754. }
  755. #if defined(CORE_PIN27_PORTSET)
  756. else if (pin == 27) {
  757. CORE_PIN27_PORTSET = CORE_PIN27_BITMASK;
  758. } else if (pin == 28) {
  759. CORE_PIN28_PORTSET = CORE_PIN28_BITMASK;
  760. } else if (pin == 29) {
  761. CORE_PIN29_PORTSET = CORE_PIN29_BITMASK;
  762. } else if (pin == 30) {
  763. CORE_PIN30_PORTSET = CORE_PIN30_BITMASK;
  764. } else if (pin == 31) {
  765. CORE_PIN31_PORTSET = CORE_PIN31_BITMASK;
  766. } else if (pin == 32) {
  767. CORE_PIN32_PORTSET = CORE_PIN32_BITMASK;
  768. } else if (pin == 33) {
  769. CORE_PIN33_PORTSET = CORE_PIN33_BITMASK;
  770. }
  771. #endif
  772. } else {
  773. if (pin == 0) {
  774. CORE_PIN0_PORTCLEAR = CORE_PIN0_BITMASK;
  775. } else if (pin == 1) {
  776. CORE_PIN1_PORTCLEAR = CORE_PIN1_BITMASK;
  777. } else if (pin == 2) {
  778. CORE_PIN2_PORTCLEAR = CORE_PIN2_BITMASK;
  779. } else if (pin == 3) {
  780. CORE_PIN3_PORTCLEAR = CORE_PIN3_BITMASK;
  781. } else if (pin == 4) {
  782. CORE_PIN4_PORTCLEAR = CORE_PIN4_BITMASK;
  783. } else if (pin == 5) {
  784. CORE_PIN5_PORTCLEAR = CORE_PIN5_BITMASK;
  785. } else if (pin == 6) {
  786. CORE_PIN6_PORTCLEAR = CORE_PIN6_BITMASK;
  787. } else if (pin == 7) {
  788. CORE_PIN7_PORTCLEAR = CORE_PIN7_BITMASK;
  789. } else if (pin == 8) {
  790. CORE_PIN8_PORTCLEAR = CORE_PIN8_BITMASK;
  791. } else if (pin == 9) {
  792. CORE_PIN9_PORTCLEAR = CORE_PIN9_BITMASK;
  793. } else if (pin == 10) {
  794. CORE_PIN10_PORTCLEAR = CORE_PIN10_BITMASK;
  795. } else if (pin == 11) {
  796. CORE_PIN11_PORTCLEAR = CORE_PIN11_BITMASK;
  797. } else if (pin == 12) {
  798. CORE_PIN12_PORTCLEAR = CORE_PIN12_BITMASK;
  799. } else if (pin == 13) {
  800. CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK;
  801. } else if (pin == 14) {
  802. CORE_PIN14_PORTCLEAR = CORE_PIN14_BITMASK;
  803. } else if (pin == 15) {
  804. CORE_PIN15_PORTCLEAR = CORE_PIN15_BITMASK;
  805. } else if (pin == 16) {
  806. CORE_PIN16_PORTCLEAR = CORE_PIN16_BITMASK;
  807. } else if (pin == 17) {
  808. CORE_PIN17_PORTCLEAR = CORE_PIN17_BITMASK;
  809. } else if (pin == 18) {
  810. CORE_PIN18_PORTCLEAR = CORE_PIN18_BITMASK;
  811. } else if (pin == 19) {
  812. CORE_PIN19_PORTCLEAR = CORE_PIN19_BITMASK;
  813. } else if (pin == 20) {
  814. CORE_PIN20_PORTCLEAR = CORE_PIN20_BITMASK;
  815. } else if (pin == 21) {
  816. CORE_PIN21_PORTCLEAR = CORE_PIN21_BITMASK;
  817. } else if (pin == 22) {
  818. CORE_PIN22_PORTCLEAR = CORE_PIN22_BITMASK;
  819. } else if (pin == 23) {
  820. CORE_PIN23_PORTCLEAR = CORE_PIN23_BITMASK;
  821. } else if (pin == 24) {
  822. CORE_PIN24_PORTCLEAR = CORE_PIN24_BITMASK;
  823. } else if (pin == 25) {
  824. CORE_PIN25_PORTCLEAR = CORE_PIN25_BITMASK;
  825. } else if (pin == 26) {
  826. CORE_PIN26_PORTCLEAR = CORE_PIN26_BITMASK;
  827. }
  828. #if defined(CORE_PIN27_PORTCLEAR)
  829. else if (pin == 27) {
  830. CORE_PIN27_PORTCLEAR = CORE_PIN27_BITMASK;
  831. } else if (pin == 28) {
  832. CORE_PIN28_PORTCLEAR = CORE_PIN28_BITMASK;
  833. } else if (pin == 29) {
  834. CORE_PIN29_PORTCLEAR = CORE_PIN29_BITMASK;
  835. } else if (pin == 30) {
  836. CORE_PIN30_PORTCLEAR = CORE_PIN30_BITMASK;
  837. } else if (pin == 31) {
  838. CORE_PIN31_PORTCLEAR = CORE_PIN31_BITMASK;
  839. } else if (pin == 32) {
  840. CORE_PIN32_PORTCLEAR = CORE_PIN32_BITMASK;
  841. } else if (pin == 33) {
  842. CORE_PIN33_PORTCLEAR = CORE_PIN33_BITMASK;
  843. }
  844. #endif
  845. }
  846. } else {
  847. if (val) {
  848. *portSetRegister(pin) = digitalPinToBitMask(pin);
  849. } else {
  850. *portClearRegister(pin) = digitalPinToBitMask(pin);
  851. }
  852. }
  853. }
  854. uint8_t digitalRead(uint8_t pin);
  855. static inline uint8_t digitalReadFast(uint8_t pin) __attribute__((always_inline, unused));
  856. static inline uint8_t digitalReadFast(uint8_t pin)
  857. {
  858. if (__builtin_constant_p(pin)) {
  859. if (pin == 0) {
  860. return (CORE_PIN0_PINREG & CORE_PIN0_BITMASK) ? 1 : 0;
  861. } else if (pin == 1) {
  862. return (CORE_PIN1_PINREG & CORE_PIN1_BITMASK) ? 1 : 0;
  863. } else if (pin == 2) {
  864. return (CORE_PIN2_PINREG & CORE_PIN2_BITMASK) ? 1 : 0;
  865. } else if (pin == 3) {
  866. return (CORE_PIN3_PINREG & CORE_PIN3_BITMASK) ? 1 : 0;
  867. } else if (pin == 4) {
  868. return (CORE_PIN4_PINREG & CORE_PIN4_BITMASK) ? 1 : 0;
  869. } else if (pin == 5) {
  870. return (CORE_PIN5_PINREG & CORE_PIN5_BITMASK) ? 1 : 0;
  871. } else if (pin == 6) {
  872. return (CORE_PIN6_PINREG & CORE_PIN6_BITMASK) ? 1 : 0;
  873. } else if (pin == 7) {
  874. return (CORE_PIN7_PINREG & CORE_PIN7_BITMASK) ? 1 : 0;
  875. } else if (pin == 8) {
  876. return (CORE_PIN8_PINREG & CORE_PIN8_BITMASK) ? 1 : 0;
  877. } else if (pin == 9) {
  878. return (CORE_PIN9_PINREG & CORE_PIN9_BITMASK) ? 1 : 0;
  879. } else if (pin == 10) {
  880. return (CORE_PIN10_PINREG & CORE_PIN10_BITMASK) ? 1 : 0;
  881. } else if (pin == 11) {
  882. return (CORE_PIN11_PINREG & CORE_PIN11_BITMASK) ? 1 : 0;
  883. } else if (pin == 12) {
  884. return (CORE_PIN12_PINREG & CORE_PIN12_BITMASK) ? 1 : 0;
  885. } else if (pin == 13) {
  886. return (CORE_PIN13_PINREG & CORE_PIN13_BITMASK) ? 1 : 0;
  887. } else if (pin == 14) {
  888. return (CORE_PIN14_PINREG & CORE_PIN14_BITMASK) ? 1 : 0;
  889. } else if (pin == 15) {
  890. return (CORE_PIN15_PINREG & CORE_PIN15_BITMASK) ? 1 : 0;
  891. } else if (pin == 16) {
  892. return (CORE_PIN16_PINREG & CORE_PIN16_BITMASK) ? 1 : 0;
  893. } else if (pin == 17) {
  894. return (CORE_PIN17_PINREG & CORE_PIN17_BITMASK) ? 1 : 0;
  895. } else if (pin == 18) {
  896. return (CORE_PIN18_PINREG & CORE_PIN18_BITMASK) ? 1 : 0;
  897. } else if (pin == 19) {
  898. return (CORE_PIN19_PINREG & CORE_PIN19_BITMASK) ? 1 : 0;
  899. } else if (pin == 20) {
  900. return (CORE_PIN20_PINREG & CORE_PIN20_BITMASK) ? 1 : 0;
  901. } else if (pin == 21) {
  902. return (CORE_PIN21_PINREG & CORE_PIN21_BITMASK) ? 1 : 0;
  903. } else if (pin == 22) {
  904. return (CORE_PIN22_PINREG & CORE_PIN22_BITMASK) ? 1 : 0;
  905. } else if (pin == 23) {
  906. return (CORE_PIN23_PINREG & CORE_PIN23_BITMASK) ? 1 : 0;
  907. } else if (pin == 24) {
  908. return (CORE_PIN24_PINREG & CORE_PIN24_BITMASK) ? 1 : 0;
  909. } else if (pin == 25) {
  910. return (CORE_PIN25_PINREG & CORE_PIN25_BITMASK) ? 1 : 0;
  911. } else if (pin == 26) {
  912. return (CORE_PIN26_PINREG & CORE_PIN26_BITMASK) ? 1 : 0;
  913. }
  914. #if defined(CORE_PIN27_PINREG)
  915. else if (pin == 27) {
  916. return (CORE_PIN27_PINREG & CORE_PIN27_BITMASK) ? 1 : 0;
  917. } else if (pin == 28) {
  918. return (CORE_PIN28_PINREG & CORE_PIN28_BITMASK) ? 1 : 0;
  919. } else if (pin == 29) {
  920. return (CORE_PIN29_PINREG & CORE_PIN29_BITMASK) ? 1 : 0;
  921. } else if (pin == 30) {
  922. return (CORE_PIN30_PINREG & CORE_PIN30_BITMASK) ? 1 : 0;
  923. } else if (pin == 31) {
  924. return (CORE_PIN31_PINREG & CORE_PIN31_BITMASK) ? 1 : 0;
  925. } else if (pin == 32) {
  926. return (CORE_PIN32_PINREG & CORE_PIN32_BITMASK) ? 1 : 0;
  927. } else if (pin == 33) {
  928. return (CORE_PIN33_PINREG & CORE_PIN33_BITMASK) ? 1 : 0;
  929. }
  930. #endif
  931. else {
  932. return 0;
  933. }
  934. } else {
  935. #if defined(KINETISK)
  936. return *portInputRegister(pin);
  937. #else
  938. return (*portInputRegister(pin) & digitalPinToBitMask(pin)) ? 1 : 0;
  939. #endif
  940. }
  941. }
  942. void pinMode(uint8_t pin, uint8_t mode);
  943. void init_pins(void);
  944. void analogWrite(uint8_t pin, int val);
  945. void analogWriteRes(uint32_t bits);
  946. static inline void analogWriteResolution(uint32_t bits) { analogWriteRes(bits); }
  947. void analogWriteFrequency(uint8_t pin, float frequency);
  948. void analogWriteDAC0(int val);
  949. #ifdef __cplusplus
  950. void attachInterruptVector(IRQ_NUMBER_t irq, void (*function)(void));
  951. #else
  952. void attachInterruptVector(enum IRQ_NUMBER_t irq, void (*function)(void));
  953. #endif
  954. void attachInterrupt(uint8_t pin, void (*function)(void), int mode);
  955. void detachInterrupt(uint8_t pin);
  956. void _init_Teensyduino_internal_(void);
  957. int analogRead(uint8_t pin);
  958. void analogReference(uint8_t type);
  959. void analogReadRes(unsigned int bits);
  960. static inline void analogReadResolution(unsigned int bits) { analogReadRes(bits); }
  961. void analogReadAveraging(unsigned int num);
  962. void analog_init(void);
  963. #if defined(__MK20DX128__) || defined(__MK20DX256__)
  964. #define DEFAULT 0
  965. #define INTERNAL 2
  966. #define INTERNAL1V2 2
  967. #define INTERNAL1V1 2
  968. #define EXTERNAL 0
  969. #elif defined(__MKL26Z64__)
  970. #define DEFAULT 0
  971. #define INTERNAL 0
  972. #define EXTERNAL 1
  973. #endif
  974. int touchRead(uint8_t pin);
  975. static inline void shiftOut(uint8_t, uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
  976. extern void _shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value) __attribute__((noinline));
  977. extern void shiftOut_lsbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
  978. extern void shiftOut_msbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
  979. static inline void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value)
  980. {
  981. if (__builtin_constant_p(bitOrder)) {
  982. if (bitOrder == LSBFIRST) {
  983. shiftOut_lsbFirst(dataPin, clockPin, value);
  984. } else {
  985. shiftOut_msbFirst(dataPin, clockPin, value);
  986. }
  987. } else {
  988. _shiftOut(dataPin, clockPin, bitOrder, value);
  989. }
  990. }
  991. static inline uint8_t shiftIn(uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
  992. extern uint8_t _shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) __attribute__((noinline));
  993. extern uint8_t shiftIn_lsbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
  994. extern uint8_t shiftIn_msbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
  995. static inline uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
  996. {
  997. if (__builtin_constant_p(bitOrder)) {
  998. if (bitOrder == LSBFIRST) {
  999. return shiftIn_lsbFirst(dataPin, clockPin);
  1000. } else {
  1001. return shiftIn_msbFirst(dataPin, clockPin);
  1002. }
  1003. } else {
  1004. return _shiftIn(dataPin, clockPin, bitOrder);
  1005. }
  1006. }
  1007. void _reboot_Teensyduino_(void) __attribute__((noreturn));
  1008. void _restart_Teensyduino_(void) __attribute__((noreturn));
  1009. void yield(void);
  1010. void delay(uint32_t msec);
  1011. extern volatile uint32_t systick_millis_count;
  1012. static inline uint32_t millis(void) __attribute__((always_inline, unused));
  1013. static inline uint32_t millis(void)
  1014. {
  1015. return systick_millis_count; // single aligned 32 bit is atomic;
  1016. }
  1017. uint32_t micros(void);
  1018. static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused));
  1019. static inline void delayMicroseconds(uint32_t usec)
  1020. {
  1021. #if F_CPU == 168000000
  1022. uint32_t n = usec * 56;
  1023. #elif F_CPU == 144000000
  1024. uint32_t n = usec * 48;
  1025. #elif F_CPU == 120000000
  1026. uint32_t n = usec * 40;
  1027. #elif F_CPU == 96000000
  1028. uint32_t n = usec << 5;
  1029. #elif F_CPU == 72000000
  1030. uint32_t n = usec * 24;
  1031. #elif F_CPU == 48000000
  1032. uint32_t n = usec << 4;
  1033. #elif F_CPU == 24000000
  1034. uint32_t n = usec << 3;
  1035. #elif F_CPU == 16000000
  1036. uint32_t n = usec << 2;
  1037. #elif F_CPU == 8000000
  1038. uint32_t n = usec << 1;
  1039. #elif F_CPU == 4000000
  1040. uint32_t n = usec;
  1041. #elif F_CPU == 2000000
  1042. uint32_t n = usec >> 1;
  1043. #endif
  1044. // changed because a delay of 1 micro Sec @ 2MHz will be 0
  1045. if (n == 0) return;
  1046. __asm__ volatile(
  1047. "L_%=_delayMicroseconds:" "\n\t"
  1048. #if F_CPU < 24000000
  1049. "nop" "\n\t"
  1050. #endif
  1051. #ifdef KINETISL
  1052. "sub %0, #1" "\n\t"
  1053. #else
  1054. "subs %0, #1" "\n\t"
  1055. #endif
  1056. "bne L_%=_delayMicroseconds" "\n"
  1057. : "+r" (n) :
  1058. );
  1059. }
  1060. #ifdef __cplusplus
  1061. }
  1062. #endif
  1063. #ifdef __cplusplus
  1064. extern "C" {
  1065. #endif
  1066. unsigned long rtc_get(void);
  1067. void rtc_set(unsigned long t);
  1068. void rtc_compensate(int adjust);
  1069. #ifdef __cplusplus
  1070. }
  1071. class teensy3_clock_class
  1072. {
  1073. public:
  1074. static unsigned long get(void) __attribute__((always_inline)) { return rtc_get(); }
  1075. static void set(unsigned long t) __attribute__((always_inline)) { rtc_set(t); }
  1076. static void compensate(int adj) __attribute__((always_inline)) { rtc_compensate(adj); }
  1077. };
  1078. extern teensy3_clock_class Teensy3Clock;
  1079. #endif
  1080. #endif