mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-17 15:15:02 +00:00
fix(esp_adc): fixed adc continue monitor don't work issue
Closes https://github.com/espressif/esp-idf/issues/14769 Closes https://github.com/espressif/esp-idf/issues/14814
This commit is contained in:
@@ -382,9 +382,6 @@ TEST_CASE("ADC continuous monitor init_deinit", "[adc]")
|
||||
TEST_ESP_OK(adc_del_continuous_monitor(monitor_handle_2));
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, adc_del_continuous_monitor(monitor_handle_3));
|
||||
|
||||
//try register cbs again
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, adc_continuous_monitor_register_event_callbacks(monitor_handle, &monitor_cb, &monitor_cb));
|
||||
|
||||
//try delete it when adc is running but monitor not running
|
||||
TEST_ESP_OK(adc_continuous_start(handle));
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, adc_del_continuous_monitor(monitor_handle));
|
||||
@@ -400,23 +397,7 @@ TEST_CASE("ADC continuous monitor init_deinit", "[adc]")
|
||||
TEST_ESP_OK(adc_continuous_deinit(handle));
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: To run this special feature test case, you need wire ADC channel pin you want to monit
|
||||
* to a wave output pin defined below.
|
||||
*
|
||||
* +---------+
|
||||
* | |
|
||||
* | (adc)|------------+
|
||||
* | | |
|
||||
* | (wave)|------------+
|
||||
* | |
|
||||
* | ESP32 |
|
||||
* +---------+
|
||||
*
|
||||
* or you can connect your signals from signal generator to ESP32 pin which you monitoring
|
||||
**/
|
||||
#define TEST_ADC_CHANNEL ADC_CHANNEL_0 //GPIO_1
|
||||
#define TEST_WAVE_OUT_PIN GPIO_NUM_2 //GPIO_2
|
||||
#define TEST_ADC_CHANNEL ADC_CHANNEL_0
|
||||
static uint32_t m1h_cnt, m1l_cnt;
|
||||
|
||||
bool IRAM_ATTR m1h_cb(adc_monitor_handle_t monitor_handle, const adc_monitor_evt_data_t *event_data, void *user_data)
|
||||
@@ -429,7 +410,7 @@ bool IRAM_ATTR m1l_cb(adc_monitor_handle_t monitor_handle, const adc_monitor_evt
|
||||
m1l_cnt ++;
|
||||
return false;
|
||||
}
|
||||
TEST_CASE("ADC continuous monitor functionary", "[adc][manual][ignore]")
|
||||
TEST_CASE("ADC continuous monitor functionary", "[adc]")
|
||||
{
|
||||
adc_continuous_handle_t handle = NULL;
|
||||
adc_continuous_handle_cfg_t adc_config = {
|
||||
@@ -474,35 +455,40 @@ TEST_CASE("ADC continuous monitor functionary", "[adc][manual][ignore]")
|
||||
};
|
||||
TEST_ESP_OK(adc_new_continuous_monitor(handle, &adc_monitor_cfg, &monitor_handle));
|
||||
TEST_ESP_OK(adc_continuous_monitor_register_event_callbacks(monitor_handle, &monitor_cb, NULL));
|
||||
|
||||
//config a pin to generate wave
|
||||
gpio_config_t gpio_cfg = {
|
||||
.pin_bit_mask = (1ULL << TEST_WAVE_OUT_PIN),
|
||||
.mode = GPIO_MODE_INPUT_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLDOWN_ENABLE,
|
||||
};
|
||||
TEST_ESP_OK(gpio_config(&gpio_cfg));
|
||||
|
||||
TEST_ESP_OK(adc_continuous_monitor_enable(monitor_handle));
|
||||
TEST_ESP_OK(adc_continuous_start(handle));
|
||||
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
vTaskDelay(1000);
|
||||
int adc_io;
|
||||
adc_continuous_channel_to_io(ADC_UNIT_1, TEST_ADC_CHANNEL, &adc_io);
|
||||
printf("Using ADC_CHANNEL_%d on GPIO%d\n", TEST_ADC_CHANNEL, adc_io);
|
||||
|
||||
// check monitor cb
|
||||
printf("%d\t high_cnt %4ld\tlow_cnt %4ld\n", i, m1h_cnt, m1l_cnt);
|
||||
if (gpio_get_level(TEST_WAVE_OUT_PIN)) {
|
||||
// Test with internal gpio pull up/down, detail and order refer to `gpio_pull_mode_t`
|
||||
// pull_up + pull_down to get half ADC convert
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
int pull_mode = i % GPIO_FLOATING;
|
||||
gpio_set_pull_mode(adc_io, pull_mode);
|
||||
vTaskDelay(10); // wait some time for GPIO level be stable
|
||||
m1h_cnt = 0;
|
||||
m1l_cnt = 0;
|
||||
vTaskDelay(1000); //time to count monitor interrupt
|
||||
printf("%d\t %s\t high_cnt %4ld\tlow_cnt %4ld\n", i, (pull_mode == 0) ? "up " : (pull_mode == 1) ? "down" : "mid ", m1h_cnt, m1l_cnt);
|
||||
|
||||
switch (pull_mode) {
|
||||
case GPIO_PULLUP_ONLY:
|
||||
#if !CONFIG_IDF_TARGET_ESP32S2
|
||||
// TEST_ASSERT_UINT32_WITHIN(SOC_ADC_SAMPLE_FREQ_THRES_LOW*0.1, SOC_ADC_SAMPLE_FREQ_THRES_LOW, m1h_cnt);
|
||||
// TEST_ASSERT_LESS_THAN_UINT32(5, m1l_cnt); //Actually, it will still encountered 1~2 times because hardware run very quickly
|
||||
TEST_ASSERT_UINT32_WITHIN(SOC_ADC_SAMPLE_FREQ_THRES_LOW * 0.1, SOC_ADC_SAMPLE_FREQ_THRES_LOW, m1h_cnt);
|
||||
TEST_ASSERT_EQUAL(0, m1l_cnt); //low limit should NOT triggrted when pull_up
|
||||
#endif
|
||||
m1h_cnt = 0;
|
||||
gpio_set_level(TEST_WAVE_OUT_PIN, 0);
|
||||
} else {
|
||||
break;
|
||||
case GPIO_PULLDOWN_ONLY:
|
||||
TEST_ASSERT_UINT32_WITHIN(SOC_ADC_SAMPLE_FREQ_THRES_LOW * 0.1, SOC_ADC_SAMPLE_FREQ_THRES_LOW, m1l_cnt);
|
||||
TEST_ASSERT_LESS_THAN_UINT32(5, m1h_cnt); //Actually, it will still encountered 1~2 times because hardware run very quickly
|
||||
m1l_cnt = 0;
|
||||
gpio_set_level(TEST_WAVE_OUT_PIN, 1);
|
||||
TEST_ASSERT_EQUAL(0, m1h_cnt);
|
||||
break;
|
||||
case GPIO_PULLUP_PULLDOWN:
|
||||
TEST_ASSERT_EQUAL(0, m1h_cnt); //half votage, both limit should NOT triggered
|
||||
TEST_ASSERT_EQUAL(0, m1l_cnt);
|
||||
break;
|
||||
default: printf("unknown gpio pull mode !!!\n");
|
||||
}
|
||||
}
|
||||
TEST_ESP_OK(adc_continuous_stop(handle));
|
||||
|
Reference in New Issue
Block a user