diff --git a/hardware/sam/cores/sam/wiring_analog.c b/hardware/sam/cores/sam/wiring_analog.c index 9aa245871..e525f29d0 100644 --- a/hardware/sam/cores/sam/wiring_analog.c +++ b/hardware/sam/cores/sam/wiring_analog.c @@ -1,156 +1,135 @@ /* - Copyright (c) 2011 Arduino. All right reserved. + Copyright (c) 2011 Arduino. All right reserved. - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ //#include "wiring_private.h" #include "Arduino.h" +#include "variant.h" #ifdef __cplusplus - extern "C" { +extern "C" { #endif +eAnalogReference analog_reference = AR_DEFAULT; -eAnalogReference analog_reference = AR_DEFAULT ; - -void analogReference( eAnalogReference ulMode ) -{ - analog_reference = ulMode ; +void analogReference(eAnalogReference ulMode) { + analog_reference = ulMode; } -uint32_t analogRead( uint32_t ulPin ) -{ - uint32_t ulValue=0 ; - uint32_t ulChannel ; +uint32_t analogRead(uint32_t ulPin) { + uint32_t ulValue = 0; + uint32_t ulChannel; - ulChannel=g_APinDescription[ulPin].ulAnalogChannel ; + if (ulPin < A0) + ulPin += A0; -#if defined SAM3U4E - switch ( ulChannel ) - { - // Handling ADC 10 bits channels - case ADC0 : - case ADC1 : - case ADC2 : - case ADC3 : - case ADC4 : - case ADC5 : - case ADC6 : - case ADC7 : - // Enable the corresponding channel - adc_enable_channel( ADC, ulChannel ) ; + ulChannel = g_APinDescription[ulPin].ulAnalogChannel; - // Start the ADC - adc_start( ADC ) ; +#if defined __SAM3U4E__ + switch ( ulChannel ) + { + // Handling ADC 10 bits channels + case ADC0 : + case ADC1 : + case ADC2 : + case ADC3 : + case ADC4 : + case ADC5 : + case ADC6 : + case ADC7 : + // Enable the corresponding channel + adc_enable_channel( ADC, ulChannel ); - // Wait for end of conversion - while ( adc_get_status( ADC ) & (1<