From b9717187fd9b11c77d75a289050cb0a58512d2b9 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 17 Apr 2013 19:49:40 +0200 Subject: Use analogPinToChannel if it's defined --- cores/arduino/wiring_analog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cores/arduino') diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index 3f19c7f..bd148cc 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -41,14 +41,14 @@ int analogRead(uint8_t pin) { uint8_t low, high; -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#if defined(analogPinToChannel) + 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_ATmega1284P__) || defined(__AVR_ATmega644P__) 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 -- cgit v1.2.3-18-g5258 From 8d26462be25560182d05ab80ea106b239c0ee1cf Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 18 Apr 2013 00:07:33 +0200 Subject: Removed call to analogPinToChannel for Leonardo --- cores/arduino/wiring_analog.c | 1 - 1 file changed, 1 deletion(-) (limited to 'cores/arduino') diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index bd148cc..81fb1e1 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -54,7 +54,6 @@ int analogRead(uint8_t pin) #endif #if defined(__AVR_ATmega32U4__) - pin = analogPinToChannel(pin); ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5); #elif defined(ADCSRB) && defined(MUX5) // the MUX5 bit of ADCSRB selects whether we're reading from channels -- cgit v1.2.3-18-g5258 From 0a7b402c4524bf3483ccef3bfa70a6d6de97a912 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 18 Apr 2013 00:15:06 +0200 Subject: Check if ATmega32u4 is defined Needed in order to work with Arduino Leonardo --- cores/arduino/wiring_analog.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cores/arduino') diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index 81fb1e1..a6b63e3 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -42,6 +42,9 @@ int analogRead(uint8_t pin) uint8_t low, high; #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 -- cgit v1.2.3-18-g5258 From 8d7deb7a1fbdbe93547839e355683fe1f2169c25 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 2 May 2013 01:00:17 +0200 Subject: Removed double instance of the same code --- cores/arduino/wiring_analog.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'cores/arduino') diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index a6b63e3..c99325f 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -55,10 +55,8 @@ int analogRead(uint8_t pin) #else if (pin >= 14) pin -= 14; // allow for channel or pin numbers #endif - -#if defined(__AVR_ATmega32U4__) - 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); -- cgit v1.2.3-18-g5258