From a379b072056c0c57cda8687d7d3038e6e13044e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Betto?= <niccolo.betto@skywarder.eu> Date: Fri, 1 Dec 2023 17:12:03 +0100 Subject: [PATCH] [InternalADC] Warn on undefined V_DDA_VOLTAGE instead of erroring out Also fix some cppcheck warnings. --- src/shared/drivers/adc/InternalADC.cpp | 15 +++++---------- src/shared/drivers/adc/InternalADCData.h | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/shared/drivers/adc/InternalADC.cpp b/src/shared/drivers/adc/InternalADC.cpp index 525c56e10..f5dbbe0af 100644 --- a/src/shared/drivers/adc/InternalADC.cpp +++ b/src/shared/drivers/adc/InternalADC.cpp @@ -61,7 +61,8 @@ static const float VBAT_DIV = 4.0f; // If it is missing you need to define it, preferably in the board_settings.h // file in miosix. Check your board schematic to find the voltage value. #ifndef V_DDA_VOLTAGE -#error Missing V_DDA_VOLTAGE definition for current target +#warning Missing V_DDA_VOLTAGE definition for current target, using default value of 3.0V +#define V_DDA_VOLTAGE 3.0f #endif InternalADC::InternalADC(ADC_TypeDef *adc) : adc(adc) @@ -115,9 +116,7 @@ InternalADCData InternalADC::sampleImpl() { newData.voltage[i] = readChannel(static_cast<Channel>(i)); newData.voltage[i] = - newData.voltage[i] * - V_DDA_VOLTAGE // cppcheck-suppress ConfigurationNotChecked - / ADC_RESOLUTION; + newData.voltage[i] * V_DDA_VOLTAGE / ADC_RESOLUTION; } } @@ -141,9 +140,7 @@ InternalADCData InternalADC::sampleImpl() if (temperatureRawValue != 0) { newData.temperature = - temperatureRawValue * - V_DDA_VOLTAGE // cppcheck-suppress ConfigurationNotChecked - / ADC_RESOLUTION; + temperatureRawValue * V_DDA_VOLTAGE / ADC_RESOLUTION; #ifdef INTERNAL_ADC_WITHOUT_CALIBRATION // Default conversion @@ -168,9 +165,7 @@ InternalADCData InternalADC::sampleImpl() ADC->CCR &= ~ADC_CCR_VBATE; newData.vBat = - vbatVoltageRawValue * - V_DDA_VOLTAGE // cppcheck-suppress ConfigurationNotChecked - / ADC_RESOLUTION * VBAT_DIV; + vbatVoltageRawValue * V_DDA_VOLTAGE / ADC_RESOLUTION * VBAT_DIV; } return newData; diff --git a/src/shared/drivers/adc/InternalADCData.h b/src/shared/drivers/adc/InternalADCData.h index 8161edeb6..816569545 100644 --- a/src/shared/drivers/adc/InternalADCData.h +++ b/src/shared/drivers/adc/InternalADCData.h @@ -34,7 +34,7 @@ struct InternalADCData float temperature; float vBat; - InternalADCData() {} + InternalADCData() : voltage(), temperature(), vBat() {} static std::string header() { -- GitLab