@pomelo, I think I figure out the things under the hood about ADC_MODE() ...
According to the doc :
This line has to appear outside of any functions, for instance right after the #include lines of your sketch.
So, it is normal that if we put the ADC_MODE(ADC_TOUT) inside any function, it doesn't compile. It should be placed on the top of the sketch since it is only redefining a function which is probably called by SDK itself while doing the analogRead(A0); and therefore make sur it is the the TOUT that we want. if it is defined as ADC_VCC, then it will be the system 3.3V.
The strange thing I found is that this mechanism is a bit ugly, because if we want to switch between mode, we have to make thing even more ugly :
Code: Select alluint8_t adc_what_I_want = ADC_TOUT;
ADC_MODE(adc_what_I_want);
[...]
loop() {
[...]
adc_what_I_want = ADC_TOUT;
Serial.printf("TOUT = %d", analogRead(A0));
[...]
adc_what_I_want = ADC_VCC;
Serial.printf("VCC = %d", analogRead(A0));
}
Ugly, right ?