From dad79f0464fcaeb066d614669028b825d3785a3d Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Thu, 15 Jan 2026 15:36:24 +0100 Subject: [PATCH] feat(lp_adc): Set LP ADC calibration params This commit sets the calibration parameters for a a given LP ADC unit and channel to improve the raw LP ADC reading when read from the LP core. The calibration params are set from the HP core. --- .../lp_core/shared/ulp_lp_core_lp_adc_shared.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/components/ulp/lp_core/shared/ulp_lp_core_lp_adc_shared.c b/components/ulp/lp_core/shared/ulp_lp_core_lp_adc_shared.c index 63bc549019..5b2e00ff8d 100644 --- a/components/ulp/lp_core/shared/ulp_lp_core_lp_adc_shared.c +++ b/components/ulp/lp_core/shared/ulp_lp_core_lp_adc_shared.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,6 +10,8 @@ #include "ulp_lp_core_lp_adc_shared.h" #include "hal/adc_types.h" #include "hal/adc_ll.h" +#include "hal/adc_hal_common.h" +#include "esp_private/adc_share_hw_ctrl.h" #define VREF (1100) /* Internal Reference voltage in millivolts (1.1V) */ #define INV_ATTEN_0DB (1000) /* Inverse of 10^0 * 1000 */ @@ -75,8 +77,19 @@ esp_err_t lp_core_lp_adc_config_channel(adc_unit_t unit_id, adc_channel_t channe .bitwidth = chan_config->bitwidth, }; - return (adc_oneshot_config_channel(s_adc1_handle, channel, &config)); + ret = adc_oneshot_config_channel(s_adc_unit_handles[unit_id], channel, &config); + if (ret != ESP_OK) { + return ret; + } + + /* Set the calibration parameters for the ADC unit and channel */ +#if SOC_ADC_CALIBRATION_V1_SUPPORTED + adc_hal_calibration_init(unit_id); + adc_set_hw_calibration_code(unit_id, chan_config->atten); +#endif /* SOC_ADC_CALIBRATION_V1_SUPPORTED */ #endif /* IS_ULP_COCPU */ + + return ESP_OK; } esp_err_t lp_core_lp_adc_read_channel_raw(adc_unit_t unit_id, adc_channel_t channel, int *adc_raw)