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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988
  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. void yield(void);
  1820. extern void delay(uint32_t);
  1821. extern volatile uint32_t timer0_millis_count;
  1822. static inline uint32_t millis(void) __attribute__((always_inline, unused));
  1823. static inline uint32_t millis(void)
  1824. {
  1825. uint32_t out;
  1826. asm volatile(
  1827. "in __tmp_reg__, __SREG__" "\n\t"
  1828. "cli" "\n\t"
  1829. "lds %A0, timer0_millis_count" "\n\t"
  1830. "lds %B0, timer0_millis_count+1" "\n\t"
  1831. "lds %C0, timer0_millis_count+2" "\n\t"
  1832. "lds %D0, timer0_millis_count+3" "\n\t"
  1833. "out __SREG__, __tmp_reg__"
  1834. : "=r" (out) : : "r0"
  1835. );
  1836. return out;
  1837. }
  1838. extern uint32_t _micros(void) __attribute__((noinline));
  1839. static inline uint32_t micros(void) __attribute__((always_inline, unused));
  1840. static inline uint32_t micros(void)
  1841. {
  1842. register uint32_t out asm("r22");
  1843. asm volatile("call _micros" : "=d" (out) : : "r0");
  1844. return out;
  1845. }
  1846. static inline void delayMicroseconds(uint16_t) __attribute__((always_inline, unused));
  1847. static inline void delayMicroseconds(uint16_t usec)
  1848. {
  1849. if (__builtin_constant_p(usec)) {
  1850. #if F_CPU == 16000000L
  1851. uint16_t tmp = usec * 4;
  1852. #elif F_CPU == 8000000L
  1853. uint16_t tmp = usec * 2;
  1854. #elif F_CPU == 4000000L
  1855. uint16_t tmp = usec;
  1856. #elif F_CPU == 2000000L
  1857. uint16_t tmp = usec / 2;
  1858. if (usec == 1) {
  1859. asm volatile("rjmp L%=\nL%=:\n" ::);
  1860. }
  1861. #elif F_CPU == 1000000L
  1862. uint16_t tmp = usec / 4;
  1863. if (usec == 1) {
  1864. asm volatile("nop\n");
  1865. } else if (usec == 2) {
  1866. asm volatile("rjmp L%=\nL%=:\n" ::);
  1867. } else if (usec == 3) {
  1868. asm volatile("rjmp L%=\nL%=:\n" ::);
  1869. asm volatile("nop\n");
  1870. }
  1871. #else
  1872. #error "Clock must be 16, 8, 4, 2 or 1 MHz"
  1873. #endif
  1874. if (tmp > 0) {
  1875. if (tmp < 256) {
  1876. uint8_t tmp2 = tmp;
  1877. asm volatile(
  1878. "L_%=_loop:" // 1 to load
  1879. "subi %0, 1" "\n\t" // 2
  1880. "brne L_%=_loop" "\n\t" // 2 (1 on last)
  1881. : "=d" (tmp2)
  1882. : "0" (tmp2)
  1883. );
  1884. } else {
  1885. asm volatile(
  1886. "L_%=_loop:" // 2 to load
  1887. "sbiw %A0, 1" "\n\t" // 2
  1888. "brne L_%=_loop" "\n\t" // 2 (1 on last)
  1889. : "=w" (tmp)
  1890. : "0" (tmp)
  1891. );
  1892. }
  1893. }
  1894. } else {
  1895. asm volatile(
  1896. #if F_CPU == 16000000L
  1897. "sbiw %A0, 2" "\n\t" // 2
  1898. "brcs L_%=_end" "\n\t" // 1
  1899. "breq L_%=_end" "\n\t" // 1
  1900. "lsl %A0" "\n\t" // 1
  1901. "rol %B0" "\n\t" // 1
  1902. "lsl %A0" "\n\t" // 1
  1903. "rol %B0" "\n\t" // 1 overhead: (8)/4 = 2us
  1904. #elif F_CPU == 8000000L
  1905. "sbiw %A0, 3" "\n\t" // 2
  1906. "brcs L_%=_end" "\n\t" // 1
  1907. "breq L_%=_end" "\n\t" // 1
  1908. "lsl %A0" "\n\t" // 1
  1909. "rol %B0" "\n\t" // 1 overhead: (6)/2 = 3 us
  1910. #elif F_CPU == 4000000L
  1911. "sbiw %A0, 4" "\n\t" // 2
  1912. "brcs L_%=_end" "\n\t" // 1
  1913. "breq L_%=_end" "\n\t" // 1 overhead: (4) = 4 us
  1914. #elif F_CPU == 2000000L
  1915. "sbiw %A0, 12" "\n\t" // 2
  1916. "brcs L_%=_end" "\n\t" // 1
  1917. "breq L_%=_end" "\n\t" // 1
  1918. "lsr %B0" "\n\t" // 1
  1919. "ror %A0" "\n\t" // 1 overhead: (6)*2 = 12 us
  1920. #elif F_CPU == 1000000L
  1921. "sbiw %A0, 32" "\n\t" // 2
  1922. "brcs L_%=_end" "\n\t" // 1
  1923. "breq L_%=_end" "\n\t" // 1
  1924. "lsr %B0" "\n\t" // 1
  1925. "ror %A0" "\n\t" // 1
  1926. "lsr %B0" "\n\t" // 1
  1927. "ror %A0" "\n\t" // 1 overhead: (8)*4 = 32 us
  1928. #endif
  1929. "L_%=_loop:"
  1930. "sbiw %A0, 1" "\n\t" // 2
  1931. "brne L_%=_loop" "\n\t" // 2
  1932. "L_%=_end:"
  1933. : "=w" (usec)
  1934. : "0" (usec)
  1935. );
  1936. }
  1937. }
  1938. #ifdef __cplusplus
  1939. } // extern "C"
  1940. #endif
  1941. #endif