Some things are unclear to me to implement that.
From pinmap_hal.h, line 107,
A5 is 15.
analogRead() -> HAL_Validate_Pin_Function()
In gpio_hal.c, line64
if (pinFunction==PF_ADC && PIN_MAP[pin].adc_channel!=ADC_CHANNEL_NONE)
From pinmap_hal.c, line 61
Here PIN_MAP.adc_channel is ADC_Channel_7
So A5 is reading from this channel. From datasheet, the internal temperature sensor is on ADC_Channel_16.
1. From the Photon pinout diagram, there are 8 ADC's(ADC0, ADC4, ADC7, ADC6, ADC5, ADC12, ADC13, ADC15) mapped to pins (WKP, DAC, A5, A4, A3, A2, A1, A0) respectively. From the STM32F2xx datasheet, there are 16 ADC channels for each ADC(ADCx_IN[15:0]).
However, in the firmware peripheral declarations(stm32f2xx.h) I can see only 3 ADC's defined - ADC1, ADC2, ADC3. Out of those 3, only 2 are initialized in HAL_ADC_Read(). How are ADC4, ADC7, ADC6 etc mapping to ADC1, ADC2, ADC3 peripheral address?
From the data sheet, the internal temperature is on ADC1_IN16 which means it's ADC1 so it makes sense to turn on ADC1. But in adc_hal.c lines 105 and 107, why are both ADC1 and ADC2 being configured? How to know if A5 is on ADC1 or ADC2?
Why enable and disable ADC before and after reading? In my code if don't do that, then the code gets stuck in the while(ADC_GetStatusFlag()) condition if there are is a second ADC enabled.
Why is there an averaging algorithm implemented in HAL_ADC_Read()? I read that this is due to low impedence on the analog pins but I didn't understand it.
What is the ADC3 in peripheral declaration for?