diff --git a/hardware/sam/cores/sam/Arduino.h b/hardware/sam/cores/sam/Arduino.h index 05caf2603..e12784529 100644 --- a/hardware/sam/cores/sam/Arduino.h +++ b/hardware/sam/cores/sam/Arduino.h @@ -115,6 +115,7 @@ typedef enum _EAnalogChannel DAC1 } EAnalogChannel ; +#define ADC_CHANNEL_NUMBER_NONE 0xffffffff /** * Pin Attributes to be OR-ed */ @@ -133,7 +134,8 @@ typedef struct _PinDescription EPioType ulPinType ; uint32_t ulPinConfiguration ; uint32_t ulPinAttribute ; - EAnalogChannel ulAnalogChannel ; + EAnalogChannel ulAnalogChannel ; /* Describe which Analog pin is linked to a MCU pin */ + EAnalogChannel ulADCChannelNumber ; /* We use the same enum than for ADC pins to describe the ADC channel in use on this pin */ } PinDescription ; /* Pins table to be instanciated into variant.cpp */ diff --git a/hardware/sam/cores/sam/wiring_analog.c b/hardware/sam/cores/sam/wiring_analog.c index e525f29d0..3e879a3b5 100644 --- a/hardware/sam/cores/sam/wiring_analog.c +++ b/hardware/sam/cores/sam/wiring_analog.c @@ -26,21 +26,25 @@ extern "C" { eAnalogReference analog_reference = AR_DEFAULT; -void analogReference(eAnalogReference ulMode) { +void analogReference(eAnalogReference ulMode) +{ analog_reference = ulMode; } -uint32_t analogRead(uint32_t ulPin) { +uint32_t analogRead(uint32_t ulPin) +{ uint32_t ulValue = 0; uint32_t ulChannel; if (ulPin < A0) + { ulPin += A0; + } - ulChannel = g_APinDescription[ulPin].ulAnalogChannel; + ulChannel = g_APinDescription[ulPin].ulADCChannelNumber ; #if defined __SAM3U4E__ - switch ( ulChannel ) + switch ( g_APinDescription[ulPin].ulAnalogChannel ) { // Handling ADC 10 bits channels case ADC0 : @@ -51,23 +55,23 @@ uint32_t analogRead(uint32_t ulPin) { case ADC5 : case ADC6 : case ADC7 : - // Enable the corresponding channel - adc_enable_channel( ADC, ulChannel ); + // Enable the corresponding channel + adc_enable_channel( ADC, ulChannel ); - // Start the ADC - adc_start( ADC ); + // Start the ADC + adc_start( ADC ); - // Wait for end of conversion - while ((adc_get_status(ADC) & (1<