refactor(adc): Remove sdkconfig dependency in adc hal layer

This commit is contained in:
gaoxu
2025-09-24 10:19:56 +08:00
committed by Gao Xu
parent bf695d08d4
commit 41a6a7daa2
4 changed files with 17 additions and 13 deletions

View File

@@ -122,6 +122,9 @@ esp_err_t adc_oneshot_new_unit(const adc_oneshot_unit_init_cfg_t *init_config, a
.unit = init_config->unit_id, .unit = init_config->unit_id,
.clk_src = clk_src, .clk_src = clk_src,
.clk_src_freq_hz = clk_src_freq_hz, .clk_src_freq_hz = clk_src_freq_hz,
#if CONFIG_ADC_DISABLE_DAC_OUTPUT
.disable_dac_output = true,
#endif
}; };
switch (init_config->ulp_mode) { switch (init_config->ulp_mode) {

View File

@@ -5,7 +5,6 @@
*/ */
#include <sys/param.h> #include <sys/param.h>
#include "sdkconfig.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#include "hal/adc_oneshot_hal.h" #include "hal/adc_oneshot_hal.h"
#include "hal/adc_hal_common.h" #include "hal/adc_hal_common.h"
@@ -13,7 +12,7 @@
#include "hal/assert.h" #include "hal/assert.h"
#include "hal/log.h" #include "hal/log.h"
#if SOC_DAC_SUPPORTED #if SOC_HAS(DAC)
#include "hal/dac_ll.h" #include "hal/dac_ll.h"
#endif #endif
@@ -26,18 +25,18 @@
HAL_LOG_ATTR_TAG(TAG, "adc_hal"); HAL_LOG_ATTR_TAG(TAG, "adc_hal");
#if CONFIG_ADC_DISABLE_DAC_OUTPUT #if SOC_HAS(DAC)
// To disable DAC, workarounds, see this function body to know more // To disable DAC, workarounds, see this function body to know more
static void s_disable_dac(adc_oneshot_hal_ctx_t *hal, adc_channel_t channel); static void s_disable_dac(adc_oneshot_hal_ctx_t *hal, adc_channel_t channel);
#endif #endif
void adc_oneshot_hal_init(adc_oneshot_hal_ctx_t *hal, const adc_oneshot_hal_cfg_t *config) void adc_oneshot_hal_init(adc_oneshot_hal_ctx_t *hal, const adc_oneshot_hal_cfg_t *config)
{ {
hal->unit = config->unit; hal->unit = config->unit;
hal->work_mode = config->work_mode; hal->work_mode = config->work_mode;
hal->clk_src = config->clk_src; hal->clk_src = config->clk_src;
hal->clk_src_freq_hz = config->clk_src_freq_hz; hal->clk_src_freq_hz = config->clk_src_freq_hz;
hal->disable_dac_output = config->disable_dac_output;
} }
void adc_oneshot_hal_channel_config(adc_oneshot_hal_ctx_t *hal, const adc_oneshot_hal_chan_cfg_t *config, adc_channel_t chan) void adc_oneshot_hal_channel_config(adc_oneshot_hal_ctx_t *hal, const adc_oneshot_hal_chan_cfg_t *config, adc_channel_t chan)
@@ -50,13 +49,15 @@ void adc_oneshot_hal_setup(adc_oneshot_hal_ctx_t *hal, adc_channel_t chan)
{ {
adc_unit_t unit = hal->unit; adc_unit_t unit = hal->unit;
#ifdef CONFIG_IDF_TARGET_ESP32 #if SOC_IS(ESP32)
adc_ll_hall_disable(); //Disable other peripherals. adc_ll_hall_disable(); //Disable other peripherals.
adc_ll_amp_disable(); //Currently the LNA is not open, close it by default. adc_ll_amp_disable(); //Currently the LNA is not open, close it by default.
#endif #endif
#if CONFIG_ADC_DISABLE_DAC_OUTPUT #if SOC_HAS(DAC)
s_disable_dac(hal, chan); if (hal->disable_dac_output) {
s_disable_dac(hal, chan);
}
#endif #endif
#if ADC_LL_POWER_MANAGE_SUPPORTED #if ADC_LL_POWER_MANAGE_SUPPORTED
@@ -171,7 +172,7 @@ bool adc_oneshot_hal_convert(adc_oneshot_hal_ctx_t *hal, int *out_raw)
/*--------------------------------------------------------------- /*---------------------------------------------------------------
Workarounds Workarounds
---------------------------------------------------------------*/ ---------------------------------------------------------------*/
#if CONFIG_ADC_DISABLE_DAC_OUTPUT #if SOC_HAS(DAC)
static void s_disable_dac(adc_oneshot_hal_ctx_t *hal, adc_channel_t channel) static void s_disable_dac(adc_oneshot_hal_ctx_t *hal, adc_channel_t channel)
{ {
/** /**
@@ -182,7 +183,7 @@ static void s_disable_dac(adc_oneshot_hal_ctx_t *hal, adc_channel_t channel)
dac_ll_rtc_sync_by_adc(false); dac_ll_rtc_sync_by_adc(false);
} }
#if CONFIG_IDF_TARGET_ESP32 #if SOC_IS(ESP32)
if (hal->unit == ADC_UNIT_2) { if (hal->unit == ADC_UNIT_2) {
if (channel == ADC_CHANNEL_8) { if (channel == ADC_CHANNEL_8) {
dac_ll_power_down(DAC_CHAN_0); // the same as DAC channel 0 dac_ll_power_down(DAC_CHAN_0); // the same as DAC channel 0
@@ -191,7 +192,7 @@ static void s_disable_dac(adc_oneshot_hal_ctx_t *hal, adc_channel_t channel)
dac_ll_power_down(DAC_CHAN_1); dac_ll_power_down(DAC_CHAN_1);
} }
} }
#elif CONFIG_IDF_TARGET_ESP32S2 #elif SOC_IS(ESP32S2)
if (hal->unit == ADC_UNIT_2) { if (hal->unit == ADC_UNIT_2) {
if (channel == ADC_CHANNEL_6) { if (channel == ADC_CHANNEL_6) {
dac_ll_power_down(DAC_CHAN_0); // the same as DAC channel 0 dac_ll_power_down(DAC_CHAN_0); // the same as DAC channel 0
@@ -204,4 +205,4 @@ static void s_disable_dac(adc_oneshot_hal_ctx_t *hal, adc_channel_t channel)
//Nothing needed (DAC is only supported on ESP32 and ESP32S2), add this if future chips needs //Nothing needed (DAC is only supported on ESP32 and ESP32S2), add this if future chips needs
#endif #endif
} }
#endif #endif // SOC_HAS(DAC)

View File

@@ -22,6 +22,7 @@ typedef struct adc_oneshot_hal_cfg_t {
adc_hal_work_mode_t work_mode; ///< ADC work mode adc_hal_work_mode_t work_mode; ///< ADC work mode
adc_oneshot_clk_src_t clk_src; ///< Clock source adc_oneshot_clk_src_t clk_src; ///< Clock source
uint32_t clk_src_freq_hz; ///< Clock source frequency in hz uint32_t clk_src_freq_hz; ///< Clock source frequency in hz
bool disable_dac_output; ///< Whether to disable DAC output, only for chips supporting DAC
} adc_oneshot_hal_cfg_t; } adc_oneshot_hal_cfg_t;
/** /**
@@ -43,6 +44,7 @@ typedef struct adc_oneshot_hal_ctx_t {
adc_oneshot_hal_chan_cfg_t chan_configs[SOC_ADC_MAX_CHANNEL_NUM]; ///< ADC configurations per channel adc_oneshot_hal_chan_cfg_t chan_configs[SOC_ADC_MAX_CHANNEL_NUM]; ///< ADC configurations per channel
adc_oneshot_clk_src_t clk_src; ///< Clock source adc_oneshot_clk_src_t clk_src; ///< Clock source
uint32_t clk_src_freq_hz; ///< Clock source frequency in hz uint32_t clk_src_freq_hz; ///< Clock source frequency in hz
bool disable_dac_output; ///< Whether to disable DAC output, only for chips supporting DAC
} adc_oneshot_hal_ctx_t; } adc_oneshot_hal_ctx_t;
/** /**

View File

@@ -13,7 +13,6 @@ ignores:
- "components/hal/test_apps/**/*" - "components/hal/test_apps/**/*"
- "components/esp_hal*/test_apps/**/*" - "components/esp_hal*/test_apps/**/*"
# the following files should be refactored to remove Kconfig macros # the following files should be refactored to remove Kconfig macros
- "components/hal/adc_oneshot_hal.c"
- "components/hal/twai_hal_sja1000.c" - "components/hal/twai_hal_sja1000.c"
- "components/hal/esp32/include/hal/twai_ll.h" - "components/hal/esp32/include/hal/twai_ll.h"
- "components/hal/esp32/include/hal/uart_ll.h" - "components/hal/esp32/include/hal/uart_ll.h"
@@ -50,7 +49,6 @@ ignores:
- "components/hal/test_apps/**/*" - "components/hal/test_apps/**/*"
- "components/esp_hal*/test_apps/**/*" - "components/esp_hal*/test_apps/**/*"
# the following files should be refactored to remove sdkconfig.h # the following files should be refactored to remove sdkconfig.h
- "components/hal/adc_oneshot_hal.c"
- "components/hal/twai_hal_sja1000.c" - "components/hal/twai_hal_sja1000.c"
- "components/hal/include/hal/twai_types_deprecated.h" - "components/hal/include/hal/twai_types_deprecated.h"
rule: rule: