@@ -143,15 +143,15 @@ esp_err_t adc_oneshot_new_unit(const adc_oneshot_unit_init_cfg_t *init_config, a
143143
144144 adc_oneshot_hal_init (& (unit -> hal ), & config );
145145
146- #if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
147- //To enable the APB_SARADC periph if needed
148- _lock_acquire (& s_ctx .mutex );
149- s_ctx .apb_periph_ref_cnts ++ ;
150- if (s_ctx .apb_periph_ref_cnts == 1 ) {
151- adc_apb_periph_claim ();
146+ if (ADC_LL_NEED_APB_PERIPH_CLAIM (unit -> unit_id )) {
147+ //To enable the APB_SARADC periph if needed
148+ _lock_acquire (& s_ctx .mutex );
149+ s_ctx .apb_periph_ref_cnts ++ ;
150+ if (s_ctx .apb_periph_ref_cnts == 1 ) {
151+ adc_apb_periph_claim ();
152+ }
153+ _lock_release (& s_ctx .mutex );
152154 }
153- _lock_release (& s_ctx .mutex );
154- #endif
155155
156156 if (init_config -> ulp_mode == ADC_ULP_MODE_DISABLE ) {
157157 sar_periph_ctrl_adc_oneshot_power_acquire ();
@@ -286,18 +286,19 @@ esp_err_t adc_oneshot_del_unit(adc_oneshot_unit_handle_t handle)
286286#endif
287287 ESP_ERROR_CHECK (esp_clk_tree_enable_src ((soc_module_clk_t )(handle -> hal .clk_src ), false));
288288 }
289- free (handle );
290289
291- #if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
292- //To free the APB_SARADC periph if needed
293- _lock_acquire (& s_ctx .mutex );
294- s_ctx .apb_periph_ref_cnts -- ;
295- assert (s_ctx .apb_periph_ref_cnts >= 0 );
296- if (s_ctx .apb_periph_ref_cnts == 0 ) {
297- adc_apb_periph_free ();
290+ if (ADC_LL_NEED_APB_PERIPH_CLAIM (handle -> unit_id )) {
291+ //To free the APB_SARADC periph if needed
292+ _lock_acquire (& s_ctx .mutex );
293+ s_ctx .apb_periph_ref_cnts -- ;
294+ assert (s_ctx .apb_periph_ref_cnts >= 0 );
295+ if (s_ctx .apb_periph_ref_cnts == 0 ) {
296+ adc_apb_periph_free ();
297+ }
298+ _lock_release (& s_ctx .mutex );
298299 }
299- _lock_release ( & s_ctx . mutex );
300- #endif
300+
301+ free ( handle );
301302
302303 return ESP_OK ;
303304}
0 commit comments