diff options
author | Cristian Maglie <c.maglie@bug.st> | 2013-07-31 17:33:55 +0200 |
---|---|---|
committer | Cristian Maglie <c.maglie@bug.st> | 2013-07-31 17:33:55 +0200 |
commit | 023434a6be86d138fe324cee3c43755d4161da40 (patch) | |
tree | e89282b839113f13ce895bb88dc623cd4c3c0454 /cores/robot | |
parent | 99bb4a573fa71a4e6c30cad144284d12b3f7edd0 (diff) | |
parent | 40b622a5d1e2cd347fcf1571e97602ec611addab (diff) |
Merge branch 'master' into ide-1.5.x
Diffstat (limited to 'cores/robot')
-rw-r--r-- | cores/robot/wiring_analog.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/cores/robot/wiring_analog.c b/cores/robot/wiring_analog.c index 7ed0e4e..8feead9 100644 --- a/cores/robot/wiring_analog.c +++ b/cores/robot/wiring_analog.c @@ -41,22 +41,22 @@ int analogRead(uint8_t pin) { uint8_t low, high; -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#if defined(analogPinToChannel) +#if defined(__AVR_ATmega32U4__) + if (pin >= 18) pin -= 18; // allow for channel or pin numbers +#endif + pin = analogPinToChannel(pin); +#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) if (pin >= 54) pin -= 54; // allow for channel or pin numbers #elif defined(__AVR_ATmega32U4__) if (pin >= 18) pin -= 18; // allow for channel or pin numbers #elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) if (pin >= 24) pin -= 24; // allow for channel or pin numbers -#elif defined(analogPinToChannel) && (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) - pin = analogPinToChannel(pin); #else if (pin >= 14) pin -= 14; // allow for channel or pin numbers #endif - -#if defined(__AVR_ATmega32U4__) - pin = analogPinToChannel(pin); - ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5); -#elif defined(ADCSRB) && defined(MUX5) + +#if defined(ADCSRB) && defined(MUX5) // the MUX5 bit of ADCSRB selects whether we're reading from channels // 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high). ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5); |