You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

core_pins.h 63KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987
  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. extern void _digitalRead(void) __attribute__((noinline));
  1118. static inline uint8_t digitalRead(uint8_t) __attribute__((always_inline, unused));
  1119. static inline uint8_t digitalRead(uint8_t pin)
  1120. {
  1121. if (__builtin_constant_p(pin)) {
  1122. if (pin == 0) {
  1123. return (CORE_PIN0_PINREG & CORE_PIN0_BITMASK) ? 1 : 0;
  1124. } else if (pin == 1) {
  1125. return (CORE_PIN1_PINREG & CORE_PIN1_BITMASK) ? 1 : 0;
  1126. } else if (pin == 2) {
  1127. return (CORE_PIN2_PINREG & CORE_PIN2_BITMASK) ? 1 : 0;
  1128. } else if (pin == 3) {
  1129. return (CORE_PIN3_PINREG & CORE_PIN3_BITMASK) ? 1 : 0;
  1130. } else if (pin == 4) {
  1131. return (CORE_PIN4_PINREG & CORE_PIN4_BITMASK) ? 1 : 0;
  1132. } else if (pin == 5) {
  1133. return (CORE_PIN5_PINREG & CORE_PIN5_BITMASK) ? 1 : 0;
  1134. } else if (pin == 6) {
  1135. return (CORE_PIN6_PINREG & CORE_PIN6_BITMASK) ? 1 : 0;
  1136. } else if (pin == 7) {
  1137. return (CORE_PIN7_PINREG & CORE_PIN7_BITMASK) ? 1 : 0;
  1138. } else if (pin == 8) {
  1139. return (CORE_PIN8_PINREG & CORE_PIN8_BITMASK) ? 1 : 0;
  1140. } else if (pin == 9) {
  1141. return (CORE_PIN9_PINREG & CORE_PIN9_BITMASK) ? 1 : 0;
  1142. } else if (pin == 10) {
  1143. return (CORE_PIN10_PINREG & CORE_PIN10_BITMASK) ? 1 : 0;
  1144. } else if (pin == 11) {
  1145. return (CORE_PIN11_PINREG & CORE_PIN11_BITMASK) ? 1 : 0;
  1146. } else if (pin == 12) {
  1147. return (CORE_PIN12_PINREG & CORE_PIN12_BITMASK) ? 1 : 0;
  1148. } else if (pin == 13) {
  1149. return (CORE_PIN13_PINREG & CORE_PIN13_BITMASK) ? 1 : 0;
  1150. } else if (pin == 14) {
  1151. return (CORE_PIN14_PINREG & CORE_PIN14_BITMASK) ? 1 : 0;
  1152. } else if (pin == 15) {
  1153. return (CORE_PIN15_PINREG & CORE_PIN15_BITMASK) ? 1 : 0;
  1154. } else if (pin == 16) {
  1155. return (CORE_PIN16_PINREG & CORE_PIN16_BITMASK) ? 1 : 0;
  1156. } else if (pin == 17) {
  1157. return (CORE_PIN17_PINREG & CORE_PIN17_BITMASK) ? 1 : 0;
  1158. } else if (pin == 18) {
  1159. return (CORE_PIN18_PINREG & CORE_PIN18_BITMASK) ? 1 : 0;
  1160. } else if (pin == 19) {
  1161. return (CORE_PIN19_PINREG & CORE_PIN19_BITMASK) ? 1 : 0;
  1162. } else if (pin == 20) {
  1163. return (CORE_PIN20_PINREG & CORE_PIN20_BITMASK) ? 1 : 0;
  1164. }
  1165. #if CORE_NUM_TOTAL_PINS > 21
  1166. else if (pin == 21) {
  1167. return (CORE_PIN21_PINREG & CORE_PIN21_BITMASK) ? 1 : 0;
  1168. } else if (pin == 22) {
  1169. return (CORE_PIN22_PINREG & CORE_PIN22_BITMASK) ? 1 : 0;
  1170. } else if (pin == 23) {
  1171. return (CORE_PIN23_PINREG & CORE_PIN23_BITMASK) ? 1 : 0;
  1172. } else if (pin == 24) {
  1173. return (CORE_PIN24_PINREG & CORE_PIN24_BITMASK) ? 1 : 0;
  1174. }
  1175. #endif
  1176. #if CORE_NUM_TOTAL_PINS > 25
  1177. else if (pin == 25) {
  1178. return (CORE_PIN25_PINREG & CORE_PIN25_BITMASK) ? 1 : 0;
  1179. } else if (pin == 26) {
  1180. return (CORE_PIN26_PINREG & CORE_PIN26_BITMASK) ? 1 : 0;
  1181. } else if (pin == 27) {
  1182. return (CORE_PIN27_PINREG & CORE_PIN27_BITMASK) ? 1 : 0;
  1183. } else if (pin == 28) {
  1184. return (CORE_PIN28_PINREG & CORE_PIN28_BITMASK) ? 1 : 0;
  1185. } else if (pin == 29) {
  1186. return (CORE_PIN29_PINREG & CORE_PIN29_BITMASK) ? 1 : 0;
  1187. } else if (pin == 30) {
  1188. return (CORE_PIN30_PINREG & CORE_PIN30_BITMASK) ? 1 : 0;
  1189. } else if (pin == 31) {
  1190. return (CORE_PIN31_PINREG & CORE_PIN31_BITMASK) ? 1 : 0;
  1191. } else if (pin == 32) {
  1192. return (CORE_PIN32_PINREG & CORE_PIN32_BITMASK) ? 1 : 0;
  1193. } else if (pin == 33) {
  1194. return (CORE_PIN33_PINREG & CORE_PIN33_BITMASK) ? 1 : 0;
  1195. } else if (pin == 34) {
  1196. return (CORE_PIN34_PINREG & CORE_PIN34_BITMASK) ? 1 : 0;
  1197. } else if (pin == 35) {
  1198. return (CORE_PIN35_PINREG & CORE_PIN35_BITMASK) ? 1 : 0;
  1199. } else if (pin == 36) {
  1200. return (CORE_PIN36_PINREG & CORE_PIN36_BITMASK) ? 1 : 0;
  1201. } else if (pin == 37) {
  1202. return (CORE_PIN37_PINREG & CORE_PIN37_BITMASK) ? 1 : 0;
  1203. } else if (pin == 38) {
  1204. return (CORE_PIN38_PINREG & CORE_PIN38_BITMASK) ? 1 : 0;
  1205. } else if (pin == 39) {
  1206. return (CORE_PIN39_PINREG & CORE_PIN39_BITMASK) ? 1 : 0;
  1207. } else if (pin == 40) {
  1208. return (CORE_PIN40_PINREG & CORE_PIN40_BITMASK) ? 1 : 0;
  1209. } else if (pin == 41) {
  1210. return (CORE_PIN41_PINREG & CORE_PIN41_BITMASK) ? 1 : 0;
  1211. } else if (pin == 42) {
  1212. return (CORE_PIN42_PINREG & CORE_PIN42_BITMASK) ? 1 : 0;
  1213. } else if (pin == 43) {
  1214. return (CORE_PIN43_PINREG & CORE_PIN43_BITMASK) ? 1 : 0;
  1215. } else if (pin == 44) {
  1216. return (CORE_PIN44_PINREG & CORE_PIN44_BITMASK) ? 1 : 0;
  1217. } else if (pin == 45) {
  1218. return (CORE_PIN45_PINREG & CORE_PIN45_BITMASK) ? 1 : 0;
  1219. }
  1220. #endif
  1221. else {
  1222. return 0;
  1223. }
  1224. } else {
  1225. uint16_t tmp = (pin);
  1226. asm volatile(
  1227. "call _digitalRead"
  1228. : "+z" (tmp)
  1229. :);
  1230. return (uint8_t)tmp;
  1231. }
  1232. }
  1233. extern void _pinMode(uint8_t pin, uint8_t mode) __attribute__((noinline));
  1234. extern void _pinMode_output(uint8_t pin) __attribute__((noinline));
  1235. extern void _pinMode_input(uint8_t pin) __attribute__((noinline));
  1236. extern void _pinMode_input_pullup(uint8_t pin) __attribute__((noinline));
  1237. static inline void pinMode(uint8_t, uint8_t) __attribute__((always_inline, unused));
  1238. static inline void pinMode(uint8_t pin, uint8_t mode)
  1239. {
  1240. if (__builtin_constant_p(pin) && __builtin_constant_p(mode)) {
  1241. if (mode == OUTPUT) {
  1242. if (pin == 0) {
  1243. CORE_PIN0_DDRREG |= CORE_PIN0_BITMASK;
  1244. } else if (pin == 1) {
  1245. CORE_PIN1_DDRREG |= CORE_PIN1_BITMASK;
  1246. } else if (pin == 2) {
  1247. CORE_PIN2_DDRREG |= CORE_PIN2_BITMASK;
  1248. } else if (pin == 3) {
  1249. CORE_PIN3_DDRREG |= CORE_PIN3_BITMASK;
  1250. } else if (pin == 4) {
  1251. CORE_PIN4_DDRREG |= CORE_PIN4_BITMASK;
  1252. } else if (pin == 5) {
  1253. CORE_PIN5_DDRREG |= CORE_PIN5_BITMASK;
  1254. } else if (pin == 6) {
  1255. CORE_PIN6_DDRREG |= CORE_PIN6_BITMASK;
  1256. } else if (pin == 7) {
  1257. CORE_PIN7_DDRREG |= CORE_PIN7_BITMASK;
  1258. } else if (pin == 8) {
  1259. CORE_PIN8_DDRREG |= CORE_PIN8_BITMASK;
  1260. } else if (pin == 9) {
  1261. CORE_PIN9_DDRREG |= CORE_PIN9_BITMASK;
  1262. } else if (pin == 10) {
  1263. CORE_PIN10_DDRREG |= CORE_PIN10_BITMASK;
  1264. } else if (pin == 11) {
  1265. CORE_PIN11_DDRREG |= CORE_PIN11_BITMASK;
  1266. } else if (pin == 12) {
  1267. CORE_PIN12_DDRREG |= CORE_PIN12_BITMASK;
  1268. } else if (pin == 13) {
  1269. CORE_PIN13_DDRREG |= CORE_PIN13_BITMASK;
  1270. } else if (pin == 14) {
  1271. CORE_PIN14_DDRREG |= CORE_PIN14_BITMASK;
  1272. } else if (pin == 15) {
  1273. CORE_PIN15_DDRREG |= CORE_PIN15_BITMASK;
  1274. } else if (pin == 16) {
  1275. CORE_PIN16_DDRREG |= CORE_PIN16_BITMASK;
  1276. } else if (pin == 17) {
  1277. CORE_PIN17_DDRREG |= CORE_PIN17_BITMASK;
  1278. } else if (pin == 18) {
  1279. CORE_PIN18_DDRREG |= CORE_PIN18_BITMASK;
  1280. } else if (pin == 19) {
  1281. CORE_PIN19_DDRREG |= CORE_PIN19_BITMASK;
  1282. } else if (pin == 20) {
  1283. CORE_PIN20_DDRREG |= CORE_PIN20_BITMASK;
  1284. }
  1285. #if CORE_NUM_TOTAL_PINS > 21
  1286. else if (pin == 21) {
  1287. CORE_PIN21_DDRREG |= CORE_PIN21_BITMASK;
  1288. } else if (pin == 22) {
  1289. CORE_PIN22_DDRREG |= CORE_PIN22_BITMASK;
  1290. } else if (pin == 23) {
  1291. CORE_PIN23_DDRREG |= CORE_PIN23_BITMASK;
  1292. } else if (pin == 24) {
  1293. CORE_PIN24_DDRREG |= CORE_PIN24_BITMASK;
  1294. }
  1295. #endif
  1296. #if CORE_NUM_TOTAL_PINS > 25
  1297. else if (pin == 25) {
  1298. CORE_PIN25_DDRREG |= CORE_PIN25_BITMASK;
  1299. } else if (pin == 26) {
  1300. CORE_PIN26_DDRREG |= CORE_PIN26_BITMASK;
  1301. } else if (pin == 27) {
  1302. CORE_PIN27_DDRREG |= CORE_PIN27_BITMASK;
  1303. } else if (pin == 28) {
  1304. CORE_PIN28_DDRREG |= CORE_PIN28_BITMASK;
  1305. } else if (pin == 29) {
  1306. CORE_PIN29_DDRREG |= CORE_PIN29_BITMASK;
  1307. } else if (pin == 30) {
  1308. CORE_PIN30_DDRREG |= CORE_PIN30_BITMASK;
  1309. } else if (pin == 31) {
  1310. CORE_PIN31_DDRREG |= CORE_PIN31_BITMASK;
  1311. } else if (pin == 32) {
  1312. CORE_PIN32_DDRREG |= CORE_PIN32_BITMASK;
  1313. } else if (pin == 33) {
  1314. CORE_PIN33_DDRREG |= CORE_PIN33_BITMASK;
  1315. } else if (pin == 34) {
  1316. CORE_PIN34_DDRREG |= CORE_PIN34_BITMASK;
  1317. } else if (pin == 35) {
  1318. CORE_PIN35_DDRREG |= CORE_PIN35_BITMASK;
  1319. } else if (pin == 36) {
  1320. CORE_PIN36_DDRREG |= CORE_PIN36_BITMASK;
  1321. } else if (pin == 37) {
  1322. CORE_PIN37_DDRREG |= CORE_PIN37_BITMASK;
  1323. } else if (pin == 38) {
  1324. CORE_PIN38_DDRREG |= CORE_PIN38_BITMASK;
  1325. } else if (pin == 39) {
  1326. CORE_PIN39_DDRREG |= CORE_PIN39_BITMASK;
  1327. } else if (pin == 40) {
  1328. CORE_PIN40_DDRREG |= CORE_PIN40_BITMASK;
  1329. } else if (pin == 41) {
  1330. CORE_PIN41_DDRREG |= CORE_PIN41_BITMASK;
  1331. } else if (pin == 42) {
  1332. CORE_PIN42_DDRREG |= CORE_PIN42_BITMASK;
  1333. } else if (pin == 43) {
  1334. CORE_PIN43_DDRREG |= CORE_PIN43_BITMASK;
  1335. } else if (pin == 44) {
  1336. CORE_PIN44_DDRREG |= CORE_PIN44_BITMASK;
  1337. } else if (pin == 45) {
  1338. CORE_PIN45_DDRREG |= CORE_PIN45_BITMASK;
  1339. }
  1340. #endif
  1341. } else if (mode == INPUT_PULLUP) {
  1342. if (pin == 0) {
  1343. CORE_PIN0_DDRREG &= ~CORE_PIN0_BITMASK;
  1344. CORE_PIN0_PORTREG |= CORE_PIN0_BITMASK;
  1345. } else if (pin == 1) {
  1346. CORE_PIN1_DDRREG &= ~CORE_PIN1_BITMASK;
  1347. CORE_PIN1_PORTREG |= CORE_PIN1_BITMASK;
  1348. } else if (pin == 2) {
  1349. CORE_PIN2_DDRREG &= ~CORE_PIN2_BITMASK;
  1350. CORE_PIN2_PORTREG |= CORE_PIN2_BITMASK;
  1351. } else if (pin == 3) {
  1352. CORE_PIN3_DDRREG &= ~CORE_PIN3_BITMASK;
  1353. CORE_PIN3_PORTREG |= CORE_PIN3_BITMASK;
  1354. } else if (pin == 4) {
  1355. CORE_PIN4_DDRREG &= ~CORE_PIN4_BITMASK;
  1356. CORE_PIN4_PORTREG |= CORE_PIN4_BITMASK;
  1357. } else if (pin == 5) {
  1358. CORE_PIN5_DDRREG &= ~CORE_PIN5_BITMASK;
  1359. CORE_PIN5_PORTREG |= CORE_PIN5_BITMASK;
  1360. } else if (pin == 6) {
  1361. CORE_PIN6_DDRREG &= ~CORE_PIN6_BITMASK;
  1362. CORE_PIN6_PORTREG |= CORE_PIN6_BITMASK;
  1363. } else if (pin == 7) {
  1364. CORE_PIN7_DDRREG &= ~CORE_PIN7_BITMASK;
  1365. CORE_PIN7_PORTREG |= CORE_PIN7_BITMASK;
  1366. } else if (pin == 8) {
  1367. CORE_PIN8_DDRREG &= ~CORE_PIN8_BITMASK;
  1368. CORE_PIN8_PORTREG |= CORE_PIN8_BITMASK;
  1369. } else if (pin == 9) {
  1370. CORE_PIN9_DDRREG &= ~CORE_PIN9_BITMASK;
  1371. CORE_PIN9_PORTREG |= CORE_PIN9_BITMASK;
  1372. } else if (pin == 10) {
  1373. CORE_PIN10_DDRREG &= ~CORE_PIN10_BITMASK;
  1374. CORE_PIN10_PORTREG |= CORE_PIN10_BITMASK;
  1375. } else if (pin == 11) {
  1376. CORE_PIN11_DDRREG &= ~CORE_PIN11_BITMASK;
  1377. CORE_PIN11_PORTREG |= CORE_PIN11_BITMASK;
  1378. } else if (pin == 12) {
  1379. CORE_PIN12_DDRREG &= ~CORE_PIN12_BITMASK;
  1380. CORE_PIN12_PORTREG |= CORE_PIN12_BITMASK;
  1381. } else if (pin == 13) {
  1382. CORE_PIN13_DDRREG &= ~CORE_PIN13_BITMASK;
  1383. CORE_PIN13_PORTREG |= CORE_PIN13_BITMASK;
  1384. } else if (pin == 14) {
  1385. CORE_PIN14_DDRREG &= ~CORE_PIN14_BITMASK;
  1386. CORE_PIN14_PORTREG |= CORE_PIN14_BITMASK;
  1387. } else if (pin == 15) {
  1388. CORE_PIN15_DDRREG &= ~CORE_PIN15_BITMASK;
  1389. CORE_PIN15_PORTREG |= CORE_PIN15_BITMASK;
  1390. } else if (pin == 16) {
  1391. CORE_PIN16_DDRREG &= ~CORE_PIN16_BITMASK;
  1392. CORE_PIN16_PORTREG |= CORE_PIN16_BITMASK;
  1393. } else if (pin == 17) {
  1394. CORE_PIN17_DDRREG &= ~CORE_PIN17_BITMASK;
  1395. CORE_PIN17_PORTREG |= CORE_PIN17_BITMASK;
  1396. } else if (pin == 18) {
  1397. CORE_PIN18_DDRREG &= ~CORE_PIN18_BITMASK;
  1398. CORE_PIN18_PORTREG |= CORE_PIN18_BITMASK;
  1399. } else if (pin == 19) {
  1400. CORE_PIN19_DDRREG &= ~CORE_PIN19_BITMASK;
  1401. CORE_PIN19_PORTREG |= CORE_PIN19_BITMASK;
  1402. } else if (pin == 20) {
  1403. CORE_PIN20_DDRREG &= ~CORE_PIN20_BITMASK;
  1404. CORE_PIN20_PORTREG |= CORE_PIN20_BITMASK;
  1405. }
  1406. #if CORE_NUM_TOTAL_PINS > 21
  1407. else if (pin == 21) {
  1408. CORE_PIN21_DDRREG &= ~CORE_PIN21_BITMASK;
  1409. CORE_PIN21_PORTREG |= CORE_PIN21_BITMASK;
  1410. } else if (pin == 22) {
  1411. CORE_PIN22_DDRREG &= ~CORE_PIN22_BITMASK;
  1412. CORE_PIN22_PORTREG |= CORE_PIN22_BITMASK;
  1413. } else if (pin == 23) {
  1414. CORE_PIN23_DDRREG &= ~CORE_PIN23_BITMASK;
  1415. CORE_PIN23_PORTREG |= CORE_PIN23_BITMASK;
  1416. } else if (pin == 24) {
  1417. CORE_PIN24_DDRREG &= ~CORE_PIN24_BITMASK;
  1418. CORE_PIN24_PORTREG |= CORE_PIN24_BITMASK;
  1419. }
  1420. #endif
  1421. #if CORE_NUM_TOTAL_PINS > 25
  1422. else if (pin == 25) {
  1423. CORE_PIN25_DDRREG &= ~CORE_PIN25_BITMASK;
  1424. CORE_PIN25_PORTREG |= CORE_PIN25_BITMASK;
  1425. } else if (pin == 26) {
  1426. CORE_PIN26_DDRREG &= ~CORE_PIN26_BITMASK;
  1427. CORE_PIN26_PORTREG |= CORE_PIN26_BITMASK;
  1428. } else if (pin == 27) {
  1429. CORE_PIN27_DDRREG &= ~CORE_PIN27_BITMASK;
  1430. CORE_PIN27_PORTREG |= CORE_PIN27_BITMASK;
  1431. } else if (pin == 28) {
  1432. CORE_PIN28_DDRREG &= ~CORE_PIN28_BITMASK;
  1433. CORE_PIN28_PORTREG |= CORE_PIN28_BITMASK;
  1434. } else if (pin == 29) {
  1435. CORE_PIN29_DDRREG &= ~CORE_PIN29_BITMASK;
  1436. CORE_PIN29_PORTREG |= CORE_PIN29_BITMASK;
  1437. } else if (pin == 30) {
  1438. CORE_PIN30_DDRREG &= ~CORE_PIN30_BITMASK;
  1439. CORE_PIN30_PORTREG |= CORE_PIN30_BITMASK;
  1440. } else if (pin == 31) {
  1441. CORE_PIN31_DDRREG &= ~CORE_PIN31_BITMASK;
  1442. CORE_PIN31_PORTREG |= CORE_PIN31_BITMASK;
  1443. } else if (pin == 32) {
  1444. CORE_PIN32_DDRREG &= ~CORE_PIN32_BITMASK;
  1445. CORE_PIN32_PORTREG |= CORE_PIN32_BITMASK;
  1446. } else if (pin == 33) {
  1447. CORE_PIN33_DDRREG &= ~CORE_PIN33_BITMASK;
  1448. CORE_PIN33_PORTREG |= CORE_PIN33_BITMASK;
  1449. } else if (pin == 34) {
  1450. CORE_PIN34_DDRREG &= ~CORE_PIN34_BITMASK;
  1451. CORE_PIN34_PORTREG |= CORE_PIN34_BITMASK;
  1452. } else if (pin == 35) {
  1453. CORE_PIN35_DDRREG &= ~CORE_PIN35_BITMASK;
  1454. CORE_PIN35_PORTREG |= CORE_PIN35_BITMASK;
  1455. } else if (pin == 36) {
  1456. CORE_PIN36_DDRREG &= ~CORE_PIN36_BITMASK;
  1457. CORE_PIN36_PORTREG |= CORE_PIN36_BITMASK;
  1458. } else if (pin == 37) {
  1459. CORE_PIN37_DDRREG &= ~CORE_PIN37_BITMASK;
  1460. CORE_PIN37_PORTREG |= CORE_PIN37_BITMASK;
  1461. } else if (pin == 38) {
  1462. CORE_PIN38_DDRREG &= ~CORE_PIN38_BITMASK;
  1463. CORE_PIN38_PORTREG |= CORE_PIN38_BITMASK;
  1464. } else if (pin == 39) {
  1465. CORE_PIN39_DDRREG &= ~CORE_PIN39_BITMASK;
  1466. CORE_PIN39_PORTREG |= CORE_PIN39_BITMASK;
  1467. } else if (pin == 40) {
  1468. CORE_PIN40_DDRREG &= ~CORE_PIN40_BITMASK;
  1469. CORE_PIN40_PORTREG |= CORE_PIN40_BITMASK;
  1470. } else if (pin == 41) {
  1471. CORE_PIN41_DDRREG &= ~CORE_PIN41_BITMASK;
  1472. CORE_PIN41_PORTREG |= CORE_PIN41_BITMASK;
  1473. } else if (pin == 42) {
  1474. CORE_PIN42_DDRREG &= ~CORE_PIN42_BITMASK;
  1475. CORE_PIN42_PORTREG |= CORE_PIN42_BITMASK;
  1476. } else if (pin == 43) {
  1477. CORE_PIN43_DDRREG &= ~CORE_PIN43_BITMASK;
  1478. CORE_PIN43_PORTREG |= CORE_PIN43_BITMASK;
  1479. } else if (pin == 44) {
  1480. CORE_PIN44_DDRREG &= ~CORE_PIN44_BITMASK;
  1481. CORE_PIN44_PORTREG |= CORE_PIN44_BITMASK;
  1482. } else if (pin == 45) {
  1483. CORE_PIN45_DDRREG &= ~CORE_PIN45_BITMASK;
  1484. CORE_PIN45_PORTREG |= CORE_PIN45_BITMASK;
  1485. }
  1486. #endif
  1487. } else {
  1488. if (pin == 0) {
  1489. CORE_PIN0_DDRREG &= ~CORE_PIN0_BITMASK;
  1490. CORE_PIN0_PORTREG &= ~CORE_PIN0_BITMASK;
  1491. } else if (pin == 1) {
  1492. CORE_PIN1_DDRREG &= ~CORE_PIN1_BITMASK;
  1493. CORE_PIN1_PORTREG &= ~CORE_PIN1_BITMASK;
  1494. } else if (pin == 2) {
  1495. CORE_PIN2_DDRREG &= ~CORE_PIN2_BITMASK;
  1496. CORE_PIN2_PORTREG &= ~CORE_PIN2_BITMASK;
  1497. } else if (pin == 3) {
  1498. CORE_PIN3_DDRREG &= ~CORE_PIN3_BITMASK;
  1499. CORE_PIN3_PORTREG &= ~CORE_PIN3_BITMASK;
  1500. } else if (pin == 4) {
  1501. CORE_PIN4_DDRREG &= ~CORE_PIN4_BITMASK;
  1502. CORE_PIN4_PORTREG &= ~CORE_PIN4_BITMASK;
  1503. } else if (pin == 5) {
  1504. CORE_PIN5_DDRREG &= ~CORE_PIN5_BITMASK;
  1505. CORE_PIN5_PORTREG &= ~CORE_PIN5_BITMASK;
  1506. } else if (pin == 6) {
  1507. CORE_PIN6_DDRREG &= ~CORE_PIN6_BITMASK;
  1508. CORE_PIN6_PORTREG &= ~CORE_PIN6_BITMASK;
  1509. } else if (pin == 7) {
  1510. CORE_PIN7_DDRREG &= ~CORE_PIN7_BITMASK;
  1511. CORE_PIN7_PORTREG &= ~CORE_PIN7_BITMASK;
  1512. } else if (pin == 8) {
  1513. CORE_PIN8_DDRREG &= ~CORE_PIN8_BITMASK;
  1514. CORE_PIN8_PORTREG &= ~CORE_PIN8_BITMASK;
  1515. } else if (pin == 9) {
  1516. CORE_PIN9_DDRREG &= ~CORE_PIN9_BITMASK;
  1517. CORE_PIN9_PORTREG &= ~CORE_PIN9_BITMASK;
  1518. } else if (pin == 10) {
  1519. CORE_PIN10_DDRREG &= ~CORE_PIN10_BITMASK;
  1520. CORE_PIN10_PORTREG &= ~CORE_PIN10_BITMASK;
  1521. } else if (pin == 11) {
  1522. CORE_PIN11_DDRREG &= ~CORE_PIN11_BITMASK;
  1523. CORE_PIN11_PORTREG &= ~CORE_PIN11_BITMASK;
  1524. } else if (pin == 12) {
  1525. CORE_PIN12_DDRREG &= ~CORE_PIN12_BITMASK;
  1526. CORE_PIN12_PORTREG &= ~CORE_PIN12_BITMASK;
  1527. } else if (pin == 13) {
  1528. CORE_PIN13_DDRREG &= ~CORE_PIN13_BITMASK;
  1529. CORE_PIN13_PORTREG &= ~CORE_PIN13_BITMASK;
  1530. } else if (pin == 14) {
  1531. CORE_PIN14_DDRREG &= ~CORE_PIN14_BITMASK;
  1532. CORE_PIN14_PORTREG &= ~CORE_PIN14_BITMASK;
  1533. } else if (pin == 15) {
  1534. CORE_PIN15_DDRREG &= ~CORE_PIN15_BITMASK;
  1535. CORE_PIN15_PORTREG &= ~CORE_PIN15_BITMASK;
  1536. } else if (pin == 16) {
  1537. CORE_PIN16_DDRREG &= ~CORE_PIN16_BITMASK;
  1538. CORE_PIN16_PORTREG &= ~CORE_PIN16_BITMASK;
  1539. } else if (pin == 17) {
  1540. CORE_PIN17_DDRREG &= ~CORE_PIN17_BITMASK;
  1541. CORE_PIN17_PORTREG &= ~CORE_PIN17_BITMASK;
  1542. } else if (pin == 18) {
  1543. CORE_PIN18_DDRREG &= ~CORE_PIN18_BITMASK;
  1544. CORE_PIN18_PORTREG &= ~CORE_PIN18_BITMASK;
  1545. } else if (pin == 19) {
  1546. CORE_PIN19_DDRREG &= ~CORE_PIN19_BITMASK;
  1547. CORE_PIN19_PORTREG &= ~CORE_PIN19_BITMASK;
  1548. } else if (pin == 20) {
  1549. CORE_PIN20_DDRREG &= ~CORE_PIN20_BITMASK;
  1550. CORE_PIN20_PORTREG &= ~CORE_PIN20_BITMASK;
  1551. }
  1552. #if CORE_NUM_TOTAL_PINS > 21
  1553. else if (pin == 21) {
  1554. CORE_PIN21_DDRREG &= ~CORE_PIN21_BITMASK;
  1555. CORE_PIN21_PORTREG &= ~CORE_PIN21_BITMASK;
  1556. } else if (pin == 22) {
  1557. CORE_PIN22_DDRREG &= ~CORE_PIN22_BITMASK;
  1558. CORE_PIN22_PORTREG &= ~CORE_PIN22_BITMASK;
  1559. } else if (pin == 23) {
  1560. CORE_PIN23_DDRREG &= ~CORE_PIN23_BITMASK;
  1561. CORE_PIN23_PORTREG &= ~CORE_PIN23_BITMASK;
  1562. } else if (pin == 24) {
  1563. CORE_PIN24_DDRREG &= ~CORE_PIN24_BITMASK;
  1564. CORE_PIN24_PORTREG &= ~CORE_PIN24_BITMASK;
  1565. }
  1566. #endif
  1567. #if CORE_NUM_TOTAL_PINS > 25
  1568. else if (pin == 25) {
  1569. CORE_PIN25_DDRREG &= ~CORE_PIN25_BITMASK;
  1570. CORE_PIN25_PORTREG &= ~CORE_PIN25_BITMASK;
  1571. } else if (pin == 26) {
  1572. CORE_PIN26_DDRREG &= ~CORE_PIN26_BITMASK;
  1573. CORE_PIN26_PORTREG &= ~CORE_PIN26_BITMASK;
  1574. } else if (pin == 27) {
  1575. CORE_PIN27_DDRREG &= ~CORE_PIN27_BITMASK;
  1576. CORE_PIN27_PORTREG &= ~CORE_PIN27_BITMASK;
  1577. } else if (pin == 28) {
  1578. CORE_PIN28_DDRREG &= ~CORE_PIN28_BITMASK;
  1579. CORE_PIN28_PORTREG &= ~CORE_PIN28_BITMASK;
  1580. } else if (pin == 29) {
  1581. CORE_PIN29_DDRREG &= ~CORE_PIN29_BITMASK;
  1582. CORE_PIN29_PORTREG &= ~CORE_PIN29_BITMASK;
  1583. } else if (pin == 30) {
  1584. CORE_PIN30_DDRREG &= ~CORE_PIN30_BITMASK;
  1585. CORE_PIN30_PORTREG &= ~CORE_PIN30_BITMASK;
  1586. } else if (pin == 31) {
  1587. CORE_PIN31_DDRREG &= ~CORE_PIN31_BITMASK;
  1588. CORE_PIN31_PORTREG &= ~CORE_PIN31_BITMASK;
  1589. } else if (pin == 32) {
  1590. CORE_PIN32_DDRREG &= ~CORE_PIN32_BITMASK;
  1591. CORE_PIN32_PORTREG &= ~CORE_PIN32_BITMASK;
  1592. } else if (pin == 33) {
  1593. CORE_PIN33_DDRREG &= ~CORE_PIN33_BITMASK;
  1594. CORE_PIN33_PORTREG &= ~CORE_PIN33_BITMASK;
  1595. } else if (pin == 34) {
  1596. CORE_PIN34_DDRREG &= ~CORE_PIN34_BITMASK;
  1597. CORE_PIN34_PORTREG &= ~CORE_PIN34_BITMASK;
  1598. } else if (pin == 35) {
  1599. CORE_PIN35_DDRREG &= ~CORE_PIN35_BITMASK;
  1600. CORE_PIN35_PORTREG &= ~CORE_PIN35_BITMASK;
  1601. } else if (pin == 36) {
  1602. CORE_PIN36_DDRREG &= ~CORE_PIN36_BITMASK;
  1603. CORE_PIN36_PORTREG &= ~CORE_PIN36_BITMASK;
  1604. } else if (pin == 37) {
  1605. CORE_PIN37_DDRREG &= ~CORE_PIN37_BITMASK;
  1606. CORE_PIN37_PORTREG &= ~CORE_PIN37_BITMASK;
  1607. } else if (pin == 38) {
  1608. CORE_PIN38_DDRREG &= ~CORE_PIN38_BITMASK;
  1609. CORE_PIN38_PORTREG &= ~CORE_PIN38_BITMASK;
  1610. } else if (pin == 39) {
  1611. CORE_PIN39_DDRREG &= ~CORE_PIN39_BITMASK;
  1612. CORE_PIN39_PORTREG &= ~CORE_PIN39_BITMASK;
  1613. } else if (pin == 40) {
  1614. CORE_PIN40_DDRREG &= ~CORE_PIN40_BITMASK;
  1615. CORE_PIN40_PORTREG &= ~CORE_PIN40_BITMASK;
  1616. } else if (pin == 41) {
  1617. CORE_PIN41_DDRREG &= ~CORE_PIN41_BITMASK;
  1618. CORE_PIN41_PORTREG &= ~CORE_PIN41_BITMASK;
  1619. } else if (pin == 42) {
  1620. CORE_PIN42_DDRREG &= ~CORE_PIN42_BITMASK;
  1621. CORE_PIN42_PORTREG &= ~CORE_PIN42_BITMASK;
  1622. } else if (pin == 43) {
  1623. CORE_PIN43_DDRREG &= ~CORE_PIN43_BITMASK;
  1624. CORE_PIN43_PORTREG &= ~CORE_PIN43_BITMASK;
  1625. } else if (pin == 44) {
  1626. CORE_PIN44_DDRREG &= ~CORE_PIN44_BITMASK;
  1627. CORE_PIN44_PORTREG &= ~CORE_PIN44_BITMASK;
  1628. } else if (pin == 45) {
  1629. CORE_PIN45_DDRREG &= ~CORE_PIN45_BITMASK;
  1630. CORE_PIN45_PORTREG &= ~CORE_PIN45_BITMASK;
  1631. }
  1632. #endif
  1633. }
  1634. #if defined(__AVR_ATmega32U4__)
  1635. if (mode == INPUT || mode == INPUT_PULLUP) {
  1636. if (pin == 11) {
  1637. DIDR2 &= ~0x02;
  1638. } else if (pin == 12) {
  1639. DIDR2 &= ~0x04;
  1640. } else if (pin == 13) {
  1641. DIDR2 &= ~0x08;
  1642. } else if (pin == 14) {
  1643. DIDR2 &= ~0x10;
  1644. } else if (pin == 15) {
  1645. DIDR2 &= ~0x20;
  1646. } else if (pin == 16) {
  1647. DIDR0 &= ~0x80;
  1648. } else if (pin == 17) {
  1649. DIDR0 &= ~0x40;
  1650. } else if (pin == 18) {
  1651. DIDR0 &= ~0x20;
  1652. } else if (pin == 19) {
  1653. DIDR0 &= ~0x10;
  1654. } else if (pin == 20) {
  1655. DIDR0 &= ~0x02;
  1656. } else if (pin == 21) {
  1657. DIDR0 &= ~0x01;
  1658. } else if (pin == 22) {
  1659. DIDR2 &= ~0x01;
  1660. }
  1661. }
  1662. #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  1663. if (mode == INPUT || mode == INPUT_PULLUP) {
  1664. if (pin == 38) {
  1665. DIDR0 &= ~0x01;
  1666. } else if (pin == 39) {
  1667. DIDR0 &= ~0x02;
  1668. } else if (pin == 40) {
  1669. DIDR0 &= ~0x04;
  1670. } else if (pin == 41) {
  1671. DIDR0 &= ~0x08;
  1672. } else if (pin == 42) {
  1673. DIDR0 &= ~0x10;
  1674. } else if (pin == 43) {
  1675. DIDR0 &= ~0x20;
  1676. } else if (pin == 44) {
  1677. DIDR0 &= ~0x40;
  1678. } else if (pin == 45) {
  1679. DIDR0 &= ~0x80;
  1680. }
  1681. }
  1682. #endif
  1683. } else if (__builtin_constant_p(mode)) {
  1684. if (mode == OUTPUT) {
  1685. _pinMode_output(pin);
  1686. } else if (mode == INPUT_PULLUP) {
  1687. _pinMode_input_pullup(pin);
  1688. } else {
  1689. _pinMode_input(pin);
  1690. }
  1691. } else {
  1692. _pinMode(pin, mode);
  1693. }
  1694. }
  1695. extern void _init_Teensyduino_internal_(void);
  1696. extern int analogRead(uint8_t);
  1697. extern void _analogWrite(uint8_t pin, int val) __attribute__((noinline));
  1698. static inline void analogWrite(uint8_t, int) __attribute__((always_inline, unused));
  1699. static inline void analogWrite(uint8_t pin, int val)
  1700. {
  1701. if (__builtin_constant_p(pin)) {
  1702. if (pin == CORE_OC0B_PIN) { // TIMER0B
  1703. CORE_DDRREG(CORE_OC0B_PIN) |= CORE_BITMASK(CORE_OC0B_PIN);
  1704. if (val) {
  1705. OCR0B = val;
  1706. _SFR_BYTE(TCCR0A) |= (1<<COM0B1);
  1707. } else {
  1708. CORE_PORTREG(CORE_OC0B_PIN) &= ~CORE_BITMASK(CORE_OC0B_PIN);
  1709. _SFR_BYTE(TCCR0A) &= ~(1<<COM0B1);
  1710. }
  1711. } else if (pin == CORE_OC1A_PIN) { //TIMER1A
  1712. CORE_DDRREG(CORE_OC1A_PIN) |= CORE_BITMASK(CORE_OC1A_PIN);
  1713. OCR1A = val;
  1714. TCCR1A |= (1<<COM1A1);
  1715. } else if (pin == CORE_OC1B_PIN) { //TIMER1B
  1716. CORE_DDRREG(CORE_OC1B_PIN) |= CORE_BITMASK(CORE_OC1B_PIN);
  1717. OCR1B = val;
  1718. TCCR1A |= (1<<COM1B1);
  1719. } else if (pin == CORE_OC1C_PIN) { //TIMER1C
  1720. CORE_DDRREG(CORE_OC1C_PIN) |= CORE_BITMASK(CORE_OC1C_PIN);
  1721. OCR1C = val;
  1722. TCCR1A |= (1<<COM1C1);
  1723. }
  1724. #if defined(__AVR_ATmega32U4__)
  1725. else if (pin == CORE_OC3A_PIN) { //TIMER3A
  1726. CORE_DDRREG(CORE_OC3A_PIN) |= CORE_BITMASK(CORE_OC3A_PIN);
  1727. OCR3A = val;
  1728. TCCR3A |= (1<<COM3A1);
  1729. } else if (pin == CORE_OC4A_PIN) { //TIMER4A
  1730. CORE_DDRREG(CORE_OC4A_PIN) |= CORE_BITMASK(CORE_OC4A_PIN);
  1731. OCR4A = val;
  1732. TCCR4A |= (1<<COM4A1);
  1733. } else if (pin == CORE_OC4D_PIN) { //TIMER4D
  1734. CORE_DDRREG(CORE_OC4D_PIN) |= CORE_BITMASK(CORE_OC4D_PIN);
  1735. OCR4D = val;
  1736. TCCR4C |= (1<<COM4D1);
  1737. }
  1738. #endif
  1739. #if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  1740. else if (pin == CORE_OC2A_PIN) { //TIMER2A
  1741. CORE_DDRREG(CORE_OC2A_PIN) |= CORE_BITMASK(CORE_OC2A_PIN);
  1742. OCR2A = val;
  1743. TCCR2A |= (1<<COM2A1);
  1744. } else if (pin == CORE_OC2B_PIN) { //TIMER2B
  1745. CORE_DDRREG(CORE_OC2B_PIN) |= CORE_BITMASK(CORE_OC2B_PIN);
  1746. OCR2B = val;
  1747. TCCR2A |= (1<<COM2B1);
  1748. } else if (pin == CORE_OC3A_PIN) { //TIMER3A
  1749. CORE_DDRREG(CORE_OC3A_PIN) |= CORE_BITMASK(CORE_OC3A_PIN);
  1750. OCR3A = val;
  1751. TCCR3A |= (1<<COM3A1);
  1752. } else if (pin == CORE_OC3B_PIN) { //TIMER3B
  1753. CORE_DDRREG(CORE_OC3B_PIN) |= CORE_BITMASK(CORE_OC3B_PIN);
  1754. OCR3B = val;
  1755. TCCR3A |= (1<<COM3B1);
  1756. } else if (pin == CORE_OC3C_PIN) { //TIMER3C
  1757. CORE_DDRREG(CORE_OC3C_PIN) |= CORE_BITMASK(CORE_OC3C_PIN);
  1758. OCR3C = val;
  1759. TCCR3A |= (1<<COM3C1);
  1760. }
  1761. #endif
  1762. else {
  1763. if (pin < CORE_NUM_TOTAL_PINS) {
  1764. pinMode(pin, OUTPUT);
  1765. if (val < 128) {
  1766. digitalWrite(pin, LOW);
  1767. } else {
  1768. digitalWrite(pin, HIGH);
  1769. }
  1770. }
  1771. }
  1772. } else {
  1773. _analogWrite(pin, val);
  1774. }
  1775. }
  1776. static inline void shiftOut(uint8_t, uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
  1777. extern void _shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value) __attribute__((noinline));
  1778. extern void shiftOut_lsbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
  1779. extern void shiftOut_msbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
  1780. static inline void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value)
  1781. {
  1782. if (__builtin_constant_p(bitOrder)) {
  1783. if (bitOrder == LSBFIRST) {
  1784. shiftOut_lsbFirst(dataPin, clockPin, value);
  1785. } else {
  1786. shiftOut_msbFirst(dataPin, clockPin, value);
  1787. }
  1788. } else {
  1789. _shiftOut(dataPin, clockPin, bitOrder, value);
  1790. }
  1791. }
  1792. static inline uint8_t shiftIn(uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
  1793. extern uint8_t _shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) __attribute__((noinline));
  1794. extern uint8_t shiftIn_lsbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
  1795. extern uint8_t shiftIn_msbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
  1796. static inline uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
  1797. {
  1798. if (__builtin_constant_p(bitOrder)) {
  1799. if (bitOrder == LSBFIRST) {
  1800. return shiftIn_lsbFirst(dataPin, clockPin);
  1801. } else {
  1802. return shiftIn_msbFirst(dataPin, clockPin);
  1803. }
  1804. } else {
  1805. return _shiftIn(dataPin, clockPin, bitOrder);
  1806. }
  1807. }
  1808. void _reboot_Teensyduino_(void) __attribute__((noreturn));
  1809. void _restart_Teensyduino_(void) __attribute__((noreturn));
  1810. #if defined(__AVR_AT90USB162__)
  1811. #define analogReference(mode)
  1812. #else
  1813. extern uint8_t w_analog_reference;
  1814. static inline void analogReference(uint8_t mode)
  1815. {
  1816. w_analog_reference = (mode << 6);
  1817. }
  1818. #endif
  1819. extern void delay(uint32_t);
  1820. extern volatile uint32_t timer0_millis_count;
  1821. static inline uint32_t millis(void) __attribute__((always_inline, unused));
  1822. static inline uint32_t millis(void)
  1823. {
  1824. uint32_t out;
  1825. asm volatile(
  1826. "in __tmp_reg__, __SREG__" "\n\t"
  1827. "cli" "\n\t"
  1828. "lds %A0, timer0_millis_count" "\n\t"
  1829. "lds %B0, timer0_millis_count+1" "\n\t"
  1830. "lds %C0, timer0_millis_count+2" "\n\t"
  1831. "lds %D0, timer0_millis_count+3" "\n\t"
  1832. "out __SREG__, __tmp_reg__"
  1833. : "=r" (out) : : "r0"
  1834. );
  1835. return out;
  1836. }
  1837. extern uint32_t _micros(void) __attribute__((noinline));
  1838. static inline uint32_t micros(void) __attribute__((always_inline, unused));
  1839. static inline uint32_t micros(void)
  1840. {
  1841. register uint32_t out asm("r22");
  1842. asm volatile("call _micros" : "=d" (out) : : "r0");
  1843. return out;
  1844. }
  1845. static inline void delayMicroseconds(uint16_t) __attribute__((always_inline, unused));
  1846. static inline void delayMicroseconds(uint16_t usec)
  1847. {
  1848. if (__builtin_constant_p(usec)) {
  1849. #if F_CPU == 16000000L
  1850. uint16_t tmp = usec * 4;
  1851. #elif F_CPU == 8000000L
  1852. uint16_t tmp = usec * 2;
  1853. #elif F_CPU == 4000000L
  1854. uint16_t tmp = usec;
  1855. #elif F_CPU == 2000000L
  1856. uint16_t tmp = usec / 2;
  1857. if (usec == 1) {
  1858. asm volatile("rjmp L%=\nL%=:\n" ::);
  1859. }
  1860. #elif F_CPU == 1000000L
  1861. uint16_t tmp = usec / 4;
  1862. if (usec == 1) {
  1863. asm volatile("nop\n");
  1864. } else if (usec == 2) {
  1865. asm volatile("rjmp L%=\nL%=:\n" ::);
  1866. } else if (usec == 3) {
  1867. asm volatile("rjmp L%=\nL%=:\n" ::);
  1868. asm volatile("nop\n");
  1869. }
  1870. #else
  1871. #error "Clock must be 16, 8, 4, 2 or 1 MHz"
  1872. #endif
  1873. if (tmp > 0) {
  1874. if (tmp < 256) {
  1875. uint8_t tmp2 = tmp;
  1876. asm volatile(
  1877. "L_%=_loop:" // 1 to load
  1878. "subi %0, 1" "\n\t" // 2
  1879. "brne L_%=_loop" "\n\t" // 2 (1 on last)
  1880. : "=d" (tmp2)
  1881. : "0" (tmp2)
  1882. );
  1883. } else {
  1884. asm volatile(
  1885. "L_%=_loop:" // 2 to load
  1886. "sbiw %A0, 1" "\n\t" // 2
  1887. "brne L_%=_loop" "\n\t" // 2 (1 on last)
  1888. : "=w" (tmp)
  1889. : "0" (tmp)
  1890. );
  1891. }
  1892. }
  1893. } else {
  1894. asm volatile(
  1895. #if F_CPU == 16000000L
  1896. "sbiw %A0, 2" "\n\t" // 2
  1897. "brcs L_%=_end" "\n\t" // 1
  1898. "breq L_%=_end" "\n\t" // 1
  1899. "lsl %A0" "\n\t" // 1
  1900. "rol %B0" "\n\t" // 1
  1901. "lsl %A0" "\n\t" // 1
  1902. "rol %B0" "\n\t" // 1 overhead: (8)/4 = 2us
  1903. #elif F_CPU == 8000000L
  1904. "sbiw %A0, 3" "\n\t" // 2
  1905. "brcs L_%=_end" "\n\t" // 1
  1906. "breq L_%=_end" "\n\t" // 1
  1907. "lsl %A0" "\n\t" // 1
  1908. "rol %B0" "\n\t" // 1 overhead: (6)/2 = 3 us
  1909. #elif F_CPU == 4000000L
  1910. "sbiw %A0, 4" "\n\t" // 2
  1911. "brcs L_%=_end" "\n\t" // 1
  1912. "breq L_%=_end" "\n\t" // 1 overhead: (4) = 4 us
  1913. #elif F_CPU == 2000000L
  1914. "sbiw %A0, 12" "\n\t" // 2
  1915. "brcs L_%=_end" "\n\t" // 1
  1916. "breq L_%=_end" "\n\t" // 1
  1917. "lsr %B0" "\n\t" // 1
  1918. "ror %A0" "\n\t" // 1 overhead: (6)*2 = 12 us
  1919. #elif F_CPU == 1000000L
  1920. "sbiw %A0, 32" "\n\t" // 2
  1921. "brcs L_%=_end" "\n\t" // 1
  1922. "breq L_%=_end" "\n\t" // 1
  1923. "lsr %B0" "\n\t" // 1
  1924. "ror %A0" "\n\t" // 1
  1925. "lsr %B0" "\n\t" // 1
  1926. "ror %A0" "\n\t" // 1 overhead: (8)*4 = 32 us
  1927. #endif
  1928. "L_%=_loop:"
  1929. "sbiw %A0, 1" "\n\t" // 2
  1930. "brne L_%=_loop" "\n\t" // 2
  1931. "L_%=_end:"
  1932. : "=w" (usec)
  1933. : "0" (usec)
  1934. );
  1935. }
  1936. }
  1937. #ifdef __cplusplus
  1938. } // extern "C"
  1939. #endif
  1940. #endif