|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205 |
- #ifndef _core_pins_h_
- #define _core_pins_h_
-
- #include <avr/io.h>
-
- #if (GCC_VERSION >= 40300) && (GCC_VERSION < 40302)
- #error "Buggy GCC 4.3.0 compiler, please upgrade!"
- #endif
-
-
- // This will speed up digitalWrite slightly, but it
- // adds to your code size. However, if you don't
- // have many digitalWrites, or most are compile time
- // constant inputs, then this might be worthwhile
- //#define DIGITAL_WRITE_EXPENSIVE_INLINE_OPTIMIZATION
-
- // This removes checking in digitalWrite for pin numbers
- // beyond the maximum number of pins. Your program
- // WILL CRASH is digitalWrite is called with a pin number
- // too large, when this is enabled. However, if you don't
- // make such mistakes, you'll get a minor speedup.
- //#define DIGITAL_WRITE_RISKY_OMIT_OVERFLOW_CHECK
-
- #define HIGH 0x1
- #define LOW 0x0
-
- #define INPUT 0x0
- #define OUTPUT 0x1
- #define INPUT_PULLUP 0x2
-
- #define LSBFIRST 0
- #define MSBFIRST 1
-
- #ifndef _BV
- #define _BV(n) (1<<(n))
- #endif
-
- ////////////////////////////////////
- // Teensy 2.0
- ////////////////////////////////////
- #if defined(__AVR_ATmega32U4__)
- #define CORE_NUM_TOTAL_PINS 25
- #define CORE_NUM_DIGITAL 13
- #define CORE_NUM_ANALOG 12
- #define CORE_NUM_PWM 7
- #define CORE_NUM_INTERRUPT 4
- #define PIN_B0 0
- #define PIN_B1 1
- #define PIN_B2 2
- #define PIN_B3 3
- #define PIN_B7 4
- #define PIN_D0 5
- #define PIN_D1 6
- #define PIN_D2 7
- #define PIN_D3 8
- #define PIN_C6 9
- #define PIN_C7 10
- #define PIN_D6 11
- #define PIN_D7 12
- #define PIN_B4 13
- #define PIN_B5 14
- #define PIN_B6 15
- #define PIN_F7 16
- #define PIN_F6 17
- #define PIN_F5 18
- #define PIN_F4 19
- #define PIN_F1 20
- #define PIN_F0 21
- #define PIN_D4 22
- #define PIN_D5 23
- #define PIN_E6 24
- #define CORE_PIN0_BIT 0
- #define CORE_PIN1_BIT 1
- #define CORE_PIN2_BIT 2
- #define CORE_PIN3_BIT 3
- #define CORE_PIN4_BIT 7
- #define CORE_PIN5_BIT 0
- #define CORE_PIN6_BIT 1
- #define CORE_PIN7_BIT 2
- #define CORE_PIN8_BIT 3
- #define CORE_PIN9_BIT 6
- #define CORE_PIN10_BIT 7
- #define CORE_PIN11_BIT 6
- #define CORE_PIN12_BIT 7
- #define CORE_PIN13_BIT 4
- #define CORE_PIN14_BIT 5
- #define CORE_PIN15_BIT 6
- #define CORE_PIN16_BIT 7
- #define CORE_PIN17_BIT 6
- #define CORE_PIN18_BIT 5
- #define CORE_PIN19_BIT 4
- #define CORE_PIN20_BIT 1
- #define CORE_PIN21_BIT 0
- #define CORE_PIN22_BIT 4
- #define CORE_PIN23_BIT 5
- #define CORE_PIN24_BIT 6
- #define CORE_PIN0_BITMASK _BV(CORE_PIN0_BIT)
- #define CORE_PIN1_BITMASK _BV(CORE_PIN1_BIT)
- #define CORE_PIN2_BITMASK _BV(CORE_PIN2_BIT)
- #define CORE_PIN3_BITMASK _BV(CORE_PIN3_BIT)
- #define CORE_PIN4_BITMASK _BV(CORE_PIN4_BIT)
- #define CORE_PIN5_BITMASK _BV(CORE_PIN5_BIT)
- #define CORE_PIN6_BITMASK _BV(CORE_PIN6_BIT)
- #define CORE_PIN7_BITMASK _BV(CORE_PIN7_BIT)
- #define CORE_PIN8_BITMASK _BV(CORE_PIN8_BIT)
- #define CORE_PIN9_BITMASK _BV(CORE_PIN9_BIT)
- #define CORE_PIN10_BITMASK _BV(CORE_PIN10_BIT)
- #define CORE_PIN11_BITMASK _BV(CORE_PIN11_BIT)
- #define CORE_PIN12_BITMASK _BV(CORE_PIN12_BIT)
- #define CORE_PIN13_BITMASK _BV(CORE_PIN13_BIT)
- #define CORE_PIN14_BITMASK _BV(CORE_PIN14_BIT)
- #define CORE_PIN15_BITMASK _BV(CORE_PIN15_BIT)
- #define CORE_PIN16_BITMASK _BV(CORE_PIN16_BIT)
- #define CORE_PIN17_BITMASK _BV(CORE_PIN17_BIT)
- #define CORE_PIN18_BITMASK _BV(CORE_PIN18_BIT)
- #define CORE_PIN19_BITMASK _BV(CORE_PIN19_BIT)
- #define CORE_PIN20_BITMASK _BV(CORE_PIN20_BIT)
- #define CORE_PIN21_BITMASK _BV(CORE_PIN21_BIT)
- #define CORE_PIN22_BITMASK _BV(CORE_PIN22_BIT)
- #define CORE_PIN23_BITMASK _BV(CORE_PIN23_BIT)
- #define CORE_PIN24_BITMASK _BV(CORE_PIN24_BIT)
- #define CORE_PIN0_PORTREG PORTB
- #define CORE_PIN1_PORTREG PORTB
- #define CORE_PIN2_PORTREG PORTB
- #define CORE_PIN3_PORTREG PORTB
- #define CORE_PIN4_PORTREG PORTB
- #define CORE_PIN5_PORTREG PORTD
- #define CORE_PIN6_PORTREG PORTD
- #define CORE_PIN7_PORTREG PORTD
- #define CORE_PIN8_PORTREG PORTD
- #define CORE_PIN9_PORTREG PORTC
- #define CORE_PIN10_PORTREG PORTC
- #define CORE_PIN11_PORTREG PORTD
- #define CORE_PIN12_PORTREG PORTD
- #define CORE_PIN13_PORTREG PORTB
- #define CORE_PIN14_PORTREG PORTB
- #define CORE_PIN15_PORTREG PORTB
- #define CORE_PIN16_PORTREG PORTF
- #define CORE_PIN17_PORTREG PORTF
- #define CORE_PIN18_PORTREG PORTF
- #define CORE_PIN19_PORTREG PORTF
- #define CORE_PIN20_PORTREG PORTF
- #define CORE_PIN21_PORTREG PORTF
- #define CORE_PIN22_PORTREG PORTD
- #define CORE_PIN23_PORTREG PORTD
- #define CORE_PIN24_PORTREG PORTE
- #define CORE_PIN0_DDRREG DDRB
- #define CORE_PIN1_DDRREG DDRB
- #define CORE_PIN2_DDRREG DDRB
- #define CORE_PIN3_DDRREG DDRB
- #define CORE_PIN4_DDRREG DDRB
- #define CORE_PIN5_DDRREG DDRD
- #define CORE_PIN6_DDRREG DDRD
- #define CORE_PIN7_DDRREG DDRD
- #define CORE_PIN8_DDRREG DDRD
- #define CORE_PIN9_DDRREG DDRC
- #define CORE_PIN10_DDRREG DDRC
- #define CORE_PIN11_DDRREG DDRD
- #define CORE_PIN12_DDRREG DDRD
- #define CORE_PIN13_DDRREG DDRB
- #define CORE_PIN14_DDRREG DDRB
- #define CORE_PIN15_DDRREG DDRB
- #define CORE_PIN16_DDRREG DDRF
- #define CORE_PIN17_DDRREG DDRF
- #define CORE_PIN18_DDRREG DDRF
- #define CORE_PIN19_DDRREG DDRF
- #define CORE_PIN20_DDRREG DDRF
- #define CORE_PIN21_DDRREG DDRF
- #define CORE_PIN22_DDRREG DDRD
- #define CORE_PIN23_DDRREG DDRD
- #define CORE_PIN24_DDRREG DDRE
- #define CORE_PIN0_PINREG PINB
- #define CORE_PIN1_PINREG PINB
- #define CORE_PIN2_PINREG PINB
- #define CORE_PIN3_PINREG PINB
- #define CORE_PIN4_PINREG PINB
- #define CORE_PIN5_PINREG PIND
- #define CORE_PIN6_PINREG PIND
- #define CORE_PIN7_PINREG PIND
- #define CORE_PIN8_PINREG PIND
- #define CORE_PIN9_PINREG PINC
- #define CORE_PIN10_PINREG PINC
- #define CORE_PIN11_PINREG PIND
- #define CORE_PIN12_PINREG PIND
- #define CORE_PIN13_PINREG PINB
- #define CORE_PIN14_PINREG PINB
- #define CORE_PIN15_PINREG PINB
- #define CORE_PIN16_PINREG PINF
- #define CORE_PIN17_PINREG PINF
- #define CORE_PIN18_PINREG PINF
- #define CORE_PIN19_PINREG PINF
- #define CORE_PIN20_PINREG PINF
- #define CORE_PIN21_PINREG PINF
- #define CORE_PIN22_PINREG PIND
- #define CORE_PIN23_PINREG PIND
- #define CORE_PIN24_PINREG PINE
- #define CORE_ADC0_PIN PIN_F0
- #define CORE_ADC1_PIN PIN_F1
- #define CORE_ADC4_PIN PIN_F4
- #define CORE_ADC5_PIN PIN_F5
- #define CORE_ADC6_PIN PIN_F6
- #define CORE_ADC7_PIN PIN_F7
- #define CORE_ADC8_PIN PIN_D4
- #define CORE_ADC9_PIN PIN_D6
- #define CORE_ADC10_PIN PIN_D7
- #define CORE_ADC11_PIN PIN_B4
- #define CORE_ADC12_PIN PIN_B5
- #define CORE_ADC13_PIN PIN_B6
- #define CORE_RXD1_PIN PIN_D2
- #define CORE_TXD1_PIN PIN_D3
- #define CORE_XCK1_PIN PIN_D5
- #define CORE_SDA0_PIN PIN_D1
- #define CORE_SCL0_PIN PIN_D0
- #define CORE_INT0_PIN PIN_D0
- #define CORE_INT1_PIN PIN_D1
- #define CORE_INT2_PIN PIN_D2
- #define CORE_INT3_PIN PIN_D3
- #define CORE_SS0_PIN PIN_B0
- #define CORE_MOSI0_PIN PIN_B2
- #define CORE_MISO0_PIN PIN_B3
- #define CORE_SCLK0_PIN PIN_B1
- #define CORE_T0_PIN PIN_D7
- #define CORE_T1_PIN PIN_D6
- #define CORE_ICP1_PIN PIN_D4
- #define CORE_ICP3_PIN PIN_C7
- #define CORE_OC0A_PIN PIN_B7
- #define CORE_OC0B_PIN PIN_D0
- #define CORE_OC1A_PIN PIN_B5
- #define CORE_OC1B_PIN PIN_B6
- #define CORE_OC1C_PIN PIN_B7
- #define CORE_OC3A_PIN PIN_C6
- #define CORE_OC4A_PIN PIN_C7
- #define CORE_OC4AN_PIN PIN_C6
- #define CORE_OC4B_PIN PIN_B6
- #define CORE_OC4BN_PIN PIN_B5
- #define CORE_OC4D_PIN PIN_D7
- #define CORE_OC4DN_PIN PIN_D6
- #define CORE_PCINT0_PIN PIN_B0
- #define CORE_PCINT1_PIN PIN_B1
- #define CORE_PCINT2_PIN PIN_B2
- #define CORE_PCINT3_PIN PIN_B3
- #define CORE_PCINT4_PIN PIN_B4
- #define CORE_PCINT5_PIN PIN_B5
- #define CORE_PCINT6_PIN PIN_B6
- #define CORE_PCINT7_PIN PIN_B7
- #define CORE_LED0_PIN PIN_D6
- #define CORE_PWM0_PIN CORE_OC1C_PIN // B7 4
- #define CORE_PWM1_PIN CORE_OC0B_PIN // D0 5
- #define CORE_PWM2_PIN CORE_OC3A_PIN // C6 9
- #define CORE_PWM3_PIN CORE_OC4A_PIN // C7 10
- #define CORE_PWM4_PIN CORE_OC4D_PIN // D7 12
- #define CORE_PWM5_PIN CORE_OC1A_PIN // B5 14
- #define CORE_PWM6_PIN CORE_OC1B_PIN // B6 15
- #define CORE_ANALOG0_PIN PIN_F0 // 21 ADC0
- #define CORE_ANALOG1_PIN PIN_F1 // 20 ADC1
- #define CORE_ANALOG2_PIN PIN_F4 // 19 ADC4
- #define CORE_ANALOG3_PIN PIN_F5 // 18 ADC5
- #define CORE_ANALOG4_PIN PIN_F6 // 17 ADC6
- #define CORE_ANALOG5_PIN PIN_F7 // 16 ADC7
- #define CORE_ANALOG6_PIN PIN_B6 // 15 ADC13
- #define CORE_ANALOG7_PIN PIN_B5 // 14 ADC12
- #define CORE_ANALOG8_PIN PIN_B4 // 13 ADC11
- #define CORE_ANALOG9_PIN PIN_D7 // 12 ADC10
- #define CORE_ANALOG10_PIN PIN_D6 // 11 ADC9
- #define CORE_ANALOG11_PIN PIN_D4 // 22 ADC8
-
-
- ////////////////////////////////////
- // Teensy 1.0
- ////////////////////////////////////
- #elif defined(__AVR_AT90USB162__)
- #define CORE_NUM_TOTAL_PINS 21
- #define CORE_NUM_DIGITAL 21
- #define CORE_NUM_ANALOG 0
- #define CORE_NUM_PWM 4
- #define CORE_NUM_INTERRUPT 8
- #define PIN_D0 0
- #define PIN_D1 1
- #define PIN_D2 2
- #define PIN_D3 3
- #define PIN_D4 4
- #define PIN_D5 5
- #define PIN_D6 6
- #define PIN_D7 7
- #define PIN_SS 8
- #define PIN_SCLK 9
- #define PIN_MOSI 10
- #define PIN_MISO 11
- #define PIN_B0 8
- #define PIN_B1 9
- #define PIN_B2 10
- #define PIN_B3 11
- #define PIN_B4 12
- #define PIN_B5 13
- #define PIN_B6 14
- #define PIN_B7 15
- #define PIN_C7 16
- #define PIN_C6 17
- #define PIN_C5 18
- #define PIN_C4 19
- #define PIN_C2 20
- #define CORE_PIN0_BIT 0
- #define CORE_PIN1_BIT 1
- #define CORE_PIN2_BIT 2
- #define CORE_PIN3_BIT 3
- #define CORE_PIN4_BIT 4
- #define CORE_PIN5_BIT 5
- #define CORE_PIN6_BIT 6
- #define CORE_PIN7_BIT 7
- #define CORE_PIN8_BIT 0
- #define CORE_PIN9_BIT 1
- #define CORE_PIN10_BIT 2
- #define CORE_PIN11_BIT 3
- #define CORE_PIN12_BIT 4
- #define CORE_PIN13_BIT 5
- #define CORE_PIN14_BIT 6
- #define CORE_PIN15_BIT 7
- #define CORE_PIN16_BIT 7
- #define CORE_PIN17_BIT 6
- #define CORE_PIN18_BIT 5
- #define CORE_PIN19_BIT 4
- #define CORE_PIN20_BIT 2
- #define CORE_PIN0_BITMASK _BV(CORE_PIN0_BIT)
- #define CORE_PIN1_BITMASK _BV(CORE_PIN1_BIT)
- #define CORE_PIN2_BITMASK _BV(CORE_PIN2_BIT)
- #define CORE_PIN3_BITMASK _BV(CORE_PIN3_BIT)
- #define CORE_PIN4_BITMASK _BV(CORE_PIN4_BIT)
- #define CORE_PIN5_BITMASK _BV(CORE_PIN5_BIT)
- #define CORE_PIN6_BITMASK _BV(CORE_PIN6_BIT)
- #define CORE_PIN7_BITMASK _BV(CORE_PIN7_BIT)
- #define CORE_PIN8_BITMASK _BV(CORE_PIN8_BIT)
- #define CORE_PIN9_BITMASK _BV(CORE_PIN9_BIT)
- #define CORE_PIN10_BITMASK _BV(CORE_PIN10_BIT)
- #define CORE_PIN11_BITMASK _BV(CORE_PIN11_BIT)
- #define CORE_PIN12_BITMASK _BV(CORE_PIN12_BIT)
- #define CORE_PIN13_BITMASK _BV(CORE_PIN13_BIT)
- #define CORE_PIN14_BITMASK _BV(CORE_PIN14_BIT)
- #define CORE_PIN15_BITMASK _BV(CORE_PIN15_BIT)
- #define CORE_PIN16_BITMASK _BV(CORE_PIN16_BIT)
- #define CORE_PIN17_BITMASK _BV(CORE_PIN17_BIT)
- #define CORE_PIN18_BITMASK _BV(CORE_PIN18_BIT)
- #define CORE_PIN19_BITMASK _BV(CORE_PIN19_BIT)
- #define CORE_PIN20_BITMASK _BV(CORE_PIN20_BIT)
- #define CORE_PIN0_PORTREG PORTD
- #define CORE_PIN1_PORTREG PORTD
- #define CORE_PIN2_PORTREG PORTD
- #define CORE_PIN3_PORTREG PORTD
- #define CORE_PIN4_PORTREG PORTD
- #define CORE_PIN5_PORTREG PORTD
- #define CORE_PIN6_PORTREG PORTD
- #define CORE_PIN7_PORTREG PORTD
- #define CORE_PIN8_PORTREG PORTB
- #define CORE_PIN9_PORTREG PORTB
- #define CORE_PIN10_PORTREG PORTB
- #define CORE_PIN11_PORTREG PORTB
- #define CORE_PIN12_PORTREG PORTB
- #define CORE_PIN13_PORTREG PORTB
- #define CORE_PIN14_PORTREG PORTB
- #define CORE_PIN15_PORTREG PORTB
- #define CORE_PIN16_PORTREG PORTC
- #define CORE_PIN17_PORTREG PORTC
- #define CORE_PIN18_PORTREG PORTC
- #define CORE_PIN19_PORTREG PORTC
- #define CORE_PIN20_PORTREG PORTC
- #define CORE_PIN0_DDRREG DDRD
- #define CORE_PIN1_DDRREG DDRD
- #define CORE_PIN2_DDRREG DDRD
- #define CORE_PIN3_DDRREG DDRD
- #define CORE_PIN4_DDRREG DDRD
- #define CORE_PIN5_DDRREG DDRD
- #define CORE_PIN6_DDRREG DDRD
- #define CORE_PIN7_DDRREG DDRD
- #define CORE_PIN8_DDRREG DDRB
- #define CORE_PIN9_DDRREG DDRB
- #define CORE_PIN10_DDRREG DDRB
- #define CORE_PIN11_DDRREG DDRB
- #define CORE_PIN12_DDRREG DDRB
- #define CORE_PIN13_DDRREG DDRB
- #define CORE_PIN14_DDRREG DDRB
- #define CORE_PIN15_DDRREG DDRB
- #define CORE_PIN16_DDRREG DDRC
- #define CORE_PIN17_DDRREG DDRC
- #define CORE_PIN18_DDRREG DDRC
- #define CORE_PIN19_DDRREG DDRC
- #define CORE_PIN20_DDRREG DDRC
- #define CORE_PIN0_PINREG PIND
- #define CORE_PIN1_PINREG PIND
- #define CORE_PIN2_PINREG PIND
- #define CORE_PIN3_PINREG PIND
- #define CORE_PIN4_PINREG PIND
- #define CORE_PIN5_PINREG PIND
- #define CORE_PIN6_PINREG PIND
- #define CORE_PIN7_PINREG PIND
- #define CORE_PIN8_PINREG PINB
- #define CORE_PIN9_PINREG PINB
- #define CORE_PIN10_PINREG PINB
- #define CORE_PIN11_PINREG PINB
- #define CORE_PIN12_PINREG PINB
- #define CORE_PIN13_PINREG PINB
- #define CORE_PIN14_PINREG PINB
- #define CORE_PIN15_PINREG PINB
- #define CORE_PIN16_PINREG PINC
- #define CORE_PIN17_PINREG PINC
- #define CORE_PIN18_PINREG PINC
- #define CORE_PIN19_PINREG PINC
- #define CORE_PIN20_PINREG PINC
- #define CORE_T1_PIN PIN_B4
- #define CORE_ICP1_PIN PIN_C7
- #define CORE_OC0A_PIN PIN_B7
- #define CORE_OC0B_PIN PIN_D0
- #define CORE_OC1A_PIN PIN_C6
- #define CORE_OC1B_PIN PIN_C5
- #define CORE_OC1C_PIN PIN_B7
- #define CORE_RXD1_PIN PIN_D2
- #define CORE_TXD1_PIN PIN_D3
- #define CORE_XCK1_PIN PIN_D5
- #define CORE_INT0_PIN PIN_D0
- #define CORE_INT1_PIN PIN_D1
- #define CORE_INT2_PIN PIN_D2
- #define CORE_INT3_PIN PIN_D3
- #define CORE_INT4_PIN PIN_C2
- #define CORE_INT5_PIN PIN_D4
- #define CORE_INT6_PIN PIN_D6
- #define CORE_INT7_PIN PIN_D7
- #define CORE_SS0_PIN PIN_B0
- #define CORE_MOSI0_PIN PIN_B2
- #define CORE_MISO0_PIN PIN_B3
- #define CORE_SCLK0_PIN PIN_B1
- #define CORE_AIN0_PIN PIN_D1
- #define CORE_AIN1_PIN PIN_D2
- #define CORE_PCINT0_PIN PIN_B0
- #define CORE_PCINT1_PIN PIN_B1
- #define CORE_PCINT2_PIN PIN_B2
- #define CORE_PCINT3_PIN PIN_B3
- #define CORE_PCINT4_PIN PIN_B4
- #define CORE_PCINT5_PIN PIN_B5
- #define CORE_PCINT6_PIN PIN_B6
- #define CORE_PCINT7_PIN PIN_B7
- #define CORE_PCINT8_PIN PIN_C6
- #define CORE_PCINT9_PIN PIN_C5
- #define CORE_PCINT10_PIN PIN_C4
- #define CORE_PCINT11_PIN PIN_C2
- #define CORE_PCINT12_PIN PIN_D5
- #define CORE_LED0_PIN PIN_D6
- #define CORE_PWM0_PIN CORE_OC0B_PIN // D0, 0
- #define CORE_PWM1_PIN CORE_OC1C_PIN // B7, 15
- #define CORE_PWM2_PIN CORE_OC1A_PIN // C6, 17
- #define CORE_PWM3_PIN CORE_OC1B_PIN // C5, 18
-
-
- ////////////////////////////////////
- // Teensy++ 1.0 & 2.0
- ////////////////////////////////////
- #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
- #define CORE_NUM_TOTAL_PINS 46
- #define CORE_NUM_DIGITAL 38
- #define CORE_NUM_ANALOG 8
- #define CORE_NUM_PWM 9
- #define CORE_NUM_INTERRUPT 8
- #define PIN_D0 0
- #define PIN_D1 1
- #define PIN_D2 2
- #define PIN_D3 3
- #define PIN_D4 4
- #define PIN_D5 5
- #define PIN_D6 6
- #define PIN_D7 7
- #define PIN_E0 8
- #define PIN_E1 9
- #define PIN_C0 10
- #define PIN_C1 11
- #define PIN_C2 12
- #define PIN_C3 13
- #define PIN_C4 14
- #define PIN_C5 15
- #define PIN_C6 16
- #define PIN_C7 17
- #define PIN_E6 18
- #define PIN_E7 19
- #define PIN_SS 20
- #define PIN_SCLK 21
- #define PIN_MOSI 22
- #define PIN_MISO 23
- #define PIN_B0 20
- #define PIN_B1 21
- #define PIN_B2 22
- #define PIN_B3 23
- #define PIN_B4 24
- #define PIN_B5 25
- #define PIN_B6 26
- #define PIN_B7 27
- #define PIN_A0 28
- #define PIN_A1 29
- #define PIN_A2 30
- #define PIN_A3 31
- #define PIN_A4 32
- #define PIN_A5 33
- #define PIN_A6 34
- #define PIN_A7 35
- #define PIN_E4 36
- #define PIN_E5 37
- #define PIN_F0 38
- #define PIN_F1 39
- #define PIN_F2 40
- #define PIN_F3 41
- #define PIN_F4 42
- #define PIN_F5 43
- #define PIN_F6 44
- #define PIN_F7 45
- #define CORE_PIN0_BIT 0
- #define CORE_PIN1_BIT 1
- #define CORE_PIN2_BIT 2
- #define CORE_PIN3_BIT 3
- #define CORE_PIN4_BIT 4
- #define CORE_PIN5_BIT 5
- #define CORE_PIN6_BIT 6
- #define CORE_PIN7_BIT 7
- #define CORE_PIN8_BIT 0
- #define CORE_PIN9_BIT 1
- #define CORE_PIN10_BIT 0
- #define CORE_PIN11_BIT 1
- #define CORE_PIN12_BIT 2
- #define CORE_PIN13_BIT 3
- #define CORE_PIN14_BIT 4
- #define CORE_PIN15_BIT 5
- #define CORE_PIN16_BIT 6
- #define CORE_PIN17_BIT 7
- #define CORE_PIN18_BIT 6
- #define CORE_PIN19_BIT 7
- #define CORE_PIN20_BIT 0
- #define CORE_PIN21_BIT 1
- #define CORE_PIN22_BIT 2
- #define CORE_PIN23_BIT 3
- #define CORE_PIN24_BIT 4
- #define CORE_PIN25_BIT 5
- #define CORE_PIN26_BIT 6
- #define CORE_PIN27_BIT 7
- #define CORE_PIN28_BIT 0
- #define CORE_PIN29_BIT 1
- #define CORE_PIN30_BIT 2
- #define CORE_PIN31_BIT 3
- #define CORE_PIN32_BIT 4
- #define CORE_PIN33_BIT 5
- #define CORE_PIN34_BIT 6
- #define CORE_PIN35_BIT 7
- #define CORE_PIN36_BIT 4
- #define CORE_PIN37_BIT 5
- #define CORE_PIN38_BIT 0
- #define CORE_PIN39_BIT 1
- #define CORE_PIN40_BIT 2
- #define CORE_PIN41_BIT 3
- #define CORE_PIN42_BIT 4
- #define CORE_PIN43_BIT 5
- #define CORE_PIN44_BIT 6
- #define CORE_PIN45_BIT 7
- #define CORE_PIN0_BITMASK _BV(CORE_PIN0_BIT)
- #define CORE_PIN1_BITMASK _BV(CORE_PIN1_BIT)
- #define CORE_PIN2_BITMASK _BV(CORE_PIN2_BIT)
- #define CORE_PIN3_BITMASK _BV(CORE_PIN3_BIT)
- #define CORE_PIN4_BITMASK _BV(CORE_PIN4_BIT)
- #define CORE_PIN5_BITMASK _BV(CORE_PIN5_BIT)
- #define CORE_PIN6_BITMASK _BV(CORE_PIN6_BIT)
- #define CORE_PIN7_BITMASK _BV(CORE_PIN7_BIT)
- #define CORE_PIN8_BITMASK _BV(CORE_PIN8_BIT)
- #define CORE_PIN9_BITMASK _BV(CORE_PIN9_BIT)
- #define CORE_PIN10_BITMASK _BV(CORE_PIN10_BIT)
- #define CORE_PIN11_BITMASK _BV(CORE_PIN11_BIT)
- #define CORE_PIN12_BITMASK _BV(CORE_PIN12_BIT)
- #define CORE_PIN13_BITMASK _BV(CORE_PIN13_BIT)
- #define CORE_PIN14_BITMASK _BV(CORE_PIN14_BIT)
- #define CORE_PIN15_BITMASK _BV(CORE_PIN15_BIT)
- #define CORE_PIN16_BITMASK _BV(CORE_PIN16_BIT)
- #define CORE_PIN17_BITMASK _BV(CORE_PIN17_BIT)
- #define CORE_PIN18_BITMASK _BV(CORE_PIN18_BIT)
- #define CORE_PIN19_BITMASK _BV(CORE_PIN19_BIT)
- #define CORE_PIN20_BITMASK _BV(CORE_PIN20_BIT)
- #define CORE_PIN21_BITMASK _BV(CORE_PIN21_BIT)
- #define CORE_PIN22_BITMASK _BV(CORE_PIN22_BIT)
- #define CORE_PIN23_BITMASK _BV(CORE_PIN23_BIT)
- #define CORE_PIN24_BITMASK _BV(CORE_PIN24_BIT)
- #define CORE_PIN25_BITMASK _BV(CORE_PIN25_BIT)
- #define CORE_PIN26_BITMASK _BV(CORE_PIN26_BIT)
- #define CORE_PIN27_BITMASK _BV(CORE_PIN27_BIT)
- #define CORE_PIN28_BITMASK _BV(CORE_PIN28_BIT)
- #define CORE_PIN29_BITMASK _BV(CORE_PIN29_BIT)
- #define CORE_PIN30_BITMASK _BV(CORE_PIN30_BIT)
- #define CORE_PIN31_BITMASK _BV(CORE_PIN31_BIT)
- #define CORE_PIN32_BITMASK _BV(CORE_PIN32_BIT)
- #define CORE_PIN33_BITMASK _BV(CORE_PIN33_BIT)
- #define CORE_PIN34_BITMASK _BV(CORE_PIN34_BIT)
- #define CORE_PIN35_BITMASK _BV(CORE_PIN35_BIT)
- #define CORE_PIN36_BITMASK _BV(CORE_PIN36_BIT)
- #define CORE_PIN37_BITMASK _BV(CORE_PIN37_BIT)
- #define CORE_PIN38_BITMASK _BV(CORE_PIN38_BIT)
- #define CORE_PIN39_BITMASK _BV(CORE_PIN39_BIT)
- #define CORE_PIN40_BITMASK _BV(CORE_PIN40_BIT)
- #define CORE_PIN41_BITMASK _BV(CORE_PIN41_BIT)
- #define CORE_PIN42_BITMASK _BV(CORE_PIN42_BIT)
- #define CORE_PIN43_BITMASK _BV(CORE_PIN43_BIT)
- #define CORE_PIN44_BITMASK _BV(CORE_PIN44_BIT)
- #define CORE_PIN45_BITMASK _BV(CORE_PIN45_BIT)
- #define CORE_PIN0_PORTREG PORTD
- #define CORE_PIN1_PORTREG PORTD
- #define CORE_PIN2_PORTREG PORTD
- #define CORE_PIN3_PORTREG PORTD
- #define CORE_PIN4_PORTREG PORTD
- #define CORE_PIN5_PORTREG PORTD
- #define CORE_PIN6_PORTREG PORTD
- #define CORE_PIN7_PORTREG PORTD
- #define CORE_PIN8_PORTREG PORTE
- #define CORE_PIN9_PORTREG PORTE
- #define CORE_PIN10_PORTREG PORTC
- #define CORE_PIN11_PORTREG PORTC
- #define CORE_PIN12_PORTREG PORTC
- #define CORE_PIN13_PORTREG PORTC
- #define CORE_PIN14_PORTREG PORTC
- #define CORE_PIN15_PORTREG PORTC
- #define CORE_PIN16_PORTREG PORTC
- #define CORE_PIN17_PORTREG PORTC
- #define CORE_PIN18_PORTREG PORTE
- #define CORE_PIN19_PORTREG PORTE
- #define CORE_PIN20_PORTREG PORTB
- #define CORE_PIN21_PORTREG PORTB
- #define CORE_PIN22_PORTREG PORTB
- #define CORE_PIN23_PORTREG PORTB
- #define CORE_PIN24_PORTREG PORTB
- #define CORE_PIN25_PORTREG PORTB
- #define CORE_PIN26_PORTREG PORTB
- #define CORE_PIN27_PORTREG PORTB
- #define CORE_PIN28_PORTREG PORTA
- #define CORE_PIN29_PORTREG PORTA
- #define CORE_PIN30_PORTREG PORTA
- #define CORE_PIN31_PORTREG PORTA
- #define CORE_PIN32_PORTREG PORTA
- #define CORE_PIN33_PORTREG PORTA
- #define CORE_PIN34_PORTREG PORTA
- #define CORE_PIN35_PORTREG PORTA
- #define CORE_PIN36_PORTREG PORTE
- #define CORE_PIN37_PORTREG PORTE
- #define CORE_PIN38_PORTREG PORTF
- #define CORE_PIN39_PORTREG PORTF
- #define CORE_PIN40_PORTREG PORTF
- #define CORE_PIN41_PORTREG PORTF
- #define CORE_PIN42_PORTREG PORTF
- #define CORE_PIN43_PORTREG PORTF
- #define CORE_PIN44_PORTREG PORTF
- #define CORE_PIN45_PORTREG PORTF
- #define CORE_PIN0_DDRREG DDRD
- #define CORE_PIN1_DDRREG DDRD
- #define CORE_PIN2_DDRREG DDRD
- #define CORE_PIN3_DDRREG DDRD
- #define CORE_PIN4_DDRREG DDRD
- #define CORE_PIN5_DDRREG DDRD
- #define CORE_PIN6_DDRREG DDRD
- #define CORE_PIN7_DDRREG DDRD
- #define CORE_PIN8_DDRREG DDRE
- #define CORE_PIN9_DDRREG DDRE
- #define CORE_PIN10_DDRREG DDRC
- #define CORE_PIN11_DDRREG DDRC
- #define CORE_PIN12_DDRREG DDRC
- #define CORE_PIN13_DDRREG DDRC
- #define CORE_PIN14_DDRREG DDRC
- #define CORE_PIN15_DDRREG DDRC
- #define CORE_PIN16_DDRREG DDRC
- #define CORE_PIN17_DDRREG DDRC
- #define CORE_PIN18_DDRREG DDRE
- #define CORE_PIN19_DDRREG DDRE
- #define CORE_PIN20_DDRREG DDRB
- #define CORE_PIN21_DDRREG DDRB
- #define CORE_PIN22_DDRREG DDRB
- #define CORE_PIN23_DDRREG DDRB
- #define CORE_PIN24_DDRREG DDRB
- #define CORE_PIN25_DDRREG DDRB
- #define CORE_PIN26_DDRREG DDRB
- #define CORE_PIN27_DDRREG DDRB
- #define CORE_PIN28_DDRREG DDRA
- #define CORE_PIN29_DDRREG DDRA
- #define CORE_PIN30_DDRREG DDRA
- #define CORE_PIN31_DDRREG DDRA
- #define CORE_PIN32_DDRREG DDRA
- #define CORE_PIN33_DDRREG DDRA
- #define CORE_PIN34_DDRREG DDRA
- #define CORE_PIN35_DDRREG DDRA
- #define CORE_PIN36_DDRREG DDRE
- #define CORE_PIN37_DDRREG DDRE
- #define CORE_PIN38_DDRREG DDRF
- #define CORE_PIN39_DDRREG DDRF
- #define CORE_PIN40_DDRREG DDRF
- #define CORE_PIN41_DDRREG DDRF
- #define CORE_PIN42_DDRREG DDRF
- #define CORE_PIN43_DDRREG DDRF
- #define CORE_PIN44_DDRREG DDRF
- #define CORE_PIN45_DDRREG DDRF
- #define CORE_PIN0_PINREG PIND
- #define CORE_PIN1_PINREG PIND
- #define CORE_PIN2_PINREG PIND
- #define CORE_PIN3_PINREG PIND
- #define CORE_PIN4_PINREG PIND
- #define CORE_PIN5_PINREG PIND
- #define CORE_PIN6_PINREG PIND
- #define CORE_PIN7_PINREG PIND
- #define CORE_PIN8_PINREG PINE
- #define CORE_PIN9_PINREG PINE
- #define CORE_PIN10_PINREG PINC
- #define CORE_PIN11_PINREG PINC
- #define CORE_PIN12_PINREG PINC
- #define CORE_PIN13_PINREG PINC
- #define CORE_PIN14_PINREG PINC
- #define CORE_PIN15_PINREG PINC
- #define CORE_PIN16_PINREG PINC
- #define CORE_PIN17_PINREG PINC
- #define CORE_PIN18_PINREG PINE
- #define CORE_PIN19_PINREG PINE
- #define CORE_PIN20_PINREG PINB
- #define CORE_PIN21_PINREG PINB
- #define CORE_PIN22_PINREG PINB
- #define CORE_PIN23_PINREG PINB
- #define CORE_PIN24_PINREG PINB
- #define CORE_PIN25_PINREG PINB
- #define CORE_PIN26_PINREG PINB
- #define CORE_PIN27_PINREG PINB
- #define CORE_PIN28_PINREG PINA
- #define CORE_PIN29_PINREG PINA
- #define CORE_PIN30_PINREG PINA
- #define CORE_PIN31_PINREG PINA
- #define CORE_PIN32_PINREG PINA
- #define CORE_PIN33_PINREG PINA
- #define CORE_PIN34_PINREG PINA
- #define CORE_PIN35_PINREG PINA
- #define CORE_PIN36_PINREG PINE
- #define CORE_PIN37_PINREG PINE
- #define CORE_PIN38_PINREG PINF
- #define CORE_PIN39_PINREG PINF
- #define CORE_PIN40_PINREG PINF
- #define CORE_PIN41_PINREG PINF
- #define CORE_PIN42_PINREG PINF
- #define CORE_PIN43_PINREG PINF
- #define CORE_PIN44_PINREG PINF
- #define CORE_PIN45_PINREG PINF
- #define CORE_ADC0_PIN PIN_F0
- #define CORE_ADC1_PIN PIN_F1
- #define CORE_ADC2_PIN PIN_F2
- #define CORE_ADC3_PIN PIN_F3
- #define CORE_ADC4_PIN PIN_F4
- #define CORE_ADC5_PIN PIN_F5
- #define CORE_ADC6_PIN PIN_F6
- #define CORE_ADC7_PIN PIN_F7
- #define CORE_RXD1_PIN PIN_D2
- #define CORE_TXD1_PIN PIN_D3
- #define CORE_XCK1_PIN PIN_D5
- #define CORE_SDA0_PIN PIN_D1
- #define CORE_SCL0_PIN PIN_D0
- #define CORE_INT0_PIN PIN_D0
- #define CORE_INT1_PIN PIN_D1
- #define CORE_INT2_PIN PIN_D2
- #define CORE_INT3_PIN PIN_D3
- #define CORE_INT4_PIN PIN_E4
- #define CORE_INT5_PIN PIN_E5
- #define CORE_INT6_PIN PIN_E6
- #define CORE_INT7_PIN PIN_E7
- #define CORE_SS0_PIN PIN_B0
- #define CORE_MOSI0_PIN PIN_B2
- #define CORE_MISO0_PIN PIN_B3
- #define CORE_SCLK0_PIN PIN_B1
- #define CORE_T0_PIN PIN_D7
- #define CORE_T1_PIN PIN_D6
- #define CORE_ICP1_PIN PIN_D4
- #define CORE_ICP3_PIN PIN_C7
- #define CORE_OC0A_PIN PIN_B7
- #define CORE_OC0B_PIN PIN_D0
- #define CORE_OC1A_PIN PIN_B5
- #define CORE_OC1B_PIN PIN_B6
- #define CORE_OC1C_PIN PIN_B7
- #define CORE_OC2A_PIN PIN_B4
- #define CORE_OC2B_PIN PIN_D1
- #define CORE_OC3A_PIN PIN_C6
- #define CORE_OC3B_PIN PIN_C5
- #define CORE_OC3C_PIN PIN_C4
- #define CORE_PCINT0_PIN PIN_B0
- #define CORE_PCINT1_PIN PIN_B1
- #define CORE_PCINT2_PIN PIN_B2
- #define CORE_PCINT3_PIN PIN_B3
- #define CORE_PCINT4_PIN PIN_B4
- #define CORE_PCINT5_PIN PIN_B5
- #define CORE_PCINT6_PIN PIN_B6
- #define CORE_PCINT7_PIN PIN_B7
- #define CORE_LED0_PIN PIN_D6
- #define CORE_PWM0_PIN CORE_OC0B_PIN // D0, 0
- #define CORE_PWM1_PIN CORE_OC2B_PIN // D1, 1
- #define CORE_PWM2_PIN CORE_OC3C_PIN // C4, 14
- #define CORE_PWM3_PIN CORE_OC3B_PIN // C5, 15
- #define CORE_PWM4_PIN CORE_OC3A_PIN // C6, 16
- #define CORE_PWM5_PIN CORE_OC2A_PIN // B4, 24
- #define CORE_PWM6_PIN CORE_OC1A_PIN // B5, 25
- #define CORE_PWM7_PIN CORE_OC1B_PIN // B6, 26
- #define CORE_PWM8_PIN CORE_OC1C_PIN // B7, 27
- #define CORE_ANALOG0_PIN PIN_F0
- #define CORE_ANALOG1_PIN PIN_F1
- #define CORE_ANALOG2_PIN PIN_F2
- #define CORE_ANALOG3_PIN PIN_F3
- #define CORE_ANALOG4_PIN PIN_F4
- #define CORE_ANALOG5_PIN PIN_F5
- #define CORE_ANALOG6_PIN PIN_F6
- #define CORE_ANALOG7_PIN PIN_F7
-
- #endif
-
-
- #define CORE_BIT(pin) CORE_PIN_CONCATENATE(pin, BIT)
- #define CORE_BITMASK(pin) CORE_PIN_CONCATENATE(pin, BITMASK)
- #define CORE_PORTREG(pin) CORE_PIN_CONCATENATE(pin, PORTREG)
- #define CORE_DDRREG(pin) CORE_PIN_CONCATENATE(pin, DDRREG)
- #define CORE_PINREG(pin) CORE_PIN_CONCATENATE(pin, PINREG)
- #define CORE_PIN_CONCATENATE(pin, reg) (CORE_PIN ## pin ## _ ## reg)
-
- #ifdef __cplusplus
- extern "C"{
- #endif
-
-
- extern void _digitalWrite(void);
- extern void _digitalWrite_HIGH(void);
- extern void _digitalWrite_LOW(void);
-
- static inline void digitalWrite(uint8_t, uint8_t) __attribute__((always_inline, unused));
- static inline void digitalWrite(uint8_t pin, uint8_t val)
- {
- if (__builtin_constant_p(pin)) {
- if (val) {
- if (pin == 0) {
- CORE_PIN0_PORTREG |= CORE_PIN0_BITMASK;
- } else if (pin == 1) {
- CORE_PIN1_PORTREG |= CORE_PIN1_BITMASK;
- } else if (pin == 2) {
- CORE_PIN2_PORTREG |= CORE_PIN2_BITMASK;
- } else if (pin == 3) {
- CORE_PIN3_PORTREG |= CORE_PIN3_BITMASK;
- } else if (pin == 4) {
- CORE_PIN4_PORTREG |= CORE_PIN4_BITMASK;
- } else if (pin == 5) {
- CORE_PIN5_PORTREG |= CORE_PIN5_BITMASK;
- } else if (pin == 6) {
- CORE_PIN6_PORTREG |= CORE_PIN6_BITMASK;
- } else if (pin == 7) {
- CORE_PIN7_PORTREG |= CORE_PIN7_BITMASK;
- } else if (pin == 8) {
- CORE_PIN8_PORTREG |= CORE_PIN8_BITMASK;
- } else if (pin == 9) {
- CORE_PIN9_PORTREG |= CORE_PIN9_BITMASK;
- } else if (pin == 10) {
- CORE_PIN10_PORTREG |= CORE_PIN10_BITMASK;
- } else if (pin == 11) {
- CORE_PIN11_PORTREG |= CORE_PIN11_BITMASK;
- } else if (pin == 12) {
- CORE_PIN12_PORTREG |= CORE_PIN12_BITMASK;
- } else if (pin == 13) {
- CORE_PIN13_PORTREG |= CORE_PIN13_BITMASK;
- } else if (pin == 14) {
- CORE_PIN14_PORTREG |= CORE_PIN14_BITMASK;
- } else if (pin == 15) {
- CORE_PIN15_PORTREG |= CORE_PIN15_BITMASK;
- } else if (pin == 16) {
- CORE_PIN16_PORTREG |= CORE_PIN16_BITMASK;
- } else if (pin == 17) {
- CORE_PIN17_PORTREG |= CORE_PIN17_BITMASK;
- } else if (pin == 18) {
- CORE_PIN18_PORTREG |= CORE_PIN18_BITMASK;
- } else if (pin == 19) {
- CORE_PIN19_PORTREG |= CORE_PIN19_BITMASK;
- } else if (pin == 20) {
- CORE_PIN20_PORTREG |= CORE_PIN20_BITMASK;
- }
- #if CORE_NUM_TOTAL_PINS > 21
- else if (pin == 21) {
- CORE_PIN21_PORTREG |= CORE_PIN21_BITMASK;
- } else if (pin == 22) {
- CORE_PIN22_PORTREG |= CORE_PIN22_BITMASK;
- } else if (pin == 23) {
- CORE_PIN23_PORTREG |= CORE_PIN23_BITMASK;
- } else if (pin == 24) {
- CORE_PIN24_PORTREG |= CORE_PIN24_BITMASK;
- }
- #endif
- #if CORE_NUM_TOTAL_PINS > 25
- else if (pin == 25) {
- CORE_PIN25_PORTREG |= CORE_PIN25_BITMASK;
- } else if (pin == 26) {
- CORE_PIN26_PORTREG |= CORE_PIN26_BITMASK;
- } else if (pin == 27) {
- CORE_PIN27_PORTREG |= CORE_PIN27_BITMASK;
- } else if (pin == 28) {
- CORE_PIN28_PORTREG |= CORE_PIN28_BITMASK;
- } else if (pin == 29) {
- CORE_PIN29_PORTREG |= CORE_PIN29_BITMASK;
- } else if (pin == 30) {
- CORE_PIN30_PORTREG |= CORE_PIN30_BITMASK;
- } else if (pin == 31) {
- CORE_PIN31_PORTREG |= CORE_PIN31_BITMASK;
- } else if (pin == 32) {
- CORE_PIN32_PORTREG |= CORE_PIN32_BITMASK;
- } else if (pin == 33) {
- CORE_PIN33_PORTREG |= CORE_PIN33_BITMASK;
- } else if (pin == 34) {
- CORE_PIN34_PORTREG |= CORE_PIN34_BITMASK;
- } else if (pin == 35) {
- CORE_PIN35_PORTREG |= CORE_PIN35_BITMASK;
- } else if (pin == 36) {
- CORE_PIN36_PORTREG |= CORE_PIN36_BITMASK;
- } else if (pin == 37) {
- CORE_PIN37_PORTREG |= CORE_PIN37_BITMASK;
- } else if (pin == 38) {
- CORE_PIN38_PORTREG |= CORE_PIN38_BITMASK;
- } else if (pin == 39) {
- CORE_PIN39_PORTREG |= CORE_PIN39_BITMASK;
- } else if (pin == 40) {
- CORE_PIN40_PORTREG |= CORE_PIN40_BITMASK;
- } else if (pin == 41) {
- CORE_PIN41_PORTREG |= CORE_PIN41_BITMASK;
- } else if (pin == 42) {
- CORE_PIN42_PORTREG |= CORE_PIN42_BITMASK;
- } else if (pin == 43) {
- CORE_PIN43_PORTREG |= CORE_PIN43_BITMASK;
- } else if (pin == 44) {
- CORE_PIN44_PORTREG |= CORE_PIN44_BITMASK;
- } else if (pin == 45) {
- CORE_PIN45_PORTREG |= CORE_PIN45_BITMASK;
- }
- #endif
- } else {
- if (pin == 0) {
- CORE_PIN0_PORTREG &= ~CORE_PIN0_BITMASK;
- } else if (pin == 1) {
- CORE_PIN1_PORTREG &= ~CORE_PIN1_BITMASK;
- } else if (pin == 2) {
- CORE_PIN2_PORTREG &= ~CORE_PIN2_BITMASK;
- } else if (pin == 3) {
- CORE_PIN3_PORTREG &= ~CORE_PIN3_BITMASK;
- } else if (pin == 4) {
- CORE_PIN4_PORTREG &= ~CORE_PIN4_BITMASK;
- } else if (pin == 5) {
- CORE_PIN5_PORTREG &= ~CORE_PIN5_BITMASK;
- } else if (pin == 6) {
- CORE_PIN6_PORTREG &= ~CORE_PIN6_BITMASK;
- } else if (pin == 7) {
- CORE_PIN7_PORTREG &= ~CORE_PIN7_BITMASK;
- } else if (pin == 8) {
- CORE_PIN8_PORTREG &= ~CORE_PIN8_BITMASK;
- } else if (pin == 9) {
- CORE_PIN9_PORTREG &= ~CORE_PIN9_BITMASK;
- } else if (pin == 10) {
- CORE_PIN10_PORTREG &= ~CORE_PIN10_BITMASK;
- } else if (pin == 11) {
- CORE_PIN11_PORTREG &= ~CORE_PIN11_BITMASK;
- } else if (pin == 12) {
- CORE_PIN12_PORTREG &= ~CORE_PIN12_BITMASK;
- } else if (pin == 13) {
- CORE_PIN13_PORTREG &= ~CORE_PIN13_BITMASK;
- } else if (pin == 14) {
- CORE_PIN14_PORTREG &= ~CORE_PIN14_BITMASK;
- } else if (pin == 15) {
- CORE_PIN15_PORTREG &= ~CORE_PIN15_BITMASK;
- } else if (pin == 16) {
- CORE_PIN16_PORTREG &= ~CORE_PIN16_BITMASK;
- } else if (pin == 17) {
- CORE_PIN17_PORTREG &= ~CORE_PIN17_BITMASK;
- } else if (pin == 18) {
- CORE_PIN18_PORTREG &= ~CORE_PIN18_BITMASK;
- } else if (pin == 19) {
- CORE_PIN19_PORTREG &= ~CORE_PIN19_BITMASK;
- } else if (pin == 20) {
- CORE_PIN20_PORTREG &= ~CORE_PIN20_BITMASK;
- }
- #if CORE_NUM_TOTAL_PINS > 21
- else if (pin == 21) {
- CORE_PIN21_PORTREG &= ~CORE_PIN21_BITMASK;
- } else if (pin == 22) {
- CORE_PIN22_PORTREG &= ~CORE_PIN22_BITMASK;
- } else if (pin == 23) {
- CORE_PIN23_PORTREG &= ~CORE_PIN23_BITMASK;
- } else if (pin == 24) {
- CORE_PIN24_PORTREG &= ~CORE_PIN24_BITMASK;
- }
- #endif
- #if CORE_NUM_TOTAL_PINS > 25
- else if (pin == 25) {
- CORE_PIN25_PORTREG &= ~CORE_PIN25_BITMASK;
- } else if (pin == 26) {
- CORE_PIN26_PORTREG &= ~CORE_PIN26_BITMASK;
- } else if (pin == 27) {
- CORE_PIN27_PORTREG &= ~CORE_PIN27_BITMASK;
- } else if (pin == 28) {
- CORE_PIN28_PORTREG &= ~CORE_PIN28_BITMASK;
- } else if (pin == 29) {
- CORE_PIN29_PORTREG &= ~CORE_PIN29_BITMASK;
- } else if (pin == 30) {
- CORE_PIN30_PORTREG &= ~CORE_PIN30_BITMASK;
- } else if (pin == 31) {
- CORE_PIN31_PORTREG &= ~CORE_PIN31_BITMASK;
- } else if (pin == 32) {
- CORE_PIN32_PORTREG &= ~CORE_PIN32_BITMASK;
- } else if (pin == 33) {
- CORE_PIN33_PORTREG &= ~CORE_PIN33_BITMASK;
- } else if (pin == 34) {
- CORE_PIN34_PORTREG &= ~CORE_PIN34_BITMASK;
- } else if (pin == 35) {
- CORE_PIN35_PORTREG &= ~CORE_PIN35_BITMASK;
- } else if (pin == 36) {
- CORE_PIN36_PORTREG &= ~CORE_PIN36_BITMASK;
- } else if (pin == 37) {
- CORE_PIN37_PORTREG &= ~CORE_PIN37_BITMASK;
- } else if (pin == 38) {
- CORE_PIN38_PORTREG &= ~CORE_PIN38_BITMASK;
- } else if (pin == 39) {
- CORE_PIN39_PORTREG &= ~CORE_PIN39_BITMASK;
- } else if (pin == 40) {
- CORE_PIN40_PORTREG &= ~CORE_PIN40_BITMASK;
- } else if (pin == 41) {
- CORE_PIN41_PORTREG &= ~CORE_PIN41_BITMASK;
- } else if (pin == 42) {
- CORE_PIN42_PORTREG &= ~CORE_PIN42_BITMASK;
- } else if (pin == 43) {
- CORE_PIN43_PORTREG &= ~CORE_PIN43_BITMASK;
- } else if (pin == 44) {
- CORE_PIN44_PORTREG &= ~CORE_PIN44_BITMASK;
- } else if (pin == 45) {
- CORE_PIN45_PORTREG &= ~CORE_PIN45_BITMASK;
- }
- #endif
- }
- if (pin == CORE_OC0B_PIN) {
- _SFR_BYTE(TCCR0A) &= ~(1<<COM0B1);
- } else if (pin == CORE_OC1A_PIN) {
- TCCR1A &= ~(1<<COM1A1);
- } else if (pin == CORE_OC1B_PIN) {
- TCCR1A &= ~(1<<COM1B1);
- } else if (pin == CORE_OC1C_PIN) {
- TCCR1A &= ~(1<<COM1C1);
- }
- #if defined(__AVR_ATmega32U4__)
- else if (pin == CORE_OC3A_PIN) {
- TCCR3A &= ~(1<<COM3A1);
- } else if (pin == CORE_OC4A_PIN) {
- TCCR4A &= ~(1<<COM4A1);
- } else if (pin == CORE_OC4D_PIN) {
- TCCR4C &= ~(1<<COM4D1);
- }
- #endif
- #if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
- else if (pin == CORE_OC2A_PIN) {
- TCCR2A &= ~(1<<COM2A1);
- } else if (pin == CORE_OC2B_PIN) {
- TCCR2A &= ~(1<<COM2B1);
- } else if (pin == CORE_OC3A_PIN) {
- TCCR3A &= ~(1<<COM3A1);
- } else if (pin == CORE_OC3B_PIN) {
- TCCR3A &= ~(1<<COM3B1);
- } else if (pin == CORE_OC3C_PIN) {
- TCCR3A &= ~(1<<COM3C1);
- }
- #endif
- } else {
- if (__builtin_constant_p(val)) {
- if (val) {
- uint16_t tmp = (pin);
- asm volatile(
- #if defined(DIGITAL_WRITE_EXPENSIVE_INLINE_OPTIMIZATION)
- #if !defined(DIGITAL_WRITE_RISKY_OMIT_OVERFLOW_CHECK)
- "cpi r30, %1" "\n\t"
- "brsh L%=end1" "\n\t"
- #endif
- "lsl r30" "\n\t"
- //"clr r31" "\n\t"
- "subi r30, lo8(-(pm(_digitalWrite_HIGH_TABLE)))" "\n\t"
- "sbci r31, hi8(-(pm(_digitalWrite_HIGH_TABLE)))" "\n\t"
- "icall" "\n\t"
- "L%=end1:" "\n"
- #else
- "call _digitalWrite_HIGH"
- #endif
- : "+z" (tmp)
- : "I" (CORE_NUM_TOTAL_PINS)
- );
- } else {
- uint16_t tmp = (pin);
- asm volatile(
- #if defined(DIGITAL_WRITE_EXPENSIVE_INLINE_OPTIMIZATION)
- #if !defined(DIGITAL_WRITE_RISKY_OMIT_OVERFLOW_CHECK)
- "cpi r30, %1" "\n\t"
- "brsh L%=end2" "\n\t"
- #endif
- "lsl r30" "\n\t"
- //"clr r31" "\n\t"
- "subi r30, lo8(-(pm(_digitalWrite_LOW_TABLE)))" "\n\t"
- "sbci r31, hi8(-(pm(_digitalWrite_LOW_TABLE)))" "\n\t"
- "icall" "\n\t"
- "L%=end2:" "\n"
- #else
- "call _digitalWrite_LOW"
- #endif
- : "+z" (tmp)
- : "I" (CORE_NUM_TOTAL_PINS)
- );
- }
- } else {
- uint16_t tmp1 = (pin);
- uint8_t tmp2 = (val);
- asm volatile(
- #if defined(DIGITAL_WRITE_EXPENSIVE_INLINE_OPTIMIZATION)
- #if !defined(DIGITAL_WRITE_RISKY_OMIT_OVERFLOW_CHECK)
- "cpi %0, %2" "\n\t"
- "brsh L%=end3" "\n\t"
- #endif
- "lsl r30" "\n\t"
- //"clr r31" "\n\t"
- "tst %1" "\n\t"
- "breq L%=low" "\n\t"
- "subi r30, lo8(-(pm(_digitalWrite_HIGH_TABLE)))" "\n\t"
- "sbci r31, hi8(-(pm(_digitalWrite_HIGH_TABLE)))" "\n\t"
- "icall" "\n\t"
- "rjmp L%=end3" "\n\t"
- "L%=low:" "\n\t"
- "subi r30, lo8(-(pm(_digitalWrite_LOW_TABLE)))" "\n\t"
- "sbci r31, hi8(-(pm(_digitalWrite_LOW_TABLE)))" "\n\t"
- "icall" "\n\t"
- "L%=end3:" "\n\t"
- : "+z" (tmp1)
- : "d" (tmp2), "I" (CORE_NUM_TOTAL_PINS)
- #else
- "mov __tmp_reg__, %1" "\n\t"
- "call _digitalWrite"
- : "+z" (tmp1)
- : "r" (tmp2)
- #endif
- );
- }
- }
- }
-
- static inline void digitalWriteFast(uint8_t, uint8_t) __attribute__((always_inline, unused));
- static inline void digitalWriteFast(uint8_t pin, uint8_t val)
- {
- if (__builtin_constant_p(pin)) {
- if (val) {
- if (pin == 0) {
- CORE_PIN0_PORTREG |= CORE_PIN0_BITMASK;
- } else if (pin == 1) {
- CORE_PIN1_PORTREG |= CORE_PIN1_BITMASK;
- } else if (pin == 2) {
- CORE_PIN2_PORTREG |= CORE_PIN2_BITMASK;
- } else if (pin == 3) {
- CORE_PIN3_PORTREG |= CORE_PIN3_BITMASK;
- } else if (pin == 4) {
- CORE_PIN4_PORTREG |= CORE_PIN4_BITMASK;
- } else if (pin == 5) {
- CORE_PIN5_PORTREG |= CORE_PIN5_BITMASK;
- } else if (pin == 6) {
- CORE_PIN6_PORTREG |= CORE_PIN6_BITMASK;
- } else if (pin == 7) {
- CORE_PIN7_PORTREG |= CORE_PIN7_BITMASK;
- } else if (pin == 8) {
- CORE_PIN8_PORTREG |= CORE_PIN8_BITMASK;
- } else if (pin == 9) {
- CORE_PIN9_PORTREG |= CORE_PIN9_BITMASK;
- } else if (pin == 10) {
- CORE_PIN10_PORTREG |= CORE_PIN10_BITMASK;
- } else if (pin == 11) {
- CORE_PIN11_PORTREG |= CORE_PIN11_BITMASK;
- } else if (pin == 12) {
- CORE_PIN12_PORTREG |= CORE_PIN12_BITMASK;
- } else if (pin == 13) {
- CORE_PIN13_PORTREG |= CORE_PIN13_BITMASK;
- } else if (pin == 14) {
- CORE_PIN14_PORTREG |= CORE_PIN14_BITMASK;
- } else if (pin == 15) {
- CORE_PIN15_PORTREG |= CORE_PIN15_BITMASK;
- } else if (pin == 16) {
- CORE_PIN16_PORTREG |= CORE_PIN16_BITMASK;
- } else if (pin == 17) {
- CORE_PIN17_PORTREG |= CORE_PIN17_BITMASK;
- } else if (pin == 18) {
- CORE_PIN18_PORTREG |= CORE_PIN18_BITMASK;
- } else if (pin == 19) {
- CORE_PIN19_PORTREG |= CORE_PIN19_BITMASK;
- } else if (pin == 20) {
- CORE_PIN20_PORTREG |= CORE_PIN20_BITMASK;
- }
- #if CORE_NUM_TOTAL_PINS > 21
- else if (pin == 21) {
- CORE_PIN21_PORTREG |= CORE_PIN21_BITMASK;
- } else if (pin == 22) {
- CORE_PIN22_PORTREG |= CORE_PIN22_BITMASK;
- } else if (pin == 23) {
- CORE_PIN23_PORTREG |= CORE_PIN23_BITMASK;
- } else if (pin == 24) {
- CORE_PIN24_PORTREG |= CORE_PIN24_BITMASK;
- }
- #endif
- #if CORE_NUM_TOTAL_PINS > 25
- else if (pin == 25) {
- CORE_PIN25_PORTREG |= CORE_PIN25_BITMASK;
- } else if (pin == 26) {
- CORE_PIN26_PORTREG |= CORE_PIN26_BITMASK;
- } else if (pin == 27) {
- CORE_PIN27_PORTREG |= CORE_PIN27_BITMASK;
- } else if (pin == 28) {
- CORE_PIN28_PORTREG |= CORE_PIN28_BITMASK;
- } else if (pin == 29) {
- CORE_PIN29_PORTREG |= CORE_PIN29_BITMASK;
- } else if (pin == 30) {
- CORE_PIN30_PORTREG |= CORE_PIN30_BITMASK;
- } else if (pin == 31) {
- CORE_PIN31_PORTREG |= CORE_PIN31_BITMASK;
- } else if (pin == 32) {
- CORE_PIN32_PORTREG |= CORE_PIN32_BITMASK;
- } else if (pin == 33) {
- CORE_PIN33_PORTREG |= CORE_PIN33_BITMASK;
- } else if (pin == 34) {
- CORE_PIN34_PORTREG |= CORE_PIN34_BITMASK;
- } else if (pin == 35) {
- CORE_PIN35_PORTREG |= CORE_PIN35_BITMASK;
- } else if (pin == 36) {
- CORE_PIN36_PORTREG |= CORE_PIN36_BITMASK;
- } else if (pin == 37) {
- CORE_PIN37_PORTREG |= CORE_PIN37_BITMASK;
- } else if (pin == 38) {
- CORE_PIN38_PORTREG |= CORE_PIN38_BITMASK;
- } else if (pin == 39) {
- CORE_PIN39_PORTREG |= CORE_PIN39_BITMASK;
- } else if (pin == 40) {
- CORE_PIN40_PORTREG |= CORE_PIN40_BITMASK;
- } else if (pin == 41) {
- CORE_PIN41_PORTREG |= CORE_PIN41_BITMASK;
- } else if (pin == 42) {
- CORE_PIN42_PORTREG |= CORE_PIN42_BITMASK;
- } else if (pin == 43) {
- CORE_PIN43_PORTREG |= CORE_PIN43_BITMASK;
- } else if (pin == 44) {
- CORE_PIN44_PORTREG |= CORE_PIN44_BITMASK;
- } else if (pin == 45) {
- CORE_PIN45_PORTREG |= CORE_PIN45_BITMASK;
- }
- #endif
- } else {
- if (pin == 0) {
- CORE_PIN0_PORTREG &= ~CORE_PIN0_BITMASK;
- } else if (pin == 1) {
- CORE_PIN1_PORTREG &= ~CORE_PIN1_BITMASK;
- } else if (pin == 2) {
- CORE_PIN2_PORTREG &= ~CORE_PIN2_BITMASK;
- } else if (pin == 3) {
- CORE_PIN3_PORTREG &= ~CORE_PIN3_BITMASK;
- } else if (pin == 4) {
- CORE_PIN4_PORTREG &= ~CORE_PIN4_BITMASK;
- } else if (pin == 5) {
- CORE_PIN5_PORTREG &= ~CORE_PIN5_BITMASK;
- } else if (pin == 6) {
- CORE_PIN6_PORTREG &= ~CORE_PIN6_BITMASK;
- } else if (pin == 7) {
- CORE_PIN7_PORTREG &= ~CORE_PIN7_BITMASK;
- } else if (pin == 8) {
- CORE_PIN8_PORTREG &= ~CORE_PIN8_BITMASK;
- } else if (pin == 9) {
- CORE_PIN9_PORTREG &= ~CORE_PIN9_BITMASK;
- } else if (pin == 10) {
- CORE_PIN10_PORTREG &= ~CORE_PIN10_BITMASK;
- } else if (pin == 11) {
- CORE_PIN11_PORTREG &= ~CORE_PIN11_BITMASK;
- } else if (pin == 12) {
- CORE_PIN12_PORTREG &= ~CORE_PIN12_BITMASK;
- } else if (pin == 13) {
- CORE_PIN13_PORTREG &= ~CORE_PIN13_BITMASK;
- } else if (pin == 14) {
- CORE_PIN14_PORTREG &= ~CORE_PIN14_BITMASK;
- } else if (pin == 15) {
- CORE_PIN15_PORTREG &= ~CORE_PIN15_BITMASK;
- } else if (pin == 16) {
- CORE_PIN16_PORTREG &= ~CORE_PIN16_BITMASK;
- } else if (pin == 17) {
- CORE_PIN17_PORTREG &= ~CORE_PIN17_BITMASK;
- } else if (pin == 18) {
- CORE_PIN18_PORTREG &= ~CORE_PIN18_BITMASK;
- } else if (pin == 19) {
- CORE_PIN19_PORTREG &= ~CORE_PIN19_BITMASK;
- } else if (pin == 20) {
- CORE_PIN20_PORTREG &= ~CORE_PIN20_BITMASK;
- }
- #if CORE_NUM_TOTAL_PINS > 21
- else if (pin == 21) {
- CORE_PIN21_PORTREG &= ~CORE_PIN21_BITMASK;
- } else if (pin == 22) {
- CORE_PIN22_PORTREG &= ~CORE_PIN22_BITMASK;
- } else if (pin == 23) {
- CORE_PIN23_PORTREG &= ~CORE_PIN23_BITMASK;
- } else if (pin == 24) {
- CORE_PIN24_PORTREG &= ~CORE_PIN24_BITMASK;
- }
- #endif
- #if CORE_NUM_TOTAL_PINS > 25
- else if (pin == 25) {
- CORE_PIN25_PORTREG &= ~CORE_PIN25_BITMASK;
- } else if (pin == 26) {
- CORE_PIN26_PORTREG &= ~CORE_PIN26_BITMASK;
- } else if (pin == 27) {
- CORE_PIN27_PORTREG &= ~CORE_PIN27_BITMASK;
- } else if (pin == 28) {
- CORE_PIN28_PORTREG &= ~CORE_PIN28_BITMASK;
- } else if (pin == 29) {
- CORE_PIN29_PORTREG &= ~CORE_PIN29_BITMASK;
- } else if (pin == 30) {
- CORE_PIN30_PORTREG &= ~CORE_PIN30_BITMASK;
- } else if (pin == 31) {
- CORE_PIN31_PORTREG &= ~CORE_PIN31_BITMASK;
- } else if (pin == 32) {
- CORE_PIN32_PORTREG &= ~CORE_PIN32_BITMASK;
- } else if (pin == 33) {
- CORE_PIN33_PORTREG &= ~CORE_PIN33_BITMASK;
- } else if (pin == 34) {
- CORE_PIN34_PORTREG &= ~CORE_PIN34_BITMASK;
- } else if (pin == 35) {
- CORE_PIN35_PORTREG &= ~CORE_PIN35_BITMASK;
- } else if (pin == 36) {
- CORE_PIN36_PORTREG &= ~CORE_PIN36_BITMASK;
- } else if (pin == 37) {
- CORE_PIN37_PORTREG &= ~CORE_PIN37_BITMASK;
- } else if (pin == 38) {
- CORE_PIN38_PORTREG &= ~CORE_PIN38_BITMASK;
- } else if (pin == 39) {
- CORE_PIN39_PORTREG &= ~CORE_PIN39_BITMASK;
- } else if (pin == 40) {
- CORE_PIN40_PORTREG &= ~CORE_PIN40_BITMASK;
- } else if (pin == 41) {
- CORE_PIN41_PORTREG &= ~CORE_PIN41_BITMASK;
- } else if (pin == 42) {
- CORE_PIN42_PORTREG &= ~CORE_PIN42_BITMASK;
- } else if (pin == 43) {
- CORE_PIN43_PORTREG &= ~CORE_PIN43_BITMASK;
- } else if (pin == 44) {
- CORE_PIN44_PORTREG &= ~CORE_PIN44_BITMASK;
- } else if (pin == 45) {
- CORE_PIN45_PORTREG &= ~CORE_PIN45_BITMASK;
- }
- #endif
- }
- } else {
- digitalWrite(pin, val);
- }
- }
-
-
- extern void _digitalRead(void) __attribute__((noinline));
-
- static inline uint8_t digitalRead(uint8_t) __attribute__((always_inline, unused));
- static inline uint8_t digitalRead(uint8_t pin)
- {
- if (__builtin_constant_p(pin)) {
- if (pin == 0) {
- return (CORE_PIN0_PINREG & CORE_PIN0_BITMASK) ? 1 : 0;
- } else if (pin == 1) {
- return (CORE_PIN1_PINREG & CORE_PIN1_BITMASK) ? 1 : 0;
- } else if (pin == 2) {
- return (CORE_PIN2_PINREG & CORE_PIN2_BITMASK) ? 1 : 0;
- } else if (pin == 3) {
- return (CORE_PIN3_PINREG & CORE_PIN3_BITMASK) ? 1 : 0;
- } else if (pin == 4) {
- return (CORE_PIN4_PINREG & CORE_PIN4_BITMASK) ? 1 : 0;
- } else if (pin == 5) {
- return (CORE_PIN5_PINREG & CORE_PIN5_BITMASK) ? 1 : 0;
- } else if (pin == 6) {
- return (CORE_PIN6_PINREG & CORE_PIN6_BITMASK) ? 1 : 0;
- } else if (pin == 7) {
- return (CORE_PIN7_PINREG & CORE_PIN7_BITMASK) ? 1 : 0;
- } else if (pin == 8) {
- return (CORE_PIN8_PINREG & CORE_PIN8_BITMASK) ? 1 : 0;
- } else if (pin == 9) {
- return (CORE_PIN9_PINREG & CORE_PIN9_BITMASK) ? 1 : 0;
- } else if (pin == 10) {
- return (CORE_PIN10_PINREG & CORE_PIN10_BITMASK) ? 1 : 0;
- } else if (pin == 11) {
- return (CORE_PIN11_PINREG & CORE_PIN11_BITMASK) ? 1 : 0;
- } else if (pin == 12) {
- return (CORE_PIN12_PINREG & CORE_PIN12_BITMASK) ? 1 : 0;
- } else if (pin == 13) {
- return (CORE_PIN13_PINREG & CORE_PIN13_BITMASK) ? 1 : 0;
- } else if (pin == 14) {
- return (CORE_PIN14_PINREG & CORE_PIN14_BITMASK) ? 1 : 0;
- } else if (pin == 15) {
- return (CORE_PIN15_PINREG & CORE_PIN15_BITMASK) ? 1 : 0;
- } else if (pin == 16) {
- return (CORE_PIN16_PINREG & CORE_PIN16_BITMASK) ? 1 : 0;
- } else if (pin == 17) {
- return (CORE_PIN17_PINREG & CORE_PIN17_BITMASK) ? 1 : 0;
- } else if (pin == 18) {
- return (CORE_PIN18_PINREG & CORE_PIN18_BITMASK) ? 1 : 0;
- } else if (pin == 19) {
- return (CORE_PIN19_PINREG & CORE_PIN19_BITMASK) ? 1 : 0;
- } else if (pin == 20) {
- return (CORE_PIN20_PINREG & CORE_PIN20_BITMASK) ? 1 : 0;
- }
- #if CORE_NUM_TOTAL_PINS > 21
- else if (pin == 21) {
- return (CORE_PIN21_PINREG & CORE_PIN21_BITMASK) ? 1 : 0;
- } else if (pin == 22) {
- return (CORE_PIN22_PINREG & CORE_PIN22_BITMASK) ? 1 : 0;
- } else if (pin == 23) {
- return (CORE_PIN23_PINREG & CORE_PIN23_BITMASK) ? 1 : 0;
- } else if (pin == 24) {
- return (CORE_PIN24_PINREG & CORE_PIN24_BITMASK) ? 1 : 0;
- }
- #endif
- #if CORE_NUM_TOTAL_PINS > 25
- else if (pin == 25) {
- return (CORE_PIN25_PINREG & CORE_PIN25_BITMASK) ? 1 : 0;
- } else if (pin == 26) {
- return (CORE_PIN26_PINREG & CORE_PIN26_BITMASK) ? 1 : 0;
- } else if (pin == 27) {
- return (CORE_PIN27_PINREG & CORE_PIN27_BITMASK) ? 1 : 0;
- } else if (pin == 28) {
- return (CORE_PIN28_PINREG & CORE_PIN28_BITMASK) ? 1 : 0;
- } else if (pin == 29) {
- return (CORE_PIN29_PINREG & CORE_PIN29_BITMASK) ? 1 : 0;
- } else if (pin == 30) {
- return (CORE_PIN30_PINREG & CORE_PIN30_BITMASK) ? 1 : 0;
- } else if (pin == 31) {
- return (CORE_PIN31_PINREG & CORE_PIN31_BITMASK) ? 1 : 0;
- } else if (pin == 32) {
- return (CORE_PIN32_PINREG & CORE_PIN32_BITMASK) ? 1 : 0;
- } else if (pin == 33) {
- return (CORE_PIN33_PINREG & CORE_PIN33_BITMASK) ? 1 : 0;
- } else if (pin == 34) {
- return (CORE_PIN34_PINREG & CORE_PIN34_BITMASK) ? 1 : 0;
- } else if (pin == 35) {
- return (CORE_PIN35_PINREG & CORE_PIN35_BITMASK) ? 1 : 0;
- } else if (pin == 36) {
- return (CORE_PIN36_PINREG & CORE_PIN36_BITMASK) ? 1 : 0;
- } else if (pin == 37) {
- return (CORE_PIN37_PINREG & CORE_PIN37_BITMASK) ? 1 : 0;
- } else if (pin == 38) {
- return (CORE_PIN38_PINREG & CORE_PIN38_BITMASK) ? 1 : 0;
- } else if (pin == 39) {
- return (CORE_PIN39_PINREG & CORE_PIN39_BITMASK) ? 1 : 0;
- } else if (pin == 40) {
- return (CORE_PIN40_PINREG & CORE_PIN40_BITMASK) ? 1 : 0;
- } else if (pin == 41) {
- return (CORE_PIN41_PINREG & CORE_PIN41_BITMASK) ? 1 : 0;
- } else if (pin == 42) {
- return (CORE_PIN42_PINREG & CORE_PIN42_BITMASK) ? 1 : 0;
- } else if (pin == 43) {
- return (CORE_PIN43_PINREG & CORE_PIN43_BITMASK) ? 1 : 0;
- } else if (pin == 44) {
- return (CORE_PIN44_PINREG & CORE_PIN44_BITMASK) ? 1 : 0;
- } else if (pin == 45) {
- return (CORE_PIN45_PINREG & CORE_PIN45_BITMASK) ? 1 : 0;
- }
- #endif
- else {
- return 0;
- }
- } else {
- uint16_t tmp = (pin);
- asm volatile(
- "call _digitalRead"
- : "+z" (tmp)
- :);
- return (uint8_t)tmp;
- }
- }
-
- static inline uint8_t digitalReadFast(uint8_t) __attribute__((always_inline, unused));
- static inline uint8_t digitalReadFast(uint8_t pin)
- {
- return digitalRead(pin);
- }
-
- extern void _pinMode(uint8_t pin, uint8_t mode) __attribute__((noinline));
- extern void _pinMode_output(uint8_t pin) __attribute__((noinline));
- extern void _pinMode_input(uint8_t pin) __attribute__((noinline));
- extern void _pinMode_input_pullup(uint8_t pin) __attribute__((noinline));
-
- static inline void pinMode(uint8_t, uint8_t) __attribute__((always_inline, unused));
- static inline void pinMode(uint8_t pin, uint8_t mode)
- {
- if (__builtin_constant_p(pin) && __builtin_constant_p(mode)) {
- if (mode == OUTPUT) {
- if (pin == 0) {
- CORE_PIN0_DDRREG |= CORE_PIN0_BITMASK;
- } else if (pin == 1) {
- CORE_PIN1_DDRREG |= CORE_PIN1_BITMASK;
- } else if (pin == 2) {
- CORE_PIN2_DDRREG |= CORE_PIN2_BITMASK;
- } else if (pin == 3) {
- CORE_PIN3_DDRREG |= CORE_PIN3_BITMASK;
- } else if (pin == 4) {
- CORE_PIN4_DDRREG |= CORE_PIN4_BITMASK;
- } else if (pin == 5) {
- CORE_PIN5_DDRREG |= CORE_PIN5_BITMASK;
- } else if (pin == 6) {
- CORE_PIN6_DDRREG |= CORE_PIN6_BITMASK;
- } else if (pin == 7) {
- CORE_PIN7_DDRREG |= CORE_PIN7_BITMASK;
- } else if (pin == 8) {
- CORE_PIN8_DDRREG |= CORE_PIN8_BITMASK;
- } else if (pin == 9) {
- CORE_PIN9_DDRREG |= CORE_PIN9_BITMASK;
- } else if (pin == 10) {
- CORE_PIN10_DDRREG |= CORE_PIN10_BITMASK;
- } else if (pin == 11) {
- CORE_PIN11_DDRREG |= CORE_PIN11_BITMASK;
- } else if (pin == 12) {
- CORE_PIN12_DDRREG |= CORE_PIN12_BITMASK;
- } else if (pin == 13) {
- CORE_PIN13_DDRREG |= CORE_PIN13_BITMASK;
- } else if (pin == 14) {
- CORE_PIN14_DDRREG |= CORE_PIN14_BITMASK;
- } else if (pin == 15) {
- CORE_PIN15_DDRREG |= CORE_PIN15_BITMASK;
- } else if (pin == 16) {
- CORE_PIN16_DDRREG |= CORE_PIN16_BITMASK;
- } else if (pin == 17) {
- CORE_PIN17_DDRREG |= CORE_PIN17_BITMASK;
- } else if (pin == 18) {
- CORE_PIN18_DDRREG |= CORE_PIN18_BITMASK;
- } else if (pin == 19) {
- CORE_PIN19_DDRREG |= CORE_PIN19_BITMASK;
- } else if (pin == 20) {
- CORE_PIN20_DDRREG |= CORE_PIN20_BITMASK;
- }
- #if CORE_NUM_TOTAL_PINS > 21
- else if (pin == 21) {
- CORE_PIN21_DDRREG |= CORE_PIN21_BITMASK;
- } else if (pin == 22) {
- CORE_PIN22_DDRREG |= CORE_PIN22_BITMASK;
- } else if (pin == 23) {
- CORE_PIN23_DDRREG |= CORE_PIN23_BITMASK;
- } else if (pin == 24) {
- CORE_PIN24_DDRREG |= CORE_PIN24_BITMASK;
- }
- #endif
- #if CORE_NUM_TOTAL_PINS > 25
- else if (pin == 25) {
- CORE_PIN25_DDRREG |= CORE_PIN25_BITMASK;
- } else if (pin == 26) {
- CORE_PIN26_DDRREG |= CORE_PIN26_BITMASK;
- } else if (pin == 27) {
- CORE_PIN27_DDRREG |= CORE_PIN27_BITMASK;
- } else if (pin == 28) {
- CORE_PIN28_DDRREG |= CORE_PIN28_BITMASK;
- } else if (pin == 29) {
- CORE_PIN29_DDRREG |= CORE_PIN29_BITMASK;
- } else if (pin == 30) {
- CORE_PIN30_DDRREG |= CORE_PIN30_BITMASK;
- } else if (pin == 31) {
- CORE_PIN31_DDRREG |= CORE_PIN31_BITMASK;
- } else if (pin == 32) {
- CORE_PIN32_DDRREG |= CORE_PIN32_BITMASK;
- } else if (pin == 33) {
- CORE_PIN33_DDRREG |= CORE_PIN33_BITMASK;
- } else if (pin == 34) {
- CORE_PIN34_DDRREG |= CORE_PIN34_BITMASK;
- } else if (pin == 35) {
- CORE_PIN35_DDRREG |= CORE_PIN35_BITMASK;
- } else if (pin == 36) {
- CORE_PIN36_DDRREG |= CORE_PIN36_BITMASK;
- } else if (pin == 37) {
- CORE_PIN37_DDRREG |= CORE_PIN37_BITMASK;
- } else if (pin == 38) {
- CORE_PIN38_DDRREG |= CORE_PIN38_BITMASK;
- } else if (pin == 39) {
- CORE_PIN39_DDRREG |= CORE_PIN39_BITMASK;
- } else if (pin == 40) {
- CORE_PIN40_DDRREG |= CORE_PIN40_BITMASK;
- } else if (pin == 41) {
- CORE_PIN41_DDRREG |= CORE_PIN41_BITMASK;
- } else if (pin == 42) {
- CORE_PIN42_DDRREG |= CORE_PIN42_BITMASK;
- } else if (pin == 43) {
- CORE_PIN43_DDRREG |= CORE_PIN43_BITMASK;
- } else if (pin == 44) {
- CORE_PIN44_DDRREG |= CORE_PIN44_BITMASK;
- } else if (pin == 45) {
- CORE_PIN45_DDRREG |= CORE_PIN45_BITMASK;
- }
- #endif
- } else if (mode == INPUT_PULLUP) {
- if (pin == 0) {
- CORE_PIN0_DDRREG &= ~CORE_PIN0_BITMASK;
- CORE_PIN0_PORTREG |= CORE_PIN0_BITMASK;
- } else if (pin == 1) {
- CORE_PIN1_DDRREG &= ~CORE_PIN1_BITMASK;
- CORE_PIN1_PORTREG |= CORE_PIN1_BITMASK;
- } else if (pin == 2) {
- CORE_PIN2_DDRREG &= ~CORE_PIN2_BITMASK;
- CORE_PIN2_PORTREG |= CORE_PIN2_BITMASK;
- } else if (pin == 3) {
- CORE_PIN3_DDRREG &= ~CORE_PIN3_BITMASK;
- CORE_PIN3_PORTREG |= CORE_PIN3_BITMASK;
- } else if (pin == 4) {
- CORE_PIN4_DDRREG &= ~CORE_PIN4_BITMASK;
- CORE_PIN4_PORTREG |= CORE_PIN4_BITMASK;
- } else if (pin == 5) {
- CORE_PIN5_DDRREG &= ~CORE_PIN5_BITMASK;
- CORE_PIN5_PORTREG |= CORE_PIN5_BITMASK;
- } else if (pin == 6) {
- CORE_PIN6_DDRREG &= ~CORE_PIN6_BITMASK;
- CORE_PIN6_PORTREG |= CORE_PIN6_BITMASK;
- } else if (pin == 7) {
- CORE_PIN7_DDRREG &= ~CORE_PIN7_BITMASK;
- CORE_PIN7_PORTREG |= CORE_PIN7_BITMASK;
- } else if (pin == 8) {
- CORE_PIN8_DDRREG &= ~CORE_PIN8_BITMASK;
- CORE_PIN8_PORTREG |= CORE_PIN8_BITMASK;
- } else if (pin == 9) {
- CORE_PIN9_DDRREG &= ~CORE_PIN9_BITMASK;
- CORE_PIN9_PORTREG |= CORE_PIN9_BITMASK;
- } else if (pin == 10) {
- CORE_PIN10_DDRREG &= ~CORE_PIN10_BITMASK;
- CORE_PIN10_PORTREG |= CORE_PIN10_BITMASK;
- } else if (pin == 11) {
- CORE_PIN11_DDRREG &= ~CORE_PIN11_BITMASK;
- CORE_PIN11_PORTREG |= CORE_PIN11_BITMASK;
- } else if (pin == 12) {
- CORE_PIN12_DDRREG &= ~CORE_PIN12_BITMASK;
- CORE_PIN12_PORTREG |= CORE_PIN12_BITMASK;
- } else if (pin == 13) {
- CORE_PIN13_DDRREG &= ~CORE_PIN13_BITMASK;
- CORE_PIN13_PORTREG |= CORE_PIN13_BITMASK;
- } else if (pin == 14) {
- CORE_PIN14_DDRREG &= ~CORE_PIN14_BITMASK;
- CORE_PIN14_PORTREG |= CORE_PIN14_BITMASK;
- } else if (pin == 15) {
- CORE_PIN15_DDRREG &= ~CORE_PIN15_BITMASK;
- CORE_PIN15_PORTREG |= CORE_PIN15_BITMASK;
- } else if (pin == 16) {
- CORE_PIN16_DDRREG &= ~CORE_PIN16_BITMASK;
- CORE_PIN16_PORTREG |= CORE_PIN16_BITMASK;
- } else if (pin == 17) {
- CORE_PIN17_DDRREG &= ~CORE_PIN17_BITMASK;
- CORE_PIN17_PORTREG |= CORE_PIN17_BITMASK;
- } else if (pin == 18) {
- CORE_PIN18_DDRREG &= ~CORE_PIN18_BITMASK;
- CORE_PIN18_PORTREG |= CORE_PIN18_BITMASK;
- } else if (pin == 19) {
- CORE_PIN19_DDRREG &= ~CORE_PIN19_BITMASK;
- CORE_PIN19_PORTREG |= CORE_PIN19_BITMASK;
- } else if (pin == 20) {
- CORE_PIN20_DDRREG &= ~CORE_PIN20_BITMASK;
- CORE_PIN20_PORTREG |= CORE_PIN20_BITMASK;
- }
- #if CORE_NUM_TOTAL_PINS > 21
- else if (pin == 21) {
- CORE_PIN21_DDRREG &= ~CORE_PIN21_BITMASK;
- CORE_PIN21_PORTREG |= CORE_PIN21_BITMASK;
- } else if (pin == 22) {
- CORE_PIN22_DDRREG &= ~CORE_PIN22_BITMASK;
- CORE_PIN22_PORTREG |= CORE_PIN22_BITMASK;
- } else if (pin == 23) {
- CORE_PIN23_DDRREG &= ~CORE_PIN23_BITMASK;
- CORE_PIN23_PORTREG |= CORE_PIN23_BITMASK;
- } else if (pin == 24) {
- CORE_PIN24_DDRREG &= ~CORE_PIN24_BITMASK;
- CORE_PIN24_PORTREG |= CORE_PIN24_BITMASK;
- }
- #endif
- #if CORE_NUM_TOTAL_PINS > 25
- else if (pin == 25) {
- CORE_PIN25_DDRREG &= ~CORE_PIN25_BITMASK;
- CORE_PIN25_PORTREG |= CORE_PIN25_BITMASK;
- } else if (pin == 26) {
- CORE_PIN26_DDRREG &= ~CORE_PIN26_BITMASK;
- CORE_PIN26_PORTREG |= CORE_PIN26_BITMASK;
- } else if (pin == 27) {
- CORE_PIN27_DDRREG &= ~CORE_PIN27_BITMASK;
- CORE_PIN27_PORTREG |= CORE_PIN27_BITMASK;
- } else if (pin == 28) {
- CORE_PIN28_DDRREG &= ~CORE_PIN28_BITMASK;
- CORE_PIN28_PORTREG |= CORE_PIN28_BITMASK;
- } else if (pin == 29) {
- CORE_PIN29_DDRREG &= ~CORE_PIN29_BITMASK;
- CORE_PIN29_PORTREG |= CORE_PIN29_BITMASK;
- } else if (pin == 30) {
- CORE_PIN30_DDRREG &= ~CORE_PIN30_BITMASK;
- CORE_PIN30_PORTREG |= CORE_PIN30_BITMASK;
- } else if (pin == 31) {
- CORE_PIN31_DDRREG &= ~CORE_PIN31_BITMASK;
- CORE_PIN31_PORTREG |= CORE_PIN31_BITMASK;
- } else if (pin == 32) {
- CORE_PIN32_DDRREG &= ~CORE_PIN32_BITMASK;
- CORE_PIN32_PORTREG |= CORE_PIN32_BITMASK;
- } else if (pin == 33) {
- CORE_PIN33_DDRREG &= ~CORE_PIN33_BITMASK;
- CORE_PIN33_PORTREG |= CORE_PIN33_BITMASK;
- } else if (pin == 34) {
- CORE_PIN34_DDRREG &= ~CORE_PIN34_BITMASK;
- CORE_PIN34_PORTREG |= CORE_PIN34_BITMASK;
- } else if (pin == 35) {
- CORE_PIN35_DDRREG &= ~CORE_PIN35_BITMASK;
- CORE_PIN35_PORTREG |= CORE_PIN35_BITMASK;
- } else if (pin == 36) {
- CORE_PIN36_DDRREG &= ~CORE_PIN36_BITMASK;
- CORE_PIN36_PORTREG |= CORE_PIN36_BITMASK;
- } else if (pin == 37) {
- CORE_PIN37_DDRREG &= ~CORE_PIN37_BITMASK;
- CORE_PIN37_PORTREG |= CORE_PIN37_BITMASK;
- } else if (pin == 38) {
- CORE_PIN38_DDRREG &= ~CORE_PIN38_BITMASK;
- CORE_PIN38_PORTREG |= CORE_PIN38_BITMASK;
- } else if (pin == 39) {
- CORE_PIN39_DDRREG &= ~CORE_PIN39_BITMASK;
- CORE_PIN39_PORTREG |= CORE_PIN39_BITMASK;
- } else if (pin == 40) {
- CORE_PIN40_DDRREG &= ~CORE_PIN40_BITMASK;
- CORE_PIN40_PORTREG |= CORE_PIN40_BITMASK;
- } else if (pin == 41) {
- CORE_PIN41_DDRREG &= ~CORE_PIN41_BITMASK;
- CORE_PIN41_PORTREG |= CORE_PIN41_BITMASK;
- } else if (pin == 42) {
- CORE_PIN42_DDRREG &= ~CORE_PIN42_BITMASK;
- CORE_PIN42_PORTREG |= CORE_PIN42_BITMASK;
- } else if (pin == 43) {
- CORE_PIN43_DDRREG &= ~CORE_PIN43_BITMASK;
- CORE_PIN43_PORTREG |= CORE_PIN43_BITMASK;
- } else if (pin == 44) {
- CORE_PIN44_DDRREG &= ~CORE_PIN44_BITMASK;
- CORE_PIN44_PORTREG |= CORE_PIN44_BITMASK;
- } else if (pin == 45) {
- CORE_PIN45_DDRREG &= ~CORE_PIN45_BITMASK;
- CORE_PIN45_PORTREG |= CORE_PIN45_BITMASK;
- }
- #endif
- } else {
- if (pin == 0) {
- CORE_PIN0_DDRREG &= ~CORE_PIN0_BITMASK;
- CORE_PIN0_PORTREG &= ~CORE_PIN0_BITMASK;
- } else if (pin == 1) {
- CORE_PIN1_DDRREG &= ~CORE_PIN1_BITMASK;
- CORE_PIN1_PORTREG &= ~CORE_PIN1_BITMASK;
- } else if (pin == 2) {
- CORE_PIN2_DDRREG &= ~CORE_PIN2_BITMASK;
- CORE_PIN2_PORTREG &= ~CORE_PIN2_BITMASK;
- } else if (pin == 3) {
- CORE_PIN3_DDRREG &= ~CORE_PIN3_BITMASK;
- CORE_PIN3_PORTREG &= ~CORE_PIN3_BITMASK;
- } else if (pin == 4) {
- CORE_PIN4_DDRREG &= ~CORE_PIN4_BITMASK;
- CORE_PIN4_PORTREG &= ~CORE_PIN4_BITMASK;
- } else if (pin == 5) {
- CORE_PIN5_DDRREG &= ~CORE_PIN5_BITMASK;
- CORE_PIN5_PORTREG &= ~CORE_PIN5_BITMASK;
- } else if (pin == 6) {
- CORE_PIN6_DDRREG &= ~CORE_PIN6_BITMASK;
- CORE_PIN6_PORTREG &= ~CORE_PIN6_BITMASK;
- } else if (pin == 7) {
- CORE_PIN7_DDRREG &= ~CORE_PIN7_BITMASK;
- CORE_PIN7_PORTREG &= ~CORE_PIN7_BITMASK;
- } else if (pin == 8) {
- CORE_PIN8_DDRREG &= ~CORE_PIN8_BITMASK;
- CORE_PIN8_PORTREG &= ~CORE_PIN8_BITMASK;
- } else if (pin == 9) {
- CORE_PIN9_DDRREG &= ~CORE_PIN9_BITMASK;
- CORE_PIN9_PORTREG &= ~CORE_PIN9_BITMASK;
- } else if (pin == 10) {
- CORE_PIN10_DDRREG &= ~CORE_PIN10_BITMASK;
- CORE_PIN10_PORTREG &= ~CORE_PIN10_BITMASK;
- } else if (pin == 11) {
- CORE_PIN11_DDRREG &= ~CORE_PIN11_BITMASK;
- CORE_PIN11_PORTREG &= ~CORE_PIN11_BITMASK;
- } else if (pin == 12) {
- CORE_PIN12_DDRREG &= ~CORE_PIN12_BITMASK;
- CORE_PIN12_PORTREG &= ~CORE_PIN12_BITMASK;
- } else if (pin == 13) {
- CORE_PIN13_DDRREG &= ~CORE_PIN13_BITMASK;
- CORE_PIN13_PORTREG &= ~CORE_PIN13_BITMASK;
- } else if (pin == 14) {
- CORE_PIN14_DDRREG &= ~CORE_PIN14_BITMASK;
- CORE_PIN14_PORTREG &= ~CORE_PIN14_BITMASK;
- } else if (pin == 15) {
- CORE_PIN15_DDRREG &= ~CORE_PIN15_BITMASK;
- CORE_PIN15_PORTREG &= ~CORE_PIN15_BITMASK;
- } else if (pin == 16) {
- CORE_PIN16_DDRREG &= ~CORE_PIN16_BITMASK;
- CORE_PIN16_PORTREG &= ~CORE_PIN16_BITMASK;
- } else if (pin == 17) {
- CORE_PIN17_DDRREG &= ~CORE_PIN17_BITMASK;
- CORE_PIN17_PORTREG &= ~CORE_PIN17_BITMASK;
- } else if (pin == 18) {
- CORE_PIN18_DDRREG &= ~CORE_PIN18_BITMASK;
- CORE_PIN18_PORTREG &= ~CORE_PIN18_BITMASK;
- } else if (pin == 19) {
- CORE_PIN19_DDRREG &= ~CORE_PIN19_BITMASK;
- CORE_PIN19_PORTREG &= ~CORE_PIN19_BITMASK;
- } else if (pin == 20) {
- CORE_PIN20_DDRREG &= ~CORE_PIN20_BITMASK;
- CORE_PIN20_PORTREG &= ~CORE_PIN20_BITMASK;
- }
- #if CORE_NUM_TOTAL_PINS > 21
- else if (pin == 21) {
- CORE_PIN21_DDRREG &= ~CORE_PIN21_BITMASK;
- CORE_PIN21_PORTREG &= ~CORE_PIN21_BITMASK;
- } else if (pin == 22) {
- CORE_PIN22_DDRREG &= ~CORE_PIN22_BITMASK;
- CORE_PIN22_PORTREG &= ~CORE_PIN22_BITMASK;
- } else if (pin == 23) {
- CORE_PIN23_DDRREG &= ~CORE_PIN23_BITMASK;
- CORE_PIN23_PORTREG &= ~CORE_PIN23_BITMASK;
- } else if (pin == 24) {
- CORE_PIN24_DDRREG &= ~CORE_PIN24_BITMASK;
- CORE_PIN24_PORTREG &= ~CORE_PIN24_BITMASK;
- }
- #endif
- #if CORE_NUM_TOTAL_PINS > 25
- else if (pin == 25) {
- CORE_PIN25_DDRREG &= ~CORE_PIN25_BITMASK;
- CORE_PIN25_PORTREG &= ~CORE_PIN25_BITMASK;
- } else if (pin == 26) {
- CORE_PIN26_DDRREG &= ~CORE_PIN26_BITMASK;
- CORE_PIN26_PORTREG &= ~CORE_PIN26_BITMASK;
- } else if (pin == 27) {
- CORE_PIN27_DDRREG &= ~CORE_PIN27_BITMASK;
- CORE_PIN27_PORTREG &= ~CORE_PIN27_BITMASK;
- } else if (pin == 28) {
- CORE_PIN28_DDRREG &= ~CORE_PIN28_BITMASK;
- CORE_PIN28_PORTREG &= ~CORE_PIN28_BITMASK;
- } else if (pin == 29) {
- CORE_PIN29_DDRREG &= ~CORE_PIN29_BITMASK;
- CORE_PIN29_PORTREG &= ~CORE_PIN29_BITMASK;
- } else if (pin == 30) {
- CORE_PIN30_DDRREG &= ~CORE_PIN30_BITMASK;
- CORE_PIN30_PORTREG &= ~CORE_PIN30_BITMASK;
- } else if (pin == 31) {
- CORE_PIN31_DDRREG &= ~CORE_PIN31_BITMASK;
- CORE_PIN31_PORTREG &= ~CORE_PIN31_BITMASK;
- } else if (pin == 32) {
- CORE_PIN32_DDRREG &= ~CORE_PIN32_BITMASK;
- CORE_PIN32_PORTREG &= ~CORE_PIN32_BITMASK;
- } else if (pin == 33) {
- CORE_PIN33_DDRREG &= ~CORE_PIN33_BITMASK;
- CORE_PIN33_PORTREG &= ~CORE_PIN33_BITMASK;
- } else if (pin == 34) {
- CORE_PIN34_DDRREG &= ~CORE_PIN34_BITMASK;
- CORE_PIN34_PORTREG &= ~CORE_PIN34_BITMASK;
- } else if (pin == 35) {
- CORE_PIN35_DDRREG &= ~CORE_PIN35_BITMASK;
- CORE_PIN35_PORTREG &= ~CORE_PIN35_BITMASK;
- } else if (pin == 36) {
- CORE_PIN36_DDRREG &= ~CORE_PIN36_BITMASK;
- CORE_PIN36_PORTREG &= ~CORE_PIN36_BITMASK;
- } else if (pin == 37) {
- CORE_PIN37_DDRREG &= ~CORE_PIN37_BITMASK;
- CORE_PIN37_PORTREG &= ~CORE_PIN37_BITMASK;
- } else if (pin == 38) {
- CORE_PIN38_DDRREG &= ~CORE_PIN38_BITMASK;
- CORE_PIN38_PORTREG &= ~CORE_PIN38_BITMASK;
- } else if (pin == 39) {
- CORE_PIN39_DDRREG &= ~CORE_PIN39_BITMASK;
- CORE_PIN39_PORTREG &= ~CORE_PIN39_BITMASK;
- } else if (pin == 40) {
- CORE_PIN40_DDRREG &= ~CORE_PIN40_BITMASK;
- CORE_PIN40_PORTREG &= ~CORE_PIN40_BITMASK;
- } else if (pin == 41) {
- CORE_PIN41_DDRREG &= ~CORE_PIN41_BITMASK;
- CORE_PIN41_PORTREG &= ~CORE_PIN41_BITMASK;
- } else if (pin == 42) {
- CORE_PIN42_DDRREG &= ~CORE_PIN42_BITMASK;
- CORE_PIN42_PORTREG &= ~CORE_PIN42_BITMASK;
- } else if (pin == 43) {
- CORE_PIN43_DDRREG &= ~CORE_PIN43_BITMASK;
- CORE_PIN43_PORTREG &= ~CORE_PIN43_BITMASK;
- } else if (pin == 44) {
- CORE_PIN44_DDRREG &= ~CORE_PIN44_BITMASK;
- CORE_PIN44_PORTREG &= ~CORE_PIN44_BITMASK;
- } else if (pin == 45) {
- CORE_PIN45_DDRREG &= ~CORE_PIN45_BITMASK;
- CORE_PIN45_PORTREG &= ~CORE_PIN45_BITMASK;
- }
- #endif
- }
- #if defined(__AVR_ATmega32U4__)
- if (mode == INPUT || mode == INPUT_PULLUP) {
- if (pin == 11) {
- DIDR2 &= ~0x02;
- } else if (pin == 12) {
- DIDR2 &= ~0x04;
- } else if (pin == 13) {
- DIDR2 &= ~0x08;
- } else if (pin == 14) {
- DIDR2 &= ~0x10;
- } else if (pin == 15) {
- DIDR2 &= ~0x20;
- } else if (pin == 16) {
- DIDR0 &= ~0x80;
- } else if (pin == 17) {
- DIDR0 &= ~0x40;
- } else if (pin == 18) {
- DIDR0 &= ~0x20;
- } else if (pin == 19) {
- DIDR0 &= ~0x10;
- } else if (pin == 20) {
- DIDR0 &= ~0x02;
- } else if (pin == 21) {
- DIDR0 &= ~0x01;
- } else if (pin == 22) {
- DIDR2 &= ~0x01;
- }
- }
- #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
- if (mode == INPUT || mode == INPUT_PULLUP) {
- if (pin == 38) {
- DIDR0 &= ~0x01;
- } else if (pin == 39) {
- DIDR0 &= ~0x02;
- } else if (pin == 40) {
- DIDR0 &= ~0x04;
- } else if (pin == 41) {
- DIDR0 &= ~0x08;
- } else if (pin == 42) {
- DIDR0 &= ~0x10;
- } else if (pin == 43) {
- DIDR0 &= ~0x20;
- } else if (pin == 44) {
- DIDR0 &= ~0x40;
- } else if (pin == 45) {
- DIDR0 &= ~0x80;
- }
- }
- #endif
- } else if (__builtin_constant_p(mode)) {
- if (mode == OUTPUT) {
- _pinMode_output(pin);
- } else if (mode == INPUT_PULLUP) {
- _pinMode_input_pullup(pin);
- } else {
- _pinMode_input(pin);
- }
- } else {
- _pinMode(pin, mode);
- }
- }
-
- extern void _init_Teensyduino_internal_(void);
- extern int analogRead(uint8_t);
-
- extern void _analogWrite(uint8_t pin, int val) __attribute__((noinline));
-
- static inline void analogWrite(uint8_t, int) __attribute__((always_inline, unused));
- static inline void analogWrite(uint8_t pin, int val)
- {
- if (__builtin_constant_p(pin)) {
- if (pin == CORE_OC0B_PIN) { // TIMER0B
- CORE_DDRREG(CORE_OC0B_PIN) |= CORE_BITMASK(CORE_OC0B_PIN);
- if (val) {
- OCR0B = val;
- _SFR_BYTE(TCCR0A) |= (1<<COM0B1);
- } else {
- CORE_PORTREG(CORE_OC0B_PIN) &= ~CORE_BITMASK(CORE_OC0B_PIN);
- _SFR_BYTE(TCCR0A) &= ~(1<<COM0B1);
- }
- } else if (pin == CORE_OC1A_PIN) { //TIMER1A
- CORE_DDRREG(CORE_OC1A_PIN) |= CORE_BITMASK(CORE_OC1A_PIN);
- OCR1A = val;
- TCCR1A |= (1<<COM1A1);
- } else if (pin == CORE_OC1B_PIN) { //TIMER1B
- CORE_DDRREG(CORE_OC1B_PIN) |= CORE_BITMASK(CORE_OC1B_PIN);
- OCR1B = val;
- TCCR1A |= (1<<COM1B1);
- } else if (pin == CORE_OC1C_PIN) { //TIMER1C
- CORE_DDRREG(CORE_OC1C_PIN) |= CORE_BITMASK(CORE_OC1C_PIN);
- OCR1C = val;
- TCCR1A |= (1<<COM1C1);
- }
- #if defined(__AVR_ATmega32U4__)
- else if (pin == CORE_OC3A_PIN) { //TIMER3A
- CORE_DDRREG(CORE_OC3A_PIN) |= CORE_BITMASK(CORE_OC3A_PIN);
- OCR3A = val;
- TCCR3A |= (1<<COM3A1);
- } else if (pin == CORE_OC4A_PIN) { //TIMER4A
- CORE_DDRREG(CORE_OC4A_PIN) |= CORE_BITMASK(CORE_OC4A_PIN);
- OCR4A = val;
- TCCR4A |= (1<<COM4A1);
- } else if (pin == CORE_OC4D_PIN) { //TIMER4D
- CORE_DDRREG(CORE_OC4D_PIN) |= CORE_BITMASK(CORE_OC4D_PIN);
- OCR4D = val;
- TCCR4C |= (1<<COM4D1);
- }
- #endif
- #if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
- else if (pin == CORE_OC2A_PIN) { //TIMER2A
- CORE_DDRREG(CORE_OC2A_PIN) |= CORE_BITMASK(CORE_OC2A_PIN);
- OCR2A = val;
- TCCR2A |= (1<<COM2A1);
- } else if (pin == CORE_OC2B_PIN) { //TIMER2B
- CORE_DDRREG(CORE_OC2B_PIN) |= CORE_BITMASK(CORE_OC2B_PIN);
- OCR2B = val;
- TCCR2A |= (1<<COM2B1);
- } else if (pin == CORE_OC3A_PIN) { //TIMER3A
- CORE_DDRREG(CORE_OC3A_PIN) |= CORE_BITMASK(CORE_OC3A_PIN);
- OCR3A = val;
- TCCR3A |= (1<<COM3A1);
- } else if (pin == CORE_OC3B_PIN) { //TIMER3B
- CORE_DDRREG(CORE_OC3B_PIN) |= CORE_BITMASK(CORE_OC3B_PIN);
- OCR3B = val;
- TCCR3A |= (1<<COM3B1);
- } else if (pin == CORE_OC3C_PIN) { //TIMER3C
- CORE_DDRREG(CORE_OC3C_PIN) |= CORE_BITMASK(CORE_OC3C_PIN);
- OCR3C = val;
- TCCR3A |= (1<<COM3C1);
- }
- #endif
- else {
- if (pin < CORE_NUM_TOTAL_PINS) {
- pinMode(pin, OUTPUT);
- if (val < 128) {
- digitalWrite(pin, LOW);
- } else {
- digitalWrite(pin, HIGH);
- }
- }
- }
- } else {
- _analogWrite(pin, val);
- }
- }
-
- static inline void shiftOut(uint8_t, uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
- extern void _shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value) __attribute__((noinline));
- extern void shiftOut_lsbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
- extern void shiftOut_msbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value) __attribute__((noinline));
-
- static inline void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value)
- {
- if (__builtin_constant_p(bitOrder)) {
- if (bitOrder == LSBFIRST) {
- shiftOut_lsbFirst(dataPin, clockPin, value);
- } else {
- shiftOut_msbFirst(dataPin, clockPin, value);
- }
- } else {
- _shiftOut(dataPin, clockPin, bitOrder, value);
- }
- }
-
- static inline uint8_t shiftIn(uint8_t, uint8_t, uint8_t) __attribute__((always_inline, unused));
- extern uint8_t _shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) __attribute__((noinline));
- extern uint8_t shiftIn_lsbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
- extern uint8_t shiftIn_msbFirst(uint8_t dataPin, uint8_t clockPin) __attribute__((noinline));
-
- static inline uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
- {
- if (__builtin_constant_p(bitOrder)) {
- if (bitOrder == LSBFIRST) {
- return shiftIn_lsbFirst(dataPin, clockPin);
- } else {
- return shiftIn_msbFirst(dataPin, clockPin);
- }
- } else {
- return _shiftIn(dataPin, clockPin, bitOrder);
- }
- }
-
- void _reboot_Teensyduino_(void) __attribute__((noreturn));
- void _restart_Teensyduino_(void) __attribute__((noreturn));
-
-
- #if defined(__AVR_AT90USB162__)
- #define analogReference(mode)
- #else
- extern uint8_t w_analog_reference;
- static inline void analogReference(uint8_t mode)
- {
- w_analog_reference = (mode << 6);
- }
- #endif
-
- void yield(void);
-
- extern void delay(uint32_t);
-
- extern volatile uint32_t timer0_millis_count;
-
- static inline uint32_t millis(void) __attribute__((always_inline, unused));
- static inline uint32_t millis(void)
- {
- uint32_t out;
- asm volatile(
- "in __tmp_reg__, __SREG__" "\n\t"
- "cli" "\n\t"
- "lds %A0, timer0_millis_count" "\n\t"
- "lds %B0, timer0_millis_count+1" "\n\t"
- "lds %C0, timer0_millis_count+2" "\n\t"
- "lds %D0, timer0_millis_count+3" "\n\t"
- "out __SREG__, __tmp_reg__"
- : "=r" (out) : : "r0"
- );
- return out;
- }
-
- extern uint32_t _micros(void) __attribute__((noinline));
-
- static inline uint32_t micros(void) __attribute__((always_inline, unused));
- static inline uint32_t micros(void)
- {
- register uint32_t out asm("r22");
- asm volatile("call _micros" : "=d" (out) : : "r0");
- return out;
- }
-
-
- static inline void delayMicroseconds(uint16_t) __attribute__((always_inline, unused));
- static inline void delayMicroseconds(uint16_t usec)
- {
- if (__builtin_constant_p(usec)) {
- #if F_CPU == 16000000L
- uint16_t tmp = usec * 4;
- #elif F_CPU == 8000000L
- uint16_t tmp = usec * 2;
- #elif F_CPU == 4000000L
- uint16_t tmp = usec;
- #elif F_CPU == 2000000L
- uint16_t tmp = usec / 2;
- if (usec == 1) {
- asm volatile("rjmp L%=\nL%=:\n" ::);
- }
- #elif F_CPU == 1000000L
- uint16_t tmp = usec / 4;
- if (usec == 1) {
- asm volatile("nop\n");
- } else if (usec == 2) {
- asm volatile("rjmp L%=\nL%=:\n" ::);
- } else if (usec == 3) {
- asm volatile("rjmp L%=\nL%=:\n" ::);
- asm volatile("nop\n");
- }
- #else
- #error "Clock must be 16, 8, 4, 2 or 1 MHz"
- #endif
- if (tmp > 0) {
- if (tmp < 256) {
- uint8_t tmp2 = tmp;
- asm volatile(
- "L_%=_loop:" // 1 to load
- "subi %0, 1" "\n\t" // 2
- "brne L_%=_loop" "\n\t" // 2 (1 on last)
- : "=d" (tmp2)
- : "0" (tmp2)
- );
- } else {
- asm volatile(
- "L_%=_loop:" // 2 to load
- "sbiw %A0, 1" "\n\t" // 2
- "brne L_%=_loop" "\n\t" // 2 (1 on last)
- : "=w" (tmp)
- : "0" (tmp)
- );
- }
- }
- } else {
- asm volatile(
- #if F_CPU == 16000000L
- "sbiw %A0, 2" "\n\t" // 2
- "brcs L_%=_end" "\n\t" // 1
- "breq L_%=_end" "\n\t" // 1
- "lsl %A0" "\n\t" // 1
- "rol %B0" "\n\t" // 1
- "lsl %A0" "\n\t" // 1
- "rol %B0" "\n\t" // 1 overhead: (8)/4 = 2us
- #elif F_CPU == 8000000L
- "sbiw %A0, 3" "\n\t" // 2
- "brcs L_%=_end" "\n\t" // 1
- "breq L_%=_end" "\n\t" // 1
- "lsl %A0" "\n\t" // 1
- "rol %B0" "\n\t" // 1 overhead: (6)/2 = 3 us
- #elif F_CPU == 4000000L
- "sbiw %A0, 4" "\n\t" // 2
- "brcs L_%=_end" "\n\t" // 1
- "breq L_%=_end" "\n\t" // 1 overhead: (4) = 4 us
- #elif F_CPU == 2000000L
- "sbiw %A0, 12" "\n\t" // 2
- "brcs L_%=_end" "\n\t" // 1
- "breq L_%=_end" "\n\t" // 1
- "lsr %B0" "\n\t" // 1
- "ror %A0" "\n\t" // 1 overhead: (6)*2 = 12 us
- #elif F_CPU == 1000000L
- "sbiw %A0, 32" "\n\t" // 2
- "brcs L_%=_end" "\n\t" // 1
- "breq L_%=_end" "\n\t" // 1
- "lsr %B0" "\n\t" // 1
- "ror %A0" "\n\t" // 1
- "lsr %B0" "\n\t" // 1
- "ror %A0" "\n\t" // 1 overhead: (8)*4 = 32 us
- #endif
- "L_%=_loop:"
- "sbiw %A0, 1" "\n\t" // 2
- "brne L_%=_loop" "\n\t" // 2
- "L_%=_end:"
- : "=w" (usec)
- : "0" (usec)
- );
- }
- }
-
-
-
-
- #ifdef __cplusplus
- } // extern "C"
- #endif
- #endif
|