@@ -156,6 +156,9 @@ esp_err_t adc_oneshot_new_unit(const adc_oneshot_unit_init_cfg_t *init_config, a
156156 if (init_config -> ulp_mode == ADC_ULP_MODE_DISABLE ) {
157157 sar_periph_ctrl_adc_oneshot_power_acquire ();
158158 } else {
159+ #if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
160+ ESP_GOTO_ON_ERROR (esp_clk_tree_enable_src ((soc_module_clk_t )(unit -> hal .clk_src ), true), err , TAG , "clock source enable failed" );
161+ #endif
159162#if SOC_LIGHT_SLEEP_SUPPORTED || SOC_DEEP_SLEEP_SUPPORTED
160163 esp_sleep_sub_mode_config (ESP_SLEEP_USE_ADC_TSEN_MONITOR_MODE , true);
161164#endif
@@ -189,9 +192,6 @@ esp_err_t adc_oneshot_config_channel(adc_oneshot_unit_handle_t handle, adc_chann
189192 portENTER_CRITICAL (& rtc_spinlock );
190193 adc_oneshot_hal_channel_config (hal , & cfg , channel );
191194 if (handle -> ulp_mode ) {
192- #if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
193- esp_clk_tree_enable_src ((soc_module_clk_t )(hal -> clk_src ), true);
194- #endif
195195 adc_oneshot_hal_setup (hal , channel );
196196 }
197197 portEXIT_CRITICAL (& rtc_spinlock );
@@ -210,7 +210,7 @@ esp_err_t adc_oneshot_read(adc_oneshot_unit_handle_t handle, adc_channel_t chan,
210210 portENTER_CRITICAL (& rtc_spinlock );
211211
212212#if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
213- esp_clk_tree_enable_src ((soc_module_clk_t )(handle -> hal .clk_src ), true);
213+ ESP_ERROR_CHECK ( esp_clk_tree_enable_src ((soc_module_clk_t )(handle -> hal .clk_src ), true) );
214214#endif
215215 ANALOG_CLOCK_ENABLE ();
216216 adc_oneshot_hal_setup (& (handle -> hal ), chan );
@@ -222,6 +222,9 @@ esp_err_t adc_oneshot_read(adc_oneshot_unit_handle_t handle, adc_channel_t chan,
222222 bool valid = false;
223223 valid = adc_oneshot_hal_convert (& (handle -> hal ), out_raw );
224224 ANALOG_CLOCK_DISABLE ();
225+ #if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
226+ ESP_ERROR_CHECK (esp_clk_tree_enable_src ((soc_module_clk_t )(handle -> hal .clk_src ), false));
227+ #endif
225228
226229 portEXIT_CRITICAL (& rtc_spinlock );
227230 adc_lock_release (handle -> unit_id );
@@ -238,7 +241,7 @@ esp_err_t adc_oneshot_read_isr(adc_oneshot_unit_handle_t handle, adc_channel_t c
238241 portENTER_CRITICAL_SAFE (& rtc_spinlock );
239242
240243#if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
241- esp_clk_tree_enable_src ((soc_module_clk_t )(handle -> hal .clk_src ), true);
244+ ESP_ERROR_CHECK ( esp_clk_tree_enable_src ((soc_module_clk_t )(handle -> hal .clk_src ), true) );
242245#endif
243246 ANALOG_CLOCK_ENABLE ();
244247 adc_oneshot_hal_setup (& (handle -> hal ), chan );
@@ -249,6 +252,9 @@ esp_err_t adc_oneshot_read_isr(adc_oneshot_unit_handle_t handle, adc_channel_t c
249252#endif
250253 adc_oneshot_hal_convert (& (handle -> hal ), out_raw );
251254 ANALOG_CLOCK_DISABLE ();
255+ #if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
256+ ESP_ERROR_CHECK (esp_clk_tree_enable_src ((soc_module_clk_t )(handle -> hal .clk_src ), false));
257+ #endif
252258
253259 portEXIT_CRITICAL_SAFE (& rtc_spinlock );
254260
@@ -271,15 +277,16 @@ esp_err_t adc_oneshot_del_unit(adc_oneshot_unit_handle_t handle)
271277 _lock_release (& s_ctx .mutex );
272278
273279 ESP_LOGD (TAG , "adc unit%" PRId32 " is deleted" , handle -> unit_id );
274- free (handle );
275280
276281 if (ulp_mode == ADC_ULP_MODE_DISABLE ) {
277282 sar_periph_ctrl_adc_oneshot_power_release ();
278283 } else {
279284#if SOC_LIGHT_SLEEP_SUPPORTED || SOC_DEEP_SLEEP_SUPPORTED
280285 esp_sleep_sub_mode_config (ESP_SLEEP_USE_ADC_TSEN_MONITOR_MODE , false);
281286#endif
287+ ESP_ERROR_CHECK (esp_clk_tree_enable_src ((soc_module_clk_t )(handle -> hal .clk_src ), false));
282288 }
289+ free (handle );
283290
284291#if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
285292 //To free the APB_SARADC periph if needed
0 commit comments