|
|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
|
|
+ * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
|
|
*
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
*/
|
|
|
@@ -49,7 +49,7 @@ const static char *TAG = "EXAMPLE";
|
|
|
|
|
|
static int adc_raw[2][10];
|
|
|
static int voltage[2][10];
|
|
|
-static bool example_adc_calibration_init(adc_unit_t unit, adc_atten_t atten, adc_cali_handle_t *out_handle);
|
|
|
+static bool example_adc_calibration_init(adc_unit_t unit, adc_channel_t channel, adc_atten_t atten, adc_cali_handle_t *out_handle);
|
|
|
static void example_adc_calibration_deinit(adc_cali_handle_t handle);
|
|
|
|
|
|
|
|
|
@@ -71,8 +71,10 @@ void app_main(void)
|
|
|
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, EXAMPLE_ADC1_CHAN1, &config));
|
|
|
|
|
|
//-------------ADC1 Calibration Init---------------//
|
|
|
- adc_cali_handle_t adc1_cali_handle = NULL;
|
|
|
- bool do_calibration1 = example_adc_calibration_init(ADC_UNIT_1, EXAMPLE_ADC_ATTEN, &adc1_cali_handle);
|
|
|
+ adc_cali_handle_t adc1_cali_chan0_handle = NULL;
|
|
|
+ adc_cali_handle_t adc1_cali_chan1_handle = NULL;
|
|
|
+ bool do_calibration1_chan0 = example_adc_calibration_init(ADC_UNIT_1, EXAMPLE_ADC1_CHAN0, EXAMPLE_ADC_ATTEN, &adc1_cali_chan0_handle);
|
|
|
+ bool do_calibration1_chan1 = example_adc_calibration_init(ADC_UNIT_1, EXAMPLE_ADC1_CHAN1, EXAMPLE_ADC_ATTEN, &adc1_cali_chan1_handle);
|
|
|
|
|
|
|
|
|
#if EXAMPLE_USE_ADC2
|
|
|
@@ -86,7 +88,7 @@ void app_main(void)
|
|
|
|
|
|
//-------------ADC2 Calibration Init---------------//
|
|
|
adc_cali_handle_t adc2_cali_handle = NULL;
|
|
|
- bool do_calibration2 = example_adc_calibration_init(ADC_UNIT_2, EXAMPLE_ADC_ATTEN, &adc2_cali_handle);
|
|
|
+ bool do_calibration2 = example_adc_calibration_init(ADC_UNIT_2, EXAMPLE_ADC2_CHAN0, EXAMPLE_ADC_ATTEN, &adc2_cali_handle);
|
|
|
|
|
|
//-------------ADC2 Config---------------//
|
|
|
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc2_handle, EXAMPLE_ADC2_CHAN0, &config));
|
|
|
@@ -95,16 +97,16 @@ void app_main(void)
|
|
|
while (1) {
|
|
|
ESP_ERROR_CHECK(adc_oneshot_read(adc1_handle, EXAMPLE_ADC1_CHAN0, &adc_raw[0][0]));
|
|
|
ESP_LOGI(TAG, "ADC%d Channel[%d] Raw Data: %d", ADC_UNIT_1 + 1, EXAMPLE_ADC1_CHAN0, adc_raw[0][0]);
|
|
|
- if (do_calibration1) {
|
|
|
- ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc1_cali_handle, adc_raw[0][0], &voltage[0][0]));
|
|
|
+ if (do_calibration1_chan0) {
|
|
|
+ ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc1_cali_chan0_handle, adc_raw[0][0], &voltage[0][0]));
|
|
|
ESP_LOGI(TAG, "ADC%d Channel[%d] Cali Voltage: %d mV", ADC_UNIT_1 + 1, EXAMPLE_ADC1_CHAN0, voltage[0][0]);
|
|
|
}
|
|
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
|
|
|
|
ESP_ERROR_CHECK(adc_oneshot_read(adc1_handle, EXAMPLE_ADC1_CHAN1, &adc_raw[0][1]));
|
|
|
ESP_LOGI(TAG, "ADC%d Channel[%d] Raw Data: %d", ADC_UNIT_1 + 1, EXAMPLE_ADC1_CHAN1, adc_raw[0][1]);
|
|
|
- if (do_calibration1) {
|
|
|
- ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc1_cali_handle, adc_raw[0][1], &voltage[0][1]));
|
|
|
+ if (do_calibration1_chan1) {
|
|
|
+ ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc1_cali_chan1_handle, adc_raw[0][1], &voltage[0][1]));
|
|
|
ESP_LOGI(TAG, "ADC%d Channel[%d] Cali Voltage: %d mV", ADC_UNIT_1 + 1, EXAMPLE_ADC1_CHAN1, voltage[0][1]);
|
|
|
}
|
|
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
|
@@ -122,8 +124,11 @@ void app_main(void)
|
|
|
|
|
|
//Tear Down
|
|
|
ESP_ERROR_CHECK(adc_oneshot_del_unit(adc1_handle));
|
|
|
- if (do_calibration1) {
|
|
|
- example_adc_calibration_deinit(adc1_cali_handle);
|
|
|
+ if (do_calibration1_chan0) {
|
|
|
+ example_adc_calibration_deinit(adc1_cali_chan0_handle);
|
|
|
+ }
|
|
|
+ if (do_calibration1_chan1) {
|
|
|
+ example_adc_calibration_deinit(adc1_cali_chan1_handle);
|
|
|
}
|
|
|
|
|
|
#if EXAMPLE_USE_ADC2
|
|
|
@@ -138,7 +143,7 @@ void app_main(void)
|
|
|
/*---------------------------------------------------------------
|
|
|
ADC Calibration
|
|
|
---------------------------------------------------------------*/
|
|
|
-static bool example_adc_calibration_init(adc_unit_t unit, adc_atten_t atten, adc_cali_handle_t *out_handle)
|
|
|
+static bool example_adc_calibration_init(adc_unit_t unit, adc_channel_t channel, adc_atten_t atten, adc_cali_handle_t *out_handle)
|
|
|
{
|
|
|
adc_cali_handle_t handle = NULL;
|
|
|
esp_err_t ret = ESP_FAIL;
|
|
|
@@ -149,6 +154,7 @@ static bool example_adc_calibration_init(adc_unit_t unit, adc_atten_t atten, adc
|
|
|
ESP_LOGI(TAG, "calibration scheme version is %s", "Curve Fitting");
|
|
|
adc_cali_curve_fitting_config_t cali_config = {
|
|
|
.unit_id = unit,
|
|
|
+ .chan = channel,
|
|
|
.atten = atten,
|
|
|
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
|
|
};
|