@@ -69,17 +69,19 @@ static bool adcDetachBus(void * pin){
6969 return false;
7070 }
7171 adc_handle [adc_unit ].adc_oneshot_handle = NULL ;
72+ if (adc_handle [adc_unit ].adc_cali_handle != NULL ){
7273 #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
73- err = adc_cali_delete_scheme_curve_fitting (adc_handle [adc_unit ].adc_cali_handle );
74- if (err != ESP_OK ){
75- return false;
76- }
74+ err = adc_cali_delete_scheme_curve_fitting (adc_handle [adc_unit ].adc_cali_handle );
75+ if (err != ESP_OK ){
76+ return false;
77+ }
7778 #elif !defined(CONFIG_IDF_TARGET_ESP32H2 )
78- err = adc_cali_delete_scheme_line_fitting (adc_handle [adc_unit ].adc_cali_handle );
79- if (err != ESP_OK ){
80- return false;
81- }
79+ err = adc_cali_delete_scheme_line_fitting (adc_handle [adc_unit ].adc_cali_handle );
80+ if (err != ESP_OK ){
81+ return false;
82+ }
8283 #endif
84+ }
8385 adc_handle [adc_unit ].adc_cali_handle = NULL ;
8486 }
8587 return true;
@@ -220,6 +222,7 @@ esp_err_t __analogInit(uint8_t pin, adc_channel_t channel, adc_unit_t adc_unit){
220222 return err ;
221223 }
222224 }
225+ perimanSetBusDeinit (ESP32_BUS_TYPE_ADC_ONESHOT , adcDetachBus );
223226
224227 if (!perimanSetPinBus (pin , ESP32_BUS_TYPE_ADC_ONESHOT , (void * )(pin + 1 ), adc_unit , channel )){
225228 adcDetachBus ((void * )(pin + 1 ));
@@ -236,7 +239,6 @@ esp_err_t __analogInit(uint8_t pin, adc_channel_t channel, adc_unit_t adc_unit){
236239 log_e ("adc_oneshot_config_channel failed with error: %d" , err );
237240 return err ;
238241 }
239- perimanSetBusDeinit (ESP32_BUS_TYPE_ADC_ONESHOT , adcDetachBus );
240242 return ESP_OK ;
241243}
242244
@@ -377,18 +379,19 @@ static bool adcContinuousDetachBus(void * adc_unit_number){
377379 return false;
378380 }
379381 adc_handle [adc_unit ].adc_continuous_handle = NULL ;
380-
381- #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
382- err = adc_cali_delete_scheme_curve_fitting (adc_handle [adc_unit ].adc_cali_handle );
383- if (err != ESP_OK ){
384- return false;
385- }
382+ if ( adc_handle [ adc_unit ]. adc_cali_handle != NULL ){
383+ #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
384+ err = adc_cali_delete_scheme_curve_fitting (adc_handle [adc_unit ].adc_cali_handle );
385+ if (err != ESP_OK ){
386+ return false;
387+ }
386388 #elif !defined(CONFIG_IDF_TARGET_ESP32H2 )
387- err = adc_cali_delete_scheme_line_fitting (adc_handle [adc_unit ].adc_cali_handle );
388- if (err != ESP_OK ){
389- return false;
390- }
389+ err = adc_cali_delete_scheme_line_fitting (adc_handle [adc_unit ].adc_cali_handle );
390+ if (err != ESP_OK ){
391+ return false;
392+ }
391393 #endif
394+ }
392395 adc_handle [adc_unit ].adc_cali_handle = NULL ;
393396
394397 //set all used pins to INIT state
0 commit comments