@@ -106,12 +106,7 @@ adc_battery_estimation_handle_t adc_battery_estimation_create(adc_battery_estima
106106 ctx -> battery_points_count = config -> battery_points_count ;
107107 }
108108
109- // Use external ADC handle if provided
110- if (config -> external .adc_handle != NULL && config -> external .adc_cali_handle != NULL ) {
111- ctx -> adc_handle = config -> external .adc_handle ;
112- ctx -> adc_cali_handle = config -> external .adc_cali_handle ;
113- ctx -> is_adc_handle_owned = false;
114- } else {
109+ if ((config -> internal .adc_unit < SOC_ADC_PERIPH_NUM ) && ((config -> internal .adc_bitwidth >= SOC_ADC_RTC_MIN_BITWIDTH && config -> internal .adc_bitwidth <= SOC_ADC_RTC_MAX_BITWIDTH ) || config -> internal .adc_bitwidth == ADC_BITWIDTH_DEFAULT )) {
115110 // Create new ADC unit and channel
116111 adc_oneshot_unit_init_cfg_t init_cfg = {
117112 .unit_id = config -> internal .adc_unit ,
@@ -141,6 +136,13 @@ adc_battery_estimation_handle_t adc_battery_estimation_create(adc_battery_estima
141136 ESP_RETURN_ON_FALSE (adc_cali_create_scheme_line_fitting (& cali_config , & ctx -> adc_cali_handle ) == ESP_OK , NULL , TAG , "Failed to create ADC calibration scheme" );
142137#endif
143138 ctx -> is_adc_handle_owned = true;
139+ ESP_LOGI (TAG , "Use internal ADC unit" );
140+ } else {
141+ // Use external ADC handle if provided
142+ ctx -> adc_handle = config -> external .adc_handle ;
143+ ctx -> adc_cali_handle = config -> external .adc_cali_handle ;
144+ ctx -> is_adc_handle_owned = false;
145+ ESP_LOGI (TAG , "Use external ADC handle" );
144146 }
145147
146148 // Validate voltage divider resistors
0 commit comments