|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890 |
- /* Pin functions for the Teensy and Teensy++
- * http://www.pjrc.com/teensy/
- * Copyright (c) 2008-2010 PJRC.COM, LLC
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-
- #include <avr/io.h>
- #include <avr/pgmspace.h>
- #include <avr/sleep.h>
- #include "wiring_private.h"
- #include "pins_arduino.h"
- #include "usb_private.h"
- #include "core_pins.h"
-
- // this doubles the analog input speed
- #define USE_ADC_HIGH_SPEED
-
-
- #ifdef USE_ADC_HIGH_SPEED
- #define DEFAULT_ADCSRB 0x80 // ADHSM
- #define ADC_PRESCALE_ADJUST (-1)
- #else
- #define DEFAULT_ADCSRB 0
- #define ADC_PRESCALE_ADJUST 0
- #endif
-
- void _init_Teensyduino_internal_(void)
- {
- cli();
- CLKPR = 0x80;
- CLKPR = CPU_PRESCALER;
- // timer 0, fast pwm mode
- TCCR0A = (1<<WGM01) | (1<<WGM00);
- TCCR0B = (1<<CS01) | (1<<CS00); // div 64 prescaler
- sbi(TIMSK0, TOIE0);
- // timer 1, 8 bit phase correct pwm
- TCCR1A = (1<<WGM10);
- TCCR1B = (1<<CS11); // div 8 prescaler
- #if defined(__AVR_ATmega32U4__)
- // timer 3, 8 bit phase correct pwm
- TCCR3A = (1<<WGM30);
- TCCR3B = (1<<CS31); // div 8 prescaler
- // timer 4, 8 bit phase correct pwm
- TCCR4A = (1<<PWM4A);
- TCCR4B = (1<<CS42); // div 8 prescaler
- TCCR4C = (1<<PWM4D);
- TCCR4D = (1<<WGM40); // phase correct pwm
- TCCR4E = 0;
- // ADC
- ADCSRA = (1<<ADEN) | (ADC_PRESCALER + ADC_PRESCALE_ADJUST);
- ADCSRB = DEFAULT_ADCSRB;
- DIDR0 = 0;
- DIDR2 = 0;
- #endif
- #if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
- // timer 2, 8 bit phase correct pwm
- TCCR2A = (1<<WGM20);
- TCCR2B = (1<<CS21); // div 8 prescaler
- // timer 3, 8 bit phase correct pwm
- TCCR3A = (1<<WGM30);
- TCCR3B = (1<<CS31); // div 8 prescaler
- // ADC
- ADCSRA = (1<<ADEN) | (ADC_PRESCALER + ADC_PRESCALE_ADJUST);
- ADCSRB = DEFAULT_ADCSRB;
- DIDR0 = 0;
- #endif
- // initialize USB
- usb_init();
- sei();
- }
-
-
- void _analogWrite(uint8_t pin, int val)
- {
- pinMode(pin, OUTPUT);
-
- switch (pin) {
- case CORE_OC0B_PIN:
- if (val == 0) {
- CORE_PORTREG(CORE_OC0B_PIN) &= ~CORE_BITMASK(CORE_OC0B_PIN);
- cbi(TCCR0A, COM0B1);
- } else {
- OCR0B = val;
- sbi(TCCR0A, COM0B1);
- }
- break;
- case CORE_OC1A_PIN: //TIMER1A:
- OCR1A = val;
- sbi(TCCR1A, COM1A1);
- break;
- case CORE_OC1B_PIN: //TIMER1B:
- OCR1B = val;
- sbi(TCCR1A, COM1B1);
- break;
- case CORE_OC1C_PIN: //TIMER1C:
- OCR1C = val;
- sbi(TCCR1A, COM1C1);
- break;
- #if defined(__AVR_ATmega32U4__)
- case CORE_OC3A_PIN: //TIMER3A:
- OCR3A = val;
- sbi(TCCR3A, COM3A1);
- break;
- case CORE_OC4A_PIN: //TIMER4A
- OCR4A = val;
- sbi(TCCR4A, COM4A1);
- break;
- case CORE_OC4D_PIN: //TIMER4D
- OCR4D = val;
- sbi(TCCR4C, COM4D1);
- break;
- #endif
- #if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
- case CORE_OC2A_PIN: //TIMER2A:
- OCR2A = val;
- sbi(TCCR2A, COM2A1);
- break;
- case CORE_OC2B_PIN: //TIMER2B:
- OCR2B = val;
- sbi(TCCR2A, COM2B1);
- break;
- case CORE_OC3A_PIN: //TIMER3A:
- OCR3A = val;
- sbi(TCCR3A, COM3A1);
- break;
- case CORE_OC3B_PIN: //TIMER3B:
- OCR3B = val;
- sbi(TCCR3A, COM3B1);
- break;
- case CORE_OC3C_PIN: //TIMER3C:
- OCR3C = val;
- sbi(TCCR3A, COM3C1);
- break;
- #endif
- default:
- if (val < 128) {
- digitalWrite(pin, LOW);
- } else {
- digitalWrite(pin, HIGH);
- }
- }
- }
-
-
-
- #if defined(__AVR_ATmega32U4__)
- uint8_t w_analog_reference = 0x40;
-
- static const uint8_t PROGMEM adc_mapping[] = {
- // 0, 1, 4, 5, 6, 7, 13, 12, 11, 10, 9, 8
- 0, 1, 4, 5, 6, 7, 13, 12, 11, 10, 9, 8, 10, 11, 12, 13, 7, 6, 5, 4, 1, 0, 8
- };
-
- int analogRead(uint8_t pin)
- {
- uint8_t low, high, adc;
-
- if (pin >= sizeof(adc_mapping)) return 0;
- adc = pgm_read_byte(adc_mapping + pin);
- if (adc < 8) {
- DIDR0 |= (1 << adc);
- //DDRF &= ~(1 << adc);
- //PORTF &= ~(1 << adc);
- ADCSRB = DEFAULT_ADCSRB;
- ADMUX = w_analog_reference | adc;
- } else {
- adc -= 8;
- DIDR2 |= (1 << adc);
- ADCSRB = DEFAULT_ADCSRB | (1<<MUX5);
- ADMUX = w_analog_reference | adc;
- }
- ADCSRA |= (1<<ADSC);
- while (ADCSRA & (1<<ADSC)) ;
- low = ADCL;
- high = ADCH;
- return (high << 8) | low;
- }
-
- #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
-
- uint8_t w_analog_reference = 0x40;
-
- int analogRead(uint8_t pin)
- {
- uint8_t low, high;
-
- if (pin >= PIN_F0 && pin <= PIN_F7) pin -= PIN_F0;
- if (pin < 8) {
- DIDR0 |= (1 << pin);
- //DDRF &= ~(1 << pin);
- //PORTF &= ~(1 << pin);
- }
- ADMUX = w_analog_reference | (pin & 0x1F);
- ADCSRA |= (1<<ADSC);
- while (ADCSRA & (1<<ADSC)) ;
- low = ADCL;
- high = ADCH;
- return (high << 8) | low;
- }
-
- #elif defined(__AVR_AT90USB162__)
- int analogRead(uint8_t pin)
- {
- return 0;
- }
- #endif
-
-
-
- void _pinMode(uint8_t pin, uint8_t mode)
- {
- if (mode == OUTPUT) {
- _pinMode_output(pin);
- } else if (mode == INPUT_PULLUP) {
- _pinMode_input_pullup(pin);
- } else {
- _pinMode_input(pin);
- }
- }
-
- #define PIN_REG_AND_MASK_LOOKUP(pin, reg, mask) \
- asm volatile( \
- "lsl %2" "\n\t" \
- "add %A3, %2" "\n\t" \
- "adc %B3, __zero_reg__" "\n\n" \
- "lpm %1, Z+" "\n\t" \
- "lpm %A0, Z" "\n\t" \
- "ldi %B0, 0" "\n" \
- : "=z" (reg), "=r" (mask), "+r" (pin) \
- : "z" (digital_pin_table_PGM), "2" (pin))
-
- void _pinMode_output(uint8_t pin)
- {
- volatile uint8_t *reg;
- uint8_t mask, status;
-
- if (pin >= CORE_NUM_TOTAL_PINS) return;
- PIN_REG_AND_MASK_LOOKUP(pin, reg, mask);
- status = SREG;
- cli();
- *(reg + 1) |= mask;
- SREG = status;
- }
-
- #if defined(__AVR_ATmega32U4__)
- static const uint8_t PROGMEM didr_table_PGM[] = {
- (int)&DIDR2, ~0x02,
- (int)&DIDR2, ~0x04,
- (int)&DIDR2, ~0x08,
- (int)&DIDR2, ~0x10,
- (int)&DIDR2, ~0x20,
- (int)&DIDR0, 0x7F, // ~0x80,
- (int)&DIDR0, ~0x40,
- (int)&DIDR0, ~0x20,
- (int)&DIDR0, ~0x10,
- (int)&DIDR0, ~0x02,
- (int)&DIDR0, ~0x01,
- (int)&DIDR2, ~0x01
- };
- #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
- static const uint8_t PROGMEM didr_table_PGM[] = {
- (int)&DIDR0, ~0x01,
- (int)&DIDR0, ~0x02,
- (int)&DIDR0, ~0x04,
- (int)&DIDR0, ~0x08,
- (int)&DIDR0, ~0x10,
- (int)&DIDR0, ~0x20,
- (int)&DIDR0, ~0x40,
- (int)&DIDR0, 0x7F // ~0x80
- };
- #endif
-
- #define PIN_DIDR_AND_MASK_LOOKUP(pin, didreg, didmask) \
- asm volatile( \
- "lsl %3" "\n\t" \
- "add %A2, %3" "\n\t" \
- "adc %B2, __zero_reg__" "\n\n" \
- "lpm %A0, Z+" "\n\t" \
- "ldi %B0, 0" "\n\t" \
- "lpm %1, Z+" "\n\t" \
- : "=x" (didreg), "=r" (didmask) \
- : "z" (didr_table_PGM), "r" (pin))
-
-
- void _pinMode_input(uint8_t pin)
- {
- volatile uint8_t *reg, *didr=0;
- uint8_t mask, didrmask=0xFF, status;
-
- if (pin >= CORE_NUM_TOTAL_PINS) return;
- #if defined(__AVR_ATmega32U4__)
- if (pin >= 11 && pin <= 22) {
- PIN_DIDR_AND_MASK_LOOKUP((uint8_t)(pin - 11), didr, didrmask);
- }
- #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
- if (pin >= PIN_F0 && pin <= PIN_F7) {
- PIN_DIDR_AND_MASK_LOOKUP((uint8_t)(pin - PIN_F0), didr, didrmask);
- }
- #endif
- PIN_REG_AND_MASK_LOOKUP(pin, reg, mask);
- status = SREG;
- cli();
- *(reg + 1) &= ~mask;
- *(reg + 2) &= ~mask;
- *didr &= didrmask;
- SREG = status;
- }
-
-
- void _pinMode_input_pullup(uint8_t pin)
- {
- volatile uint8_t *reg, *didr=0;
- uint8_t mask, didrmask=0xFF, status;
-
- if (pin >= CORE_NUM_TOTAL_PINS) return;
- #if defined(__AVR_ATmega32U4__)
- if (pin >= 11 && pin <= 22) {
- PIN_DIDR_AND_MASK_LOOKUP((uint8_t)(pin - 11), didr, didrmask);
- }
- #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
- if (pin >= PIN_F0 && pin <= PIN_F7) {
- PIN_DIDR_AND_MASK_LOOKUP((uint8_t)(pin - PIN_F0), didr, didrmask);
- }
- #endif
- PIN_REG_AND_MASK_LOOKUP(pin, reg, mask);
- status = SREG;
- cli();
- *(reg + 1) &= ~mask;
- *(reg + 2) |= mask;
- *didr &= didrmask;
- SREG = status;
- }
-
-
-
- void _digitalWrite(void) __attribute__((naked));
- void _digitalWrite_HIGH(void) __attribute__((naked));
- void _digitalWrite_LOW(void) __attribute__((naked));
- void _digitalWrite_bailout(void);
- void _digitalWrite_HIGH_TABLE(void) __attribute__((naked));
- void _digitalWrite_LOW_TABLE(void) __attribute__((naked));
- void _digitalWrite_OC0B(void) __attribute__((naked));
- void _digitalWrite_OC1A(void) __attribute__((naked));
- void _digitalWrite_OC1B(void) __attribute__((naked));
- void _digitalWrite_OC1C(void) __attribute__((naked));
- void _digitalWrite_OC2A(void) __attribute__((naked));
- void _digitalWrite_OC2B(void) __attribute__((naked));
- void _digitalWrite_OC3A(void) __attribute__((naked));
- void _digitalWrite_OC3B(void) __attribute__((naked));
- void _digitalWrite_OC3C(void) __attribute__((naked));
- void _digitalWrite_OC4A(void) __attribute__((naked));
- void _digitalWrite_OC4D(void) __attribute__((naked));
-
-
- void _digitalWrite(void)
- {
- asm volatile(
- "tst r0" "\n\t"
- "breq _digitalWrite_LOW" "\n\t"
- "rjmp _digitalWrite_HIGH" "\n\t"
- );
- }
-
- void _digitalWrite_HIGH(void)
- {
- asm volatile (
- #if !defined(DIGITAL_WRITE_RISKY_OMIT_OVERFLOW_CHECK)
- "cpi r30, %0" "\n\t"
- "brsh _digitalWrite_bailout" "\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"
- "ijmp" "\n\t"
- : : "M" (CORE_NUM_TOTAL_PINS)
- );
- }
-
- void _digitalWrite_LOW(void)
- {
- asm volatile (
- #if !defined(DIGITAL_WRITE_RISKY_OMIT_OVERFLOW_CHECK)
- "cpi r30, %0" "\n\t"
- "brsh _digitalWrite_bailout" "\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"
- "ijmp" "\n\t"
- : : "M" (CORE_NUM_TOTAL_PINS)
- );
- }
-
- void _digitalWrite_bailout(void) {}
-
- #if defined(__AVR_ATmega32U4__)
- void _digitalWrite_HIGH_TABLE(void)
- {
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 0
- "ret" "\n\t"
- "sbi %2, %3" "\n\t" // pin 1
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 2
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 3
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 4
- "rjmp _digitalWrite_OC1C" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN0_PORTREG)), "I" (CORE_PIN0_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN1_PORTREG)), "I" (CORE_PIN1_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN2_PORTREG)), "I" (CORE_PIN2_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN3_PORTREG)), "I" (CORE_PIN3_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN4_PORTREG)), "I" (CORE_PIN4_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 5
- "rjmp _digitalWrite_OC0B" "\n\t"
- "sbi %2, %3" "\n\t" // pin 6
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 7
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 8
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 9
- "rjmp _digitalWrite_OC3A" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN5_PORTREG)), "I" (CORE_PIN5_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN6_PORTREG)), "I" (CORE_PIN6_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN7_PORTREG)), "I" (CORE_PIN7_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN8_PORTREG)), "I" (CORE_PIN8_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN9_PORTREG)), "I" (CORE_PIN9_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 10
- "rjmp _digitalWrite_OC4A" "\n\t"
- "sbi %2, %3" "\n\t" // pin 11
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 12
- "rjmp _digitalWrite_OC4D" "\n\t"
- "sbi %6, %7" "\n\t" // pin 13
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 14
- "rjmp _digitalWrite_OC1A" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN10_PORTREG)), "I" (CORE_PIN10_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN11_PORTREG)), "I" (CORE_PIN11_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN12_PORTREG)), "I" (CORE_PIN12_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN13_PORTREG)), "I" (CORE_PIN13_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN14_PORTREG)), "I" (CORE_PIN14_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 15
- "rjmp _digitalWrite_OC1B" "\n\t"
- "sbi %2, %3" "\n\t" // pin 16
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 17
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 18
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 19
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN15_PORTREG)), "I" (CORE_PIN15_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN16_PORTREG)), "I" (CORE_PIN16_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN17_PORTREG)), "I" (CORE_PIN17_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN18_PORTREG)), "I" (CORE_PIN18_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN19_PORTREG)), "I" (CORE_PIN19_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 20
- "ret" "\n\t"
- "sbi %2, %3" "\n\t" // pin 21
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 22
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 23
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 24
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN20_PORTREG)), "I" (CORE_PIN20_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN21_PORTREG)), "I" (CORE_PIN21_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN22_PORTREG)), "I" (CORE_PIN22_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN23_PORTREG)), "I" (CORE_PIN23_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN24_PORTREG)), "I" (CORE_PIN24_BIT)
- );
- }
- void _digitalWrite_LOW_TABLE(void)
- {
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 0
- "ret" "\n\t"
- "cbi %2, %3" "\n\t" // pin 1
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 2
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 3
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 4
- "rjmp _digitalWrite_OC1C" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN0_PORTREG)), "I" (CORE_PIN0_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN1_PORTREG)), "I" (CORE_PIN1_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN2_PORTREG)), "I" (CORE_PIN2_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN3_PORTREG)), "I" (CORE_PIN3_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN4_PORTREG)), "I" (CORE_PIN4_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 5
- "rjmp _digitalWrite_OC0B" "\n\t"
- "cbi %2, %3" "\n\t" // pin 6
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 7
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 8
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 9
- "rjmp _digitalWrite_OC3A" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN5_PORTREG)), "I" (CORE_PIN5_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN6_PORTREG)), "I" (CORE_PIN6_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN7_PORTREG)), "I" (CORE_PIN7_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN8_PORTREG)), "I" (CORE_PIN8_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN9_PORTREG)), "I" (CORE_PIN9_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 10
- "rjmp _digitalWrite_OC4A" "\n\t"
- "cbi %2, %3" "\n\t" // pin 11
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 12
- "rjmp _digitalWrite_OC4D" "\n\t"
- "cbi %6, %7" "\n\t" // pin 13
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 14
- "rjmp _digitalWrite_OC1A" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN10_PORTREG)), "I" (CORE_PIN10_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN11_PORTREG)), "I" (CORE_PIN11_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN12_PORTREG)), "I" (CORE_PIN12_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN13_PORTREG)), "I" (CORE_PIN13_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN14_PORTREG)), "I" (CORE_PIN14_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 15
- "rjmp _digitalWrite_OC1B" "\n\t"
- "cbi %2, %3" "\n\t" // pin 16
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 17
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 18
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 19
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN15_PORTREG)), "I" (CORE_PIN15_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN16_PORTREG)), "I" (CORE_PIN16_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN17_PORTREG)), "I" (CORE_PIN17_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN18_PORTREG)), "I" (CORE_PIN18_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN19_PORTREG)), "I" (CORE_PIN19_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 20
- "ret" "\n\t"
- "cbi %2, %3" "\n\t" // pin 21
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 22
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 23
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 24
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN20_PORTREG)), "I" (CORE_PIN20_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN21_PORTREG)), "I" (CORE_PIN21_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN22_PORTREG)), "I" (CORE_PIN22_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN23_PORTREG)), "I" (CORE_PIN23_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN24_PORTREG)), "I" (CORE_PIN24_BIT)
- );
- }
- #elif defined(__AVR_AT90USB162__)
- void _digitalWrite_HIGH_TABLE(void)
- {
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 0
- "rjmp _digitalWrite_OC0B" "\n\t"
- "sbi %2, %3" "\n\t" // pin 1
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 2
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 3
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 4
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN0_PORTREG)), "I" (CORE_PIN0_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN1_PORTREG)), "I" (CORE_PIN1_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN2_PORTREG)), "I" (CORE_PIN2_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN3_PORTREG)), "I" (CORE_PIN3_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN4_PORTREG)), "I" (CORE_PIN4_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 5
- "ret" "\n\t"
- "sbi %2, %3" "\n\t" // pin 6
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 7
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 8
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 9
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN5_PORTREG)), "I" (CORE_PIN5_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN6_PORTREG)), "I" (CORE_PIN6_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN7_PORTREG)), "I" (CORE_PIN7_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN8_PORTREG)), "I" (CORE_PIN8_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN9_PORTREG)), "I" (CORE_PIN9_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 10
- "ret" "\n\t"
- "sbi %2, %3" "\n\t" // pin 11
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 12
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 13
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 14
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN10_PORTREG)), "I" (CORE_PIN10_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN11_PORTREG)), "I" (CORE_PIN11_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN12_PORTREG)), "I" (CORE_PIN12_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN13_PORTREG)), "I" (CORE_PIN13_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN14_PORTREG)), "I" (CORE_PIN14_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 15
- "rjmp _digitalWrite_OC1C" "\n\t"
- "sbi %2, %3" "\n\t" // pin 16
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 17
- "rjmp _digitalWrite_OC1A" "\n\t"
- "sbi %6, %7" "\n\t" // pin 18
- "rjmp _digitalWrite_OC1B" "\n\t"
- "sbi %8, %9" "\n\t" // pin 19
- "ret" "\n\t"
- "sbi %10, %11" "\n\t" // pin 20
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN15_PORTREG)), "I" (CORE_PIN15_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN16_PORTREG)), "I" (CORE_PIN16_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN17_PORTREG)), "I" (CORE_PIN17_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN18_PORTREG)), "I" (CORE_PIN18_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN19_PORTREG)), "I" (CORE_PIN19_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN20_PORTREG)), "I" (CORE_PIN20_BIT)
- );
- }
- void _digitalWrite_LOW_TABLE(void)
- {
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 0
- "rjmp _digitalWrite_OC0B" "\n\t"
- "cbi %2, %3" "\n\t" // pin 1
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 2
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 3
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 4
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN0_PORTREG)), "I" (CORE_PIN0_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN1_PORTREG)), "I" (CORE_PIN1_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN2_PORTREG)), "I" (CORE_PIN2_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN3_PORTREG)), "I" (CORE_PIN3_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN4_PORTREG)), "I" (CORE_PIN4_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 5
- "ret" "\n\t"
- "cbi %2, %3" "\n\t" // pin 6
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 7
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 8
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 9
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN5_PORTREG)), "I" (CORE_PIN5_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN6_PORTREG)), "I" (CORE_PIN6_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN7_PORTREG)), "I" (CORE_PIN7_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN8_PORTREG)), "I" (CORE_PIN8_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN9_PORTREG)), "I" (CORE_PIN9_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 10
- "ret" "\n\t"
- "cbi %2, %3" "\n\t" // pin 11
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 12
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 13
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 14
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN10_PORTREG)), "I" (CORE_PIN10_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN11_PORTREG)), "I" (CORE_PIN11_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN12_PORTREG)), "I" (CORE_PIN12_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN13_PORTREG)), "I" (CORE_PIN13_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN14_PORTREG)), "I" (CORE_PIN14_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 15
- "rjmp _digitalWrite_OC1C" "\n\t"
- "cbi %2, %3" "\n\t" // pin 16
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 17
- "rjmp _digitalWrite_OC1A" "\n\t"
- "cbi %6, %7" "\n\t" // pin 18
- "rjmp _digitalWrite_OC1B" "\n\t"
- "cbi %8, %9" "\n\t" // pin 19
- "ret" "\n\t"
- "cbi %10, %11" "\n\t" // pin 20
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN15_PORTREG)), "I" (CORE_PIN15_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN16_PORTREG)), "I" (CORE_PIN16_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN17_PORTREG)), "I" (CORE_PIN17_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN18_PORTREG)), "I" (CORE_PIN18_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN19_PORTREG)), "I" (CORE_PIN19_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN20_PORTREG)), "I" (CORE_PIN20_BIT)
- );
- }
-
-
-
- #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
- void _digitalWrite_HIGH_TABLE(void)
- {
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 0
- "rjmp _digitalWrite_OC0B" "\n\t"
- "sbi %2, %3" "\n\t" // pin 1
- "rjmp _digitalWrite_OC2B" "\n\t"
- "sbi %4, %5" "\n\t" // pin 2
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 3
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 4
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN0_PORTREG)), "I" (CORE_PIN0_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN1_PORTREG)), "I" (CORE_PIN1_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN2_PORTREG)), "I" (CORE_PIN2_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN3_PORTREG)), "I" (CORE_PIN3_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN4_PORTREG)), "I" (CORE_PIN4_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 5
- "ret" "\n\t"
- "sbi %2, %3" "\n\t" // pin 6
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 7
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 8
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 9
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN5_PORTREG)), "I" (CORE_PIN5_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN6_PORTREG)), "I" (CORE_PIN6_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN7_PORTREG)), "I" (CORE_PIN7_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN8_PORTREG)), "I" (CORE_PIN8_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN9_PORTREG)), "I" (CORE_PIN9_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 10
- "ret" "\n\t"
- "sbi %2, %3" "\n\t" // pin 11
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 12
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 13
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 14
- "rjmp _digitalWrite_OC3C" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN10_PORTREG)), "I" (CORE_PIN10_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN11_PORTREG)), "I" (CORE_PIN11_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN12_PORTREG)), "I" (CORE_PIN12_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN13_PORTREG)), "I" (CORE_PIN13_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN14_PORTREG)), "I" (CORE_PIN14_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 15
- "rjmp _digitalWrite_OC3B" "\n\t"
- "sbi %2, %3" "\n\t" // pin 16
- "rjmp _digitalWrite_OC3A" "\n\t"
- "sbi %4, %5" "\n\t" // pin 17
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 18
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 19
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN15_PORTREG)), "I" (CORE_PIN15_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN16_PORTREG)), "I" (CORE_PIN16_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN17_PORTREG)), "I" (CORE_PIN17_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN18_PORTREG)), "I" (CORE_PIN18_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN19_PORTREG)), "I" (CORE_PIN19_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 20
- "ret" "\n\t"
- "sbi %2, %3" "\n\t" // pin 21
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 22
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 23
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 24
- "rjmp _digitalWrite_OC2A" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN20_PORTREG)), "I" (CORE_PIN20_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN21_PORTREG)), "I" (CORE_PIN21_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN22_PORTREG)), "I" (CORE_PIN22_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN23_PORTREG)), "I" (CORE_PIN23_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN24_PORTREG)), "I" (CORE_PIN24_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 25
- "rjmp _digitalWrite_OC1A" "\n\t"
- "sbi %2, %3" "\n\t" // pin 26
- "rjmp _digitalWrite_OC1B" "\n\t"
- "sbi %4, %5" "\n\t" // pin 27
- "rjmp _digitalWrite_OC1C" "\n\t"
- "sbi %6, %7" "\n\t" // pin 28
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 29
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN25_PORTREG)), "I" (CORE_PIN25_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN26_PORTREG)), "I" (CORE_PIN26_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN27_PORTREG)), "I" (CORE_PIN27_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN28_PORTREG)), "I" (CORE_PIN28_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN29_PORTREG)), "I" (CORE_PIN29_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 30
- "ret" "\n\t"
- "sbi %2, %3" "\n\t" // pin 31
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 32
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 33
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 34
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN30_PORTREG)), "I" (CORE_PIN30_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN31_PORTREG)), "I" (CORE_PIN31_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN32_PORTREG)), "I" (CORE_PIN32_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN33_PORTREG)), "I" (CORE_PIN33_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN34_PORTREG)), "I" (CORE_PIN34_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 35
- "ret" "\n\t"
- "sbi %2, %3" "\n\t" // pin 36
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 37
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 38
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 39
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN35_PORTREG)), "I" (CORE_PIN35_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN36_PORTREG)), "I" (CORE_PIN36_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN37_PORTREG)), "I" (CORE_PIN37_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN38_PORTREG)), "I" (CORE_PIN38_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN39_PORTREG)), "I" (CORE_PIN39_BIT)
- );
- asm volatile (
- "sbi %0, %1" "\n\t" // pin 40
- "ret" "\n\t"
- "sbi %2, %3" "\n\t" // pin 41
- "ret" "\n\t"
- "sbi %4, %5" "\n\t" // pin 42
- "ret" "\n\t"
- "sbi %6, %7" "\n\t" // pin 43
- "ret" "\n\t"
- "sbi %8, %9" "\n\t" // pin 44
- "ret" "\n\t"
- "sbi %10, %11" "\n\t" // pin 45
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN40_PORTREG)), "I" (CORE_PIN40_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN41_PORTREG)), "I" (CORE_PIN41_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN42_PORTREG)), "I" (CORE_PIN42_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN43_PORTREG)), "I" (CORE_PIN43_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN44_PORTREG)), "I" (CORE_PIN44_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN45_PORTREG)), "I" (CORE_PIN45_BIT)
- );
- }
- void _digitalWrite_LOW_TABLE(void)
- {
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 0
- "rjmp _digitalWrite_OC0B" "\n\t"
- "cbi %2, %3" "\n\t" // pin 1
- "rjmp _digitalWrite_OC2B" "\n\t"
- "cbi %4, %5" "\n\t" // pin 2
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 3
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 4
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN0_PORTREG)), "I" (CORE_PIN0_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN1_PORTREG)), "I" (CORE_PIN1_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN2_PORTREG)), "I" (CORE_PIN2_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN3_PORTREG)), "I" (CORE_PIN3_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN4_PORTREG)), "I" (CORE_PIN4_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 5
- "ret" "\n\t"
- "cbi %2, %3" "\n\t" // pin 6
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 7
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 8
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 9
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN5_PORTREG)), "I" (CORE_PIN5_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN6_PORTREG)), "I" (CORE_PIN6_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN7_PORTREG)), "I" (CORE_PIN7_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN8_PORTREG)), "I" (CORE_PIN8_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN9_PORTREG)), "I" (CORE_PIN9_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 10
- "ret" "\n\t"
- "cbi %2, %3" "\n\t" // pin 11
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 12
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 13
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 14
- "rjmp _digitalWrite_OC3C" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN10_PORTREG)), "I" (CORE_PIN10_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN11_PORTREG)), "I" (CORE_PIN11_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN12_PORTREG)), "I" (CORE_PIN12_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN13_PORTREG)), "I" (CORE_PIN13_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN14_PORTREG)), "I" (CORE_PIN14_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 15
- "rjmp _digitalWrite_OC3B" "\n\t"
- "cbi %2, %3" "\n\t" // pin 16
- "rjmp _digitalWrite_OC3A" "\n\t"
- "cbi %4, %5" "\n\t" // pin 17
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 18
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 19
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN15_PORTREG)), "I" (CORE_PIN15_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN16_PORTREG)), "I" (CORE_PIN16_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN17_PORTREG)), "I" (CORE_PIN17_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN18_PORTREG)), "I" (CORE_PIN18_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN19_PORTREG)), "I" (CORE_PIN19_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 20
- "ret" "\n\t"
- "cbi %2, %3" "\n\t" // pin 21
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 22
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 23
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 24
- "rjmp _digitalWrite_OC2A" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN20_PORTREG)), "I" (CORE_PIN20_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN21_PORTREG)), "I" (CORE_PIN21_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN22_PORTREG)), "I" (CORE_PIN22_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN23_PORTREG)), "I" (CORE_PIN23_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN24_PORTREG)), "I" (CORE_PIN24_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 25
- "rjmp _digitalWrite_OC1A" "\n\t"
- "cbi %2, %3" "\n\t" // pin 26
- "rjmp _digitalWrite_OC1B" "\n\t"
- "cbi %4, %5" "\n\t" // pin 27
- "rjmp _digitalWrite_OC1C" "\n\t"
- "cbi %6, %7" "\n\t" // pin 28
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 29
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN25_PORTREG)), "I" (CORE_PIN25_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN26_PORTREG)), "I" (CORE_PIN26_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN27_PORTREG)), "I" (CORE_PIN27_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN28_PORTREG)), "I" (CORE_PIN28_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN29_PORTREG)), "I" (CORE_PIN29_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 30
- "ret" "\n\t"
- "cbi %2, %3" "\n\t" // pin 31
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 32
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 33
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 34
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN30_PORTREG)), "I" (CORE_PIN30_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN31_PORTREG)), "I" (CORE_PIN31_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN32_PORTREG)), "I" (CORE_PIN32_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN33_PORTREG)), "I" (CORE_PIN33_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN34_PORTREG)), "I" (CORE_PIN34_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 35
- "ret" "\n\t"
- "cbi %2, %3" "\n\t" // pin 36
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 37
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 38
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 39
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN35_PORTREG)), "I" (CORE_PIN35_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN36_PORTREG)), "I" (CORE_PIN36_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN37_PORTREG)), "I" (CORE_PIN37_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN38_PORTREG)), "I" (CORE_PIN38_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN39_PORTREG)), "I" (CORE_PIN39_BIT)
- );
- asm volatile (
- "cbi %0, %1" "\n\t" // pin 40
- "ret" "\n\t"
- "cbi %2, %3" "\n\t" // pin 41
- "ret" "\n\t"
- "cbi %4, %5" "\n\t" // pin 42
- "ret" "\n\t"
- "cbi %6, %7" "\n\t" // pin 43
- "ret" "\n\t"
- "cbi %8, %9" "\n\t" // pin 44
- "ret" "\n\t"
- "cbi %10, %11" "\n\t" // pin 45
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN40_PORTREG)), "I" (CORE_PIN40_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN41_PORTREG)), "I" (CORE_PIN41_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN42_PORTREG)), "I" (CORE_PIN42_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN43_PORTREG)), "I" (CORE_PIN43_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN44_PORTREG)), "I" (CORE_PIN44_BIT),
- "I" (_SFR_IO_ADDR(CORE_PIN45_PORTREG)), "I" (CORE_PIN45_BIT)
- );
- }
- #endif
-
- void _digitalWrite_OC0B(void)
- {
- asm volatile (
- "in r30, %0" "\n\t"
- "andi r30, ~(1 << %1)" "\n\t"
- "out %0, r30" "\n\t"
- "ret"
- :: "I" (_SFR_IO_ADDR(TCCR0A)), "I" (COM0B1)
- );
- }
-
- void _digitalWrite_OC1A(void)
- {
- asm volatile (
- "lds r30, %0" "\n\t"
- "andi r30, ~(1 << %1)" "\n\t"
- "sts %0, r30" "\n\t"
- "ret"
- :: "M" (&TCCR1A), "I" (COM1A1)
- );
- }
-
- void _digitalWrite_OC1B(void)
- {
- asm volatile (
- "lds r30, %0" "\n\t"
- "andi r30, ~(1 << %1)" "\n\t"
- "sts %0, r30" "\n\t"
- "ret"
- :: "M" (&TCCR1A), "I" (COM1B1)
- );
- }
-
- void _digitalWrite_OC1C(void)
- {
- asm volatile (
- "lds r30, %0" "\n\t"
- "andi r30, ~(1 << %1)" "\n\t"
- "sts %0, r30" "\n\t"
- "ret"
- :: "M" (&TCCR1A), "I" (COM1C1)
- );
- }
-
- #if defined(__AVR_ATmega32U4__)
- void _digitalWrite_OC3A(void)
- {
- asm volatile (
- "lds r30, %0" "\n\t"
- "andi r30, ~(1 << %1)" "\n\t"
- "sts %0, r30" "\n\t"
- "ret"
- :: "M" (&TCCR3A), "I" (COM3A1)
- );
- }
-
- void _digitalWrite_OC4A(void)
- {
- asm volatile (
- "lds r30, %0" "\n\t"
- "andi r30, ~(1 << %1)" "\n\t"
- "sts %0, r30" "\n\t"
- "ret"
- :: "M" (&TCCR4A), "I" (COM4A1)
- );
- }
-
- void _digitalWrite_OC4D(void)
- {
- asm volatile (
- "lds r30, %0" "\n\t"
- "andi r30, ~(1 << %1)" "\n\t"
- "sts %0, r30" "\n\t"
- "ret"
- :: "M" (&TCCR4C), "I" (COM4D1)
- );
- }
- #endif
- #if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
- void _digitalWrite_OC2A(void)
- {
- asm volatile (
- "lds r30, %0" "\n\t"
- "andi r30, ~(1 << %1)" "\n\t"
- "sts %0, r30" "\n\t"
- "ret"
- :: "M" (&TCCR2A), "I" (COM3A1)
- );
- }
-
- void _digitalWrite_OC2B(void)
- {
- asm volatile (
- "lds r30, %0" "\n\t"
- "andi r30, ~(1 << %1)" "\n\t"
- "sts %0, r30" "\n\t"
- "ret"
- :: "M" (&TCCR2A), "I" (COM3B1)
- );
- }
-
- void _digitalWrite_OC3A(void)
- {
- asm volatile (
- "lds r30, %0" "\n\t"
- "andi r30, ~(1 << %1)" "\n\t"
- "sts %0, r30" "\n\t"
- "ret"
- :: "M" (&TCCR3A), "I" (COM3A1)
- );
- }
-
- void _digitalWrite_OC3B(void)
- {
- asm volatile (
- "lds r30, %0" "\n\t"
- "andi r30, ~(1 << %1)" "\n\t"
- "sts %0, r30" "\n\t"
- "ret"
- :: "M" (&TCCR3A), "I" (COM3B1)
- );
- }
-
- void _digitalWrite_OC3C(void)
- {
- asm volatile (
- "lds r30, %0" "\n\t"
- "andi r30, ~(1 << %1)" "\n\t"
- "sts %0, r30" "\n\t"
- "ret"
- :: "M" (&TCCR3A), "I" (COM3C1)
- );
- }
-
- #endif
-
- void _digitalRead(void) __attribute__((naked));
- void _digitalRead_false(void) __attribute__((naked));
- void _digitalRead_true(void) __attribute__((naked));
- void _digitalRead_TABLE(void) __attribute__((naked));
- void _digitalRead_true2(void) __attribute__((naked));
- void _digitalRead_TABLE2(void) __attribute__((naked));
-
- void _digitalRead(void)
- {
- asm volatile (
- #if !defined(DIGITAL_WRITE_RISKY_OMIT_OVERFLOW_CHECK)
- "cpi r30, %0" "\n\t"
- "brsh _digitalRead_false" "\n\t"
- #endif
- "lsl r30" "\n\t"
- "lsl r30" "\n\t"
- "clr r31" "\n\t"
- #if CORE_NUM_TOTAL_PINS > 25
- "cpi r30, 124" "\n\t"
- "brsh L%=2" "\n\t"
- #endif
- "subi r30, lo8(-(pm(_digitalRead_TABLE)))" "\n\t"
- "sbci r31, hi8(-(pm(_digitalRead_TABLE)))" "\n\t"
- "ijmp" "\n"
- #if CORE_NUM_TOTAL_PINS > 25
- "L%=2:" "\n\t"
- "subi r30, lo8(-(pm(_digitalRead_TABLE2 - 248)))" "\n\t"
- "sbci r31, hi8(-(pm(_digitalRead_TABLE2 - 248)))" "\n\t"
- "ijmp" "\n"
- #endif
- : : "M" (CORE_NUM_TOTAL_PINS)
- );
- }
-
- #if !defined(DIGITAL_WRITE_RISKY_OMIT_OVERFLOW_CHECK)
- void _digitalRead_false(void)
- {
- asm volatile (
- "clr r30" "\n\t"
- "ret" "\n"
- );
- }
- #endif
-
- void _digitalRead_true(void)
- {
- asm volatile (
- "ldi r30, 1" "\n\t"
- "ret" "\n"
- );
- }
-
- void _digitalRead_TABLE(void)
- {
- asm volatile (
- "in r30, %0" "\n\t" // pin 0
- "andi r30, %1" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- "in r30, %2" "\n\t" // pin 1
- "andi r30, %3" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- "in r30, %4" "\n\t" // pin 2
- "andi r30, %5" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- "in r30, %6" "\n\t" // pin 3
- "andi r30, %7" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- "in r30, %8" "\n\t" // pin 4
- "andi r30, %9" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN0_PINREG)), "M" (CORE_PIN0_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN1_PINREG)), "M" (CORE_PIN1_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN2_PINREG)), "M" (CORE_PIN2_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN3_PINREG)), "M" (CORE_PIN3_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN4_PINREG)), "M" (CORE_PIN4_BITMASK)
- );
- asm volatile (
- "in r30, %0" "\n\t" // pin 5
- "andi r30, %1" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- "in r30, %2" "\n\t" // pin 6
- "andi r30, %3" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- "in r30, %4" "\n\t" // pin 7
- "andi r30, %5" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- "in r30, %6" "\n\t" // pin 8
- "andi r30, %7" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- "in r30, %8" "\n\t" // pin 9
- "andi r30, %9" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN5_PINREG)), "M" (CORE_PIN5_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN6_PINREG)), "M" (CORE_PIN6_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN7_PINREG)), "M" (CORE_PIN7_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN8_PINREG)), "M" (CORE_PIN8_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN9_PINREG)), "M" (CORE_PIN9_BITMASK)
- );
- asm volatile (
- "in r30, %0" "\n\t" // pin 10
- "andi r30, %1" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- "in r30, %2" "\n\t" // pin 11
- "andi r30, %3" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- "in r30, %4" "\n\t" // pin 12
- "andi r30, %5" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- "in r30, %6" "\n\t" // pin 13
- "andi r30, %7" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- "in r30, %8" "\n\t" // pin 14
- "andi r30, %9" "\n\t"
- "brne _digitalRead_true" "\n\t"
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN10_PINREG)), "M" (CORE_PIN10_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN11_PINREG)), "M" (CORE_PIN11_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN12_PINREG)), "M" (CORE_PIN12_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN13_PINREG)), "M" (CORE_PIN13_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN14_PINREG)), "M" (CORE_PIN14_BITMASK)
- );
- asm volatile (
- "in r30, %0" "\n\t" // pin 15
- "andi r30, %1" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %2" "\n\t" // pin 16
- "andi r30, %3" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %4" "\n\t" // pin 17
- "andi r30, %5" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %6" "\n\t" // pin 18
- "andi r30, %7" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %8" "\n\t" // pin 19
- "andi r30, %9" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %10" "\n\t" // pin 20
- "andi r30, %11" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN15_PINREG)), "M" (CORE_PIN15_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN16_PINREG)), "M" (CORE_PIN16_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN17_PINREG)), "M" (CORE_PIN17_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN18_PINREG)), "M" (CORE_PIN18_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN19_PINREG)), "M" (CORE_PIN19_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN20_PINREG)), "M" (CORE_PIN20_BITMASK)
- );
- #if CORE_NUM_TOTAL_PINS > 21
- asm volatile (
- "in r30, %0" "\n\t" // pin 21
- "andi r30, %1" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %2" "\n\t" // pin 22
- "andi r30, %3" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %4" "\n\t" // pin 23
- "andi r30, %5" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %6" "\n\t" // pin 24
- "andi r30, %7" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN21_PINREG)), "M" (CORE_PIN21_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN22_PINREG)), "M" (CORE_PIN22_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN23_PINREG)), "M" (CORE_PIN23_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN24_PINREG)), "M" (CORE_PIN24_BITMASK)
- );
- #endif
- #if CORE_NUM_TOTAL_PINS > 25
- asm volatile (
- "in r30, %0" "\n\t" // pin 25
- "andi r30, %1" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %2" "\n\t" // pin 26
- "andi r30, %3" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %4" "\n\t" // pin 27
- "andi r30, %5" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %6" "\n\t" // pin 28
- "andi r30, %7" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %8" "\n\t" // pin 29
- "andi r30, %9" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %10" "\n\t" // pin 30
- "andi r30, %11" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN25_PINREG)), "M" (CORE_PIN25_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN26_PINREG)), "M" (CORE_PIN26_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN27_PINREG)), "M" (CORE_PIN27_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN28_PINREG)), "M" (CORE_PIN28_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN29_PINREG)), "M" (CORE_PIN29_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN30_PINREG)), "M" (CORE_PIN30_BITMASK)
- );
- #endif
- }
-
- void _digitalRead_true2(void)
- {
- asm volatile (
- "ldi r30, 1" "\n\t"
- "ret" "\n"
- );
- }
-
- #if CORE_NUM_TOTAL_PINS > 25
- void _digitalRead_TABLE2(void)
- {
- asm volatile (
- "in r30, %0" "\n\t" // pin 31
- "andi r30, %1" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %2" "\n\t" // pin 32
- "andi r30, %3" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %4" "\n\t" // pin 33
- "andi r30, %5" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %6" "\n\t" // pin 34
- "andi r30, %7" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN31_PINREG)), "M" (CORE_PIN31_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN32_PINREG)), "M" (CORE_PIN32_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN33_PINREG)), "M" (CORE_PIN33_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN34_PINREG)), "M" (CORE_PIN34_BITMASK)
- );
- asm volatile (
- "in r30, %0" "\n\t" // pin 35
- "andi r30, %1" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %2" "\n\t" // pin 36
- "andi r30, %3" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %4" "\n\t" // pin 37
- "andi r30, %5" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %6" "\n\t" // pin 38
- "andi r30, %7" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %8" "\n\t" // pin 39
- "andi r30, %9" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN35_PINREG)), "M" (CORE_PIN35_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN36_PINREG)), "M" (CORE_PIN36_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN37_PINREG)), "M" (CORE_PIN37_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN38_PINREG)), "M" (CORE_PIN38_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN39_PINREG)), "M" (CORE_PIN39_BITMASK)
- );
- asm volatile (
- "in r30, %0" "\n\t" // pin 40
- "andi r30, %1" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %2" "\n\t" // pin 41
- "andi r30, %3" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %4" "\n\t" // pin 42
- "andi r30, %5" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %6" "\n\t" // pin 43
- "andi r30, %7" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %8" "\n\t" // pin 44
- "andi r30, %9" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- "in r30, %10" "\n\t" // pin 45
- "andi r30, %11" "\n\t"
- "brne _digitalRead_true2" "\n\t"
- "ret" "\n\t"
- :: "I" (_SFR_IO_ADDR(CORE_PIN40_PINREG)), "M" (CORE_PIN40_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN41_PINREG)), "M" (CORE_PIN41_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN42_PINREG)), "M" (CORE_PIN42_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN43_PINREG)), "M" (CORE_PIN43_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN44_PINREG)), "M" (CORE_PIN44_BITMASK),
- "I" (_SFR_IO_ADDR(CORE_PIN45_PINREG)), "M" (CORE_PIN45_BITMASK)
- );
- }
- #endif
-
-
-
- const uint8_t PROGMEM digital_pin_table_PGM[] = {
- CORE_PIN0_BITMASK, (int)&CORE_PIN0_PINREG,
- CORE_PIN1_BITMASK, (int)&CORE_PIN1_PINREG,
- CORE_PIN2_BITMASK, (int)&CORE_PIN2_PINREG,
- CORE_PIN3_BITMASK, (int)&CORE_PIN3_PINREG,
- CORE_PIN4_BITMASK, (int)&CORE_PIN4_PINREG,
- CORE_PIN5_BITMASK, (int)&CORE_PIN5_PINREG,
- CORE_PIN6_BITMASK, (int)&CORE_PIN6_PINREG,
- CORE_PIN7_BITMASK, (int)&CORE_PIN7_PINREG,
- CORE_PIN8_BITMASK, (int)&CORE_PIN8_PINREG,
- CORE_PIN9_BITMASK, (int)&CORE_PIN9_PINREG,
- CORE_PIN10_BITMASK, (int)&CORE_PIN10_PINREG,
- CORE_PIN11_BITMASK, (int)&CORE_PIN11_PINREG,
- CORE_PIN12_BITMASK, (int)&CORE_PIN12_PINREG,
- CORE_PIN13_BITMASK, (int)&CORE_PIN13_PINREG,
- CORE_PIN14_BITMASK, (int)&CORE_PIN14_PINREG,
- CORE_PIN15_BITMASK, (int)&CORE_PIN15_PINREG,
- CORE_PIN16_BITMASK, (int)&CORE_PIN16_PINREG,
- CORE_PIN17_BITMASK, (int)&CORE_PIN17_PINREG,
- CORE_PIN18_BITMASK, (int)&CORE_PIN18_PINREG,
- CORE_PIN19_BITMASK, (int)&CORE_PIN19_PINREG,
- CORE_PIN20_BITMASK, (int)&CORE_PIN20_PINREG,
- #if CORE_NUM_TOTAL_PINS > 21
- CORE_PIN21_BITMASK, (int)&CORE_PIN21_PINREG,
- CORE_PIN22_BITMASK, (int)&CORE_PIN22_PINREG,
- CORE_PIN23_BITMASK, (int)&CORE_PIN23_PINREG,
- CORE_PIN24_BITMASK, (int)&CORE_PIN24_PINREG,
- #endif
- #if CORE_NUM_TOTAL_PINS > 25
- CORE_PIN25_BITMASK, (int)&CORE_PIN25_PINREG,
- CORE_PIN26_BITMASK, (int)&CORE_PIN26_PINREG,
- CORE_PIN27_BITMASK, (int)&CORE_PIN27_PINREG,
- CORE_PIN28_BITMASK, (int)&CORE_PIN28_PINREG,
- CORE_PIN29_BITMASK, (int)&CORE_PIN29_PINREG,
- CORE_PIN30_BITMASK, (int)&CORE_PIN30_PINREG,
- CORE_PIN31_BITMASK, (int)&CORE_PIN31_PINREG,
- CORE_PIN32_BITMASK, (int)&CORE_PIN32_PINREG,
- CORE_PIN33_BITMASK, (int)&CORE_PIN33_PINREG,
- CORE_PIN34_BITMASK, (int)&CORE_PIN34_PINREG,
- CORE_PIN35_BITMASK, (int)&CORE_PIN35_PINREG,
- CORE_PIN36_BITMASK, (int)&CORE_PIN36_PINREG,
- CORE_PIN37_BITMASK, (int)&CORE_PIN37_PINREG,
- CORE_PIN38_BITMASK, (int)&CORE_PIN38_PINREG,
- CORE_PIN39_BITMASK, (int)&CORE_PIN39_PINREG,
- CORE_PIN40_BITMASK, (int)&CORE_PIN40_PINREG,
- CORE_PIN41_BITMASK, (int)&CORE_PIN41_PINREG,
- CORE_PIN42_BITMASK, (int)&CORE_PIN42_PINREG,
- CORE_PIN43_BITMASK, (int)&CORE_PIN43_PINREG,
- CORE_PIN44_BITMASK, (int)&CORE_PIN44_PINREG,
- CORE_PIN45_BITMASK, (int)&CORE_PIN45_PINREG
- #endif
- };
-
- void _shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value)
- {
- if (bitOrder == LSBFIRST) {
- shiftOut_lsbFirst(dataPin, clockPin, value);
- } else {
- shiftOut_msbFirst(dataPin, clockPin, value);
- }
- }
-
- void shiftOut_lsbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value)
- {
- uint8_t mask;
- for (mask=0x01; mask; mask <<= 1) {
- digitalWrite(dataPin, value & mask);
- digitalWrite(clockPin, HIGH);
- digitalWrite(clockPin, LOW);
- }
- }
-
- void shiftOut_msbFirst(uint8_t dataPin, uint8_t clockPin, uint8_t value)
- {
- uint8_t mask;
- for (mask=0x80; mask; mask >>= 1) {
- digitalWrite(dataPin, value & mask);
- digitalWrite(clockPin, HIGH);
- digitalWrite(clockPin, LOW);
- }
- }
-
- uint8_t _shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
- {
- if (bitOrder == LSBFIRST) {
- return shiftIn_lsbFirst(dataPin, clockPin);
- } else {
- return shiftIn_msbFirst(dataPin, clockPin);
- }
- }
-
- uint8_t shiftIn_lsbFirst(uint8_t dataPin, uint8_t clockPin)
- {
- uint8_t mask, value=0;
- for (mask=0x01; mask; mask <<= 1) {
- digitalWrite(clockPin, HIGH);
- if (digitalRead(dataPin)) value |= mask;
- digitalWrite(clockPin, LOW);
- }
- return value;
- }
-
- uint8_t shiftIn_msbFirst(uint8_t dataPin, uint8_t clockPin)
- {
- uint8_t mask, value=0;
- for (mask=0x80; mask; mask >>= 1) {
- digitalWrite(clockPin, HIGH);
- if (digitalRead(dataPin)) value |= mask;
- digitalWrite(clockPin, LOW);
- }
- return value;
- }
-
- static void disable_peripherals(void) __attribute__((noinline));
- static void disable_peripherals(void)
- {
- #if defined(__AVR_AT90USB162__)
- EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0;
- TIMSK0 = 0; TIMSK1 = 0; UCSR1B = 0;
- DDRB = 0; DDRC = 0; DDRD = 0;
- PORTB = 0; PORTC = 0; PORTD = 0;
- #elif defined(__AVR_ATmega32U4__)
- EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
- TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0; UCSR1B = 0; TWCR = 0;
- DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; TWCR = 0;
- PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
- #elif defined(__AVR_AT90USB646__)
- EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
- TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
- DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
- PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
- #elif defined(__AVR_AT90USB1286__)
- EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
- TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
- DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
- PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
- #endif
- }
-
-
- void _reboot_Teensyduino_(void)
- {
- cli();
- delayMicroseconds(5000);
- UDCON = 1;
- USBCON = (1<<FRZCLK);
- delayMicroseconds(15000);
- disable_peripherals();
- #if defined(__AVR_AT90USB162__)
- asm volatile("jmp 0x3E00");
- #elif defined(__AVR_ATmega32U4__)
- asm volatile("jmp 0x7E00");
- #elif defined(__AVR_AT90USB646__)
- asm volatile("jmp 0xFC00");
- #elif defined(__AVR_AT90USB1286__)
- asm volatile("jmp 0x1FC00");
- #endif
- //__builtin_unreachable(); // available in gcc 4.5
- while (1) ;
- }
-
- void _restart_Teensyduino_(void)
- {
- cli();
- disable_peripherals(); // but leave USB intact
- delayMicroseconds(15000);
- asm volatile("jmp 0");
- //__builtin_unreachable(); // available in gcc 4.5
- while (1) ;
- }
-
-
-
- #if F_CPU == 16000000L
- #define TIMER0_MILLIS_INC 1
- #define TIMER0_FRACT_INC 3
- #define TIMER0_MICROS_INC 4
- #elif F_CPU == 8000000L
- #define TIMER0_MILLIS_INC 2
- #define TIMER0_FRACT_INC 6
- #define TIMER0_MICROS_INC 8
- #elif F_CPU == 4000000L
- #define TIMER0_MILLIS_INC 4
- #define TIMER0_FRACT_INC 12
- #define TIMER0_MICROS_INC 16
- #elif F_CPU == 2000000L
- #define TIMER0_MILLIS_INC 8
- #define TIMER0_FRACT_INC 24
- #define TIMER0_MICROS_INC 32
- #elif F_CPU == 1000000L
- #define TIMER0_MILLIS_INC 16
- #define TIMER0_FRACT_INC 48
- #define TIMER0_MICROS_INC 64
- #endif
-
- volatile unsigned long timer0_micros_count = 0;
- volatile unsigned long timer0_millis_count = 0;
- volatile unsigned char timer0_fract_count = 0;
-
- void TIMER0_OVF_vect() __attribute__((naked));
- void TIMER0_OVF_vect()
- {
- asm volatile(
- "push r24" "\n\t"
- "in r24, __SREG__" "\n\t"
- "push r24" "\n\t"
-
- "lds r24, timer0_fract_count" "\n\t"
- "subi r24, 256 - %0" "\n\t"
- "cpi r24, 125" "\n\t"
- "brsh L_%=_fract_roll" "\n\t"
-
- "L_%=_fract_noroll:" "\n\t"
- "sts timer0_fract_count, r24" "\n\t"
- "lds r24, timer0_millis_count" "\n\t"
- "subi r24, 256 - %1" "\n\t"
- "sts timer0_millis_count, r24" "\n\t"
- "brcs L_%=_ovcount" "\n\t"
-
- "L_%=_millis_inc_sext:"
- "lds r24, timer0_millis_count+1" "\n\t"
- "sbci r24, 255" "\n\t"
- "sts timer0_millis_count+1, r24" "\n\t"
- "brcs L_%=_ovcount" "\n\t"
- "lds r24, timer0_millis_count+2" "\n\t"
- "sbci r24, 255" "\n\t"
- "sts timer0_millis_count+2, r24" "\n\t"
- "brcs L_%=_ovcount" "\n\t"
- "lds r24, timer0_millis_count+3" "\n\t"
- "sbci r24, 255" "\n\t"
- "sts timer0_millis_count+3, r24" "\n\t"
- "rjmp L_%=_ovcount" "\n\t"
-
- "L_%=_fract_roll:" "\n\t"
- "subi r24, 125" "\n\t"
- "sts timer0_fract_count, r24" "\n\t"
- "lds r24, timer0_millis_count" "\n\t"
- "subi r24, 256 - %1 - 1" "\n\t"
- "sts timer0_millis_count, r24" "\n\t"
- "brcc L_%=_millis_inc_sext" "\n\t"
-
- "L_%=_ovcount:"
- "lds r24, timer0_micros_count" "\n\t"
- "subi r24, 256 - %2" "\n\t"
- "sts timer0_micros_count, r24" "\n\t"
- "brcs L_%=_end" "\n\t"
- "lds r24, timer0_micros_count+1" "\n\t"
- "sbci r24, 255" "\n\t"
- "sts timer0_micros_count+1, r24" "\n\t"
- "brcs L_%=_end" "\n\t"
- "lds r24, timer0_micros_count+2" "\n\t"
- "sbci r24, 255" "\n\t"
- "sts timer0_micros_count+2, r24" "\n\t"
-
- "L_%=_end:"
- "pop r24" "\n\t"
- "out __SREG__, r24" "\n\t"
- "pop r24" "\n\t"
- "reti"
- :
- : "M" (TIMER0_FRACT_INC), "M" (TIMER0_MILLIS_INC),
- "M" (TIMER0_MICROS_INC)
- );
- }
-
-
- void delay(uint32_t ms)
- {
- uint16_t start = (uint16_t)micros();
-
- while (ms > 0) {
- if (((uint16_t)micros() - start) >= 1000) {
- ms--;
- start += 1000;
- }
- }
- #if 0
- // This doesn't save a lot of power on Teensy, which
- // lacks the power saving flash memory of some newer
- // chips, and also usually consumes lots of power for
- // the USB port. There is also some strange (probably
- // hardware) bug involving the A/D mux for the first
- // conversion after the processor wakes from idle mode.
- uint32_t start;
- if (!(SREG & 0x80)) {
- // if interrupts are disabled, busy loop
- while (ms--) delayMicroseconds(1000);
- return;
- }
- // if interrupt are enabled, use low power idle mode
- cli();
- start = timer0_millis_count;
- do {
- _SLEEP_CONTROL_REG = SLEEP_MODE_IDLE | _SLEEP_ENABLE_MASK;
- sei();
- sleep_cpu();
- _SLEEP_CONTROL_REG = SLEEP_MODE_IDLE;
- cli();
- } while (timer0_millis_count - start <= ms);
- sei();
- #endif
- }
-
-
- uint32_t _micros(void)
- {
- register uint32_t out asm("r22");
- asm volatile(
- "in __tmp_reg__, __SREG__" "\n\t"
- "cli" "\n\t"
- "in %A0, %2" "\n\t"
- "in __zero_reg__, %3" "\n\t"
- "lds %B0, timer0_micros_count" "\n\t"
- "lds %C0, timer0_micros_count+1" "\n\t"
- "lds %D0, timer0_micros_count+2" "\n\t"
- "out __SREG__, __tmp_reg__" "\n\t"
- "sbrs __zero_reg__, %4" "\n\t"
- "rjmp L_%=_skip" "\n\t"
- "cpi %A0, 255" "\n\t"
- "breq L_%=_skip" "\n\t"
- "subi %B0, 256 - %1" "\n\t"
- "sbci %C0, 255" "\n\t"
- "sbci %D0, 255" "\n\t"
- "L_%=_skip:"
- "clr __zero_reg__" "\n\t"
- "clr __tmp_reg__" "\n\t"
- #if F_CPU == 16000000L || F_CPU == 8000000L || F_CPU == 4000000L
- "lsl %A0" "\n\t"
- "rol __tmp_reg__" "\n\t"
- "lsl %A0" "\n\t"
- "rol __tmp_reg__" "\n\t"
- #if F_CPU == 8000000L || F_CPU == 4000000L
- "lsl %A0" "\n\t"
- "rol __tmp_reg__" "\n\t"
- #endif
- #if F_CPU == 4000000L
- "lsl %A0" "\n\t"
- "rol __tmp_reg__" "\n\t"
- #endif
- "or %B0, __tmp_reg__" "\n\t"
- #endif
- #if F_CPU == 1000000L || F_CPU == 2000000L
- "lsr %A0" "\n\t"
- "ror __tmp_reg__" "\n\t"
- "lsr %A0" "\n\t"
- "ror __tmp_reg__" "\n\t"
- #if F_CPU == 2000000L
- "lsr %A0" "\n\t"
- "ror __tmp_reg__" "\n\t"
- #endif
- "or %B0, %A0" "\n\t"
- "mov %A0, __tmp_reg__" "\n\t"
- #endif
- : "=d" (out)
- : "M" (TIMER0_MICROS_INC),
- "I" (_SFR_IO_ADDR(TCNT0)),
- "I" (_SFR_IO_ADDR(TIFR0)),
- "I" (TOV0)
- : "r0"
- );
- return out;
- }
-
-
-
|