PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

2454 行
78KB

  1. #ifndef _core_pins_h_
  2. #define _core_pins_h_
  3. #include <avr/io.h>
  4. #if (GCC_VERSION >= 40300) && (GCC_VERSION < 40302)
  5. #error "Buggy GCC 4.3.0 compiler, please upgrade!"
  6. #endif
  7. // This will speed up digitalWrite slightly, but it
  8. // adds to your code size. However, if you don't
  9. // have many digitalWrites, or most are compile time
  10. // constant inputs, then this might be worthwhile
  11. //#define DIGITAL_WRITE_EXPENSIVE_INLINE_OPTIMIZATION
  12. // This removes checking in digitalWrite for pin numbers
  13. // beyond the maximum number of pins. Your program
  14. // WILL CRASH is digitalWrite is called with a pin number
  15. // too large, when this is enabled. However, if you don't
  16. // make such mistakes, you'll get a minor speedup.
  17. //#define DIGITAL_WRITE_RISKY_OMIT_OVERFLOW_CHECK
  18. #define HIGH 0x1
  19. #define LOW 0x0
  20. #define INPUT 0x0
  21. #define OUTPUT 0x1
  22. #define INPUT_PULLUP 0x2
  23. #define LSBFIRST 0
  24. #define MSBFIRST 1
  25. #ifndef _BV
  26. #define _BV(n) (1<<(n))
  27. #endif
  28. ////////////////////////////////////
  29. // Teensy 2.0
  30. ////////////////////////////////////
  31. #if defined(__AVR_ATmega32U4__)
  32. #define CORE_NUM_TOTAL_PINS 25
  33. #define CORE_NUM_DIGITAL 13
  34. #define CORE_NUM_ANALOG 12
  35. #define CORE_NUM_PWM 7
  36. #define CORE_NUM_INTERRUPT 4
  37. #define PIN_B0 0
  38. #define PIN_B1 1
  39. #define PIN_B2 2
  40. #define PIN_B3 3
  41. #define PIN_B7 4
  42. #define PIN_D0 5
  43. #define PIN_D1 6
  44. #define PIN_D2 7
  45. #define PIN_D3 8
  46. #define PIN_C6 9
  47. #define PIN_C7 10
  48. #define PIN_D6 11
  49. #define PIN_D7 12
  50. #define PIN_B4 13
  51. #define PIN_B5 14
  52. #define PIN_B6 15
  53. #define PIN_F7 16
  54. #define PIN_F6 17
  55. #define PIN_F5 18
  56. #define PIN_F4 19
  57. #define PIN_F1 20
  58. #define PIN_F0 21
  59. #define PIN_D4 22
  60. #define PIN_D5 23
  61. #define PIN_E6 24
  62. #define CORE_PIN0_BIT 0
  63. #define CORE_PIN1_BIT 1
  64. #define CORE_PIN2_BIT 2
  65. #define CORE_PIN3_BIT 3
  66. #define CORE_PIN4_BIT 7
  67. #define CORE_PIN5_BIT 0
  68. #define CORE_PIN6_BIT 1
  69. #define CORE_PIN7_BIT 2
  70. #define CORE_PIN8_BIT 3
  71. #define CORE_PIN9_BIT 6
  72. #define CORE_PIN10_BIT 7
  73. #define CORE_PIN11_BIT 6
  74. #define CORE_PIN12_BIT 7
  75. #define CORE_PIN13_BIT 4
  76. #define CORE_PIN14_BIT 5
  77. #define CORE_PIN15_BIT 6
  78. #define CORE_PIN16_BIT 7
  79. #define CORE_PIN17_BIT 6
  80. #define CORE_PIN18_BIT 5
  81. #define CORE_PIN19_BIT 4
  82. #define CORE_PIN20_BIT 1
  83. #define CORE_PIN21_BIT 0
  84. #define CORE_PIN22_BIT 4
  85. #define CORE_PIN23_BIT 5
  86. #define CORE_PIN24_BIT 6
  87. #define CORE_PIN0_BITMASK _BV(CORE_PIN0_BIT)
  88. #define CORE_PIN1_BITMASK _BV(CORE_PIN1_BIT)
  89. #define CORE_PIN2_BITMASK _BV(CORE_PIN2_BIT)
  90. #define CORE_PIN3_BITMASK _BV(CORE_PIN3_BIT)
  91. #define CORE_PIN4_BITMASK _BV(CORE_PIN4_BIT)
  92. #define CORE_PIN5_BITMASK _BV(CORE_PIN5_BIT)
  93. #define CORE_PIN6_BITMASK _BV(CORE_PIN6_BIT)
  94. #define CORE_PIN7_BITMASK _BV(CORE_PIN7_BIT)
  95. #define CORE_PIN8_BITMASK _BV(CORE_PIN8_BIT)
  96. #define CORE_PIN9_BITMASK _BV(CORE_PIN9_BIT)
  97. #define CORE_PIN10_BITMASK _BV(CORE_PIN10_BIT)
  98. #define CORE_PIN11_BITMASK _BV(CORE_PIN11_BIT)
  99. #define CORE_PIN12_BITMASK _BV(CORE_PIN12_BIT)
  100. #define CORE_PIN13_BITMASK _BV(CORE_PIN13_BIT)
  101. #define CORE_PIN14_BITMASK _BV(CORE_PIN14_BIT)
  102. #define CORE_PIN15_BITMASK _BV(CORE_PIN15_BIT)
  103. #define CORE_PIN16_BITMASK _BV(CORE_PIN16_BIT)
  104. #define CORE_PIN17_BITMASK _BV(CORE_PIN17_BIT)
  105. #define CORE_PIN18_BITMASK _BV(CORE_PIN18_BIT)
  106. #define CORE_PIN19_BITMASK _BV(CORE_PIN19_BIT)
  107. #define CORE_PIN20_BITMASK _BV(CORE_PIN20_BIT)
  108. #define CORE_PIN21_BITMASK _BV(CORE_PIN21_BIT)
  109. #define CORE_PIN22_BITMASK _BV(CORE_PIN22_BIT)
  110. #define CORE_PIN23_BITMASK _BV(CORE_PIN23_BIT)
  111. #define CORE_PIN24_BITMASK _BV(CORE_PIN24_BIT)
  112. #define CORE_PIN0_PORTREG PORTB
  113. #define CORE_PIN1_PORTREG PORTB
  114. #define CORE_PIN2_PORTREG PORTB
  115. #define CORE_PIN3_PORTREG PORTB
  116. #define CORE_PIN4_PORTREG PORTB
  117. #define CORE_PIN5_PORTREG PORTD
  118. #define CORE_PIN6_PORTREG PORTD
  119. #define CORE_PIN7_PORTREG PORTD
  120. #define CORE_PIN8_PORTREG PORTD
  121. #define CORE_PIN9_PORTREG PORTC
  122. #define CORE_PIN10_PORTREG PORTC
  123. #define CORE_PIN11_PORTREG PORTD
  124. #define CORE_PIN12_PORTREG PORTD
  125. #define CORE_PIN13_PORTREG PORTB
  126. #define CORE_PIN14_PORTREG PORTB
  127. #define CORE_PIN15_PORTREG PORTB
  128. #define CORE_PIN16_PORTREG PORTF
  129. #define CORE_PIN17_PORTREG PORTF
  130. #define CORE_PIN18_PORTREG PORTF
  131. #define CORE_PIN19_PORTREG PORTF
  132. #define CORE_PIN20_PORTREG PORTF
  133. #define CORE_PIN21_PORTREG PORTF
  134. #define CORE_PIN22_PORTREG PORTD
  135. #define CORE_PIN23_PORTREG PORTD
  136. #define CORE_PIN24_PORTREG PORTE
  137. #define CORE_PIN0_DDRREG DDRB
  138. #define CORE_PIN1_DDRREG DDRB
  139. #define CORE_PIN2_DDRREG DDRB
  140. #define CORE_PIN3_DDRREG DDRB
  141. #define CORE_PIN4_DDRREG DDRB
  142. #define CORE_PIN5_DDRREG DDRD
  143. #define CORE_PIN6_DDRREG DDRD
  144. #define CORE_PIN7_DDRREG DDRD
  145. #define CORE_PIN8_DDRREG DDRD
  146. #define CORE_PIN9_DDRREG DDRC
  147. #define CORE_PIN10_DDRREG DDRC
  148. #define CORE_PIN11_DDRREG DDRD
  149. #define CORE_PIN12_DDRREG DDRD
  150. #define CORE_PIN13_DDRREG DDRB
  151. #define CORE_PIN14_DDRREG DDRB
  152. #define CORE_PIN15_DDRREG DDRB
  153. #define CORE_PIN16_DDRREG DDRF
  154. #define CORE_PIN17_DDRREG DDRF
  155. #define CORE_PIN18_DDRREG DDRF
  156. #define CORE_PIN19_DDRREG DDRF
  157. #define CORE_PIN20_DDRREG DDRF
  158. #define CORE_PIN21_DDRREG DDRF
  159. #define CORE_PIN22_DDRREG DDRD
  160. #define CORE_PIN23_DDRREG DDRD
  161. #define CORE_PIN24_DDRREG DDRE
  162. #define CORE_PIN0_PINREG PINB
  163. #define CORE_PIN1_PINREG PINB
  164. #define CORE_PIN2_PINREG PINB
  165. #define CORE_PIN3_PINREG PINB
  166. #define CORE_PIN4_PINREG PINB
  167. #define CORE_PIN5_PINREG PIND
  168. #define CORE_PIN6_PINREG PIND
  169. #define CORE_PIN7_PINREG PIND
  170. #define CORE_PIN8_PINREG PIND
  171. #define CORE_PIN9_PINREG PINC
  172. #define CORE_PIN10_PINREG PINC
  173. #define CORE_PIN11_PINREG PIND
  174. #define CORE_PIN12_PINREG PIND
  175. #define CORE_PIN13_PINREG PINB
  176. #define CORE_PIN14_PINREG PINB
  177. #define CORE_PIN15_PINREG PINB
  178. #define CORE_PIN16_PINREG PINF
  179. #define CORE_PIN17_PINREG PINF
  180. #define CORE_PIN18_PINREG PINF
  181. #define CORE_PIN19_PINREG PINF
  182. #define CORE_PIN20_PINREG PINF
  183. #define CORE_PIN21_PINREG PINF
  184. #define CORE_PIN22_PINREG PIND
  185. #define CORE_PIN23_PINREG PIND
  186. #define CORE_PIN24_PINREG PINE
  187. #define CORE_ADC0_PIN PIN_F0
  188. #define CORE_ADC1_PIN PIN_F1
  189. #define CORE_ADC4_PIN PIN_F4
  190. #define CORE_ADC5_PIN PIN_F5
  191. #define CORE_ADC6_PIN PIN_F6
  192. #define CORE_ADC7_PIN PIN_F7
  193. #define CORE_ADC8_PIN PIN_D4
  194. #define CORE_ADC9_PIN PIN_D6
  195. #define CORE_ADC10_PIN PIN_D7
  196. #define CORE_ADC11_PIN PIN_B4
  197. #define CORE_ADC12_PIN PIN_B5
  198. #define CORE_ADC13_PIN PIN_B6
  199. #define CORE_RXD1_PIN PIN_D2
  200. #define CORE_TXD1_PIN PIN_D3
  201. #define CORE_XCK1_PIN PIN_D5
  202. #define CORE_SDA0_PIN PIN_D1
  203. #define CORE_SCL0_PIN PIN_D0
  204. #define CORE_INT0_PIN PIN_D0
  205. #define CORE_INT1_PIN PIN_D1
  206. #define CORE_INT2_PIN PIN_D2
  207. #define CORE_INT3_PIN PIN_D3
  208. #define CORE_SS0_PIN PIN_B0
  209. #define CORE_MOSI0_PIN PIN_B2
  210. #define CORE_MISO0_PIN PIN_B3
  211. #define CORE_SCLK0_PIN PIN_B1
  212. #define CORE_T0_PIN PIN_D7
  213. #define CORE_T1_PIN PIN_D6
  214. #define CORE_ICP1_PIN PIN_D4
  215. #define CORE_ICP3_PIN PIN_C7
  216. #define CORE_OC0A_PIN PIN_B7
  217. #define CORE_OC0B_PIN PIN_D0
  218. #define CORE_OC1A_PIN PIN_B5
  219. #define CORE_OC1B_PIN PIN_B6
  220. #define CORE_OC1C_PIN PIN_B7
  221. #define CORE_OC3A_PIN PIN_C6
  222. #define CORE_OC4A_PIN PIN_C7
  223. #define CORE_OC4AN_PIN PIN_C6
  224. #define CORE_OC4B_PIN PIN_B6
  225. #define CORE_OC4BN_PIN PIN_B5
  226. #define CORE_OC4D_PIN PIN_D7
  227. #define CORE_OC4DN_PIN PIN_D6
  228. #define CORE_PCINT0_PIN PIN_B0
  229. #define CORE_PCINT1_PIN PIN_B1
  230. #define CORE_PCINT2_PIN PIN_B2
  231. #define CORE_PCINT3_PIN PIN_B3
  232. #define CORE_PCINT4_PIN PIN_B4
  233. #define CORE_PCINT5_PIN PIN_B5
  234. #define CORE_PCINT6_PIN PIN_B6
  235. #define CORE_PCINT7_PIN PIN_B7
  236. #define CORE_LED0_PIN PIN_D6
  237. #define CORE_PWM0_PIN CORE_OC1C_PIN // B7 4
  238. #define CORE_PWM1_PIN CORE_OC0B_PIN // D0 5
  239. #define CORE_PWM2_PIN CORE_OC3A_PIN // C6 9
  240. #define CORE_PWM3_PIN CORE_OC4A_PIN // C7 10
  241. #define CORE_PWM4_PIN CORE_OC4D_PIN // D7 12
  242. #define CORE_PWM5_PIN CORE_OC1A_PIN // B5 14
  243. #define CORE_PWM6_PIN CORE_OC1B_PIN // B6 15
  244. #define CORE_ANALOG0_PIN PIN_F0 // 21 ADC0
  245. #define CORE_ANALOG1_PIN PIN_F1 // 20 ADC1
  246. #define CORE_ANALOG2_PIN PIN_F4 // 19 ADC4
  247. #define CORE_ANALOG3_PIN PIN_F5 // 18 ADC5
  248. #define CORE_ANALOG4_PIN PIN_F6 // 17 ADC6
  249. #define CORE_ANALOG5_PIN PIN_F7 // 16 ADC7
  250. #define CORE_ANALOG6_PIN PIN_B6 // 15 ADC13
  251. #define CORE_ANALOG7_PIN PIN_B5 // 14 ADC12
  252. #define CORE_ANALOG8_PIN PIN_B4 // 13 ADC11
  253. #define CORE_ANALOG9_PIN PIN_D7 // 12 ADC10
  254. #define CORE_ANALOG10_PIN PIN_D6 // 11 ADC9
  255. #define CORE_ANALOG11_PIN PIN_D4 // 22 ADC8
  256. ////////////////////////////////////
  257. // Teensy 1.0
  258. ////////////////////////////////////
  259. #elif defined(__AVR_AT90USB162__)
  260. #define CORE_NUM_TOTAL_PINS 21
  261. #define CORE_NUM_DIGITAL 21
  262. #define CORE_NUM_ANALOG 0
  263. #define CORE_NUM_PWM 4
  264. #define CORE_NUM_INTERRUPT 8
  265. #define PIN_D0 0
  266. #define PIN_D1 1
  267. #define PIN_D2 2
  268. #define PIN_D3 3
  269. #define PIN_D4 4
  270. #define PIN_D5 5
  271. #define PIN_D6 6
  272. #define PIN_D7 7
  273. #define PIN_SS 8
  274. #define PIN_SCLK 9
  275. #define PIN_MOSI 10
  276. #define PIN_MISO 11
  277. #define PIN_B0 8
  278. #define PIN_B1 9
  279. #define PIN_B2 10
  280. #define PIN_B3 11
  281. #define PIN_B4 12
  282. #define PIN_B5 13
  283. #define PIN_B6 14
  284. #define PIN_B7 15
  285. #define PIN_C7 16
  286. #define PIN_C6 17
  287. #define PIN_C5 18
  288. #define PIN_C4 19
  289. #define PIN_C2 20
  290. #define CORE_PIN0_BIT 0
  291. #define CORE_PIN1_BIT 1
  292. #define CORE_PIN2_BIT 2
  293. #define CORE_PIN3_BIT 3
  294. #define CORE_PIN4_BIT 4
  295. #define CORE_PIN5_BIT 5
  296. #define CORE_PIN6_BIT 6
  297. #define CORE_PIN7_BIT 7
  298. #define CORE_PIN8_BIT 0
  299. #define CORE_PIN9_BIT 1
  300. #define CORE_PIN10_BIT 2
  301. #define CORE_PIN11_BIT 3
  302. #define CORE_PIN12_BIT 4
  303. #define CORE_PIN13_BIT 5
  304. #define CORE_PIN14_BIT 6
  305. #define CORE_PIN15_BIT 7
  306. #define CORE_PIN16_BIT 7
  307. #define CORE_PIN17_BIT 6
  308. #define CORE_PIN18_BIT 5
  309. #define CORE_PIN19_BIT 4
  310. #define CORE_PIN20_BIT 2
  311. #define CORE_PIN0_BITMASK _BV(CORE_PIN0_BIT)
  312. #define CORE_PIN1_BITMASK _BV(CORE_PIN1_BIT)
  313. #define CORE_PIN2_BITMASK _BV(CORE_PIN2_BIT)
  314. #define CORE_PIN3_BITMASK _BV(CORE_PIN3_BIT)
  315. #define CORE_PIN4_BITMASK _BV(CORE_PIN4_BIT)
  316. #define CORE_PIN5_BITMASK _BV(CORE_PIN5_BIT)
  317. #define CORE_PIN6_BITMASK _BV(CORE_PIN6_BIT)
  318. #define CORE_PIN7_BITMASK _BV(CORE_PIN7_BIT)
  319. #define CORE_PIN8_BITMASK _BV(CORE_PIN8_BIT)
  320. #define CORE_PIN9_BITMASK _BV(CORE_PIN9_BIT)
  321. #define CORE_PIN10_BITMASK _BV(CORE_PIN10_BIT)
  322. #define CORE_PIN11_BITMASK _BV(CORE_PIN11_BIT)
  323. #define CORE_PIN12_BITMASK _BV(CORE_PIN12_BIT)
  324. #define CORE_PIN13_BITMASK _BV(CORE_PIN13_BIT)
  325. #define CORE_PIN14_BITMASK _BV(CORE_PIN14_BIT)
  326. #define CORE_PIN15_BITMASK _BV(CORE_PIN15_BIT)
  327. #define CORE_PIN16_BITMASK _BV(CORE_PIN16_BIT)
  328. #define CORE_PIN17_BITMASK _BV(CORE_PIN17_BIT)
  329. #define CORE_PIN18_BITMASK _BV(CORE_PIN18_BIT)
  330. #define CORE_PIN19_BITMASK _BV(CORE_PIN19_BIT)
  331. #define CORE_PIN20_BITMASK _BV(CORE_PIN20_BIT)
  332. #define CORE_PIN0_PORTREG PORTD
  333. #define CORE_PIN1_PORTREG PORTD
  334. #define CORE_PIN2_PORTREG PORTD
  335. #define CORE_PIN3_PORTREG PORTD
  336. #define CORE_PIN4_PORTREG PORTD
  337. #define CORE_PIN5_PORTREG PORTD
  338. #define CORE_PIN6_PORTREG PORTD
  339. #define CORE_PIN7_PORTREG PORTD
  340. #define CORE_PIN8_PORTREG PORTB
  341. #define CORE_PIN9_PORTREG PORTB
  342. #define CORE_PIN10_PORTREG PORTB
  343. #define CORE_PIN11_PORTREG PORTB
  344. #define CORE_PIN12_PORTREG PORTB
  345. #define CORE_PIN13_PORTREG PORTB
  346. #define CORE_PIN14_PORTREG PORTB
  347. #define CORE_PIN15_PORTREG PORTB
  348. #define CORE_PIN16_PORTREG PORTC
  349. #define CORE_PIN17_PORTREG PORTC
  350. #define CORE_PIN18_PORTREG PORTC
  351. #define CORE_PIN19_PORTREG PORTC
  352. #define CORE_PIN20_PORTREG PORTC
  353. #define CORE_PIN0_DDRREG DDRD
  354. #define CORE_PIN1_DDRREG DDRD
  355. #define CORE_PIN2_DDRREG DDRD
  356. #define CORE_PIN3_DDRREG DDRD
  357. #define CORE_PIN4_DDRREG DDRD
  358. #define CORE_PIN5_DDRREG DDRD
  359. #define CORE_PIN6_DDRREG DDRD
  360. #define CORE_PIN7_DDRREG DDRD
  361. #define CORE_PIN8_DDRREG DDRB
  362. #define CORE_PIN9_DDRREG DDRB
  363. #define CORE_PIN10_DDRREG DDRB
  364. #define CORE_PIN11_DDRREG DDRB
  365. #define CORE_PIN12_DDRREG DDRB
  366. #define CORE_PIN13_DDRREG DDRB
  367. #define CORE_PIN14_DDRREG DDRB
  368. #define CORE_PIN15_DDRREG DDRB
  369. #define CORE_PIN16_DDRREG DDRC
  370. #define CORE_PIN17_DDRREG DDRC
  371. #define CORE_PIN18_DDRREG DDRC
  372. #define CORE_PIN19_DDRREG DDRC
  373. #define CORE_PIN20_DDRREG DDRC
  374. #define CORE_PIN0_PINREG PIND
  375. #define CORE_PIN1_PINREG PIND
  376. #define CORE_PIN2_PINREG PIND
  377. #define CORE_PIN3_PINREG PIND
  378. #define CORE_PIN4_PINREG PIND
  379. #define CORE_PIN5_PINREG PIND
  380. #define CORE_PIN6_PINREG PIND
  381. #define CORE_PIN7_PINREG PIND
  382. #define CORE_PIN8_PINREG PINB
  383. #define CORE_PIN9_PINREG PINB
  384. #define CORE_PIN10_PINREG PINB
  385. #define CORE_PIN11_PINREG PINB
  386. #define CORE_PIN12_PINREG PINB
  387. #define CORE_PIN13_PINREG PINB
  388. #define CORE_PIN14_PINREG PINB
  389. #define CORE_PIN15_PINREG PINB
  390. #define CORE_PIN16_PINREG PINC
  391. #define CORE_PIN17_PINREG PINC
  392. #define CORE_PIN18_PINREG PINC
  393. #define CORE_PIN19_PINREG PINC
  394. #define CORE_PIN20_PINREG PINC
  395. #define CORE_T1_PIN PIN_B4
  396. #define CORE_ICP1_PIN PIN_C7
  397. #define CORE_OC0A_PIN PIN_B7
  398. #define CORE_OC0B_PIN PIN_D0
  399. #define CORE_OC1A_PIN PIN_C6
  400. #define CORE_OC1B_PIN PIN_C5
  401. #define CORE_OC1C_PIN PIN_B7
  402. #define CORE_RXD1_PIN PIN_D2
  403. #define CORE_TXD1_PIN PIN_D3
  404. #define CORE_XCK1_PIN PIN_D5
  405. #define CORE_INT0_PIN PIN_D0
  406. #define CORE_INT1_PIN PIN_D1
  407. #define CORE_INT2_PIN PIN_D2
  408. #define CORE_INT3_PIN PIN_D3
  409. #define CORE_INT4_PIN PIN_C2
  410. #define CORE_INT5_PIN PIN_D4
  411. #define CORE_INT6_PIN PIN_D6
  412. #define CORE_INT7_PIN PIN_D7
  413. #define CORE_SS0_PIN PIN_B0
  414. #define CORE_MOSI0_PIN PIN_B2
  415. #define CORE_MISO0_PIN PIN_B3
  416. #define CORE_SCLK0_PIN PIN_B1
  417. #define CORE_AIN0_PIN PIN_D1
  418. #define CORE_AIN1_PIN PIN_D2
  419. #define CORE_PCINT0_PIN PIN_B0
  420. #define CORE_PCINT1_PIN PIN_B1
  421. #define CORE_PCINT2_PIN PIN_B2
  422. #define CORE_PCINT3_PIN PIN_B3
  423. #define CORE_PCINT4_PIN PIN_B4
  424. #define CORE_PCINT5_PIN PIN_B5
  425. #define CORE_PCINT6_PIN PIN_B6
  426. #define CORE_PCINT7_PIN PIN_B7
  427. #define CORE_PCINT8_PIN PIN_C6
  428. #define CORE_PCINT9_PIN PIN_C5
  429. #define CORE_PCINT10_PIN PIN_C4
  430. #define CORE_PCINT11_PIN PIN_C2
  431. #define CORE_PCINT12_PIN PIN_D5
  432. #define CORE_LED0_PIN PIN_D6
  433. #define CORE_PWM0_PIN CORE_OC0B_PIN // D0, 0
  434. #define CORE_PWM1_PIN CORE_OC1C_PIN // B7, 15
  435. #define CORE_PWM2_PIN CORE_OC1A_PIN // C6, 17
  436. #define CORE_PWM3_PIN CORE_OC1B_PIN // C5, 18
  437. ////////////////////////////////////
  438. // Teensy++ 1.0 & 2.0
  439. ////////////////////////////////////
  440. #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  441. #define CORE_NUM_TOTAL_PINS 46
  442. #define CORE_NUM_DIGITAL 38
  443. #define CORE_NUM_ANALOG 8
  444. #define CORE_NUM_PWM 9
  445. #define CORE_NUM_INTERRUPT 8
  446. #define PIN_D0 0
  447. #define PIN_D1 1
  448. #define PIN_D2 2
  449. #define PIN_D3 3
  450. #define PIN_D4 4
  451. #define PIN_D5 5
  452. #define PIN_D6 6
  453. #define PIN_D7 7
  454. #define PIN_E0 8
  455. #define PIN_E1 9
  456. #define PIN_C0 10
  457. #define PIN_C1 11
  458. #define PIN_C2 12
  459. #define PIN_C3 13
  460. #define PIN_C4 14
  461. #define PIN_C5 15
  462. #define PIN_C6 16
  463. #define PIN_C7 17
  464. #define PIN_E6 18
  465. #define PIN_E7 19
  466. #define PIN_SS 20
  467. #define PIN_SCLK 21
  468. #define PIN_MOSI 22
  469. #define PIN_MISO 23
  470. #define PIN_B0 20
  471. #define PIN_B1 21
  472. #define PIN_B2 22
  473. #define PIN_B3 23
  474. #define PIN_B4 24
  475. #define PIN_B5 25
  476. #define PIN_B6 26
  477. #define PIN_B7 27
  478. #define PIN_A0 28
  479. #define PIN_A1 29
  480. #define PIN_A2 30
  481. #define PIN_A3 31
  482. #define PIN_A4 32
  483. #define PIN_A5 33
  484. #define PIN_A6 34
  485. #define PIN_A7 35
  486. #define PIN_E4 36
  487. #define PIN_E5 37
  488. #define PIN_F0 38
  489. #define PIN_F1 39
  490. #define PIN_F2 40
  491. #define PIN_F3 41
  492. #define PIN_F4 42
  493. #define PIN_F5 43
  494. #define PIN_F6 44
  495. #define PIN_F7 45
  496. #define CORE_PIN0_BIT 0
  497. #define CORE_PIN1_BIT 1
  498. #define CORE_PIN2_BIT 2
  499. #define CORE_PIN3_BIT 3
  500. #define CORE_PIN4_BIT 4
  501. #define CORE_PIN5_BIT 5
  502. #define CORE_PIN6_BIT 6
  503. #define CORE_PIN7_BIT 7
  504. #define CORE_PIN8_BIT 0
  505. #define CORE_PIN9_BIT 1
  506. #define CORE_PIN10_BIT 0
  507. #define CORE_PIN11_BIT 1
  508. #define CORE_PIN12_BIT 2
  509. #define CORE_PIN13_BIT 3
  510. #define CORE_PIN14_BIT 4
  511. #define CORE_PIN15_BIT 5
  512. #define CORE_PIN16_BIT 6
  513. #define CORE_PIN17_BIT 7
  514. #define CORE_PIN18_BIT 6
  515. #define CORE_PIN19_BIT 7
  516. #define CORE_PIN20_BIT 0
  517. #define CORE_PIN21_BIT 1
  518. #define CORE_PIN22_BIT 2
  519. #define CORE_PIN23_BIT 3
  520. #define CORE_PIN24_BIT 4
  521. #define CORE_PIN25_BIT 5
  522. #define CORE_PIN26_BIT 6
  523. #define CORE_PIN27_BIT 7
  524. #define CORE_PIN28_BIT 0
  525. #define CORE_PIN29_BIT 1
  526. #define CORE_PIN30_BIT 2
  527. #define CORE_PIN31_BIT 3
  528. #define CORE_PIN32_BIT 4
  529. #define CORE_PIN33_BIT 5
  530. #define CORE_PIN34_BIT 6
  531. #define CORE_PIN35_BIT 7
  532. #define CORE_PIN36_BIT 4
  533. #define CORE_PIN37_BIT 5
  534. #define CORE_PIN38_BIT 0
  535. #define CORE_PIN39_BIT 1
  536. #define CORE_PIN40_BIT 2
  537. #define CORE_PIN41_BIT 3
  538. #define CORE_PIN42_BIT 4
  539. #define CORE_PIN43_BIT 5
  540. #define CORE_PIN44_BIT 6
  541. #define CORE_PIN45_BIT 7
  542. #define CORE_PIN0_BITMASK _BV(CORE_PIN0_BIT)
  543. #define CORE_PIN1_BITMASK _BV(CORE_PIN1_BIT)
  544. #define CORE_PIN2_BITMASK _BV(CORE_PIN2_BIT)
  545. #define CORE_PIN3_BITMASK _BV(CORE_PIN3_BIT)
  546. #define CORE_PIN4_BITMASK _BV(CORE_PIN4_BIT)
  547. #define CORE_PIN5_BITMASK _BV(CORE_PIN5_BIT)
  548. #define CORE_PIN6_BITMASK _BV(CORE_PIN6_BIT)
  549. #define CORE_PIN7_BITMASK _BV(CORE_PIN7_BIT)
  550. #define CORE_PIN8_BITMASK _BV(CORE_PIN8_BIT)
  551. #define CORE_PIN9_BITMASK _BV(CORE_PIN9_BIT)
  552. #define CORE_PIN10_BITMASK _BV(CORE_PIN10_BIT)
  553. #define CORE_PIN11_BITMASK _BV(CORE_PIN11_BIT)
  554. #define CORE_PIN12_BITMASK _BV(CORE_PIN12_BIT)
  555. #define CORE_PIN13_BITMASK _BV(CORE_PIN13_BIT)
  556. #define CORE_PIN14_BITMASK _BV(CORE_PIN14_BIT)
  557. #define CORE_PIN15_BITMASK _BV(CORE_PIN15_BIT)
  558. #define CORE_PIN16_BITMASK _BV(CORE_PIN16_BIT)
  559. #define CORE_PIN17_BITMASK _BV(CORE_PIN17_BIT)
  560. #define CORE_PIN18_BITMASK _BV(CORE_PIN18_BIT)
  561. #define CORE_PIN19_BITMASK _BV(CORE_PIN19_BIT)
  562. #define CORE_PIN20_BITMASK _BV(CORE_PIN20_BIT)
  563. #define CORE_PIN21_BITMASK _BV(CORE_PIN21_BIT)
  564. #define CORE_PIN22_BITMASK _BV(CORE_PIN22_BIT)
  565. #define CORE_PIN23_BITMASK _BV(CORE_PIN23_BIT)
  566. #define CORE_PIN24_BITMASK _BV(CORE_PIN24_BIT)
  567. #define CORE_PIN25_BITMASK _BV(CORE_PIN25_BIT)
  568. #define CORE_PIN26_BITMASK _BV(CORE_PIN26_BIT)
  569. #define CORE_PIN27_BITMASK _BV(CORE_PIN27_BIT)
  570. #define CORE_PIN28_BITMASK _BV(CORE_PIN28_BIT)
  571. #define CORE_PIN29_BITMASK _BV(CORE_PIN29_BIT)
  572. #define CORE_PIN30_BITMASK _BV(CORE_PIN30_BIT)
  573. #define CORE_PIN31_BITMASK _BV(CORE_PIN31_BIT)
  574. #define CORE_PIN32_BITMASK _BV(CORE_PIN32_BIT)
  575. #define CORE_PIN33_BITMASK _BV(CORE_PIN33_BIT)
  576. #define CORE_PIN34_BITMASK _BV(CORE_PIN34_BIT)
  577. #define CORE_PIN35_BITMASK _BV(CORE_PIN35_BIT)
  578. #define CORE_PIN36_BITMASK _BV(CORE_PIN36_BIT)
  579. #define CORE_PIN37_BITMASK _BV(CORE_PIN37_BIT)
  580. #define CORE_PIN38_BITMASK _BV(CORE_PIN38_BIT)
  581. #define CORE_PIN39_BITMASK _BV(CORE_PIN39_BIT)
  582. #define CORE_PIN40_BITMASK _BV(CORE_PIN40_BIT)
  583. #define CORE_PIN41_BITMASK _BV(CORE_PIN41_BIT)
  584. #define CORE_PIN42_BITMASK _BV(CORE_PIN42_BIT)
  585. #define CORE_PIN43_BITMASK _BV(CORE_PIN43_BIT)
  586. #define CORE_PIN44_BITMASK _BV(CORE_PIN44_BIT)
  587. #define CORE_PIN45_BITMASK _BV(CORE_PIN45_BIT)
  588. #define CORE_PIN0_PORTREG PORTD
  589. #define CORE_PIN1_PORTREG PORTD
  590. #define CORE_PIN2_PORTREG PORTD
  591. #define CORE_PIN3_PORTREG PORTD
  592. #define CORE_PIN4_PORTREG PORTD
  593. #define CORE_PIN5_PORTREG PORTD
  594. #define CORE_PIN6_PORTREG PORTD
  595. #define CORE_PIN7_PORTREG PORTD
  596. #define CORE_PIN8_PORTREG PORTE
  597. #define CORE_PIN9_PORTREG PORTE
  598. #define CORE_PIN10_PORTREG PORTC
  599. #define CORE_PIN11_PORTREG PORTC
  600. #define CORE_PIN12_PORTREG PORTC
  601. #define CORE_PIN13_PORTREG PORTC
  602. #define CORE_PIN14_PORTREG PORTC
  603. #define CORE_PIN15_PORTREG PORTC
  604. #define CORE_PIN16_PORTREG PORTC
  605. #define CORE_PIN17_PORTREG PORTC
  606. #define CORE_PIN18_PORTREG PORTE
  607. #define CORE_PIN19_PORTREG PORTE
  608. #define CORE_PIN20_PORTREG PORTB
  609. #define CORE_PIN21_PORTREG PORTB
  610. #define CORE_PIN22_PORTREG PORTB
  611. #define CORE_PIN23_PORTREG PORTB
  612. #define CORE_PIN24_PORTREG PORTB
  613. #define CORE_PIN25_PORTREG PORTB
  614. #define CORE_PIN26_PORTREG PORTB
  615. #define CORE_PIN27_PORTREG PORTB
  616. #define CORE_PIN28_PORTREG PORTA
  617. #define CORE_PIN29_PORTREG PORTA
  618. #define CORE_PIN30_PORTREG PORTA
  619. #define CORE_PIN31_PORTREG PORTA
  620. #define CORE_PIN32_PORTREG PORTA
  621. #define CORE_PIN33_PORTREG PORTA
  622. #define CORE_PIN34_PORTREG PORTA
  623. #define CORE_PIN35_PORTREG PORTA
  624. #define CORE_PIN36_PORTREG PORTE
  625. #define CORE_PIN37_PORTREG PORTE
  626. #define CORE_PIN38_PORTREG PORTF
  627. #define CORE_PIN39_PORTREG PORTF
  628. #define CORE_PIN40_PORTREG PORTF
  629. #define CORE_PIN41_PORTREG PORTF
  630. #define CORE_PIN42_PORTREG PORTF
  631. #define CORE_PIN43_PORTREG PORTF
  632. #define CORE_PIN44_PORTREG PORTF
  633. #define CORE_PIN45_PORTREG PORTF
  634. #define CORE_PIN0_DDRREG DDRD
  635. #define CORE_PIN1_DDRREG DDRD
  636. #define CORE_PIN2_DDRREG DDRD
  637. #define CORE_PIN3_DDRREG DDRD
  638. #define CORE_PIN4_DDRREG DDRD
  639. #define CORE_PIN5_DDRREG DDRD
  640. #define CORE_PIN6_DDRREG DDRD
  641. #define CORE_PIN7_DDRREG DDRD
  642. #define CORE_PIN8_DDRREG DDRE
  643. #define CORE_PIN9_DDRREG DDRE
  644. #define CORE_PIN10_DDRREG DDRC
  645. #define CORE_PIN11_DDRREG DDRC
  646. #define CORE_PIN12_DDRREG DDRC
  647. #define CORE_PIN13_DDRREG DDRC
  648. #define CORE_PIN14_DDRREG DDRC
  649. #define CORE_PIN15_DDRREG DDRC
  650. #define CORE_PIN16_DDRREG DDRC
  651. #define CORE_PIN17_DDRREG DDRC
  652. #define CORE_PIN18_DDRREG DDRE
  653. #define CORE_PIN19_DDRREG DDRE
  654. #define CORE_PIN20_DDRREG DDRB
  655. #define CORE_PIN21_DDRREG DDRB
  656. #define CORE_PIN22_DDRREG DDRB
  657. #define CORE_PIN23_DDRREG DDRB
  658. #define CORE_PIN24_DDRREG DDRB
  659. #define CORE_PIN25_DDRREG DDRB
  660. #define CORE_PIN26_DDRREG DDRB
  661. #define CORE_PIN27_DDRREG DDRB
  662. #define CORE_PIN28_DDRREG DDRA
  663. #define CORE_PIN29_DDRREG DDRA
  664. #define CORE_PIN30_DDRREG DDRA
  665. #define CORE_PIN31_DDRREG DDRA
  666. #define CORE_PIN32_DDRREG DDRA
  667. #define CORE_PIN33_DDRREG DDRA
  668. #define CORE_PIN34_DDRREG DDRA
  669. #define CORE_PIN35_DDRREG DDRA
  670. #define CORE_PIN36_DDRREG DDRE
  671. #define CORE_PIN37_DDRREG DDRE
  672. #define CORE_PIN38_DDRREG DDRF
  673. #define CORE_PIN39_DDRREG DDRF
  674. #define CORE_PIN40_DDRREG DDRF
  675. #define CORE_PIN41_DDRREG DDRF
  676. #define CORE_PIN42_DDRREG DDRF
  677. #define CORE_PIN43_DDRREG DDRF
  678. #define CORE_PIN44_DDRREG DDRF
  679. #define CORE_PIN45_DDRREG DDRF
  680. #define CORE_PIN0_PINREG PIND
  681. #define CORE_PIN1_PINREG PIND
  682. #define CORE_PIN2_PINREG PIND
  683. #define CORE_PIN3_PINREG PIND
  684. #define CORE_PIN4_PINREG PIND
  685. #define CORE_PIN5_PINREG PIND
  686. #define CORE_PIN6_PINREG PIND
  687. #define CORE_PIN7_PINREG PIND
  688. #define CORE_PIN8_PINREG PINE
  689. #define CORE_PIN9_PINREG PINE
  690. #define CORE_PIN10_PINREG PINC
  691. #define CORE_PIN11_PINREG PINC
  692. #define CORE_PIN12_PINREG PINC
  693. #define CORE_PIN13_PINREG PINC
  694. #define CORE_PIN14_PINREG PINC
  695. #define CORE_PIN15_PINREG PINC
  696. #define CORE_PIN16_PINREG PINC
  697. #define CORE_PIN17_PINREG PINC
  698. #define CORE_PIN18_PINREG PINE
  699. #define CORE_PIN19_PINREG PINE
  700. #define CORE_PIN20_PINREG PINB
  701. #define CORE_PIN21_PINREG PINB
  702. #define CORE_PIN22_PINREG PINB
  703. #define CORE_PIN23_PINREG PINB
  704. #define CORE_PIN24_PINREG PINB
  705. #define CORE_PIN25_PINREG PINB
  706. #define CORE_PIN26_PINREG PINB
  707. #define CORE_PIN27_PINREG PINB
  708. #define CORE_PIN28_PINREG PINA
  709. #define CORE_PIN29_PINREG PINA
  710. #define CORE_PIN30_PINREG PINA
  711. #define CORE_PIN31_PINREG PINA
  712. #define CORE_PIN32_PINREG PINA
  713. #define CORE_PIN33_PINREG PINA
  714. #define CORE_PIN34_PINREG PINA
  715. #define CORE_PIN35_PINREG PINA
  716. #define CORE_PIN36_PINREG PINE
  717. #define CORE_PIN37_PINREG PINE
  718. #define CORE_PIN38_PINREG PINF
  719. #define CORE_PIN39_PINREG PINF
  720. #define CORE_PIN40_PINREG PINF
  721. #define CORE_PIN41_PINREG PINF
  722. #define CORE_PIN42_PINREG PINF
  723. #define CORE_PIN43_PINREG PINF
  724. #define CORE_PIN44_PINREG PINF
  725. #define CORE_PIN45_PINREG PINF
  726. #define CORE_ADC0_PIN PIN_F0
  727. #define CORE_ADC1_PIN PIN_F1
  728. #define CORE_ADC2_PIN PIN_F2
  729. #define CORE_ADC3_PIN PIN_F3
  730. #define CORE_ADC4_PIN PIN_F4
  731. #define CORE_ADC5_PIN PIN_F5
  732. #define CORE_ADC6_PIN PIN_F6
  733. #define CORE_ADC7_PIN PIN_F7
  734. #define CORE_RXD1_PIN PIN_D2
  735. #define CORE_TXD1_PIN PIN_D3
  736. #define CORE_XCK1_PIN PIN_D5
  737. #define CORE_SDA0_PIN PIN_D1
  738. #define CORE_SCL0_PIN PIN_D0
  739. #define CORE_INT0_PIN PIN_D0
  740. #define CORE_INT1_PIN PIN_D1
  741. #define CORE_INT2_PIN PIN_D2
  742. #define CORE_INT3_PIN PIN_D3
  743. #define CORE_INT4_PIN PIN_E4
  744. #define CORE_INT5_PIN PIN_E5
  745. #define CORE_INT6_PIN PIN_E6
  746. #define CORE_INT7_PIN PIN_E7
  747. #define CORE_SS0_PIN PIN_B0
  748. #define CORE_MOSI0_PIN PIN_B2
  749. #define CORE_MISO0_PIN PIN_B3
  750. #define CORE_SCLK0_PIN PIN_B1
  751. #define CORE_T0_PIN PIN_D7
  752. #define CORE_T1_PIN PIN_D6
  753. #define CORE_ICP1_PIN PIN_D4
  754. #define CORE_ICP3_PIN PIN_C7
  755. #define CORE_OC0A_PIN PIN_B7
  756. #define CORE_OC0B_PIN PIN_D0
  757. #define CORE_OC1A_PIN PIN_B5
  758. #define CORE_OC1B_PIN PIN_B6
  759. #define CORE_OC1C_PIN PIN_B7
  760. #define CORE_OC2A_PIN PIN_B4
  761. #define CORE_OC2B_PIN PIN_D1
  762. #define CORE_OC3A_PIN PIN_C6
  763. #define CORE_OC3B_PIN PIN_C5
  764. #define CORE_OC3C_PIN PIN_C4
  765. #define CORE_PCINT0_PIN PIN_B0
  766. #define CORE_PCINT1_PIN PIN_B1
  767. #define CORE_PCINT2_PIN PIN_B2
  768. #define CORE_PCINT3_PIN PIN_B3
  769. #define CORE_PCINT4_PIN PIN_B4
  770. #define CORE_PCINT5_PIN PIN_B5
  771. #define CORE_PCINT6_PIN PIN_B6
  772. #define CORE_PCINT7_PIN PIN_B7
  773. #define CORE_LED0_PIN PIN_D6
  774. #define CORE_PWM0_PIN CORE_OC0B_PIN // D0, 0
  775. #define CORE_PWM1_PIN CORE_OC2B_PIN // D1, 1
  776. #define CORE_PWM2_PIN CORE_OC3C_PIN // C4, 14
  777. #define CORE_PWM3_PIN CORE_OC3B_PIN // C5, 15
  778. #define CORE_PWM4_PIN CORE_OC3A_PIN // C6, 16
  779. #define CORE_PWM5_PIN CORE_OC2A_PIN // B4, 24
  780. #define CORE_PWM6_PIN CORE_OC1A_PIN // B5, 25
  781. #define CORE_PWM7_PIN CORE_OC1B_PIN // B6, 26
  782. #define CORE_PWM8_PIN CORE_OC1C_PIN // B7, 27
  783. #define CORE_ANALOG0_PIN PIN_F0
  784. #define CORE_ANALOG1_PIN PIN_F1
  785. #define CORE_ANALOG2_PIN PIN_F2
  786. #define CORE_ANALOG3_PIN PIN_F3
  787. #define CORE_ANALOG4_PIN PIN_F4
  788. #define CORE_ANALOG5_PIN PIN_F5
  789. #define CORE_ANALOG6_PIN PIN_F6
  790. #define CORE_ANALOG7_PIN PIN_F7
  791. #endif
  792. #define CORE_BIT(pin) CORE_PIN_CONCATENATE(pin, BIT)
  793. #define CORE_BITMASK(pin) CORE_PIN_CONCATENATE(pin, BITMASK)
  794. #define CORE_PORTREG(pin) CORE_PIN_CONCATENATE(pin, PORTREG)
  795. #define CORE_DDRREG(pin) CORE_PIN_CONCATENATE(pin, DDRREG)
  796. #define CORE_PINREG(pin) CORE_PIN_CONCATENATE(pin, PINREG)
  797. #define CORE_PIN_CONCATENATE(pin, reg) (CORE_PIN ## pin ## _ ## reg)
  798. #ifdef __cplusplus
  799. extern "C"{
  800. #endif
  801. extern void _digitalWrite(void);
  802. extern void _digitalWrite_HIGH(void);
  803. extern void _digitalWrite_LOW(void);
  804. static inline void digitalWrite(uint8_t, uint8_t) __attribute__((always_inline, unused));
  805. static inline void digitalWrite(uint8_t pin, uint8_t val)
  806. {
  807. if (__builtin_constant_p(pin)) {
  808. if (val) {
  809. if (pin == 0) {
  810. CORE_PIN0_PORTREG |= CORE_PIN0_BITMASK;
  811. } else if (pin == 1) {
  812. CORE_PIN1_PORTREG |= CORE_PIN1_BITMASK;
  813. } else if (pin == 2) {
  814. CORE_PIN2_PORTREG |= CORE_PIN2_BITMASK;
  815. } else if (pin == 3) {
  816. CORE_PIN3_PORTREG |= CORE_PIN3_BITMASK;
  817. } else if (pin == 4) {
  818. CORE_PIN4_PORTREG |= CORE_PIN4_BITMASK;
  819. } else if (pin == 5) {
  820. CORE_PIN5_PORTREG |= CORE_PIN5_BITMASK;
  821. } else if (pin == 6) {
  822. CORE_PIN6_PORTREG |= CORE_PIN6_BITMASK;
  823. } else if (pin == 7) {
  824. CORE_PIN7_PORTREG |= CORE_PIN7_BITMASK;
  825. } else if (pin == 8) {
  826. CORE_PIN8_PORTREG |= CORE_PIN8_BITMASK;
  827. } else if (pin == 9) {
  828. CORE_PIN9_PORTREG |= CORE_PIN9_BITMASK;
  829. } else if (pin == 10) {
  830. CORE_PIN10_PORTREG |= CORE_PIN10_BITMASK;
  831. } else if (pin == 11) {
  832. CORE_PIN11_PORTREG |= CORE_PIN11_BITMASK;
  833. } else if (pin == 12) {
  834. CORE_PIN12_PORTREG |= CORE_PIN12_BITMASK;
  835. } else if (pin == 13) {
  836. CORE_PIN13_PORTREG |= CORE_PIN13_BITMASK;
  837. } else if (pin == 14) {
  838. CORE_PIN14_PORTREG |= CORE_PIN14_BITMASK;
  839. } else if (pin == 15) {
  840. CORE_PIN15_PORTREG |= CORE_PIN15_BITMASK;
  841. } else if (pin == 16) {
  842. CORE_PIN16_PORTREG |= CORE_PIN16_BITMASK;
  843. } else if (pin == 17) {
  844. CORE_PIN17_PORTREG |= CORE_PIN17_BITMASK;
  845. } else if (pin == 18) {
  846. CORE_PIN18_PORTREG |= CORE_PIN18_BITMASK;
  847. } else if (pin == 19) {
  848. CORE_PIN19_PORTREG |= CORE_PIN19_BITMASK;
  849. } else if (pin == 20) {
  850. CORE_PIN20_PORTREG |= CORE_PIN20_BITMASK;
  851. }
  852. #if CORE_NUM_TOTAL_PINS > 21
  853. else if (pin == 21) {
  854. CORE_PIN21_PORTREG |= CORE_PIN21_BITMASK;
  855. } else if (pin == 22) {
  856. CORE_PIN22_PORTREG |= CORE_PIN22_BITMASK;
  857. } else if (pin == 23) {
  858. CORE_PIN23_PORTREG |= CORE_PIN23_BITMASK;
  859. } else if (pin == 24) {
  860. CORE_PIN24_PORTREG |= CORE_PIN24_BITMASK;
  861. }
  862. #endif
  863. #if CORE_NUM_TOTAL_PINS > 25
  864. else if (pin == 25) {
  865. CORE_PIN25_PORTREG |= CORE_PIN25_BITMASK;
  866. } else if (pin == 26) {
  867. CORE_PIN26_PORTREG |= CORE_PIN26_BITMASK;
  868. } else if (pin == 27) {
  869. CORE_PIN27_PORTREG |= CORE_PIN27_BITMASK;
  870. } else if (pin == 28) {
  871. CORE_PIN28_PORTREG |= CORE_PIN28_BITMASK;
  872. } else if (pin == 29) {
  873. CORE_PIN29_PORTREG |= CORE_PIN29_BITMASK;
  874. } else if (pin == 30) {
  875. CORE_PIN30_PORTREG |= CORE_PIN30_BITMASK;
  876. } else if (pin == 31) {
  877. CORE_PIN31_PORTREG |= CORE_PIN31_BITMASK;
  878. } else if (pin == 32) {
  879. CORE_PIN32_PORTREG |= CORE_PIN32_BITMASK;
  880. } else if (pin == 33) {
  881. CORE_PIN33_PORTREG |= CORE_PIN33_BITMASK;
  882. } else if (pin == 34) {
  883. CORE_PIN34_PORTREG |= CORE_PIN34_BITMASK;
  884. } else if (pin == 35) {
  885. CORE_PIN35_PORTREG |= CORE_PIN35_BITMASK;
  886. } else if (pin == 36) {
  887. CORE_PIN36_PORTREG |= CORE_PIN36_BITMASK;
  888. } else if (pin == 37) {
  889. CORE_PIN37_PORTREG |= CORE_PIN37_BITMASK;
  890. } else if (pin == 38) {
  891. CORE_PIN38_PORTREG |= CORE_PIN38_BITMASK;
  892. } else if (pin == 39) {
  893. CORE_PIN39_PORTREG |= CORE_PIN39_BITMASK;
  894. } else if (pin == 40) {
  895. CORE_PIN40_PORTREG |= CORE_PIN40_BITMASK;
  896. } else if (pin == 41) {
  897. CORE_PIN41_PORTREG |= CORE_PIN41_BITMASK;
  898. } else if (pin == 42) {
  899. CORE_PIN42_PORTREG |= CORE_PIN42_BITMASK;
  900. } else if (pin == 43) {
  901. CORE_PIN43_PORTREG |= CORE_PIN43_BITMASK;
  902. } else if (pin == 44) {
  903. CORE_PIN44_PORTREG |= CORE_PIN44_BITMASK;
  904. } else if (pin == 45) {
  905. CORE_PIN45_PORTREG |= CORE_PIN45_BITMASK;
  906. }
  907. #endif
  908. } else {
  909. if (pin == 0) {
  910. CORE_PIN0_PORTREG &= ~CORE_PIN0_BITMASK;
  911. } else if (pin == 1) {
  912. CORE_PIN1_PORTREG &= ~CORE_PIN1_BITMASK;
  913. } else if (pin == 2) {
  914. CORE_PIN2_PORTREG &= ~CORE_PIN2_BITMASK;
  915. } else if (pin == 3) {
  916. CORE_PIN3_PORTREG &= ~CORE_PIN3_BITMASK;
  917. } else if (pin == 4) {
  918. CORE_PIN4_PORTREG &= ~CORE_PIN4_BITMASK;
  919. } else if (pin == 5) {
  920. CORE_PIN5_PORTREG &= ~CORE_PIN5_BITMASK;
  921. } else if (pin == 6) {
  922. CORE_PIN6_PORTREG &= ~CORE_PIN6_BITMASK;
  923. } else if (pin == 7) {
  924. CORE_PIN7_PORTREG &= ~CORE_PIN7_BITMASK;
  925. } else if (pin == 8) {
  926. CORE_PIN8_PORTREG &= ~CORE_PIN8_BITMASK;
  927. } else if (pin == 9) {
  928. CORE_PIN9_PORTREG &= ~CORE_PIN9_BITMASK;
  929. } else if (pin == 10) {
  930. CORE_PIN10_PORTREG &= ~CORE_PIN10_BITMASK;
  931. } else if (pin == 11) {
  932. CORE_PIN11_PORTREG &= ~CORE_PIN11_BITMASK;
  933. } else if (pin == 12) {
  934. CORE_PIN12_PORTREG &= ~CORE_PIN12_BITMASK;
  935. } else if (pin == 13) {
  936. CORE_PIN13_PORTREG &= ~CORE_PIN13_BITMASK;
  937. } else if (pin == 14) {
  938. CORE_PIN14_PORTREG &= ~CORE_PIN14_BITMASK;
  939. } else if (pin == 15) {
  940. CORE_PIN15_PORTREG &= ~CORE_PIN15_BITMASK;
  941. } else if (pin == 16) {
  942. CORE_PIN16_PORTREG &= ~CORE_PIN16_BITMASK;
  943. } else if (pin == 17) {
  944. CORE_PIN17_PORTREG &= ~CORE_PIN17_BITMASK;
  945. } else if (pin == 18) {
  946. CORE_PIN18_PORTREG &= ~CORE_PIN18_BITMASK;
  947. } else if (pin == 19) {
  948. CORE_PIN19_PORTREG &= ~CORE_PIN19_BITMASK;
  949. } else if (pin == 20) {
  950. CORE_PIN20_PORTREG &= ~CORE_PIN20_BITMASK;
  951. }
  952. #if CORE_NUM_TOTAL_PINS > 21
  953. else if (pin == 21) {
  954. CORE_PIN21_PORTREG &= ~CORE_PIN21_BITMASK;
  955. } else if (pin == 22) {
  956. CORE_PIN22_PORTREG &= ~CORE_PIN22_BITMASK;
  957. } else if (pin == 23) {
  958. CORE_PIN23_PORTREG &= ~CORE_PIN23_BITMASK;
  959. } else if (pin == 24) {
  960. CORE_PIN24_PORTREG &= ~CORE_PIN24_BITMASK;
  961. }
  962. #endif
  963. #if CORE_NUM_TOTAL_PINS > 25
  964. else if (pin == 25) {
  965. CORE_PIN25_PORTREG &= ~CORE_PIN25_BITMASK;
  966. } else if (pin == 26) {
  967. CORE_PIN26_PORTREG &= ~CORE_PIN26_BITMASK;
  968. } else if (pin == 27) {
  969. CORE_PIN27_PORTREG &= ~CORE_PIN27_BITMASK;
  970. } else if (pin == 28) {
  971. CORE_PIN28_PORTREG &= ~CORE_PIN28_BITMASK;
  972. } else if (pin == 29) {
  973. CORE_PIN29_PORTREG &= ~CORE_PIN29_BITMASK;
  974. } else if (pin == 30) {
  975. CORE_PIN30_PORTREG &= ~CORE_PIN30_BITMASK;
  976. } else if (pin == 31) {
  977. CORE_PIN31_PORTREG &= ~CORE_PIN31_BITMASK;
  978. } else if (pin == 32) {
  979. CORE_PIN32_PORTREG &= ~CORE_PIN32_BITMASK;
  980. } else if (pin == 33) {
  981. CORE_PIN33_PORTREG &= ~CORE_PIN33_BITMASK;
  982. } else if (pin == 34) {
  983. CORE_PIN34_PORTREG &= ~CORE_PIN34_BITMASK;
  984. } else if (pin == 35) {
  985. CORE_PIN35_PORTREG &= ~CORE_PIN35_BITMASK;
  986. } else if (pin == 36) {
  987. CORE_PIN36_PORTREG &= ~CORE_PIN36_BITMASK;
  988. } else if (pin == 37) {
  989. CORE_PIN37_PORTREG &= ~CORE_PIN37_BITMASK;
  990. } else if (pin == 38) {
  991. CORE_PIN38_PORTREG &= ~CORE_PIN38_BITMASK;
  992. } else if (pin == 39) {
  993. CORE_PIN39_PORTREG &= ~CORE_PIN39_BITMASK;
  994. } else if (pin == 40) {
  995. CORE_PIN40_PORTREG &= ~CORE_PIN40_BITMASK;
  996. } else if (pin == 41) {
  997. CORE_PIN41_PORTREG &= ~CORE_PIN41_BITMASK;
  998. } else if (pin == 42) {
  999. CORE_PIN42_PORTREG &= ~CORE_PIN42_BITMASK;
  1000. } else if (pin == 43) {
  1001. CORE_PIN43_PORTREG &= ~CORE_PIN43_BITMASK;
  1002. } else if (pin == 44) {
  1003. CORE_PIN44_PORTREG &= ~CORE_PIN44_BITMASK;
  1004. } else if (pin == 45) {
  1005. CORE_PIN45_PORTREG &= ~CORE_PIN45_BITMASK;
  1006. }
  1007. #endif
  1008. }
  1009. if (pin == CORE_OC0B_PIN) {
  1010. _SFR_BYTE(TCCR0A) &= ~(1<<COM0B1);
  1011. } else if (pin == CORE_OC1A_PIN) {
  1012. TCCR1A &= ~(1<<COM1A1);
  1013. } else if (pin == CORE_OC1B_PIN) {
  1014. TCCR1A &= ~(1<<COM1B1);
  1015. } else if (pin == CORE_OC1C_PIN) {
  1016. TCCR1A &= ~(1<<COM1C1);
  1017. }
  1018. #if defined(__AVR_ATmega32U4__)
  1019. else if (pin == CORE_OC3A_PIN) {
  1020. TCCR3A &= ~(1<<COM3A1);
  1021. } else if (pin == CORE_OC4A_PIN) {
  1022. TCCR4A &= ~(1<<COM4A1);
  1023. } else if (pin == CORE_OC4D_PIN) {
  1024. TCCR4C &= ~(1<<COM4D1);
  1025. }
  1026. #endif
  1027. #if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  1028. else if (pin == CORE_OC2A_PIN) {
  1029. TCCR2A &= ~(1<<COM2A1);
  1030. } else if (pin == CORE_OC2B_PIN) {
  1031. TCCR2A &= ~(1<<COM2B1);
  1032. } else if (pin == CORE_OC3A_PIN) {
  1033. TCCR3A &= ~(1<<COM3A1);
  1034. } else if (pin == CORE_OC3B_PIN) {
  1035. TCCR3A &= ~(1<<COM3B1);
  1036. } else if (pin == CORE_OC3C_PIN) {
  1037. TCCR3A &= ~(1<<COM3C1);
  1038. }
  1039. #endif
  1040. } else {
  1041. if (__builtin_constant_p(val)) {
  1042. if (val) {
  1043. uint16_t tmp = (pin);
  1044. asm volatile(
  1045. #if defined(DIGITAL_WRITE_EXPENSIVE_INLINE_OPTIMIZATION)
  1046. #if !defined(DIGITAL_WRITE_RISKY_OMIT_OVERFLOW_CHECK)
  1047. "cpi r30, %1" "\n\t"
  1048. "brsh L%=end1" "\n\t"
  1049. #endif
  1050. "lsl r30" "\n\t"
  1051. //"clr r31" "\n\t"
  1052. "subi r30, lo8(-(pm(_digitalWrite_HIGH_TABLE)))" "\n\t"
  1053. "sbci r31, hi8(-(pm(_digitalWrite_HIGH_TABLE)))" "\n\t"
  1054. "icall" "\n\t"
  1055. "L%=end1:" "\n"
  1056. #else
  1057. "call _digitalWrite_HIGH"
  1058. #endif
  1059. : "+z" (tmp)
  1060. : "I" (CORE_NUM_TOTAL_PINS)
  1061. );
  1062. } else {
  1063. uint16_t tmp = (pin);
  1064. asm volatile(
  1065. #if defined(DIGITAL_WRITE_EXPENSIVE_INLINE_OPTIMIZATION)
  1066. #if !defined(DIGITAL_WRITE_RISKY_OMIT_OVERFLOW_CHECK)
  1067. "cpi r30, %1" "\n\t"
  1068. "brsh L%=end2" "\n\t"
  1069. #endif
  1070. "lsl r30" "\n\t"
  1071. //"clr r31" "\n\t"
  1072. "subi r30, lo8(-(pm(_digitalWrite_LOW_TABLE)))" "\n\t"
  1073. "sbci r31, hi8(-(pm(_digitalWrite_LOW_TABLE)))" "\n\t"
  1074. "icall" "\n\t"
  1075. "L%=end2:" "\n"
  1076. #else
  1077. "call _digitalWrite_LOW"
  1078. #endif
  1079. : "+z" (tmp)
  1080. : "I" (CORE_NUM_TOTAL_PINS)
  1081. );
  1082. }
  1083. } else {
  1084. uint16_t tmp1 = (pin);
  1085. uint8_t tmp2 = (val);
  1086. asm volatile(
  1087. #if defined(DIGITAL_WRITE_EXPENSIVE_INLINE_OPTIMIZATION)
  1088. #if !defined(DIGITAL_WRITE_RISKY_OMIT_OVERFLOW_CHECK)
  1089. "cpi %0, %2" "\n\t"
  1090. "brsh L%=end3" "\n\t"
  1091. #endif
  1092. "lsl r30" "\n\t"
  1093. //"clr r31" "\n\t"
  1094. "tst %1" "\n\t"
  1095. "breq L%=low" "\n\t"
  1096. "subi r30, lo8(-(pm(_digitalWrite_HIGH_TABLE)))" "\n\t"
  1097. "sbci r31, hi8(-(pm(_digitalWrite_HIGH_TABLE)))" "\n\t"
  1098. "icall" "\n\t"
  1099. "rjmp L%=end3" "\n\t"
  1100. "L%=low:" "\n\t"
  1101. "subi r30, lo8(-(pm(_digitalWrite_LOW_TABLE)))" "\n\t"
  1102. "sbci r31, hi8(-(pm(_digitalWrite_LOW_TABLE)))" "\n\t"
  1103. "icall" "\n\t"
  1104. "L%=end3:" "\n\t"
  1105. : "+z" (tmp1)
  1106. : "d" (tmp2), "I" (CORE_NUM_TOTAL_PINS)
  1107. #else
  1108. "mov __tmp_reg__, %1" "\n\t"
  1109. "call _digitalWrite"
  1110. : "+z" (tmp1)
  1111. : "r" (tmp2)
  1112. #endif
  1113. );
  1114. }
  1115. }
  1116. }
  1117. static inline void digitalWriteFast(uint8_t, uint8_t) __attribute__((always_inline, unused));
  1118. static inline void digitalWriteFast(uint8_t pin, uint8_t val)
  1119. {
  1120. if (__builtin_constant_p(pin)) {
  1121. if (val) {
  1122. if (pin == 0) {
  1123. CORE_PIN0_PORTREG |= CORE_PIN0_BITMASK;
  1124. } else if (pin == 1) {
  1125. CORE_PIN1_PORTREG |= CORE_PIN1_BITMASK;
  1126. } else if (pin == 2) {
  1127. CORE_PIN2_PORTREG |= CORE_PIN2_BITMASK;
  1128. } else if (pin == 3) {
  1129. CORE_PIN3_PORTREG |= CORE_PIN3_BITMASK;
  1130. } else if (pin == 4) {
  1131. CORE_PIN4_PORTREG |= CORE_PIN4_BITMASK;
  1132. } else if (pin == 5) {
  1133. CORE_PIN5_PORTREG |= CORE_PIN5_BITMASK;
  1134. } else if (pin == 6) {
  1135. CORE_PIN6_PORTREG |= CORE_PIN6_BITMASK;
  1136. } else if (pin == 7) {
  1137. CORE_PIN7_PORTREG |= CORE_PIN7_BITMASK;
  1138. } else if (pin == 8) {
  1139. CORE_PIN8_PORTREG |= CORE_PIN8_BITMASK;
  1140. } else if (pin == 9) {
  1141. CORE_PIN9_PORTREG |= CORE_PIN9_BITMASK;
  1142. } else if (pin == 10) {
  1143. CORE_PIN10_PORTREG |= CORE_PIN10_BITMASK;
  1144. } else if (pin == 11) {
  1145. CORE_PIN11_PORTREG |= CORE_PIN11_BITMASK;
  1146. } else if (pin == 12) {
  1147. CORE_PIN12_PORTREG |= CORE_PIN12_BITMASK;
  1148. } else if (pin == 13) {
  1149. CORE_PIN13_PORTREG |= CORE_PIN13_BITMASK;
  1150. } else if (pin == 14) {
  1151. CORE_PIN14_PORTREG |= CORE_PIN14_BITMASK;
  1152. } else if (pin == 15) {
  1153. CORE_PIN15_PORTREG |= CORE_PIN15_BITMASK;
  1154. } else if (pin == 16) {
  1155. CORE_PIN16_PORTREG |= CORE_PIN16_BITMASK;
  1156. } else if (pin == 17) {
  1157. CORE_PIN17_PORTREG |= CORE_PIN17_BITMASK;
  1158. } else if (pin == 18) {
  1159. CORE_PIN18_PORTREG |= CORE_PIN18_BITMASK;
  1160. } else if (pin == 19) {
  1161. CORE_PIN19_PORTREG |= CORE_PIN19_BITMASK;
  1162. } else if (pin == 20) {
  1163. CORE_PIN20_PORTREG |= CORE_PIN20_BITMASK;
  1164. }
  1165. #if CORE_NUM_TOTAL_PINS > 21
  1166. else if (pin == 21) {
  1167. CORE_PIN21_PORTREG |= CORE_PIN21_BITMASK;
  1168. } else if (pin == 22) {
  1169. CORE_PIN22_PORTREG |= CORE_PIN22_BITMASK;
  1170. } else if (pin == 23) {
  1171. CORE_PIN23_PORTREG |= CORE_PIN23_BITMASK;
  1172. } else if (pin == 24) {
  1173. CORE_PIN24_PORTREG |= CORE_PIN24_BITMASK;
  1174. }
  1175. #endif
  1176. #if CORE_NUM_TOTAL_PINS > 25
  1177. else if (pin == 25) {
  1178. CORE_PIN25_PORTREG |= CORE_PIN25_BITMASK;
  1179. } else if (pin == 26) {
  1180. CORE_PIN26_PORTREG |= CORE_PIN26_BITMASK;
  1181. } else if (pin == 27) {
  1182. CORE_PIN27_PORTREG |= CORE_PIN27_BITMASK;
  1183. } else if (pin == 28) {
  1184. CORE_PIN28_PORTREG |= CORE_PIN28_BITMASK;
  1185. } else if (pin == 29) {
  1186. CORE_PIN29_PORTREG |= CORE_PIN29_BITMASK;
  1187. } else if (pin == 30) {
  1188. CORE_PIN30_PORTREG |= CORE_PIN30_BITMASK;
  1189. } else if (pin == 31) {
  1190. CORE_PIN31_PORTREG |= CORE_PIN31_BITMASK;
  1191. } else if (pin == 32) {
  1192. CORE_PIN32_PORTREG |= CORE_PIN32_BITMASK;
  1193. } else if (pin == 33) {
  1194. CORE_PIN33_PORTREG |= CORE_PIN33_BITMASK;
  1195. } else if (pin == 34) {
  1196. CORE_PIN34_PORTREG |= CORE_PIN34_BITMASK;
  1197. } else if (pin == 35) {
  1198. CORE_PIN35_PORTREG |= CORE_PIN35_BITMASK;
  1199. } else if (pin == 36) {
  1200. CORE_PIN36_PORTREG |= CORE_PIN36_BITMASK;
  1201. } else if (pin == 37) {
  1202. CORE_PIN37_PORTREG |= CORE_PIN37_BITMASK;
  1203. } else if (pin == 38) {
  1204. CORE_PIN38_PORTREG |= CORE_PIN38_BITMASK;
  1205. } else if (pin == 39) {
  1206. CORE_PIN39_PORTREG |= CORE_PIN39_BITMASK;
  1207. } else if (pin == 40) {
  1208. CORE_PIN40_PORTREG |= CORE_PIN40_BITMASK;
  1209. } else if (pin == 41) {
  1210. CORE_PIN41_PORTREG |= CORE_PIN41_BITMASK;
  1211. } else if (pin == 42) {
  1212. CORE_PIN42_PORTREG |= CORE_PIN42_BITMASK;
  1213. } else if (pin == 43) {
  1214. CORE_PIN43_PORTREG |= CORE_PIN43_BITMASK;
  1215. } else if (pin == 44) {
  1216. CORE_PIN44_PORTREG |= CORE_PIN44_BITMASK;
  1217. } else if (pin == 45) {
  1218. CORE_PIN45_PORTREG |= CORE_PIN45_BITMASK;
  1219. }
  1220. #endif
  1221. } else {
  1222. if (pin == 0) {
  1223. CORE_PIN0_PORTREG &= ~CORE_PIN0_BITMASK;
  1224. } else if (pin == 1) {
  1225. CORE_PIN1_PORTREG &= ~CORE_PIN1_BITMASK;
  1226. } else if (pin == 2) {
  1227. CORE_PIN2_PORTREG &= ~CORE_PIN2_BITMASK;
  1228. } else if (pin == 3) {
  1229. CORE_PIN3_PORTREG &= ~CORE_PIN3_BITMASK;
  1230. } else if (pin == 4) {
  1231. CORE_PIN4_PORTREG &= ~CORE_PIN4_BITMASK;
  1232. } else if (pin == 5) {
  1233. CORE_PIN5_PORTREG &= ~CORE_PIN5_BITMASK;
  1234. } else if (pin == 6) {
  1235. CORE_PIN6_PORTREG &= ~CORE_PIN6_BITMASK;
  1236. } else if (pin == 7) {
  1237. CORE_PIN7_PORTREG &= ~CORE_PIN7_BITMASK;
  1238. } else if (pin == 8) {
  1239. CORE_PIN8_PORTREG &= ~CORE_PIN8_BITMASK;
  1240. } else if (pin == 9) {
  1241. CORE_PIN9_PORTREG &= ~CORE_PIN9_BITMASK;
  1242. } else if (pin == 10) {
  1243. CORE_PIN10_PORTREG &= ~CORE_PIN10_BITMASK;
  1244. } else if (pin == 11) {
  1245. CORE_PIN11_PORTREG &= ~CORE_PIN11_BITMASK;
  1246. } else if (pin == 12) {
  1247. CORE_PIN12_PORTREG &= ~CORE_PIN12_BITMASK;
  1248. } else if (pin == 13) {
  1249. CORE_PIN13_PORTREG &= ~CORE_PIN13_BITMASK;
  1250. } else if (pin == 14) {
  1251. CORE_PIN14_PORTREG &= ~CORE_PIN14_BITMASK;
  1252. } else if (pin == 15) {
  1253. CORE_PIN15_PORTREG &= ~CORE_PIN15_BITMASK;
  1254. } else if (pin == 16) {
  1255. CORE_PIN16_PORTREG &= ~CORE_PIN16_BITMASK;
  1256. } else if (pin == 17) {
  1257. CORE_PIN17_PORTREG &= ~CORE_PIN17_BITMASK;
  1258. } else if (pin == 18) {
  1259. CORE_PIN18_PORTREG &= ~CORE_PIN18_BITMASK;
  1260. } else if (pin == 19) {
  1261. CORE_PIN19_PORTREG &= ~CORE_PIN19_BITMASK;
  1262. } else if (pin == 20) {
  1263. CORE_PIN20_PORTREG &= ~CORE_PIN20_BITMASK;
  1264. }
  1265. #if CORE_NUM_TOTAL_PINS > 21
  1266. else if (pin == 21) {
  1267. CORE_PIN21_PORTREG &= ~CORE_PIN21_BITMASK;
  1268. } else if (pin == 22) {
  1269. CORE_PIN22_PORTREG &= ~CORE_PIN22_BITMASK;
  1270. } else if (pin == 23) {
  1271. CORE_PIN23_PORTREG &= ~CORE_PIN23_BITMASK;
  1272. } else if (pin == 24) {
  1273. CORE_PIN24_PORTREG &= ~CORE_PIN24_BITMASK;
  1274. }
  1275. #endif
  1276. #if CORE_NUM_TOTAL_PINS > 25
  1277. else if (pin == 25) {
  1278. CORE_PIN25_PORTREG &= ~CORE_PIN25_BITMASK;
  1279. } else if (pin == 26) {
  1280. CORE_PIN26_PORTREG &= ~CORE_PIN26_BITMASK;
  1281. } else if (pin == 27) {
  1282. CORE_PIN27_PORTREG &= ~CORE_PIN27_BITMASK;
  1283. } else if (pin == 28) {
  1284. CORE_PIN28_PORTREG &= ~CORE_PIN28_BITMASK;
  1285. } else if (pin == 29) {
  1286. CORE_PIN29_PORTREG &= ~CORE_PIN29_BITMASK;
  1287. } else if (pin == 30) {
  1288. CORE_PIN30_PORTREG &= ~CORE_PIN30_BITMASK;
  1289. } else if (pin == 31) {
  1290. CORE_PIN31_PORTREG &= ~CORE_PIN31_BITMASK;
  1291. } else if (pin == 32) {
  1292. CORE_PIN32_PORTREG &= ~CORE_PIN32_BITMASK;
  1293. } else if (pin == 33) {
  1294. CORE_PIN33_PORTREG &= ~CORE_PIN33_BITMASK;
  1295. } else if (pin == 34) {
  1296. CORE_PIN34_PORTREG &= ~CORE_PIN34_BITMASK;
  1297. } else if (pin == 35) {
  1298. CORE_PIN35_PORTREG &= ~CORE_PIN35_BITMASK;
  1299. } else if (pin == 36) {
  1300. CORE_PIN36_PORTREG &= ~CORE_PIN36_BITMASK;
  1301. } else if (pin == 37) {
  1302. CORE_PIN37_PORTREG &= ~CORE_PIN37_BITMASK;
  1303. } else if (pin == 38) {
  1304. CORE_PIN38_PORTREG &= ~CORE_PIN38_BITMASK;
  1305. } else if (pin == 39) {
  1306. CORE_PIN39_PORTREG &= ~CORE_PIN39_BITMASK;
  1307. } else if (pin == 40) {
  1308. CORE_PIN40_PORTREG &= ~CORE_PIN40_BITMASK;
  1309. } else if (pin == 41) {
  1310. CORE_PIN41_PORTREG &= ~CORE_PIN41_BITMASK;
  1311. } else if (pin == 42) {
  1312. CORE_PIN42_PORTREG &= ~CORE_PIN42_BITMASK;
  1313. } else if (pin == 43) {
  1314. CORE_PIN43_PORTREG &= ~CORE_PIN43_BITMASK;
  1315. } else if (pin == 44) {
  1316. CORE_PIN44_PORTREG &= ~CORE_PIN44_BITMASK;
  1317. } else if (pin == 45) {
  1318. CORE_PIN45_PORTREG &= ~CORE_PIN45_BITMASK;
  1319. }
  1320. #endif
  1321. }
  1322. } else {
  1323. digitalWrite(pin, val);
  1324. }
  1325. }
  1326. extern void _digitalRead(void) __attribute__((noinline));
  1327. static inline uint8_t digitalRead(uint8_t) __attribute__((always_inline, unused));
  1328. static inline uint8_t digitalRead(uint8_t pin)
  1329. {
  1330. if (__builtin_constant_p(pin)) {
  1331. if (pin == 0) {
  1332. return (CORE_PIN0_PINREG & CORE_PIN0_BITMASK) ? 1 : 0;
  1333. } else if (pin == 1) {
  1334. return (CORE_PIN1_PINREG & CORE_PIN1_BITMASK) ? 1 : 0;
  1335. } else if (pin == 2) {
  1336. return (CORE_PIN2_PINREG & CORE_PIN2_BITMASK) ? 1 : 0;
  1337. } else if (pin == 3) {
  1338. return (CORE_PIN3_PINREG & CORE_PIN3_BITMASK) ? 1 : 0;
  1339. } else if (pin == 4) {
  1340. return (CORE_PIN4_PINREG & CORE_PIN4_BITMASK) ? 1 : 0;
  1341. } else if (pin == 5) {
  1342. return (CORE_PIN5_PINREG & CORE_PIN5_BITMASK) ? 1 : 0;
  1343. } else if (pin == 6) {
  1344. return (CORE_PIN6_PINREG & CORE_PIN6_BITMASK) ? 1 : 0;
  1345. } else if (pin == 7) {
  1346. return (CORE_PIN7_PINREG & CORE_PIN7_BITMASK) ? 1 : 0;
  1347. } else if (pin == 8) {
  1348. return (CORE_PIN8_PINREG & CORE_PIN8_BITMASK) ? 1 : 0;
  1349. } else if (pin == 9) {
  1350. return (CORE_PIN9_PINREG & CORE_PIN9_BITMASK) ? 1 : 0;
  1351. } else if (pin == 10) {
  1352. return (CORE_PIN10_PINREG & CORE_PIN10_BITMASK) ? 1 : 0;
  1353. } else if (pin == 11) {
  1354. return (CORE_PIN11_PINREG & CORE_PIN11_BITMASK) ? 1 : 0;
  1355. } else if (pin == 12) {
  1356. return (CORE_PIN12_PINREG & CORE_PIN12_BITMASK) ? 1 : 0;
  1357. } else if (pin == 13) {
  1358. return (CORE_PIN13_PINREG & CORE_PIN13_BITMASK) ? 1 : 0;
  1359. } else if (pin == 14) {
  1360. return (CORE_PIN14_PINREG & CORE_PIN14_BITMASK) ? 1 : 0;
  1361. } else if (pin == 15) {
  1362. return (CORE_PIN15_PINREG & CORE_PIN15_BITMASK) ? 1 : 0;
  1363. } else if (pin == 16) {
  1364. return (CORE_PIN16_PINREG & CORE_PIN16_BITMASK) ? 1 : 0;
  1365. } else if (pin == 17) {
  1366. return (CORE_PIN17_PINREG & CORE_PIN17_BITMASK) ? 1 : 0;
  1367. } else if (pin == 18) {
  1368. return (CORE_PIN18_PINREG & CORE_PIN18_BITMASK) ? 1 : 0;
  1369. } else if (pin == 19) {
  1370. return (CORE_PIN19_PINREG & CORE_PIN19_BITMASK) ? 1 : 0;
  1371. } else if (pin == 20) {
  1372. return (CORE_PIN20_PINREG & CORE_PIN20_BITMASK) ? 1 : 0;
  1373. }
  1374. #if CORE_NUM_TOTAL_PINS > 21
  1375. else if (pin == 21) {
  1376. return (CORE_PIN21_PINREG & CORE_PIN21_BITMASK) ? 1 : 0;
  1377. } else if (pin == 22) {
  1378. return (CORE_PIN22_PINREG & CORE_PIN22_BITMASK) ? 1 : 0;
  1379. } else if (pin == 23) {
  1380. return (CORE_PIN23_PINREG & CORE_PIN23_BITMASK) ? 1 : 0;
  1381. } else if (pin == 24) {
  1382. return (CORE_PIN24_PINREG & CORE_PIN24_BITMASK) ? 1 : 0;
  1383. }
  1384. #endif
  1385. #if CORE_NUM_TOTAL_PINS > 25
  1386. else if (pin == 25) {
  1387. return (CORE_PIN25_PINREG & CORE_PIN25_BITMASK) ? 1 : 0;
  1388. } else if (pin == 26) {
  1389. return (CORE_PIN26_PINREG & CORE_PIN26_BITMASK) ? 1 : 0;
  1390. } else if (pin == 27) {
  1391. return (CORE_PIN27_PINREG & CORE_PIN27_BITMASK) ? 1 : 0;
  1392. } else if (pin == 28) {
  1393. return (CORE_PIN28_PINREG & CORE_PIN28_BITMASK) ? 1 : 0;
  1394. } else if (pin == 29) {
  1395. return (CORE_PIN29_PINREG & CORE_PIN29_BITMASK) ? 1 : 0;
  1396. } else if (pin == 30) {
  1397. return (CORE_PIN30_PINREG & CORE_PIN30_BITMASK) ? 1 : 0;
  1398. } else if (pin == 31) {
  1399. return (CORE_PIN31_PINREG & CORE_PIN31_BITMASK) ? 1 : 0;
  1400. } else if (pin == 32) {
  1401. return (CORE_PIN32_PINREG & CORE_PIN32_BITMASK) ? 1 : 0;
  1402. } else if (pin == 33) {
  1403. return (CORE_PIN33_PINREG & CORE_PIN33_BITMASK) ? 1 : 0;
  1404. } else if (pin == 34) {
  1405. return (CORE_PIN34_PINREG & CORE_PIN34_BITMASK) ? 1 : 0;
  1406. } else if (pin == 35) {
  1407. return (CORE_PIN35_PINREG & CORE_PIN35_BITMASK) ? 1 : 0;
  1408. } else if (pin == 36) {
  1409. return (CORE_PIN36_PINREG & CORE_PIN36_BITMASK) ? 1 : 0;
  1410. } else if (pin == 37) {
  1411. return (CORE_PIN37_PINREG & CORE_PIN37_BITMASK) ? 1 : 0;
  1412. } else if (pin == 38) {
  1413. return (CORE_PIN38_PINREG & CORE_PIN38_BITMASK) ? 1 : 0;
  1414. } else if (pin == 39) {
  1415. return (CORE_PIN39_PINREG & CORE_PIN39_BITMASK) ? 1 : 0;
  1416. } else if (pin == 40) {
  1417. return (CORE_PIN40_PINREG & CORE_PIN40_BITMASK) ? 1 : 0;
  1418. } else if (pin == 41) {
  1419. return (CORE_PIN41_PINREG & CORE_PIN41_BITMASK) ? 1 : 0;
  1420. } else if (pin == 42) {
  1421. return (CORE_PIN42_PINREG & CORE_PIN42_BITMASK) ? 1 : 0;
  1422. } else if (pin == 43) {
  1423. return (CORE_PIN43_PINREG & CORE_PIN43_BITMASK) ? 1 : 0;
  1424. } else if (pin == 44) {
  1425. return (CORE_PIN44_PINREG & CORE_PIN44_BITMASK) ? 1 : 0;
  1426. } else if (pin == 45) {
  1427. return (CORE_PIN45_PINREG & CORE_PIN45_BITMASK) ? 1 : 0;
  1428. }
  1429. #endif
  1430. else {
  1431. return 0;
  1432. }
  1433. } else {
  1434. uint16_t tmp = (pin);
  1435. asm volatile(
  1436. "call _digitalRead"
  1437. : "+z" (tmp)
  1438. :);
  1439. return (uint8_t)tmp;
  1440. }
  1441. }
  1442. static inline uint8_t digitalReadFast(uint8_t) __attribute__((always_inline, unused));
  1443. static inline uint8_t digitalReadFast(uint8_t pin)
  1444. {
  1445. return digitalRead(pin);
  1446. }
  1447. extern void _pinMode(uint8_t pin, uint8_t mode) __attribute__((noinline));
  1448. extern void _pinMode_output(uint8_t pin) __attribute__((noinline));
  1449. extern void _pinMode_input(uint8_t pin) __attribute__((noinline));
  1450. extern void _pinMode_input_pullup(uint8_t pin) __attribute__((noinline));
  1451. static inline void pinMode(uint8_t, uint8_t) __attribute__((always_inline, unused));
  1452. static inline void pinMode(uint8_t pin, uint8_t mode)
  1453. {
  1454. if (__builtin_constant_p(pin) && __builtin_constant_p(mode)) {
  1455. if (mode == OUTPUT) {
  1456. if (pin == 0) {
  1457. CORE_PIN0_DDRREG |= CORE_PIN0_BITMASK;
  1458. } else if (pin == 1) {
  1459. CORE_PIN1_DDRREG |= CORE_PIN1_BITMASK;
  1460. } else if (pin == 2) {
  1461. CORE_PIN2_DDRREG |= CORE_PIN2_BITMASK;
  1462. } else if (pin == 3) {
  1463. CORE_PIN3_DDRREG |= CORE_PIN3_BITMASK;
  1464. } else if (pin == 4) {
  1465. CORE_PIN4_DDRREG |= CORE_PIN4_BITMASK;
  1466. } else if (pin == 5) {
  1467. CORE_PIN5_DDRREG |= CORE_PIN5_BITMASK;
  1468. } else if (pin == 6) {
  1469. CORE_PIN6_DDRREG |= CORE_PIN6_BITMASK;
  1470. } else if (pin == 7) {
  1471. CORE_PIN7_DDRREG |= CORE_PIN7_BITMASK;
  1472. } else if (pin == 8) {
  1473. CORE_PIN8_DDRREG |= CORE_PIN8_BITMASK;
  1474. } else if (pin == 9) {
  1475. CORE_PIN9_DDRREG |= CORE_PIN9_BITMASK;
  1476. } else if (pin == 10) {
  1477. CORE_PIN10_DDRREG |= CORE_PIN10_BITMASK;
  1478. } else if (pin == 11) {
  1479. CORE_PIN11_DDRREG |= CORE_PIN11_BITMASK;
  1480. } else if (pin == 12) {
  1481. CORE_PIN12_DDRREG |= CORE_PIN12_BITMASK;
  1482. } else if (pin == 13) {
  1483. CORE_PIN13_DDRREG |= CORE_PIN13_BITMASK;
  1484. } else if (pin == 14) {
  1485. CORE_PIN14_DDRREG |= CORE_PIN14_BITMASK;
  1486. } else if (pin == 15) {
  1487. CORE_PIN15_DDRREG |= CORE_PIN15_BITMASK;
  1488. } else if (pin == 16) {
  1489. CORE_PIN16_DDRREG |= CORE_PIN16_BITMASK;
  1490. } else if (pin == 17) {
  1491. CORE_PIN17_DDRREG |= CORE_PIN17_BITMASK;
  1492. } else if (pin == 18) {
  1493. CORE_PIN18_DDRREG |= CORE_PIN18_BITMASK;
  1494. } else if (pin == 19) {
  1495. CORE_PIN19_DDRREG |= CORE_PIN19_BITMASK;
  1496. } else if (pin == 20) {
  1497. CORE_PIN20_DDRREG |= CORE_PIN20_BITMASK;
  1498. }
  1499. #if CORE_NUM_TOTAL_PINS > 21
  1500. else if (pin == 21) {
  1501. CORE_PIN21_DDRREG |= CORE_PIN21_BITMASK;
  1502. } else if (pin == 22) {
  1503. CORE_PIN22_DDRREG |= CORE_PIN22_BITMASK;
  1504. } else if (pin == 23) {
  1505. CORE_PIN23_DDRREG |= CORE_PIN23_BITMASK;
  1506. } else if (pin == 24) {
  1507. CORE_PIN24_DDRREG |= CORE_PIN24_BITMASK;
  1508. }
  1509. #endif
  1510. #if CORE_NUM_TOTAL_PINS > 25
  1511. else if (pin == 25) {
  1512. CORE_PIN25_DDRREG |= CORE_PIN25_BITMASK;
  1513. } else if (pin == 26) {
  1514. CORE_PIN26_DDRREG |= CORE_PIN26_BITMASK;
  1515. } else if (pin == 27) {
  1516. CORE_PIN27_DDRREG |= CORE_PIN27_BITMASK;
  1517. } else if (pin == 28) {
  1518. CORE_PIN28_DDRREG |= CORE_PIN28_BITMASK;
  1519. } else if (pin == 29) {
  1520. CORE_PIN29_DDRREG |= CORE_PIN29_BITMASK;
  1521. } else if (pin == 30) {
  1522. CORE_PIN30_DDRREG |= CORE_PIN30_BITMASK;
  1523. } else if (pin == 31) {
  1524. CORE_PIN31_DDRREG |= CORE_PIN31_BITMASK;
  1525. } else if (pin == 32) {
  1526. CORE_PIN32_DDRREG |= CORE_PIN32_BITMASK;
  1527. } else if (pin == 33) {
  1528. CORE_PIN33_DDRREG |= CORE_PIN33_BITMASK;
  1529. } else if (pin == 34) {
  1530. CORE_PIN34_DDRREG |= CORE_PIN34_BITMASK;
  1531. } else if (pin == 35) {
  1532. CORE_PIN35_DDRREG |= CORE_PIN35_BITMASK;
  1533. } else if (pin == 36) {
  1534. CORE_PIN36_DDRREG |= CORE_PIN36_BITMASK;
  1535. } else if (pin == 37) {
  1536. CORE_PIN37_DDRREG |= CORE_PIN37_BITMASK;
  1537. } else if (pin == 38) {
  1538. CORE_PIN38_DDRREG |= CORE_PIN38_BITMASK;
  1539. } else if (pin == 39) {
  1540. CORE_PIN39_DDRREG |= CORE_PIN39_BITMASK;
  1541. } else if (pin == 40) {
  1542. CORE_PIN40_DDRREG |= CORE_PIN40_BITMASK;
  1543. } else if (pin == 41) {
  1544. CORE_PIN41_DDRREG |= CORE_PIN41_BITMASK;
  1545. } else if (pin == 42) {
  1546. CORE_PIN42_DDRREG |= CORE_PIN42_BITMASK;
  1547. } else if (pin == 43) {
  1548. CORE_PIN43_DDRREG |= CORE_PIN43_BITMASK;
  1549. } else if (pin == 44) {
  1550. CORE_PIN44_DDRREG |= CORE_PIN44_BITMASK;
  1551. } else if (pin == 45) {
  1552. CORE_PIN45_DDRREG |= CORE_PIN45_BITMASK;
  1553. }
  1554. #endif
  1555. } else if (mode == INPUT_PULLUP) {
  1556. if (pin == 0) {
  1557. CORE_PIN0_DDRREG &= ~CORE_PIN0_BITMASK;
  1558. CORE_PIN0_PORTREG |= CORE_PIN0_BITMASK;
  1559. } else if (pin == 1) {
  1560. CORE_PIN1_DDRREG &= ~CORE_PIN1_BITMASK;
  1561. CORE_PIN1_PORTREG |= CORE_PIN1_BITMASK;
  1562. } else if (pin == 2) {
  1563. CORE_PIN2_DDRREG &= ~CORE_PIN2_BITMASK;
  1564. CORE_PIN2_PORTREG |= CORE_PIN2_BITMASK;
  1565. } else if (pin == 3) {
  1566. CORE_PIN3_DDRREG &= ~CORE_PIN3_BITMASK;
  1567. CORE_PIN3_PORTREG |= CORE_PIN3_BITMASK;
  1568. } else if (pin == 4) {
  1569. CORE_PIN4_DDRREG &= ~CORE_PIN4_BITMASK;
  1570. CORE_PIN4_PORTREG |= CORE_PIN4_BITMASK;
  1571. } else if (pin == 5) {
  1572. CORE_PIN5_DDRREG &= ~CORE_PIN5_BITMASK;
  1573. CORE_PIN5_PORTREG |= CORE_PIN5_BITMASK;
  1574. } else if (pin == 6) {
  1575. CORE_PIN6_DDRREG &= ~CORE_PIN6_BITMASK;
  1576. CORE_PIN6_PORTREG |= CORE_PIN6_BITMASK;
  1577. } else if (pin == 7) {
  1578. CORE_PIN7_DDRREG &= ~CORE_PIN7_BITMASK;
  1579. CORE_PIN7_PORTREG |= CORE_PIN7_BITMASK;
  1580. } else if (pin == 8) {
  1581. CORE_PIN8_DDRREG &= ~CORE_PIN8_BITMASK;
  1582. CORE_PIN8_PORTREG |= CORE_PIN8_BITMASK;
  1583. } else if (pin == 9) {
  1584. CORE_PIN9_DDRREG &= ~CORE_PIN9_BITMASK;
  1585. CORE_PIN9_PORTREG |= CORE_PIN9_BITMASK;
  1586. } else if (pin == 10) {
  1587. CORE_PIN10_DDRREG &= ~CORE_PIN10_BITMASK;
  1588. CORE_PIN10_PORTREG |= CORE_PIN10_BITMASK;
  1589. } else if (pin == 11) {
  1590. CORE_PIN11_DDRREG &= ~CORE_PIN11_BITMASK;
  1591. CORE_PIN11_PORTREG |= CORE_PIN11_BITMASK;
  1592. } else if (pin == 12) {
  1593. CORE_PIN12_DDRREG &= ~CORE_PIN12_BITMASK;
  1594. CORE_PIN12_PORTREG |= CORE_PIN12_BITMASK;
  1595. } else if (pin == 13) {
  1596. CORE_PIN13_DDRREG &= ~CORE_PIN13_BITMASK;
  1597. CORE_PIN13_PORTREG |= CORE_PIN13_BITMASK;
  1598. } else if (pin == 14) {
  1599. CORE_PIN14_DDRREG &= ~CORE_PIN14_BITMASK;
  1600. CORE_PIN14_PORTREG |= CORE_PIN14_BITMASK;
  1601. } else if (pin == 15) {
  1602. CORE_PIN15_DDRREG &= ~CORE_PIN15_BITMASK;
  1603. CORE_PIN15_PORTREG |= CORE_PIN15_BITMASK;
  1604. } else if (pin == 16) {
  1605. CORE_PIN16_DDRREG &= ~CORE_PIN16_BITMASK;
  1606. CORE_PIN16_PORTREG |= CORE_PIN16_BITMASK;
  1607. } else if (pin == 17) {
  1608. CORE_PIN17_DDRREG &= ~CORE_PIN17_BITMASK;
  1609. CORE_PIN17_PORTREG |= CORE_PIN17_BITMASK;
  1610. } else if (pin == 18) {
  1611. CORE_PIN18_DDRREG &= ~CORE_PIN18_BITMASK;
  1612. CORE_PIN18_PORTREG |= CORE_PIN18_BITMASK;
  1613. } else if (pin == 19) {
  1614. CORE_PIN19_DDRREG &= ~CORE_PIN19_BITMASK;
  1615. CORE_PIN19_PORTREG |= CORE_PIN19_BITMASK;
  1616. } else if (pin == 20) {
  1617. CORE_PIN20_DDRREG &= ~CORE_PIN20_BITMASK;
  1618. CORE_PIN20_PORTREG |= CORE_PIN20_BITMASK;
  1619. }
  1620. #if CORE_NUM_TOTAL_PINS > 21
  1621. else if (pin == 21) {
  1622. CORE_PIN21_DDRREG &= ~CORE_PIN21_BITMASK;
  1623. CORE_PIN21_PORTREG |= CORE_PIN21_BITMASK;
  1624. } else if (pin == 22) {
  1625. CORE_PIN22_DDRREG &= ~CORE_PIN22_BITMASK;
  1626. CORE_PIN22_PORTREG |= CORE_PIN22_BITMASK;
  1627. } else if (pin == 23) {
  1628. CORE_PIN23_DDRREG &= ~CORE_PIN23_BITMASK;
  1629. CORE_PIN23_PORTREG |= CORE_PIN23_BITMASK;
  1630. } else if (pin == 24) {
  1631. CORE_PIN24_DDRREG &= ~CORE_PIN24_BITMASK;
  1632. CORE_PIN24_PORTREG |= CORE_PIN24_BITMASK;
  1633. }
  1634. #endif
  1635. #if CORE_NUM_TOTAL_PINS > 25
  1636. else if (pin == 25) {
  1637. CORE_PIN25_DDRREG &= ~CORE_PIN25_BITMASK;
  1638. CORE_PIN25_PORTREG |= CORE_PIN25_BITMASK;
  1639. } else if (pin == 26) {
  1640. CORE_PIN26_DDRREG &= ~CORE_PIN26_BITMASK;
  1641. CORE_PIN26_PORTREG |= CORE_PIN26_BITMASK;
  1642. } else if (pin == 27) {
  1643. CORE_PIN27_DDRREG &= ~CORE_PIN27_BITMASK;
  1644. CORE_PIN27_PORTREG |= CORE_PIN27_BITMASK;
  1645. } else if (pin == 28) {
  1646. CORE_PIN28_DDRREG &= ~CORE_PIN28_BITMASK;
  1647. CORE_PIN28_PORTREG |= CORE_PIN28_BITMASK;
  1648. } else if (pin == 29) {
  1649. CORE_PIN29_DDRREG &= ~CORE_PIN29_BITMASK;
  1650. CORE_PIN29_PORTREG |= CORE_PIN29_BITMASK;
  1651. } else if (pin == 30) {
  1652. CORE_PIN30_DDRREG &= ~CORE_PIN30_BITMASK;
  1653. CORE_PIN30_PORTREG |= CORE_PIN30_BITMASK;
  1654. } else if (pin == 31) {
  1655. CORE_PIN31_DDRREG &= ~CORE_PIN31_BITMASK;
  1656. CORE_PIN31_PORTREG |= CORE_PIN31_BITMASK;
  1657. } else if (pin == 32) {
  1658. CORE_PIN32_DDRREG &= ~CORE_PIN32_BITMASK;
  1659. CORE_PIN32_PORTREG |= CORE_PIN32_BITMASK;
  1660. } else if (pin == 33) {
  1661. CORE_PIN33_DDRREG &= ~CORE_PIN33_BITMASK;
  1662. CORE_PIN33_PORTREG |= CORE_PIN33_BITMASK;
  1663. } else if (pin == 34) {
  1664. CORE_PIN34_DDRREG &= ~CORE_PIN34_BITMASK;
  1665. CORE_PIN34_PORTREG |= CORE_PIN34_BITMASK;
  1666. } else if (pin == 35) {
  1667. CORE_PIN35_DDRREG &= ~CORE_PIN35_BITMASK;
  1668. CORE_PIN35_PORTREG |= CORE_PIN35_BITMASK;
  1669. } else if (pin == 36) {
  1670. CORE_PIN36_DDRREG &= ~CORE_PIN36_BITMASK;
  1671. CORE_PIN36_PORTREG |= CORE_PIN36_BITMASK;
  1672. } else if (pin == 37) {
  1673. CORE_PIN37_DDRREG &= ~CORE_PIN37_BITMASK;
  1674. CORE_PIN37_PORTREG |= CORE_PIN37_BITMASK;
  1675. } else if (pin == 38) {
  1676. CORE_PIN38_DDRREG &= ~CORE_PIN38_BITMASK;
  1677. CORE_PIN38_PORTREG |= CORE_PIN38_BITMASK;
  1678. } else if (pin == 39) {
  1679. CORE_PIN39_DDRREG &= ~CORE_PIN39_BITMASK;
  1680. CORE_PIN39_PORTREG |= CORE_PIN39_BITMASK;
  1681. } else if (pin == 40) {
  1682. CORE_PIN40_DDRREG &= ~CORE_PIN40_BITMASK;
  1683. CORE_PIN40_PORTREG |= CORE_PIN40_BITMASK;
  1684. } else if (pin == 41) {
  1685. CORE_PIN41_DDRREG &= ~CORE_PIN41_BITMASK;
  1686. CORE_PIN41_PORTREG |= CORE_PIN41_BITMASK;
  1687. } else if (pin == 42) {
  1688. CORE_PIN42_DDRREG &= ~CORE_PIN42_BITMASK;
  1689. CORE_PIN42_PORTREG |= CORE_PIN42_BITMASK;
  1690. } else if (pin == 43) {
  1691. CORE_PIN43_DDRREG &= ~CORE_PIN43_BITMASK;
  1692. CORE_PIN43_PORTREG |= CORE_PIN43_BITMASK;
  1693. } else if (pin == 44) {
  1694. CORE_PIN44_DDRREG &= ~CORE_PIN44_BITMASK;
  1695. CORE_PIN44_PORTREG |= CORE_PIN44_BITMASK;
  1696. } else if (pin == 45) {
  1697. CORE_PIN45_DDRREG &= ~CORE_PIN45_BITMASK;
  1698. CORE_PIN45_PORTREG |= CORE_PIN45_BITMASK;
  1699. }
  1700. #endif
  1701. } else {
  1702. if (pin == 0) {
  1703. CORE_PIN0_DDRREG &= ~CORE_PIN0_BITMASK;
  1704. CORE_PIN0_PORTREG &= ~CORE_PIN0_BITMASK;
  1705. } else if (pin == 1) {
  1706. CORE_PIN1_DDRREG &= ~CORE_PIN1_BITMASK;
  1707. CORE_PIN1_PORTREG &= ~CORE_PIN1_BITMASK;
  1708. } else if (pin == 2) {
  1709. CORE_PIN2_DDRREG &= ~CORE_PIN2_BITMASK;
  1710. CORE_PIN2_PORTREG &= ~CORE_PIN2_BITMASK;
  1711. } else if (pin == 3) {
  1712. CORE_PIN3_DDRREG &= ~CORE_PIN3_BITMASK;
  1713. CORE_PIN3_PORTREG &= ~CORE_PIN3_BITMASK;
  1714. } else if (pin == 4) {
  1715. CORE_PIN4_DDRREG &= ~CORE_PIN4_BITMASK;
  1716. CORE_PIN4_PORTREG &= ~CORE_PIN4_BITMASK;
  1717. } else if (pin == 5) {
  1718. CORE_PIN5_DDRREG &= ~CORE_PIN5_BITMASK;
  1719. CORE_PIN5_PORTREG &= ~CORE_PIN5_BITMASK;
  1720. } else if (pin == 6) {
  1721. CORE_PIN6_DDRREG &= ~CORE_PIN6_BITMASK;
  1722. CORE_PIN6_PORTREG &= ~CORE_PIN6_BITMASK;
  1723. } else if (pin == 7) {
  1724. CORE_PIN7_DDRREG &= ~CORE_PIN7_BITMASK;
  1725. CORE_PIN7_PORTREG &= ~CORE_PIN7_BITMASK;
  1726. } else if (pin == 8) {
  1727. CORE_PIN8_DDRREG &= ~CORE_PIN8_BITMASK;
  1728. CORE_PIN8_PORTREG &= ~CORE_PIN8_BITMASK;
  1729. } else if (pin == 9) {
  1730. CORE_PIN9_DDRREG &= ~CORE_PIN9_BITMASK;
  1731. CORE_PIN9_PORTREG &= ~CORE_PIN9_BITMASK;
  1732. } else if (pin == 10) {
  1733. CORE_PIN10_DDRREG &= ~CORE_PIN10_BITMASK;
  1734. CORE_PIN10_PORTREG &= ~CORE_PIN10_BITMASK;
  1735. } else if (pin == 11) {
  1736. CORE_PIN11_DDRREG &= ~CORE_PIN11_BITMASK;
  1737. CORE_PIN11_PORTREG &= ~CORE_PIN11_BITMASK;
  1738. } else if (pin == 12) {
  1739. CORE_PIN12_DDRREG &= ~CORE_PIN12_BITMASK;
  1740. CORE_PIN12_PORTREG &= ~CORE_PIN12_BITMASK;
  1741. } else if (pin == 13) {
  1742. CORE_PIN13_DDRREG &= ~CORE_PIN13_BITMASK;
  1743. CORE_PIN13_PORTREG &= ~CORE_PIN13_BITMASK;
  1744. } else if (pin == 14) {
  1745. CORE_PIN14_DDRREG &= ~CORE_PIN14_BITMASK;
  1746. CORE_PIN14_PORTREG &= ~CORE_PIN14_BITMASK;
  1747. } else if (pin == 15) {
  1748. CORE_PIN15_DDRREG &= ~CORE_PIN15_BITMASK;
  1749. CORE_PIN15_PORTREG &= ~CORE_PIN15_BITMASK;
  1750. } else if (pin == 16) {
  1751. CORE_PIN16_DDRREG &= ~CORE_PIN16_BITMASK;
  1752. CORE_PIN16_PORTREG &= ~CORE_PIN16_BITMASK;
  1753. } else if (pin == 17) {
  1754. CORE_PIN17_DDRREG &= ~CORE_PIN17_BITMASK;
  1755. CORE_PIN17_PORTREG &= ~CORE_PIN17_BITMASK;
  1756. } else if (pin == 18) {
  1757. CORE_PIN18_DDRREG &= ~CORE_PIN18_BITMASK;
  1758. CORE_PIN18_PORTREG &= ~CORE_PIN18_BITMASK;
  1759. } else if (pin == 19) {
  1760. CORE_PIN19_DDRREG &= ~CORE_PIN19_BITMASK;
  1761. CORE_PIN19_PORTREG &= ~CORE_PIN19_BITMASK;
  1762. } else if (pin == 20) {
  1763. CORE_PIN20_DDRREG &= ~CORE_PIN20_BITMASK;
  1764. CORE_PIN20_PORTREG &= ~CORE_PIN20_BITMASK;
  1765. }
  1766. #if CORE_NUM_TOTAL_PINS > 21
  1767. else if (pin == 21) {
  1768. CORE_PIN21_DDRREG &= ~CORE_PIN21_BITMASK;
  1769. CORE_PIN21_PORTREG &= ~CORE_PIN21_BITMASK;
  1770. } else if (pin == 22) {
  1771. CORE_PIN22_DDRREG &= ~CORE_PIN22_BITMASK;
  1772. CORE_PIN22_PORTREG &= ~CORE_PIN22_BITMASK;
  1773. } else if (pin == 23) {
  1774. CORE_PIN23_DDRREG &= ~CORE_PIN23_BITMASK;
  1775. CORE_PIN23_PORTREG &= ~CORE_PIN23_BITMASK;
  1776. } else if (pin == 24) {
  1777. CORE_PIN24_DDRREG &= ~CORE_PIN24_BITMASK;
  1778. CORE_PIN24_PORTREG &= ~CORE_PIN24_BITMASK;
  1779. }
  1780. #endif
  1781. #if CORE_NUM_TOTAL_PINS > 25
  1782. else if (pin == 25) {
  1783. CORE_PIN25_DDRREG &= ~CORE_PIN25_BITMASK;
  1784. CORE_PIN25_PORTREG &= ~CORE_PIN25_BITMASK;
  1785. } else if (pin == 26) {
  1786. CORE_PIN26_DDRREG &= ~CORE_PIN26_BITMASK;
  1787. CORE_PIN26_PORTREG &= ~CORE_PIN26_BITMASK;
  1788. } else if (pin == 27) {
  1789. CORE_PIN27_DDRREG &= ~CORE_PIN27_BITMASK;
  1790. CORE_PIN27_PORTREG &= ~CORE_PIN27_BITMASK;
  1791. } else if (pin == 28) {
  1792. CORE_PIN28_DDRREG &= ~CORE_PIN28_BITMASK;
  1793. CORE_PIN28_PORTREG &= ~CORE_PIN28_BITMASK;
  1794. } else if (pin == 29) {
  1795. CORE_PIN29_DDRREG &= ~CORE_PIN29_BITMASK;
  1796. CORE_PIN29_PORTREG &= ~CORE_PIN29_BITMASK;
  1797. } else if (pin == 30) {
  1798. CORE_PIN30_DDRREG &= ~CORE_PIN30_BITMASK;
  1799. CORE_PIN30_PORTREG &= ~CORE_PIN30_BITMASK;
  1800. } else if (pin == 31) {
  1801. CORE_PIN31_DDRREG &= ~CORE_PIN31_BITMASK;
  1802. CORE_PIN31_PORTREG &= ~CORE_PIN31_BITMASK;
  1803. } else if (pin == 32) {
  1804. CORE_PIN32_DDRREG &= ~CORE_PIN32_BITMASK;
  1805. CORE_PIN32_PORTREG &= ~CORE_PIN32_BITMASK;
  1806. } else if (pin == 33) {
  1807. CORE_PIN33_DDRREG &= ~CORE_PIN33_BITMASK;
  1808. CORE_PIN33_PORTREG &= ~CORE_PIN33_BITMASK;
  1809. } else if (pin == 34) {
  1810. CORE_PIN34_DDRREG &= ~CORE_PIN34_BITMASK;
  1811. CORE_PIN34_PORTREG &= ~CORE_PIN34_BITMASK;
  1812. } else if (pin == 35) {
  1813. CORE_PIN35_DDRREG &= ~CORE_PIN35_BITMASK;
  1814. CORE_PIN35_PORTREG &= ~CORE_PIN35_BITMASK;
  1815. } else if (pin == 36) {
  1816. CORE_PIN36_DDRREG &= ~CORE_PIN36_BITMASK;
  1817. CORE_PIN36_PORTREG &= ~CORE_PIN36_BITMASK;
  1818. } else if (pin == 37) {
  1819. CORE_PIN37_DDRREG &= ~CORE_PIN37_BITMASK;
  1820. CORE_PIN37_PORTREG &= ~CORE_PIN37_BITMASK;
  1821. } else if (pin == 38) {
  1822. CORE_PIN38_DDRREG &= ~CORE_PIN38_BITMASK;
  1823. CORE_PIN38_PORTREG &= ~CORE_PIN38_BITMASK;
  1824. } else if (pin == 39) {
  1825. CORE_PIN39_DDRREG &= ~CORE_PIN39_BITMASK;
  1826. CORE_PIN39_PORTREG &= ~CORE_PIN39_BITMASK;
  1827. } else if (pin == 40) {
  1828. CORE_PIN40_DDRREG &= ~CORE_PIN40_BITMASK;
  1829. CORE_PIN40_PORTREG &= ~CORE_PIN40_BITMASK;
  1830. } else if (pin == 41) {
  1831. CORE_PIN41_DDRREG &= ~CORE_PIN41_BITMASK;
  1832. CORE_PIN41_PORTREG &= ~CORE_PIN41_BITMASK;
  1833. } else if (pin == 42) {
  1834. CORE_PIN42_DDRREG &= ~CORE_PIN42_BITMASK;
  1835. CORE_PIN42_PORTREG &= ~CORE_PIN42_BITMASK;
  1836. } else if (pin == 43) {
  1837. CORE_PIN43_DDRREG &= ~CORE_PIN43_BITMASK;
  1838. CORE_PIN43_PORTREG &= ~CORE_PIN43_BITMASK;
  1839. } else if (pin == 44) {
  1840. CORE_PIN44_DDRREG &= ~CORE_PIN44_BITMASK;
  1841. CORE_PIN44_PORTREG &= ~CORE_PIN44_BITMASK;
  1842. } else if (pin == 45) {
  1843. CORE_PIN45_DDRREG &= ~CORE_PIN45_BITMASK;
  1844. CORE_PIN45_PORTREG &= ~CORE_PIN45_BITMASK;
  1845. }
  1846. #endif
  1847. }
  1848. #if defined(__AVR_ATmega32U4__)
  1849. if (mode == INPUT || mode == INPUT_PULLUP) {
  1850. if (pin == 11) {
  1851. DIDR2 &= ~0x02;
  1852. } else if (pin == 12) {
  1853. DIDR2 &= ~0x04;
  1854. } else if (pin == 13) {
  1855. DIDR2 &= ~0x08;
  1856. } else if (pin == 14) {
  1857. DIDR2 &= ~0x10;
  1858. } else if (pin == 15) {
  1859. DIDR2 &= ~0x20;
  1860. } else if (pin == 16) {
  1861. DIDR0 &= ~0x80;
  1862. } else if (pin == 17) {
  1863. DIDR0 &= ~0x40;
  1864. } else if (pin == 18) {
  1865. DIDR0 &= ~0x20;
  1866. } else if (pin == 19) {
  1867. DIDR0 &= ~0x10;
  1868. } else if (pin == 20) {
  1869. DIDR0 &= ~0x02;
  1870. } else if (pin == 21) {
  1871. DIDR0 &= ~0x01;
  1872. } else if (pin == 22) {
  1873. DIDR2 &= ~0x01;
  1874. }
  1875. }
  1876. #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  1877. if (mode == INPUT || mode == INPUT_PULLUP) {
  1878. if (pin == 38) {
  1879. DIDR0 &= ~0x01;
  1880. } else if (pin == 39) {
  1881. DIDR0 &= ~0x02;
  1882. } else if (pin == 40) {
  1883. DIDR0 &= ~0x04;
  1884. } else if (pin == 41) {
  1885. DIDR0 &= ~0x08;
  1886. } else if (pin == 42) {
  1887. DIDR0 &= ~0x10;
  1888. } else if (pin == 43) {
  1889. DIDR0 &= ~0x20;
  1890. } else if (pin == 44) {
  1891. DIDR0 &= ~0x40;
  1892. } else if (pin == 45) {
  1893. DIDR0 &= ~0x80;
  1894. }
  1895. }
  1896. #endif
  1897. } else if (__builtin_constant_p(mode)) {
  1898. if (mode == OUTPUT) {
  1899. _pinMode_output(pin);
  1900. } else if (mode == INPUT_PULLUP) {
  1901. _pinMode_input_pullup(pin);
  1902. } else {
  1903. _pinMode_input(pin);
  1904. }
  1905. } else {
  1906. _pinMode(pin, mode);
  1907. }
  1908. }
  1909. static inline void digitalToggle(uint8_t) __attribute__((always_inline, unused));
  1910. static inline void digitalToggle(uint8_t pin)
  1911. {
  1912. if (__builtin_constant_p(pin)) {
  1913. if (pin == 0) {
  1914. CORE_PIN0_PINREG = CORE_PIN0_BITMASK;
  1915. } else if (pin == 1) {
  1916. CORE_PIN1_PINREG = CORE_PIN1_BITMASK;
  1917. } else if (pin == 2) {
  1918. CORE_PIN2_PINREG = CORE_PIN2_BITMASK;
  1919. } else if (pin == 3) {
  1920. CORE_PIN3_PINREG = CORE_PIN3_BITMASK;
  1921. } else if (pin == 4) {
  1922. CORE_PIN4_PINREG = CORE_PIN4_BITMASK;
  1923. } else if (pin == 5) {
  1924. CORE_PIN5_PINREG = CORE_PIN5_BITMASK;
  1925. } else if (pin == 6) {
  1926. CORE_PIN6_PINREG = CORE_PIN6_BITMASK;
  1927. } else if (pin == 7) {
  1928. CORE_PIN7_PINREG = CORE_PIN7_BITMASK;
  1929. } else if (pin == 8) {
  1930. CORE_PIN8_PINREG = CORE_PIN8_BITMASK;
  1931. } else if (pin == 9) {
  1932. CORE_PIN9_PINREG = CORE_PIN9_BITMASK;
  1933. } else if (pin == 10) {
  1934. CORE_PIN10_PINREG = CORE_PIN10_BITMASK;
  1935. } else if (pin == 11) {
  1936. CORE_PIN11_PINREG = CORE_PIN11_BITMASK;
  1937. } else if (pin == 12) {
  1938. CORE_PIN12_PINREG = CORE_PIN12_BITMASK;
  1939. } else if (pin == 13) {
  1940. CORE_PIN13_PINREG = CORE_PIN13_BITMASK;
  1941. } else if (pin == 14) {
  1942. CORE_PIN14_PINREG = CORE_PIN14_BITMASK;
  1943. } else if (pin == 15) {
  1944. CORE_PIN15_PINREG = CORE_PIN15_BITMASK;
  1945. } else if (pin == 16) {
  1946. CORE_PIN16_PINREG = CORE_PIN16_BITMASK;
  1947. } else if (pin == 17) {
  1948. CORE_PIN17_PINREG = CORE_PIN17_BITMASK;
  1949. } else if (pin == 18) {
  1950. CORE_PIN18_PINREG = CORE_PIN18_BITMASK;
  1951. } else if (pin == 19) {
  1952. CORE_PIN19_PINREG = CORE_PIN19_BITMASK;
  1953. } else if (pin == 20) {
  1954. CORE_PIN20_PINREG = CORE_PIN20_BITMASK;
  1955. }
  1956. #if CORE_NUM_TOTAL_PINS > 21
  1957. else if (pin == 21) {
  1958. CORE_PIN21_PINREG = CORE_PIN21_BITMASK;
  1959. } else if (pin == 22) {
  1960. CORE_PIN22_PINREG = CORE_PIN22_BITMASK;
  1961. } else if (pin == 23) {
  1962. CORE_PIN23_PINREG = CORE_PIN23_BITMASK;
  1963. } else if (pin == 24) {
  1964. CORE_PIN24_PINREG = CORE_PIN24_BITMASK;
  1965. }
  1966. #endif
  1967. #if CORE_NUM_TOTAL_PINS > 25
  1968. else if (pin == 25) {
  1969. CORE_PIN25_PINREG = CORE_PIN25_BITMASK;
  1970. } else if (pin == 26) {
  1971. CORE_PIN26_PINREG = CORE_PIN26_BITMASK;
  1972. } else if (pin == 27) {
  1973. CORE_PIN27_PINREG = CORE_PIN27_BITMASK;
  1974. } else if (pin == 28) {
  1975. CORE_PIN28_PINREG = CORE_PIN28_BITMASK;
  1976. } else if (pin == 29) {
  1977. CORE_PIN29_PINREG = CORE_PIN29_BITMASK;
  1978. } else if (pin == 30) {
  1979. CORE_PIN30_PINREG = CORE_PIN30_BITMASK;
  1980. } else if (pin == 31) {
  1981. CORE_PIN31_PINREG = CORE_PIN31_BITMASK;
  1982. } else if (pin == 32) {
  1983. CORE_PIN32_PINREG = CORE_PIN32_BITMASK;
  1984. } else if (pin == 33) {
  1985. CORE_PIN33_PINREG = CORE_PIN33_BITMASK;
  1986. } else if (pin == 34) {
  1987. CORE_PIN34_PINREG = CORE_PIN34_BITMASK;
  1988. } else if (pin == 35) {
  1989. CORE_PIN35_PINREG = CORE_PIN35_BITMASK;
  1990. } else if (pin == 36) {
  1991. CORE_PIN36_PINREG = CORE_PIN36_BITMASK;
  1992. } else if (pin == 37) {
  1993. CORE_PIN37_PINREG = CORE_PIN37_BITMASK;
  1994. } else if (pin == 38) {
  1995. CORE_PIN38_PINREG = CORE_PIN38_BITMASK;
  1996. } else if (pin == 39) {
  1997. CORE_PIN39_PINREG = CORE_PIN39_BITMASK;
  1998. } else if (pin == 40) {
  1999. CORE_PIN40_PINREG = CORE_PIN40_BITMASK;
  2000. } else if (pin == 41) {
  2001. CORE_PIN41_PINREG = CORE_PIN41_BITMASK;
  2002. } else if (pin == 42) {
  2003. CORE_PIN42_PINREG = CORE_PIN42_BITMASK;
  2004. } else if (pin == 43) {
  2005. CORE_PIN43_PINREG = CORE_PIN43_BITMASK;
  2006. } else if (pin == 44) {
  2007. CORE_PIN44_PINREG = CORE_PIN44_BITMASK;
  2008. } else if (pin == 45) {
  2009. CORE_PIN45_PINREG = CORE_PIN45_BITMASK;
  2010. }
  2011. #endif
  2012. if (pin == CORE_OC0B_PIN) {
  2013. _SFR_BYTE(TCCR0A) &= ~(1<<COM0B1);
  2014. } else if (pin == CORE_OC1A_PIN) {
  2015. TCCR1A &= ~(1<<COM1A1);
  2016. } else if (pin == CORE_OC1B_PIN) {
  2017. TCCR1A &= ~(1<<COM1B1);
  2018. } else if (pin == CORE_OC1C_PIN) {
  2019. TCCR1A &= ~(1<<COM1C1);
  2020. }
  2021. #if defined(__AVR_ATmega32U4__)
  2022. else if (pin == CORE_OC3A_PIN) {
  2023. TCCR3A &= ~(1<<COM3A1);
  2024. } else if (pin == CORE_OC4A_PIN) {
  2025. TCCR4A &= ~(1<<COM4A1);
  2026. } else if (pin == CORE_OC4D_PIN) {
  2027. TCCR4C &= ~(1<<COM4D1);
  2028. }
  2029. #endif
  2030. #if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  2031. else if (pin == CORE_OC2A_PIN) {
  2032. TCCR2A &= ~(1<<COM2A1);
  2033. } else if (pin == CORE_OC2B_PIN) {
  2034. TCCR2A &= ~(1<<COM2B1);
  2035. } else if (pin == CORE_OC3A_PIN) {
  2036. TCCR3A &= ~(1<<COM3A1);
  2037. } else if (pin == CORE_OC3B_PIN) {
  2038. TCCR3A &= ~(1<<COM3B1);
  2039. } else if (pin == CORE_OC3C_PIN) {
  2040. TCCR3A &= ~(1<<COM3C1);
  2041. }
  2042. #endif
  2043. } else {
  2044. digitalWrite(pin, !(digitalRead(pin)));
  2045. }
  2046. }
  2047. static inline void digitalToggleFast(uint8_t) __attribute__((always_inline, unused));
  2048. static inline void digitalToggleFast(uint8_t pin)
  2049. {
  2050. if (__builtin_constant_p(pin)) {
  2051. if (pin == 0) {
  2052. CORE_PIN0_PINREG = CORE_PIN0_BITMASK;
  2053. } else if (pin == 1) {
  2054. CORE_PIN1_PINREG = CORE_PIN1_BITMASK;
  2055. } else if (pin == 2) {
  2056. CORE_PIN2_PINREG = CORE_PIN2_BITMASK;
  2057. } else if (pin == 3) {
  2058. CORE_PIN3_PINREG = CORE_PIN3_BITMASK;
  2059. } else if (pin == 4) {
  2060. CORE_PIN4_PINREG = CORE_PIN4_BITMASK;
  2061. } else if (pin == 5) {
  2062. CORE_PIN5_PINREG = CORE_PIN5_BITMASK;
  2063. } else if (pin == 6) {
  2064. CORE_PIN6_PINREG = CORE_PIN6_BITMASK;
  2065. } else if (pin == 7) {
  2066. CORE_PIN7_PINREG = CORE_PIN7_BITMASK;
  2067. } else if (pin == 8) {
  2068. CORE_PIN8_PINREG = CORE_PIN8_BITMASK;
  2069. } else if (pin == 9) {
  2070. CORE_PIN9_PINREG = CORE_PIN9_BITMASK;
  2071. } else if (pin == 10) {
  2072. CORE_PIN10_PINREG = CORE_PIN10_BITMASK;
  2073. } else if (pin == 11) {
  2074. CORE_PIN11_PINREG = CORE_PIN11_BITMASK;
  2075. } else if (pin == 12) {
  2076. CORE_PIN12_PINREG = CORE_PIN12_BITMASK;
  2077. } else if (pin == 13) {
  2078. CORE_PIN13_PINREG = CORE_PIN13_BITMASK;
  2079. } else if (pin == 14) {
  2080. CORE_PIN14_PINREG = CORE_PIN14_BITMASK;
  2081. } else if (pin == 15) {
  2082. CORE_PIN15_PINREG = CORE_PIN15_BITMASK;
  2083. } else if (pin == 16) {
  2084. CORE_PIN16_PINREG = CORE_PIN16_BITMASK;
  2085. } else if (pin == 17) {
  2086. CORE_PIN17_PINREG = CORE_PIN17_BITMASK;
  2087. } else if (pin == 18) {
  2088. CORE_PIN18_PINREG = CORE_PIN18_BITMASK;
  2089. } else if (pin == 19) {
  2090. CORE_PIN19_PINREG = CORE_PIN19_BITMASK;
  2091. } else if (pin == 20) {
  2092. CORE_PIN20_PINREG = CORE_PIN20_BITMASK;
  2093. }
  2094. #if CORE_NUM_TOTAL_PINS > 21
  2095. else if (pin == 21) {
  2096. CORE_PIN21_PINREG = CORE_PIN21_BITMASK;
  2097. } else if (pin == 22) {
  2098. CORE_PIN22_PINREG = CORE_PIN22_BITMASK;
  2099. } else if (pin == 23) {
  2100. CORE_PIN23_PINREG = CORE_PIN23_BITMASK;
  2101. } else if (pin == 24) {
  2102. CORE_PIN24_PINREG = CORE_PIN24_BITMASK;
  2103. }
  2104. #endif
  2105. #if CORE_NUM_TOTAL_PINS > 25
  2106. else if (pin == 25) {
  2107. CORE_PIN25_PINREG = CORE_PIN25_BITMASK;
  2108. } else if (pin == 26) {
  2109. CORE_PIN26_PINREG = CORE_PIN26_BITMASK;
  2110. } else if (pin == 27) {
  2111. CORE_PIN27_PINREG = CORE_PIN27_BITMASK;
  2112. } else if (pin == 28) {
  2113. CORE_PIN28_PINREG = CORE_PIN28_BITMASK;
  2114. } else if (pin == 29) {
  2115. CORE_PIN29_PINREG = CORE_PIN29_BITMASK;
  2116. } else if (pin == 30) {
  2117. CORE_PIN30_PINREG = CORE_PIN30_BITMASK;
  2118. } else if (pin == 31) {
  2119. CORE_PIN31_PINREG = CORE_PIN31_BITMASK;
  2120. } else if (pin == 32) {
  2121. CORE_PIN32_PINREG = CORE_PIN32_BITMASK;
  2122. } else if (pin == 33) {
  2123. CORE_PIN33_PINREG = CORE_PIN33_BITMASK;
  2124. } else if (pin == 34) {
  2125. CORE_PIN34_PINREG = CORE_PIN34_BITMASK;
  2126. } else if (pin == 35) {
  2127. CORE_PIN35_PINREG = CORE_PIN35_BITMASK;
  2128. } else if (pin == 36) {
  2129. CORE_PIN36_PINREG = CORE_PIN36_BITMASK;
  2130. } else if (pin == 37) {
  2131. CORE_PIN37_PINREG = CORE_PIN37_BITMASK;
  2132. } else if (pin == 38) {
  2133. CORE_PIN38_PINREG = CORE_PIN38_BITMASK;
  2134. } else if (pin == 39) {
  2135. CORE_PIN39_PINREG = CORE_PIN39_BITMASK;
  2136. } else if (pin == 40) {
  2137. CORE_PIN40_PINREG = CORE_PIN40_BITMASK;
  2138. } else if (pin == 41) {
  2139. CORE_PIN41_PINREG = CORE_PIN41_BITMASK;
  2140. } else if (pin == 42) {
  2141. CORE_PIN42_PINREG = CORE_PIN42_BITMASK;
  2142. } else if (pin == 43) {
  2143. CORE_PIN43_PINREG = CORE_PIN43_BITMASK;
  2144. } else if (pin == 44) {
  2145. CORE_PIN44_PINREG = CORE_PIN44_BITMASK;
  2146. } else if (pin == 45) {
  2147. CORE_PIN45_PINREG = CORE_PIN45_BITMASK;
  2148. }
  2149. #endif
  2150. } else {
  2151. digitalWrite(pin, !(digitalRead(pin)));
  2152. }
  2153. }
  2154. extern void _init_Teensyduino_internal_(void);
  2155. extern int analogRead(uint8_t);
  2156. extern void _analogWrite(uint8_t pin, int val) __attribute__((noinline));
  2157. static inline void analogWrite(uint8_t, int) __attribute__((always_inline, unused));
  2158. static inline void analogWrite(uint8_t pin, int val)
  2159. {
  2160. if (__builtin_constant_p(pin)) {
  2161. if (pin == CORE_OC0B_PIN) { // TIMER0B
  2162. CORE_DDRREG(CORE_OC0B_PIN) |= CORE_BITMASK(CORE_OC0B_PIN);
  2163. if (val) {
  2164. OCR0B = val;
  2165. _SFR_BYTE(TCCR0A) |= (1<<COM0B1);
  2166. } else {
  2167. CORE_PORTREG(CORE_OC0B_PIN) &= ~CORE_BITMASK(CORE_OC0B_PIN);
  2168. _SFR_BYTE(TCCR0A) &= ~(1<<COM0B1);
  2169. }
  2170. } else if (pin == CORE_OC1A_PIN) { //TIMER1A
  2171. CORE_DDRREG(CORE_OC1A_PIN) |= CORE_BITMASK(CORE_OC1A_PIN);
  2172. OCR1A = val;
  2173. TCCR1A |= (1<<COM1A1);
  2174. } else if (pin == CORE_OC1B_PIN) { //TIMER1B
  2175. CORE_DDRREG(CORE_OC1B_PIN) |= CORE_BITMASK(CORE_OC1B_PIN);
  2176. OCR1B = val;
  2177. TCCR1A |= (1<<COM1B1);
  2178. } else if (pin == CORE_OC1C_PIN) { //TIMER1C
  2179. CORE_DDRREG(CORE_OC1C_PIN) |= CORE_BITMASK(CORE_OC1C_PIN);
  2180. OCR1C = val;
  2181. TCCR1A |= (1<<COM1C1);
  2182. }
  2183. #if defined(__AVR_ATmega32U4__)
  2184. else if (pin == CORE_OC3A_PIN) { //TIMER3A
  2185. CORE_DDRREG(CORE_OC3A_PIN) |= CORE_BITMASK(CORE_OC3A_PIN);
  2186. OCR3A = val;
  2187. TCCR3A |= (1<<COM3A1);
  2188. } else if (pin == CORE_OC4A_PIN) { //TIMER4A
  2189. CORE_DDRREG(CORE_OC4A_PIN) |= CORE_BITMASK(CORE_OC4A_PIN);
  2190. OCR4A = val;
  2191. TCCR4A |= (1<<COM4A1);
  2192. } else if (pin == CORE_OC4D_PIN) { //TIMER4D
  2193. CORE_DDRREG(CORE_OC4D_PIN) |= CORE_BITMASK(CORE_OC4D_PIN);
  2194. OCR4D = val;
  2195. TCCR4C |= (1<<COM4D1);
  2196. }
  2197. #endif
  2198. #if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  2199. else if (pin == CORE_OC2A_PIN) { //TIMER2A
  2200. CORE_DDRREG(CORE_OC2A_PIN) |= CORE_BITMASK(CORE_OC2A_PIN);
  2201. OCR2A = val;
  2202. TCCR2A |= (1<<COM2A1);
  2203. } else if (pin == CORE_OC2B_PIN) { //TIMER2B
  2204. CORE_DDRREG(CORE_OC2B_PIN) |= CORE_BITMASK(CORE_OC2B_PIN);
  2205. OCR2B = val;
  2206. TCCR2A |= (1<<COM2B1);
  2207. } else if (pin == CORE_OC3A_PIN) { //TIMER3A
  2208. CORE_DDRREG(CORE_OC3A_PIN) |= CORE_BITMASK(CORE_OC3A_PIN);
  2209. OCR3A = val;
  2210. TCCR3A |= (1<<COM3A1);
  2211. } else if (pin == CORE_OC3B_PIN) { //TIMER3B
  2212. CORE_DDRREG(CORE_OC3B_PIN) |= CORE_BITMASK(CORE_OC3B_PIN);
  2213. OCR3B = val;
  2214. TCCR3A |= (1<<COM3B1);
  2215. } else if (pin == CORE_OC3C_PIN) { //TIMER3C
  2216. CORE_DDRREG(CORE_OC3C_PIN) |= CORE_BITMASK(CORE_OC3C_PIN);
  2217. OCR3C = val;
  2218. TCCR3A |= (1<<COM3C1);
  2219. }
  2220. #endif
  2221. else {
  2222. if (pin < CORE_NUM_TOTAL_PINS) {
  2223. pinMode(pin, OUTPUT);
  2224. if (val < 128) {
  2225. digitalWrite(pin, LOW);
  2226. } else {
  2227. digitalWrite(pin, HIGH);
  2228. }
  2229. }
  2230. }
  2231. } else {
  2232. _analogWrite(pin, val);
  2233. }
  2234. }
  2235. static inline void shiftOut(uint8_t, uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
  2236. extern void _shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value) __attribute__((noinline));
  2237. extern void shiftOut_lsbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
  2238. extern void shiftOut_msbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
  2239. static inline void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value)
  2240. {
  2241. if (__builtin_constant_p(bitOrder)) {
  2242. if (bitOrder == LSBFIRST) {
  2243. shiftOut_lsbFirst(dataPin, clockPin, value);
  2244. } else {
  2245. shiftOut_msbFirst(dataPin, clockPin, value);
  2246. }
  2247. } else {
  2248. _shiftOut(dataPin, clockPin, bitOrder, value);
  2249. }
  2250. }
  2251. static inline uint8_t shiftIn(uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
  2252. extern uint8_t _shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) __attribute__((noinline));
  2253. extern uint8_t shiftIn_lsbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
  2254. extern uint8_t shiftIn_msbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
  2255. static inline uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
  2256. {
  2257. if (__builtin_constant_p(bitOrder)) {
  2258. if (bitOrder == LSBFIRST) {
  2259. return shiftIn_lsbFirst(dataPin, clockPin);
  2260. } else {
  2261. return shiftIn_msbFirst(dataPin, clockPin);
  2262. }
  2263. } else {
  2264. return _shiftIn(dataPin, clockPin, bitOrder);
  2265. }
  2266. }
  2267. void _reboot_Teensyduino_(void) __attribute__((noreturn));
  2268. void _restart_Teensyduino_(void) __attribute__((noreturn));
  2269. #if defined(__AVR_AT90USB162__)
  2270. #define analogReference(mode)
  2271. #else
  2272. extern uint8_t w_analog_reference;
  2273. static inline void analogReference(uint8_t mode)
  2274. {
  2275. w_analog_reference = (mode << 6);
  2276. }
  2277. #endif
  2278. void yield(void);
  2279. extern void delay(uint32_t);
  2280. extern volatile uint32_t timer0_millis_count;
  2281. static inline uint32_t millis(void) __attribute__((always_inline, unused));
  2282. static inline uint32_t millis(void)
  2283. {
  2284. uint32_t out;
  2285. asm volatile(
  2286. "in __tmp_reg__, __SREG__" "\n\t"
  2287. "cli" "\n\t"
  2288. "lds %A0, timer0_millis_count" "\n\t"
  2289. "lds %B0, timer0_millis_count+1" "\n\t"
  2290. "lds %C0, timer0_millis_count+2" "\n\t"
  2291. "lds %D0, timer0_millis_count+3" "\n\t"
  2292. "out __SREG__, __tmp_reg__"
  2293. : "=r" (out) : : "r0"
  2294. );
  2295. return out;
  2296. }
  2297. extern uint32_t _micros(void) __attribute__((noinline));
  2298. static inline uint32_t micros(void) __attribute__((always_inline, unused));
  2299. static inline uint32_t micros(void)
  2300. {
  2301. register uint32_t out asm("r22");
  2302. asm volatile("call _micros" : "=d" (out) : : "r0");
  2303. return out;
  2304. }
  2305. static inline void delayMicroseconds(uint16_t) __attribute__((always_inline, unused));
  2306. static inline void delayMicroseconds(uint16_t usec)
  2307. {
  2308. if (__builtin_constant_p(usec)) {
  2309. #if F_CPU == 16000000L
  2310. uint16_t tmp = usec * 4;
  2311. #elif F_CPU == 8000000L
  2312. uint16_t tmp = usec * 2;
  2313. #elif F_CPU == 4000000L
  2314. uint16_t tmp = usec;
  2315. #elif F_CPU == 2000000L
  2316. uint16_t tmp = usec / 2;
  2317. if (usec == 1) {
  2318. asm volatile("rjmp L%=\nL%=:\n" ::);
  2319. }
  2320. #elif F_CPU == 1000000L
  2321. uint16_t tmp = usec / 4;
  2322. if (usec == 1) {
  2323. asm volatile("nop\n");
  2324. } else if (usec == 2) {
  2325. asm volatile("rjmp L%=\nL%=:\n" ::);
  2326. } else if (usec == 3) {
  2327. asm volatile("rjmp L%=\nL%=:\n" ::);
  2328. asm volatile("nop\n");
  2329. }
  2330. #else
  2331. #error "Clock must be 16, 8, 4, 2 or 1 MHz"
  2332. #endif
  2333. if (tmp > 0) {
  2334. if (tmp < 256) {
  2335. uint8_t tmp2 = tmp;
  2336. asm volatile(
  2337. "L_%=_loop:" // 1 to load
  2338. "subi %0, 1" "\n\t" // 1
  2339. "nop" "\n\t" // 1
  2340. "brne L_%=_loop" "\n\t" // 2 (1 on last)
  2341. : "=d" (tmp2)
  2342. : "0" (tmp2)
  2343. );
  2344. } else {
  2345. asm volatile(
  2346. "L_%=_loop:" // 2 to load
  2347. "sbiw %A0, 1" "\n\t" // 2
  2348. "brne L_%=_loop" "\n\t" // 2 (1 on last)
  2349. : "=w" (tmp)
  2350. : "0" (tmp)
  2351. );
  2352. }
  2353. }
  2354. } else {
  2355. asm volatile(
  2356. #if F_CPU == 16000000L
  2357. "sbiw %A0, 2" "\n\t" // 2
  2358. "brcs L_%=_end" "\n\t" // 1
  2359. "breq L_%=_end" "\n\t" // 1
  2360. "lsl %A0" "\n\t" // 1
  2361. "rol %B0" "\n\t" // 1
  2362. "lsl %A0" "\n\t" // 1
  2363. "rol %B0" "\n\t" // 1 overhead: (8)/4 = 2us
  2364. #elif F_CPU == 8000000L
  2365. "sbiw %A0, 3" "\n\t" // 2
  2366. "brcs L_%=_end" "\n\t" // 1
  2367. "breq L_%=_end" "\n\t" // 1
  2368. "lsl %A0" "\n\t" // 1
  2369. "rol %B0" "\n\t" // 1 overhead: (6)/2 = 3 us
  2370. #elif F_CPU == 4000000L
  2371. "sbiw %A0, 4" "\n\t" // 2
  2372. "brcs L_%=_end" "\n\t" // 1
  2373. "breq L_%=_end" "\n\t" // 1 overhead: (4) = 4 us
  2374. #elif F_CPU == 2000000L
  2375. "sbiw %A0, 12" "\n\t" // 2
  2376. "brcs L_%=_end" "\n\t" // 1
  2377. "breq L_%=_end" "\n\t" // 1
  2378. "lsr %B0" "\n\t" // 1
  2379. "ror %A0" "\n\t" // 1 overhead: (6)*2 = 12 us
  2380. #elif F_CPU == 1000000L
  2381. "sbiw %A0, 32" "\n\t" // 2
  2382. "brcs L_%=_end" "\n\t" // 1
  2383. "breq L_%=_end" "\n\t" // 1
  2384. "lsr %B0" "\n\t" // 1
  2385. "ror %A0" "\n\t" // 1
  2386. "lsr %B0" "\n\t" // 1
  2387. "ror %A0" "\n\t" // 1 overhead: (8)*4 = 32 us
  2388. #endif
  2389. "L_%=_loop:"
  2390. "sbiw %A0, 1" "\n\t" // 2
  2391. "brne L_%=_loop" "\n\t" // 2
  2392. "L_%=_end:"
  2393. : "=w" (usec)
  2394. : "0" (usec)
  2395. );
  2396. }
  2397. }
  2398. #ifdef __cplusplus
  2399. } // extern "C"
  2400. #endif
  2401. #endif