diff options
author | David Madison <dmadison@users.noreply.github.com> | 2022-02-22 02:11:13 -0500 |
---|---|---|
committer | David Madison <dmadison@users.noreply.github.com> | 2022-02-22 02:11:13 -0500 |
commit | 65f1968b755855315b931b4b8fa45747576d6536 (patch) | |
tree | 77f4cf88950d90182f57c73f69027b4d39375d64 /cores/arduino/wiring_analog.c | |
parent | f47a97522dc28c16c432422e3085035de69cfaf6 (diff) | |
parent | a1c76c0651192587f495d88b419553edd12a4881 (diff) |
Merge tag '1.8.4' into upstream-1.8.4
Diffstat (limited to 'cores/arduino/wiring_analog.c')
-rw-r--r-- | cores/arduino/wiring_analog.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index e237d6d..0de64f7 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -37,7 +37,6 @@ void analogReference(uint8_t mode) int analogRead(uint8_t pin) { - uint8_t low, high; #if defined(analogPinToChannel) #if defined(__AVR_ATmega32U4__) @@ -74,27 +73,20 @@ int analogRead(uint8_t pin) // without a delay, we seem to read from the wrong channel //delay(1); -#if defined(ADCSRA) && defined(ADCL) +#if defined(ADCSRA) && defined(ADC) // start the conversion sbi(ADCSRA, ADSC); // ADSC is cleared when the conversion finishes while (bit_is_set(ADCSRA, ADSC)); - // we have to read ADCL first; doing so locks both ADCL - // and ADCH until ADCH is read. reading ADCL second would - // cause the results of each conversion to be discarded, - // as ADCL and ADCH would be locked when it completed. - low = ADCL; - high = ADCH; + // ADC macro takes care of reading ADC register. + // avr-gcc implements the proper reading order: ADCL is read first. + return ADC; #else // we dont have an ADC, return 0 - low = 0; - high = 0; + return 0; #endif - - // combine the two bytes - return (high << 8) | low; } // Right now, PWM output only works on the pins with |