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
2625
2726HAL_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
3130static void s_disable_dac (adc_oneshot_hal_ctx_t * hal , adc_channel_t channel );
3231#endif
3332
34-
3533void 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
4342void 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 )
175176static 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)
0 commit comments