Skip to content

Commit 26e77d1

Browse files
committed
Merge branch 'refactor/adc_hal_no_config' into 'master'
refactor(adc): Remove sdkconfig dependency in adc hal layer Closes IDF-13624 See merge request espressif/esp-idf!42015
2 parents 056c404 + 41a6a7d commit 26e77d1

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

components/esp_adc/adc_oneshot.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ esp_err_t adc_oneshot_new_unit(const adc_oneshot_unit_init_cfg_t *init_config, a
122122
.unit = init_config->unit_id,
123123
.clk_src = clk_src,
124124
.clk_src_freq_hz = clk_src_freq_hz,
125+
#if CONFIG_ADC_DISABLE_DAC_OUTPUT
126+
.disable_dac_output = true,
127+
#endif
125128
};
126129

127130
switch (init_config->ulp_mode) {

components/hal/adc_oneshot_hal.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
*/
66

77
#include <sys/param.h>
8-
#include "sdkconfig.h"
98
#include "soc/soc_caps.h"
109
#include "hal/adc_oneshot_hal.h"
1110
#include "hal/adc_hal_common.h"
1211
#include "hal/adc_ll.h"
1312
#include "hal/assert.h"
1413
#include "hal/log.h"
1514

16-
#if SOC_DAC_SUPPORTED
15+
#if SOC_HAS(DAC)
1716
#include "hal/dac_ll.h"
1817
#endif
1918

@@ -26,18 +25,18 @@
2625

2726
HAL_LOG_ATTR_TAG(TAG, "adc_hal");
2827

29-
#if CONFIG_ADC_DISABLE_DAC_OUTPUT
28+
#if SOC_HAS(DAC)
3029
// To disable DAC, workarounds, see this function body to know more
3130
static void s_disable_dac(adc_oneshot_hal_ctx_t *hal, adc_channel_t channel);
3231
#endif
3332

34-
3533
void adc_oneshot_hal_init(adc_oneshot_hal_ctx_t *hal, const adc_oneshot_hal_cfg_t *config)
3634
{
3735
hal->unit = config->unit;
3836
hal->work_mode = config->work_mode;
3937
hal->clk_src = config->clk_src;
4038
hal->clk_src_freq_hz = config->clk_src_freq_hz;
39+
hal->disable_dac_output = config->disable_dac_output;
4140
}
4241

4342
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)
5049
{
5150
adc_unit_t unit = hal->unit;
5251

53-
#ifdef CONFIG_IDF_TARGET_ESP32
52+
#if SOC_IS(ESP32)
5453
adc_ll_hall_disable(); //Disable other peripherals.
5554
adc_ll_amp_disable(); //Currently the LNA is not open, close it by default.
5655
#endif
5756

58-
#if CONFIG_ADC_DISABLE_DAC_OUTPUT
59-
s_disable_dac(hal, chan);
57+
#if SOC_HAS(DAC)
58+
if (hal->disable_dac_output) {
59+
s_disable_dac(hal, chan);
60+
}
6061
#endif
6162

6263
#if ADC_LL_POWER_MANAGE_SUPPORTED
@@ -171,7 +172,7 @@ bool adc_oneshot_hal_convert(adc_oneshot_hal_ctx_t *hal, int *out_raw)
171172
/*---------------------------------------------------------------
172173
Workarounds
173174
---------------------------------------------------------------*/
174-
#if CONFIG_ADC_DISABLE_DAC_OUTPUT
175+
#if SOC_HAS(DAC)
175176
static void s_disable_dac(adc_oneshot_hal_ctx_t *hal, adc_channel_t channel)
176177
{
177178
/**
@@ -182,7 +183,7 @@ static void s_disable_dac(adc_oneshot_hal_ctx_t *hal, adc_channel_t channel)
182183
dac_ll_rtc_sync_by_adc(false);
183184
}
184185

185-
#if CONFIG_IDF_TARGET_ESP32
186+
#if SOC_IS(ESP32)
186187
if (hal->unit == ADC_UNIT_2) {
187188
if (channel == ADC_CHANNEL_8) {
188189
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)
191192
dac_ll_power_down(DAC_CHAN_1);
192193
}
193194
}
194-
#elif CONFIG_IDF_TARGET_ESP32S2
195+
#elif SOC_IS(ESP32S2)
195196
if (hal->unit == ADC_UNIT_2) {
196197
if (channel == ADC_CHANNEL_6) {
197198
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)
204205
//Nothing needed (DAC is only supported on ESP32 and ESP32S2), add this if future chips needs
205206
#endif
206207
}
207-
#endif
208+
#endif // SOC_HAS(DAC)

components/hal/include/hal/adc_oneshot_hal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typedef struct adc_oneshot_hal_cfg_t {
2222
adc_hal_work_mode_t work_mode; ///< ADC work mode
2323
adc_oneshot_clk_src_t clk_src; ///< Clock source
2424
uint32_t clk_src_freq_hz; ///< Clock source frequency in hz
25+
bool disable_dac_output; ///< Whether to disable DAC output, only for chips supporting DAC
2526
} adc_oneshot_hal_cfg_t;
2627

2728
/**
@@ -43,6 +44,7 @@ typedef struct adc_oneshot_hal_ctx_t {
4344
adc_oneshot_hal_chan_cfg_t chan_configs[SOC_ADC_MAX_CHANNEL_NUM]; ///< ADC configurations per channel
4445
adc_oneshot_clk_src_t clk_src; ///< Clock source
4546
uint32_t clk_src_freq_hz; ///< Clock source frequency in hz
47+
bool disable_dac_output; ///< Whether to disable DAC output, only for chips supporting DAC
4648
} adc_oneshot_hal_ctx_t;
4749

4850
/**

tools/ci/sg_rules/no_kconfig_in_hal_component.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ ignores:
1313
- "components/hal/test_apps/**/*"
1414
- "components/esp_hal*/test_apps/**/*"
1515
# the following files should be refactored to remove Kconfig macros
16-
- "components/hal/adc_oneshot_hal.c"
1716
- "components/hal/twai_hal_sja1000.c"
1817
- "components/hal/esp32/include/hal/twai_ll.h"
1918
- "components/hal/esp32/include/hal/uart_ll.h"
@@ -50,7 +49,6 @@ ignores:
5049
- "components/hal/test_apps/**/*"
5150
- "components/esp_hal*/test_apps/**/*"
5251
# the following files should be refactored to remove sdkconfig.h
53-
- "components/hal/adc_oneshot_hal.c"
5452
- "components/hal/twai_hal_sja1000.c"
5553
- "components/hal/include/hal/twai_types_deprecated.h"
5654
rule:

0 commit comments

Comments
 (0)