diff --git a/components/adc/include/continuous_adc.hpp b/components/adc/include/continuous_adc.hpp index 78be586f0..8d9ec6231 100644 --- a/components/adc/include/continuous_adc.hpp +++ b/components/adc/include/continuous_adc.hpp @@ -342,11 +342,11 @@ class ContinuousAdc : public espp::BaseComponent { #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED logger_.info("calibration scheme version is {}", "Curve Fitting"); - adc_cali_curve_fitting_config_t cali_config = { - .unit_id = unit, - .atten = atten, - .bitwidth = bitwidth, - }; + adc_cali_curve_fitting_config_t cali_config; + memset(&cali_config, 0, sizeof(cali_config)); + cali_config.unit_id = unit; + cali_config.atten = atten; + cali_config.bitwidth = bitwidth; ret = adc_cali_create_scheme_curve_fitting(&cali_config, &handle); if (ret == ESP_OK) { calibrated = true; @@ -357,11 +357,11 @@ class ContinuousAdc : public espp::BaseComponent { // cppcheck-suppress knownConditionTrueFalse if (!calibrated) { logger_.info("calibration scheme version is {}", "Line Fitting"); - adc_cali_line_fitting_config_t cali_config = { - .unit_id = unit, - .atten = atten, - .bitwidth = bitwidth, - }; + adc_cali_line_fitting_config_t cali_config; + memset(&cali_config, 0, sizeof(cali_config)); + cali_config.unit_id = unit; + cali_config.atten = atten; + cali_config.bitwidth = bitwidth; ret = adc_cali_create_scheme_line_fitting(&cali_config, &handle); if (ret == ESP_OK) { calibrated = true; diff --git a/components/adc/include/oneshot_adc.hpp b/components/adc/include/oneshot_adc.hpp index adede08e7..33a94ec04 100644 --- a/components/adc/include/oneshot_adc.hpp +++ b/components/adc/include/oneshot_adc.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -76,6 +77,7 @@ class OneshotAdc : public BaseComponent { std::vector read_all_mv() { std::vector values; values.reserve(configs_.size()); + std::lock_guard lock(mutex_); for (const auto &config : configs_) { int raw = 0; auto err = adc_oneshot_read(adc_handle_, config.channel, &raw); @@ -96,6 +98,7 @@ class OneshotAdc : public BaseComponent { * it was configured). */ std::optional read_raw(const AdcConfig &config) { + std::lock_guard lock(mutex_); if (std::find(configs_.begin(), configs_.end(), config) != configs_.end()) { int raw; auto err = adc_oneshot_read(adc_handle_, config.channel, &raw); @@ -120,6 +123,7 @@ class OneshotAdc : public BaseComponent { * (if it was configured). */ std::optional read_mv(const AdcConfig &config) { + std::lock_guard lock(mutex_); auto maybe_raw = read_raw(config); if (maybe_raw.has_value()) { return raw_to_mv(maybe_raw.value()); @@ -205,6 +209,7 @@ class OneshotAdc : public BaseComponent { } } + std::recursive_mutex mutex_; std::vector configs_; adc_oneshot_unit_handle_t adc_handle_; adc_cali_handle_t adc_cali_handle_;