Unverified Commit b01775ed authored by Jan Procházka's avatar Jan Procházka Committed by GitHub

Fix ADC detach bus calibration handle error when not existing. (#8932)

* Add check if adc calibration habdle exists before deleting

* check also on adc continous detach
parent 57e8e50e
......@@ -69,17 +69,19 @@ static bool adcDetachBus(void * pin){
return false;
}
adc_handle[adc_unit].adc_oneshot_handle = NULL;
if(adc_handle[adc_unit].adc_cali_handle != NULL){
#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
err = adc_cali_delete_scheme_curve_fitting(adc_handle[adc_unit].adc_cali_handle);
if(err != ESP_OK){
return false;
}
err = adc_cali_delete_scheme_curve_fitting(adc_handle[adc_unit].adc_cali_handle);
if(err != ESP_OK){
return false;
}
#elif !defined(CONFIG_IDF_TARGET_ESP32H2)
err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle);
if(err != ESP_OK){
return false;
}
err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle);
if(err != ESP_OK){
return false;
}
#endif
}
adc_handle[adc_unit].adc_cali_handle = NULL;
}
return true;
......@@ -220,6 +222,7 @@ esp_err_t __analogInit(uint8_t pin, adc_channel_t channel, adc_unit_t adc_unit){
return err;
}
}
perimanSetBusDeinit(ESP32_BUS_TYPE_ADC_ONESHOT, adcDetachBus);
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_ADC_ONESHOT, (void *)(pin+1), adc_unit, channel)){
adcDetachBus((void *)(pin+1));
......@@ -236,7 +239,6 @@ esp_err_t __analogInit(uint8_t pin, adc_channel_t channel, adc_unit_t adc_unit){
log_e("adc_oneshot_config_channel failed with error: %d", err);
return err;
}
perimanSetBusDeinit(ESP32_BUS_TYPE_ADC_ONESHOT, adcDetachBus);
return ESP_OK;
}
......@@ -377,18 +379,19 @@ static bool adcContinuousDetachBus(void * adc_unit_number){
return false;
}
adc_handle[adc_unit].adc_continuous_handle = NULL;
#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
err = adc_cali_delete_scheme_curve_fitting(adc_handle[adc_unit].adc_cali_handle);
if(err != ESP_OK){
return false;
}
if(adc_handle[adc_unit].adc_cali_handle != NULL){
#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
err = adc_cali_delete_scheme_curve_fitting(adc_handle[adc_unit].adc_cali_handle);
if(err != ESP_OK){
return false;
}
#elif !defined(CONFIG_IDF_TARGET_ESP32H2)
err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle);
if(err != ESP_OK){
return false;
}
err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle);
if(err != ESP_OK){
return false;
}
#endif
}
adc_handle[adc_unit].adc_cali_handle = NULL;
//set all used pins to INIT state
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment