From 93558ce71477f92c14b63a68b99031b8b637fb63 Mon Sep 17 00:00:00 2001 From: Maxint R&D Date: Tue, 14 May 2024 09:08:49 +0200 Subject: [PATCH] Fix for reading PADC_VREF 1.2V reference voltage Silly workaround in analogInputToPinName(), since PADC_VREF maps to PA_1 instead of just PADC_VREF Note: requires ADC enabled in .../variants/CH32V00x/CH32V004F4/variant_CH32V003F4.h: `#define ADC_MODULE_ENABLED // no difference in flash usage` --- cores/arduino/pins_arduino.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cores/arduino/pins_arduino.cpp b/cores/arduino/pins_arduino.cpp index 1c9613a..0bcd00f 100644 --- a/cores/arduino/pins_arduino.cpp +++ b/cores/arduino/pins_arduino.cpp @@ -39,6 +39,13 @@ WEAK uint32_t pinNametoDigitalPin(PinName p) PinName analogInputToPinName(uint32_t pin) { PinName pn = digitalPinToPinName(analogInputToDigitalPin(pin)); + // MMOLE 240330: Don't know what's going on, but PADC_VREF maps to PA_1 instead of just PADC_VREF + // --->>> +#ifdef ADC_MODULE_ENABLED + if(pin==PADC_VREF) + return(PADC_VREF); +#endif + // <<<--- if (pn == NC) { switch (pin) { #if defined(ADC_CHANNEL_TEMPSENSOR) || defined(ADC_CHANNEL_TEMPSENSOR_ADC1)