Skip to content

Adds additional analog inputs: A6-A11 #267

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 5 commits into from
Closed
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
8 changes: 8 additions & 0 deletions variants/arduino_zero/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ const PinDescription g_APinDescription[]=
// ----------------------
// 43 - Alternate use of A0 (DAC output)
{ PORTA, 2, PIO_ANALOG, PIN_ATTR_ANALOG, DAC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 }, // DAC/VOUT
// 44..49 - Analog pins
// --------------------
{ PORTA, 11, PIO_ANALOG, 0, ADC_Channel19, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_11 }, // A6 same as D0
{ PORTA, 10, PIO_ANALOG, 0, ADC_Channel18, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_10 }, // A7 same as D1
{ PORTA, 9, PIO_ANALOG, (PIN_ATTR_PWM|PIN_ATTR_TIMER), ADC_Channel17, PWM0_CH1, TCC0_CH1, EXTERNAL_INT_9 }, // A8 same as D3
{ PORTA, 8, PIO_ANALOG, (PIN_ATTR_PWM|PIN_ATTR_TIMER), ADC_Channel16, PWM0_CH0, TCC0_CH0, EXTERNAL_INT_NMI }, // A9 same as D4
{ PORTA, 6, PIO_ANALOG, (PIN_ATTR_PWM|PIN_ATTR_TIMER), ADC_Channel6, PWM1_CH0, TCC1_CH0, EXTERNAL_INT_6 }, // A10 same as D8
{ PORTA, 7, PIO_ANALOG, (PIN_ATTR_PWM|PIN_ATTR_TIMER), ADC_Channel7, PWM1_CH1, TCC1_CH1, EXTERNAL_INT_7 }, // A11 same as D9
} ;

const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM]={ TCC0, TCC1, TCC2, TC3, TC4, TC5 } ;
Expand Down
16 changes: 14 additions & 2 deletions variants/arduino_zero/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ extern "C"
// Number of pins defined in PinDescription array
#define PINS_COUNT (26u)
#define NUM_DIGITAL_PINS (20u)
#define NUM_ANALOG_INPUTS (6u)
#define NUM_ANALOG_INPUTS (12u)
#define NUM_ANALOG_OUTPUTS (1u)
#define analogInputToDigitalPin(p) ((p < 6u) ? (p) + 14u : -1)
#define analogInputToDigitalPin(p) ((p < 6u) ? (p) + 14u : (p > 11u) ? -1 : (p) + 38u)

#define digitalPinToPort(P) ( &(PORT->Group[g_APinDescription[P].ulPort]) )
#define digitalPinToBitMask(P) ( 1 << g_APinDescription[P].ulPin )
Expand Down Expand Up @@ -94,6 +94,12 @@ extern "C"
#define PIN_A3 (17ul)
#define PIN_A4 (18ul)
#define PIN_A5 (19ul)
#define PIN_A6 (44ul)
#define PIN_A7 (45ul)
#define PIN_A8 (46ul)
#define PIN_A9 (47ul)
#define PIN_A10 (48ul)
#define PIN_A11 (49ul)
#define PIN_DAC0 (14ul)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic is for using analogRead function with 0-5 instead of A0-A5...
so that means:

 if (pin < A0) {
    pin += A0;
  }else if(pin > 5 && pin <= 11){
    pin += 38;
 }

@sandeepmistry is it ok for you?


static const uint8_t A0 = PIN_A0;
Expand All @@ -102,6 +108,12 @@ static const uint8_t A2 = PIN_A2;
static const uint8_t A3 = PIN_A3;
static const uint8_t A4 = PIN_A4;
static const uint8_t A5 = PIN_A5;
static const uint8_t A6 = PIN_A6;
static const uint8_t A7 = PIN_A7;
static const uint8_t A8 = PIN_A8;
static const uint8_t A9 = PIN_A9;
static const uint8_t A10 = PIN_A10;
static const uint8_t A11 = PIN_A11;
static const uint8_t DAC0 = PIN_DAC0;
#define ADC_RESOLUTION 12

Expand Down