Skip to content

Analog pin handling generalizations #2071

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

Open
wants to merge 4 commits into
base: ide-1.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions hardware/arduino/avr/cores/arduino/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@ int analogRead(uint8_t pin)
{
uint8_t low, high;

// If a pin number is passed (e.g. the "digital pin number" for
// an Ax pin), then translate it to the corresponding "analog
// pin number (e.g., A0 => 0, A1 => 1, etc).
#if defined(A0)
if (pin >= A0)
pin -= A0;
#endif

#if defined(NUM_ANALOG_INPUTS)
if (pin >= NUM_ANALOG_INPUTS)
return 0;
#endif

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

#if defined(ADCSRB) && defined(MUX5)
Expand Down
3 changes: 3 additions & 0 deletions hardware/arduino/avr/variants/robot_control/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

#include <avr/pgmspace.h>

#define NUM_DIGITAL_PINS 30
#define NUM_ANALOG_INPUTS 12

#define ARDUINO_MODEL_USB_PID 0x0038

#define TX_RX_LED_INIT DDRD |= (1<<5), DDRB |= (1<<0)
Expand Down
5 changes: 4 additions & 1 deletion hardware/arduino/avr/variants/robot_motor/pins_arduino.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
pins_arduino.h - Pin definition functions for Arduino Robot Control Board
pins_arduino.h - Pin definition functions for Arduino Robot Motor Board
Part of Arduino - http://www.arduino.cc/

Copyright (c) 2913 D. Cuartielles, X. Yang (Arduino Verkstad)
Expand Down Expand Up @@ -28,6 +28,9 @@

#include <avr/pgmspace.h>

#define NUM_DIGITAL_PINS 30
#define NUM_ANALOG_INPUTS 12

#define ARDUINO_MODEL_USB_PID 0x0039

#define TX_RX_LED_INIT DDRD |= (1<<5), DDRB |= (1<<0)
Expand Down