Skip to content

Changes from cpu based #ifdefs to register based #ifdefs #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
Changed from cpu #ifdefs to register #ifdefs
  • Loading branch information
Mark Sproul committed Oct 1, 2010
commit 202e0741f33e81641cc21750226a6105d4f70e9c
10 changes: 8 additions & 2 deletions hardware/arduino/cores/arduino/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,34 @@ void analogReference(uint8_t mode)
analog_reference = mode;
}

//*********************************************************************
int analogRead(uint8_t pin)
{
uint8_t low, high;

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
if (pin >= 54) pin -= 54; // allow for channel or pin numbers
#else
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
#endif

#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);
#else
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
#endif

// set the analog reference (high two bits of ADMUX) and select the
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
// to 0 (the default).
#if defined(ADMUX)
ADMUX = (analog_reference << 6) | (pin & 0x07);
#endif

// without a delay, we seem to read from the wrong channel
//delay(1);

#if defined(ADCSRA) && defined(ADCL)
// start the conversion
sbi(ADCSRA, ADSC);

Expand Down