ci(adc): refactor adc basic oneshot test

This commit is contained in:
gaoxu
2025-04-11 17:04:30 +08:00
parent f56cc82c04
commit b282338c68

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -41,12 +41,16 @@ static const char *TAG_CH[2][10] = {{"ADC1_CH2", "ADC1_CH3"}, {"ADC2_CH0"}};
//ESP32C3 ADC2 oneshot mode is not supported anymore
#define ADC_TEST_ONESHOT_HIGH_LOW_TEST_ADC2 ((SOC_ADC_PERIPH_NUM >= 2) && !CONFIG_IDF_TARGET_ESP32C3)
TEST_CASE("ADC oneshot high/low test", "[adc_oneshot]")
{
static int adc_raw[2][10];
static int adc_raw[2][10];
static adc_oneshot_unit_handle_t adc1_handle;
#if ADC_TEST_ONESHOT_HIGH_LOW_TEST_ADC2
static adc_oneshot_unit_handle_t adc2_handle;
#endif
static void adc_oneshot_init_test(void)
{
//-------------ADC1 Init---------------//
adc_oneshot_unit_handle_t adc1_handle;
adc_oneshot_unit_init_cfg_t init_config1 = {
.unit_id = ADC_UNIT_1,
.ulp_mode = ADC_ULP_MODE_DISABLE,
@@ -55,7 +59,6 @@ TEST_CASE("ADC oneshot high/low test", "[adc_oneshot]")
#if ADC_TEST_ONESHOT_HIGH_LOW_TEST_ADC2
//-------------ADC2 Init---------------//
adc_oneshot_unit_handle_t adc2_handle;
adc_oneshot_unit_init_cfg_t init_config2 = {
.unit_id = ADC_UNIT_2,
.ulp_mode = ADC_ULP_MODE_DISABLE,
@@ -77,7 +80,10 @@ TEST_CASE("ADC oneshot high/low test", "[adc_oneshot]")
//-------------ADC2 TEST Channel 0 Config---------------//
TEST_ESP_OK(adc_oneshot_config_channel(adc2_handle, ADC2_TEST_CHAN0, &config));
#endif //#if ADC_TEST_ONESHOT_HIGH_LOW_TEST_ADC2
}
static void adc_oneshot_read_test(void)
{
test_adc_set_io_level(ADC_UNIT_1, ADC1_TEST_CHAN0, 0);
TEST_ESP_OK(adc_oneshot_read(adc1_handle, ADC1_TEST_CHAN0, &adc_raw[0][0]));
ESP_LOGI(TAG_CH[0][0], "low raw data: %d", adc_raw[0][0]);
@@ -111,13 +117,30 @@ TEST_CASE("ADC oneshot high/low test", "[adc_oneshot]")
ESP_LOGI(TAG_CH[1][0], "high raw data: %d", adc_raw[1][0]);
TEST_ASSERT_INT_WITHIN(ADC_TEST_HIGH_THRESH, ADC_TEST_HIGH_VAL, adc_raw[1][0]);
#endif //#if ADC_TEST_ONESHOT_HIGH_LOW_TEST_ADC2
}
static void adc_oneshot_deinit_test(void)
{
TEST_ESP_OK(adc_oneshot_del_unit(adc1_handle));
#if ADC_TEST_ONESHOT_HIGH_LOW_TEST_ADC2
TEST_ESP_OK(adc_oneshot_del_unit(adc2_handle));
#endif //#if ADC_TEST_ONESHOT_HIGH_LOW_TEST_ADC2
}
TEST_CASE("ADC oneshot basic test", "[adc_oneshot]")
{
adc_oneshot_init_test();
adc_oneshot_read_test();
printf("ADC onshot re-read: \n");
adc_oneshot_read_test();
adc_oneshot_deinit_test();
printf("ADC onshot re-start: \n");
adc_oneshot_init_test();
adc_oneshot_read_test();
adc_oneshot_deinit_test();
}
TEST_CASE("ADC oneshot stress test that get zero even if convent done", "[adc_oneshot]")
{
//There is a hardware limitation. After ADC get DONE signal, it still need a delay to synchronize ADC raw data or it may get zero even if getting DONE signal.