diff --git a/module/cores/arduino/port_sam/core_analog.c b/module/cores/arduino/port_sam/core_analog.c index cb24797..abebf19 100644 --- a/module/cores/arduino/port_sam/core_analog.c +++ b/module/cores/arduino/port_sam/core_analog.c @@ -60,14 +60,17 @@ uint32_t analogRead(uint32_t ulPin) { uint32_t ulValue = 0; -#if 0 // TODO: implement uint32_t ulChannel; +#if defined(PIN_A0) if (ulPin < A0) ulPin += A0; +#endif ulChannel = g_aPinMap[ulPin].ulADCChannelNumber ; +#if 0 // TODO: implement + #if defined __SAM3U4E__ switch ( g_aPinMap[ulPin].ulAnalogChannel ) { @@ -185,6 +188,27 @@ uint32_t analogRead(uint32_t ulPin) #endif #endif // 0 + + +#if defined(_SAMG55J19_) + //ADC setup is done in variant_init.cpp + //enable channel + ADC->ADC_CHER=(0x1<ADC_IER=(0x1<ADC_CR=ADC_CR_START; + //wait till conversion is over + while(!(ADC->ADC_ISR & (0x1<ADC_CDR[ulChannel]; + //disable channel + ADC->ADC_CHDR=(0x1<ADC_IDR=(0x1<PMC_PCR = PMC_PCR_PID(ID_ADC)|PMC_PCR_CMD|PMC_PCR_DIV(1)|PMC_PCR_EN; //Set ADC peripheral clock to MCK/1 = 120MHz + PMC->PMC_PCER0 = (1< PRESCAL=(PERIPHCLK/(2*ADCCLK))-1 + ADC->ADC_MR =ADC_MR_PRESCAL(5); //fastest ADC conversion clock (10MHz with 120MHz peripheral clock) }