Skip to content

Commit 030a332

Browse files
committed
Merge branch 'fix/fix_adc_batt_est_external_judge' into 'master'
fix(adc_battery_est): fix internal/external judgment during creation See merge request ae_group/esp-iot-solution!1392
2 parents 63e9a51 + d432f31 commit 030a332

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

components/sensors/battery_fuel_gauge/adc_battery_estimation/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ChangeLog
22

3+
## v0.2.1 - 2025-10-9
4+
5+
### Bug Fix:
6+
7+
* Fix ADC internal/external judge via unit & bitwidth (avoid union issue)
8+
39
## v0.2.0 - 2025-6-18
410

511
* Add software estimation for charging state

components/sensors/battery_fuel_gauge/adc_battery_estimation/adc_battery_estimation.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

components/sensors/battery_fuel_gauge/adc_battery_estimation/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 0.2.0
1+
version: 0.2.1
22
description: Battery capacity estimation based on ADC
33
url: https://github.com/espressif/esp-iot-solution/tree/master/components/sensors/battery_fuel_gauge/adc_battery_estimation
44
repository: https://github.com/espressif/esp-iot-solution.git

0 commit comments

Comments
 (0)