Skip to content

Commit

Permalink
feat(adc): added adc enable debug log config
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce297 committed Nov 1, 2023
1 parent f1e8cfb commit c14d7fb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/esp_adc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions components/esp_adc/adc_continuous.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include <ctype.h>
#include <string.h>
#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"
Expand Down Expand Up @@ -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`");

Expand Down
8 changes: 8 additions & 0 deletions components/esp_adc/adc_oneshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#include <esp_types.h>
#include <sys/lock.h>
#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"
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit c14d7fb

Please sign in to comment.