From bd70b441441aa464bacdefc47238f3028816b1de Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Mon, 22 May 2023 15:24:55 +0800 Subject: [PATCH 1/2] adc_oneshot: move power acquire back to adc_oneshot_new_unit Revert and fix of d197c59eaa5107c7c2981d308363c7d643e16774 in !23575 --- components/esp_adc/adc_oneshot.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/esp_adc/adc_oneshot.c b/components/esp_adc/adc_oneshot.c index 9ecb491285..c06901367f 100644 --- a/components/esp_adc/adc_oneshot.c +++ b/components/esp_adc/adc_oneshot.c @@ -113,7 +113,9 @@ esp_err_t adc_oneshot_new_unit(const adc_oneshot_unit_init_cfg_t *init_config, a _lock_release(&s_ctx.mutex); #endif - sar_periph_ctrl_adc_oneshot_power_acquire(); + if (init_config->ulp_mode == ADC_ULP_MODE_DISABLE) { + sar_periph_ctrl_adc_oneshot_power_acquire(); + } ESP_LOGD(TAG, "new adc unit%"PRId32" is created", unit->unit_id); *ret_unit = unit; @@ -200,6 +202,7 @@ esp_err_t adc_oneshot_read_isr(adc_oneshot_unit_handle_t handle, adc_channel_t c esp_err_t adc_oneshot_del_unit(adc_oneshot_unit_handle_t handle) { ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer"); + adc_ulp_mode_t ulp_mode = handle->ulp_mode; bool success_free = s_adc_unit_free(handle->unit_id); ESP_RETURN_ON_FALSE(success_free, ESP_ERR_NOT_FOUND, TAG, "adc%"PRId32" isn't in use", handle->unit_id + 1); @@ -210,7 +213,9 @@ esp_err_t adc_oneshot_del_unit(adc_oneshot_unit_handle_t handle) ESP_LOGD(TAG, "adc unit%"PRId32" is deleted", handle->unit_id); free(handle); - sar_periph_ctrl_adc_oneshot_power_release(); + if (ulp_mode == ADC_ULP_MODE_DISABLE) { + sar_periph_ctrl_adc_oneshot_power_release(); + } #if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED //To free the APB_SARADC periph if needed From bf5e10dd23a42f0df0f9ae2f56e47c77c7a3b0bd Mon Sep 17 00:00:00 2001 From: Armando Date: Thu, 6 Jul 2023 16:48:59 +0800 Subject: [PATCH 2/2] fix(adc): fix s_adc_tsen_enabled not set issue --- components/esp_adc/adc_oneshot.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/esp_adc/adc_oneshot.c b/components/esp_adc/adc_oneshot.c index c06901367f..9ff61a4b5c 100644 --- a/components/esp_adc/adc_oneshot.c +++ b/components/esp_adc/adc_oneshot.c @@ -18,6 +18,7 @@ #include "esp_private/adc_private.h" #include "esp_private/adc_share_hw_ctrl.h" #include "esp_private/sar_periph_ctrl.h" +#include "esp_private/esp_sleep_internal.h" #include "hal/adc_types.h" #include "hal/adc_oneshot_hal.h" #include "hal/adc_ll.h" @@ -115,6 +116,8 @@ esp_err_t adc_oneshot_new_unit(const adc_oneshot_unit_init_cfg_t *init_config, a if (init_config->ulp_mode == ADC_ULP_MODE_DISABLE) { sar_periph_ctrl_adc_oneshot_power_acquire(); + } else { + esp_sleep_enable_adc_tsens_monitor(true); } ESP_LOGD(TAG, "new adc unit%"PRId32" is created", unit->unit_id); @@ -215,6 +218,8 @@ esp_err_t adc_oneshot_del_unit(adc_oneshot_unit_handle_t handle) if (ulp_mode == ADC_ULP_MODE_DISABLE) { sar_periph_ctrl_adc_oneshot_power_release(); + } else { + esp_sleep_enable_adc_tsens_monitor(false); } #if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED