From c14d7fbb17b00a28b21ee8e19e451e6ab7f6801e Mon Sep 17 00:00:00 2001 From: gaoxu Date: Wed, 1 Nov 2023 15:06:20 +0800 Subject: [PATCH] feat(adc): added adc enable debug log config --- components/esp_adc/Kconfig | 9 +++++++++ components/esp_adc/adc_continuous.c | 8 ++++++++ components/esp_adc/adc_oneshot.c | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/components/esp_adc/Kconfig b/components/esp_adc/Kconfig index 16ca097037..24faca9919 100644 --- a/components/esp_adc/Kconfig +++ b/components/esp_adc/Kconfig @@ -76,4 +76,13 @@ menu "ADC and ADC Calibration" If you stick to this, you can enable this option to force use ADC2 under above conditions. For more details, you can search for errata on espressif website. + + config ADC_ENABLE_DEBUG_LOG + bool "Enable ADC debug log" + default n + help + Wether to enable the debug log message for ADC driver. + Note that this option only controls the ADC driver log, will not affect other drivers. + + note: This cannot be used in the ADC legacy driver. endmenu diff --git a/components/esp_adc/adc_continuous.c b/components/esp_adc/adc_continuous.c index a52799210d..d954e880ea 100644 --- a/components/esp_adc/adc_continuous.c +++ b/components/esp_adc/adc_continuous.c @@ -9,6 +9,11 @@ #include #include #include "sdkconfig.h" +#if CONFIG_ADC_ENABLE_DEBUG_LOG +// The local log level must be defined before including esp_log.h +// Set the maximum log level for this source file +#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG +#endif #include "esp_intr_alloc.h" #include "esp_log.h" #include "esp_pm.h" @@ -102,6 +107,9 @@ static esp_err_t adc_digi_gpio_init(adc_unit_t adc_unit, uint16_t channel_mask) esp_err_t adc_continuous_new_handle(const adc_continuous_handle_cfg_t *hdl_config, adc_continuous_handle_t *ret_handle) { +#if CONFIG_ADC_ENABLE_DEBUG_LOG + esp_log_level_set(ADC_TAG, ESP_LOG_DEBUG); +#endif esp_err_t ret = ESP_OK; ESP_RETURN_ON_FALSE((hdl_config->conv_frame_size % SOC_ADC_DIGI_DATA_BYTES_PER_CONV == 0), ESP_ERR_INVALID_ARG, ADC_TAG, "conv_frame_size should be in multiples of `SOC_ADC_DIGI_DATA_BYTES_PER_CONV`"); diff --git a/components/esp_adc/adc_oneshot.c b/components/esp_adc/adc_oneshot.c index dba3fd6b1c..80f2711489 100644 --- a/components/esp_adc/adc_oneshot.c +++ b/components/esp_adc/adc_oneshot.c @@ -7,6 +7,11 @@ #include #include #include "sdkconfig.h" +#if CONFIG_ADC_ENABLE_DEBUG_LOG +// The local log level must be defined before including esp_log.h +// Set the maximum log level for this source file +#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG +#endif #include "stdatomic.h" #include "esp_log.h" #include "esp_check.h" @@ -69,6 +74,9 @@ esp_err_t adc_oneshot_channel_to_io(adc_unit_t unit_id, adc_channel_t channel, i esp_err_t adc_oneshot_new_unit(const adc_oneshot_unit_init_cfg_t *init_config, adc_oneshot_unit_handle_t *ret_unit) { +#if CONFIG_ADC_ENABLE_DEBUG_LOG + esp_log_level_set(TAG, ESP_LOG_DEBUG); +#endif esp_err_t ret = ESP_OK; adc_oneshot_unit_ctx_t *unit = NULL; ESP_GOTO_ON_FALSE(init_config && ret_unit, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument: null pointer");