diff --git a/hardware/arduino/sam/cores/sam/Arduino.h b/hardware/arduino/sam/cores/sam/Arduino.h index 970ac0ad0..a31492fb7 100644 --- a/hardware/arduino/sam/cores/sam/Arduino.h +++ b/hardware/arduino/sam/cores/sam/Arduino.h @@ -8,7 +8,7 @@ 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. + 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 @@ -175,8 +175,8 @@ typedef struct _PinDescription EPioType ulPinType ; uint32_t ulPinConfiguration ; uint32_t ulPinAttribute ; - 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 */ + EAnalogChannel ulAnalogChannel ; /* Analog pin in the Arduino context (label on the board) */ + EAnalogChannel ulADCChannelNumber ; /* ADC Channel number in the SAM device */ EPWMChannel ulPWMChannel ; ETCChannel ulTCChannel ; } PinDescription ; diff --git a/hardware/arduino/sam/cores/sam/validation/test.cpp b/hardware/arduino/sam/cores/sam/validation/test.cpp index f3fab045a..f4f67e4b9 100644 --- a/hardware/arduino/sam/cores/sam/validation/test.cpp +++ b/hardware/arduino/sam/cores/sam/validation/test.cpp @@ -85,7 +85,7 @@ void loop( void ) // Serial1.write( "test1\n" ) ; // send a string // Serial1.write( "test2" ) ; // send another string - Serial1.print("Analog ins: "); + Serial1.print("Analog pins: "); for (int i=A0; i<=MAX_ANALOG; i++) { int a = analogRead(i); Serial1.print(a, DEC); diff --git a/hardware/atmel/sam/variants/sam3x_ek/variant.cpp b/hardware/atmel/sam/variants/sam3x_ek/variant.cpp index 285d178f5..b1c03af63 100644 --- a/hardware/atmel/sam/variants/sam3x_ek/variant.cpp +++ b/hardware/atmel/sam/variants/sam3x_ek/variant.cpp @@ -70,7 +70,7 @@ extern const PinDescription g_APinDescription[]= // 10 - Analog pins // ---------------------- - { PIOA, PIO_PA3, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC0, ADC7, NO_PWM, NO_TC }, // AD0 + { PIOA, PIO_PA3, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC0, ADC1, NO_PWM, NO_TC }, // AD0 { NULL, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC } // END } ; @@ -109,9 +109,6 @@ void USART0_Handler( void ) extern "C" { #endif -// Should be made in a better way... -extern void analogOutputInit(void); - /** * */ @@ -148,6 +145,18 @@ extern void init( void ) g_APinDescription[PIN_LED_RED].ulPinConfiguration ) ; PIO_Clear( g_APinDescription[PIN_LED_RED].pPort, g_APinDescription[PIN_LED_RED].ulPin ) ; + + // Initialize 10bit Analog Controller + pmc_enable_periph_clk( ID_ADC ) ; + adc_init( ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST ) ; + adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1); + adc_configure_trigger(ADC, ADC_TRIG_SW, 0); // Disable hardware trigger. + adc_disable_interrupt( ADC, 0xFFFFFFFF ) ; // Disable all ADC interrupts. + adc_disable_all_channel( ADC ) ; + + // Initialize analogOutput module + analogOutputInit(); + } #ifdef __cplusplus }