← Back to Pull requests

ESP32-S31 DAC support #698

Open
wmrsouza opened this pull request with 744 lines diff across 10 files
View on GitHub
wmrsouza wmrsouza commented on Nov 13, 2026 01:11 UTC
Author

This PR enables DAC support on ESP32-S31 by:

  • Pointing dac_reg.h at DR_REG_LP_DAC_BASE and publish the LP_DAC symbol from dac_struct.h.

  • Adding the ESP32-S31 DAC LL, the private data-source type, and the channel pad map (channel 0 on GPIO4, channel 1 on GPIO5).

  • Setting SOC_DAC_SUPPORTED and the 12-bit, two-channel capabilities.

  • Adding the DAC digital and cosine clock-source enums. The default functional clock is XTAL.

  • On ESP32_LP_DAC_MODULE, reseting the block, selecting that default clock, and enabling it before any LP_DAC access.

  • Building dac_periph.c when CONFIG_DAC_ESP32 is set.
  • Depends on #657

    Diff: 744 lines (+727 / -17) across 10 files Reviewer: raffarost Review duration: 32096m
    All Vouch review confidence checks passed
    Residual risk 0.10 = Change Risk (0.56) × (1 − Review Confidence (0.83)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.56 · 744 lines diff across 10 files
    0.56
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.82 · 5 substantive comment(s)
    0.82
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    82%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.396
    Real PR Conversation Timeline
    14 items
    raffarost raffarost approved these changes on Nov 19, 2026 19:28 UTC
    Approved Reviewer

    Approved these changes.

    marekmatej marekmatej commented on code on Nov 27, 2026 12:30 UTC
    Code Review
    components/esp_hw_support/periph_ctrl.c:1
    @@ -498,6 +501,15 @@ void non_shared_periph_module_enable(int periph)
     #endif
     #endif
     #endif
    +#if defined(ESP32_LP_DAC_MODULE) && SOC_DAC_SUPPORTED
    +#if ESP32_LP_DAC_MODULE >= 100
    +    case ESP32_LP_DAC_MODULE:
    +        dac_ll_reset_register();

    Every other LP peripheral enables clock first and then reset. We should follow the pattern here.

    marekmatej marekmatej commented on code on Nov 27, 2026 13:23 UTC
    Code Review
    components/esp_hal_ana_conv/esp32s31/include/hal/dac_ll.h:1
    @@ -0,0 +1,566 @@
    +/*
    + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
    + *
    + * SPDX-License-Identifier: Apache-2.0
    + */
    +
    +#pragma once
    +
    +#include <stdbool.h>
    +#include <stdint.h>
    +#include "hal/assert.h"
    +#include "soc/dac_struct.h"
    +#include "soc/lp_peri_clkrst_struct.h"
    +#include "soc/clk_tree_defs.h"
    +#include "hal/dac_types.h"
    +#include "hal/dac_types_private.h"
    +
    +#if SOC_DAC_SUPPORTED
    +
    +#define SOC_DAC_DC_VIA_SINTX           1

    those symbols seems they belong to soc_caps.h

    marekmatej marekmatej commented on code on Nov 27, 2026 13:39 UTC
    Code Review
    components/soc/esp32s31/include/soc/soc_caps.h:1
    @@ -158,6 +158,13 @@
     /*!< ADC power control is shared by PWDET, TempSensor */
     #define SOC_ADC_SHARED_POWER                    1
     
    +/*-------------------------- DAC CAPS ----------------------------------------*/
    +#define SOC_DAC_SUPPORTED                       1

    Shouldn't those caps be synced with the HALs esp32s31/include/soc/Kconfig.soc_caps.in too?

    marekmatej marekmatej commented on code on Nov 27, 2026 13:40 UTC
    Code Review
    components/esp_hal_ana_conv/esp32s31/include/hal/dac_ll.h:1
    @@ -0,0 +1,566 @@
    +/*
    + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
    + *
    + * SPDX-License-Identifier: Apache-2.0
    + */
    +
    +#pragma once
    +
    +#include <stdbool.h>
    +#include <stdint.h>
    +#include "hal/assert.h"
    +#include "soc/dac_struct.h"
    +#include "soc/lp_peri_clkrst_struct.h"
    +#include "soc/clk_tree_defs.h"
    +#include "hal/dac_types.h"
    +#include "hal/dac_types_private.h"
    +
    +#if SOC_DAC_SUPPORTED
    +
    +#define SOC_DAC_DC_VIA_SINTX           1
    +#define SOC_DAC_SINTX_HAS_TIMER_TARGET 1
    +#define SOC_DAC_SINTX_LUT_SIGNED       0
    +
    +#ifdef __cplusplus
    +extern "C" {
    +#endif
    +
    +/*---------------------------------------------------------------
    +                    Clock setting
    +---------------------------------------------------------------*/
    +/**
    + * @brief Reset the DAC module
    + */
    +static inline void dac_ll_reset_register(void)
    +{
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_rst_en = 1;
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_rst_en = 0;
    +}
    +
    +/**
    + * @brief Select the source clock of the DAC functional clock (DAC_HS_CLK).
    + *
    + * @note  On ESP32-S31 both the Sintx (cosine) path and the GDMA path share this
    + *        functional clock, so the source applies to both.
    + *
    + * @param clk_src Clock source, see `soc_periph_dac_digi_clk_src_t`
    + */
    +static inline void dac_ll_clk_set_source(soc_periph_dac_digi_clk_src_t clk_src)
    +{
    +    switch (clk_src) {
    +    case DAC_DIGI_CLK_SRC_LP_FAST:
    +        LP_PERI_CLKRST.dac_ctrl.lp_dac_clk_sel = 0;
    +        break;
    +    case DAC_DIGI_CLK_SRC_XTAL:
    +        LP_PERI_CLKRST.dac_ctrl.lp_dac_clk_sel = 1;
    +        break;
    +    default:
    +        HAL_ASSERT(false);
    +    }
    +}
    +
    +/**
    + * @brief Enable or disable the DAC functional clock (DAC_HS_CLK).
    + *
    + * @note  The DAC functional clock (DAC_HS_CLK) gates the whole LP_DAC register block.
    + *        While it is disabled, NONE of the registers under `LP_DAC` can be accessed
    + *        (writes are dropped and reads return invalid data). Therefore this clock must
    + *        be enabled before configuring/accessing any `LP_DAC.*` register.
    + *
    + * @param enable true to enable, false to disable
    + */
    +static inline void dac_ll_clk_enable(bool enable)
    +{
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_clk_en = enable;
    +}
    +
    +/**
    + * @brief Set the divider from the source clock to DAC_HS_CLK.
    + *
    + * @note  DAC_HS_CLK = clock_source / (hs_div + 1)
    + */
    +static inline void dac_ll_clk_set_hs_div(uint8_t hs_div)
    +{
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_div_num = hs_div;
    +}
    +
    +/**
    + * @brief Get the divider from the source clock to DAC_HS_CLK.
    + */
    +static inline uint8_t dac_ll_clk_get_hs_div(void)
    +{
    +    return LP_PERI_CLKRST.dac_ctrl.lp_dac_div_num;
    +}
    +
    +/**
    + * @brief Set the internal divider from DAC_HS_CLK to the low-speed pad clock (clk_ls).
    + *
    + * @note  clk_ls = DAC_HS_CLK / (ls_div + 1)
    + */
    +static inline void dac_ll_clk_set_ls_div(uint16_t ls_div)
    +{
    +    LP_DAC.pad_cfg.div_num = ls_div;
    +}
    +
    +/**
    + * @brief Get the divider from DAC_HS_CLK to the low-speed pad clock (clk_ls).
    + */
    +static inline uint16_t dac_ll_clk_get_ls_div(void)
    +{
    +    return LP_DAC.pad_cfg.div_num;
    +}
    +
    +/*---------------------------------------------------------------
    +                    DAC pad setting
    +---------------------------------------------------------------*/
    +/**
    + * @brief Power on the DAC pad and start outputting.
    + *
    + * @param channel DAC channel num
    + */
    +static inline void dac_ll_pad_power_on(dac_channel_t channel)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.xpd_pad_0 = 1;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.xpd_pad_1 = 1;
    +    }
    +}
    +
    +/**
    + * @brief Power down the DAC pad and stop outputting.
    + *
    + * @param channel DAC channel num
    + */
    +static inline void dac_ll_pad_power_down(dac_channel_t channel)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.xpd_pad_0 = 0;
    +        LP_DAC.pad_cfg.dbuf_ls_pad_0 = 0;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.xpd_pad_1 = 0;
    +        LP_DAC.pad_cfg.dbuf_ls_pad_1 = 0;
    +    }
    +}
    +
    +/**
    + * @brief Select the internal data source that drives a DAC channel output.
    + *
    + * @note  The hardware data-select bit only distinguishes DMA vs Sintx. Both
    + *        `DAC_DATA_SOURCE_COSINE` and `DAC_DATA_SOURCE_DIRECT` map onto the Sintx path.
    + *
    + * @param channel DAC channel num
    + * @param source  Data source, see `dac_data_source_t`
    + */
    +static inline void dac_ll_pad_set_data_source(dac_channel_t channel, dac_data_source_t source)
    +{
    +    const uint32_t sel = (source == DAC_DATA_SOURCE_DMA) ? 1 : 0;
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.data_output_cfg.pad_0_data_sel = sel;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.data_output_cfg.pad_1_data_sel = sel;
    +    }
    +}
    +
    +/**
    + * @brief Set the DAC output code through the Sintx (direct software output) path.
    + *
    + * @param channel DAC channel num
    + * @param code    Output code. Bit width depends on the DAC resolution and speed mode.
    + */
    +__attribute__((always_inline))
    +static inline void dac_ll_pad_set_output_code(dac_channel_t channel, uint16_t code)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.sintx_data.dc_1 = code;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.sintx_data.dc_2 = code;
    +    }
    +}
    +
    +/**
    + * @brief Enable or disable the high-speed mode of a DAC pad.
    + *
    + * @param channel  DAC channel num
    + * @param enable   true to enable, false to disable
    + */
    +static inline void dac_ll_pad_enable_high_speed(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.hs_mode_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.hs_mode_pad_1 = enable;
    +    }
    +}
    +
    +/**
    + * @brief Enable or bypass the analog output buffer of a DAC pad (low-speed mode only).
    + *
    + * @param channel DAC channel num
    + * @param enable  true: enable the analog buffer; false: bypass it
    + */
    +static inline void dac_ll_pad_enable_buffer(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.dbuf_ls_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.dbuf_ls_pad_1 = enable;
    +    }
    +}
    +
    +/**
    + * @brief Select the input code range supported by the DAC analog buffer.
    + *
    + * @note Only applicable in low-speed mode with the analog buffer enabled.
    + * @note Full-code-range mode reduces the output voltage swing
    + *
    + * @param channel DAC channel num
    + * @param full_code_range true: support input codes 0 to 4095 with reduced output voltage swing;
    + *                        false: use input codes 248 to 3848 for linear operation with wider output
    + *                        voltage swing. Codes outside this range may cause output saturation.
    + */
    +static inline void dac_ll_pad_set_buffer_code_range(dac_channel_t channel, bool full_code_range)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.dbuf_range_ls_pad_0 = full_code_range;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.dbuf_range_ls_pad_1 = full_code_range;
    +    }
    +}
    +
    +/*---------------------------------------------------------------
    +                    Controller setting
    +---------------------------------------------------------------*/
    +
    +/**
    + * @brief Enable/disable the synchronization operation between ADC and DAC.
    + *
    + * @note  ESP32-S31 has no equivalent register bit, keep this as a no-op for API compatibility.
    + */
    +static inline void dac_ll_sync_by_adc(bool enable)
    +{
    +    (void)enable;
    +}
    +
    +/**
    + * @brief Enable/disable the ADC mux of a DAC pad.
    + *
    + * @note  For internal testing only.
    + *
    + * @param channel DAC channel num
    + * @param enable  true to enable, false to disable
    + */
    +static inline void dac_ll_enable_adc_mux(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.en_adc_mux_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.en_adc_mux_pad_1 = enable;
    +    }
    +}
    +
    +/*---------------------------------------------------------------
    +                    Sample-hold setting
    +---------------------------------------------------------------*/
    +
    +/**
    + * @brief Enable/disable the sample-hold mode of a DAC pad.
    + *
    + * @param channel DAC channel num
    + * @param enable  true to enable, false to disable
    + */
    +static inline void dac_ll_sh_enable(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.dsamp_ls_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.dsamp_ls_pad_1 = enable;
    +    }
    +}
    +
    +/**
    + * @brief Set the sample-phase wait cycle.
    + *
    + * @note Clocked by clk_ls.
    + *
    + * @param channel DAC channel num
    + * @param cycle   Wait cycles
    + */
    +static inline void dac_ll_sh_set_sample_cycle(dac_channel_t channel, uint16_t cycle)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.sample_wait_cfg.wait_target_sample_pad_0 = cycle;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.sample_wait_cfg.wait_target_sample_pad_1 = cycle;
    +    }
    +}
    +
    +/**
    + * @brief Set the hold-phase wait cycle.
    + *
    + * @note Clocked by clk_ls.
    + *
    + * @param channel DAC channel num
    + * @param cycle   Wait cycles
    + */
    +static inline void dac_ll_sh_set_hold_cycle(dac_channel_t channel, uint16_t cycle)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.hold_wait_cfg.wait_target_hold_pad_0 = cycle;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.hold_wait_cfg.wait_target_hold_pad_1 = cycle;
    +    }
    +}
    +
    +/**
    + * @brief Set the refresh-phase wait cycle.
    + *
    + * @note Clocked by clk_ls.
    + *
    + * @param channel DAC channel num
    + * @param cycle   Wait cycles
    + */
    +static inline void dac_ll_sh_set_refresh_cycle(dac_channel_t channel, uint16_t cycle)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.refresh_wait_cfg.wait_target_refresh_pad_0 = cycle;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.refresh_wait_cfg.wait_target_refresh_pad_1 = cycle;
    +    }
    +}
    +
    +/*---------------------------------------------------------------
    +                    Calibration setting
    +---------------------------------------------------------------*/
    +/**
    + * @brief Enable/disable the calibration of a DAC pad buffer.
    + *
    + * @note Valid only when the analog buffer is enabled.
    + *
    + * @param channel DAC channel num
    + * @param enable  true to enable, false to disable
    + */
    +static inline void dac_ll_cali_enable(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.dcal_ls_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.dcal_ls_pad_1 = enable;
    +    }
    +}
    +
    +/**
    + * @brief Get the calibration comparison result of a DAC pad buffer.
    + *
    + * @param channel DAC channel num
    + * @return Calibration comparison result
    + */
    +static inline bool dac_ll_cali_get_comparison_result(dac_channel_t channel)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        return LP_DAC.cali.cali_out_pad_0;
    +    } else if (channel == DAC_CHAN_1) {
    +        return LP_DAC.cali.cali_out_pad_1;
    +    } else {
    +        HAL_ASSERT(false);
    +        return false;
    +    }
    +}
    +
    +/**
    + * @brief Set the calibration result of a DAC pad buffer.
    + *
    + * @param channel DAC channel num
    + * @param result Calibration result, 12-bit
    + */
    +static inline void dac_ll_cali_set_result(dac_channel_t channel, uint16_t result)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.cali_result.cali_result_pad_0 = result;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.cali_result.cali_result_pad_1 = result;
    +    }
    +}
    +
    +/**
    + * @brief Get the calibration result of a DAC pad buffer.
    + *
    + * @param channel DAC channel num
    + * @return Calibration result, 12-bit
    + */
    +static inline uint16_t dac_ll_cali_get_result(dac_channel_t channel)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        return LP_DAC.cali_result.cali_result_pad_0;
    +    } else if (channel == DAC_CHAN_1) {
    +        return LP_DAC.cali_result.cali_result_pad_1;
    +    } else {
    +        HAL_ASSERT(false);
    +        return 0;
    +    }
    +}
    +
    +/*---------------------------------------------------------------
    +                    Cosine (Sintx) path setting
    +---------------------------------------------------------------*/
    +/**
    + * @brief Enable the cosine wave generator (Sintx tone mode).
    + *
    + * @note  Starts the phase accumulator and the Sintx timer that pushes samples to the pad.
    + */
    +static inline void dac_ll_cw_enable_tone(void)
    +{
    +    LP_DAC.sintx_cfg.sw_tone = 1;
    +    LP_DAC.sintx_timer_cfg.sintx_timer_en = 1;
    +}
    +
    +/**
    + * @brief Enable the Sintx generator for direct (DC) software output.
    + *
    + * @note  The DC value written by `dac_ll_pad_set_output_code()` is pushed to the pad
    + *        by the Sintx timer; the phase accumulator is left disabled.
    + */
    +static inline void dac_ll_cw_enable_dc(void)
    +{
    +    LP_DAC.sintx_cfg.sw_tone = 0;
    +    LP_DAC.sintx_timer_cfg.sintx_timer_en = 1;
    +}
    +
    +/**
    + * @brief Disable the cosine wave / Sintx generator.
    + */
    +static inline void dac_ll_cw_disable(void)
    +{
    +    LP_DAC.sintx_cfg.sw_tone = 0;
    +    LP_DAC.sintx_timer_cfg.sintx_timer_en = 0;
    +}
    +
    +/**
    + * @brief Set the timer target of the cosine wave (Sintx) generator timer.
    + *
    + * @note timer_target: 24-bit, range 0 ~ 0xFFFFFF.
    + *       Effective divider is timer_target, except that 0 is treated as 1
    + *       (i.e. dac_hs_clk / max(timer_target, 1)).
    + */
    +static inline void dac_ll_cw_set_timer_target(uint32_t timer_target)
    +{
    +    LP_DAC.sintx_timer_cfg.sintx_timer_target = timer_target;
    +}
    +
    +/**
    + * @brief Set the step increment of the cosine wave generator.
    + *
    + * @note A 16-bit phase accumulator freq_acc is incremented by DAC_SW_FSTEP on every Sintx trigger edge.
    + *       The upper 8 bits of the accumulator (freq_acc[15:8]) form the angle index freq_idx.
    + * @note sintx output frequency = (dac_hs_clk / max(timer_target, 1)) * (fstep / 2^16)
    + */
    +static inline void dac_ll_cw_set_fstep(uint16_t fstep)
    +{
    +    LP_DAC.sintx_cfg.sw_fstep = fstep;
    +}
    +
    +/**
    + * @brief Set the attenuation of the cosine wave generator output.
    + *
    + * @param channel DAC channel num
    + * @param atten   Attenuation config
    + */
    +static inline void dac_ll_cw_set_atten(dac_channel_t channel, dac_cosine_atten_t atten)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.sintx_cfg.scale_1 = atten;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.sintx_cfg.scale_2 = atten;
    +    }
    +}
    +
    +/**
    + * @brief Set the phase of the cosine wave generator output.
    + *
    + * @note  On ESP32-S31 the sine LUT stores unsigned values, so phase 0/180 maps to 0/1 directly.
    + *
    + * @param channel DAC channel num
    + * @param phase   Phase value
    + */
    +static inline void dac_ll_cw_set_phase(dac_channel_t channel, dac_cosine_phase_t phase)
    +{
    +    uint8_t dac_inv = phase == DAC_COSINE_PHASE_180 ? 0x01 : 0x00;
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.sintx_cfg.inv_1 = dac_inv;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.sintx_cfg.inv_2 = dac_inv;
    +    }
    +}
    +
    +/**
    + * @brief Set the offset of the cosine wave generator output.
    + *
    + * @note  On ESP32-S31 the offset is a 12-bit unsigned value added to the scaled sample with saturation.
    + *
    + * @param channel DAC channel num
    + * @param offset  DC offset. Range: 0 ~ 4095 (LS) or 0 ~ 1023 (HS)
    + */
    +static inline void dac_ll_cw_set_offset(dac_channel_t channel, int16_t offset)

    should the offset be unsigned number?

    wmrsouza wmrsouza commented on code on Nov 30, 2026 22:36 UTC
    Code Review
    components/esp_hal_ana_conv/esp32s31/include/hal/dac_ll.h:1
    @@ -0,0 +1,566 @@
    +/*
    + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
    + *
    + * SPDX-License-Identifier: Apache-2.0
    + */
    +
    +#pragma once
    +
    +#include <stdbool.h>
    +#include <stdint.h>
    +#include "hal/assert.h"
    +#include "soc/dac_struct.h"
    +#include "soc/lp_peri_clkrst_struct.h"
    +#include "soc/clk_tree_defs.h"
    +#include "hal/dac_types.h"
    +#include "hal/dac_types_private.h"
    +
    +#if SOC_DAC_SUPPORTED
    +
    +#define SOC_DAC_DC_VIA_SINTX           1
    +#define SOC_DAC_SINTX_HAS_TIMER_TARGET 1
    +#define SOC_DAC_SINTX_LUT_SIGNED       0
    +
    +#ifdef __cplusplus
    +extern "C" {
    +#endif
    +
    +/*---------------------------------------------------------------
    +                    Clock setting
    +---------------------------------------------------------------*/
    +/**
    + * @brief Reset the DAC module
    + */
    +static inline void dac_ll_reset_register(void)
    +{
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_rst_en = 1;
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_rst_en = 0;
    +}
    +
    +/**
    + * @brief Select the source clock of the DAC functional clock (DAC_HS_CLK).
    + *
    + * @note  On ESP32-S31 both the Sintx (cosine) path and the GDMA path share this
    + *        functional clock, so the source applies to both.
    + *
    + * @param clk_src Clock source, see `soc_periph_dac_digi_clk_src_t`
    + */
    +static inline void dac_ll_clk_set_source(soc_periph_dac_digi_clk_src_t clk_src)
    +{
    +    switch (clk_src) {
    +    case DAC_DIGI_CLK_SRC_LP_FAST:
    +        LP_PERI_CLKRST.dac_ctrl.lp_dac_clk_sel = 0;
    +        break;
    +    case DAC_DIGI_CLK_SRC_XTAL:
    +        LP_PERI_CLKRST.dac_ctrl.lp_dac_clk_sel = 1;
    +        break;
    +    default:
    +        HAL_ASSERT(false);
    +    }
    +}
    +
    +/**
    + * @brief Enable or disable the DAC functional clock (DAC_HS_CLK).
    + *
    + * @note  The DAC functional clock (DAC_HS_CLK) gates the whole LP_DAC register block.
    + *        While it is disabled, NONE of the registers under `LP_DAC` can be accessed
    + *        (writes are dropped and reads return invalid data). Therefore this clock must
    + *        be enabled before configuring/accessing any `LP_DAC.*` register.
    + *
    + * @param enable true to enable, false to disable
    + */
    +static inline void dac_ll_clk_enable(bool enable)
    +{
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_clk_en = enable;
    +}
    +
    +/**
    + * @brief Set the divider from the source clock to DAC_HS_CLK.
    + *
    + * @note  DAC_HS_CLK = clock_source / (hs_div + 1)
    + */
    +static inline void dac_ll_clk_set_hs_div(uint8_t hs_div)
    +{
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_div_num = hs_div;
    +}
    +
    +/**
    + * @brief Get the divider from the source clock to DAC_HS_CLK.
    + */
    +static inline uint8_t dac_ll_clk_get_hs_div(void)
    +{
    +    return LP_PERI_CLKRST.dac_ctrl.lp_dac_div_num;
    +}
    +
    +/**
    + * @brief Set the internal divider from DAC_HS_CLK to the low-speed pad clock (clk_ls).
    + *
    + * @note  clk_ls = DAC_HS_CLK / (ls_div + 1)
    + */
    +static inline void dac_ll_clk_set_ls_div(uint16_t ls_div)
    +{
    +    LP_DAC.pad_cfg.div_num = ls_div;
    +}
    +
    +/**
    + * @brief Get the divider from DAC_HS_CLK to the low-speed pad clock (clk_ls).
    + */
    +static inline uint16_t dac_ll_clk_get_ls_div(void)
    +{
    +    return LP_DAC.pad_cfg.div_num;
    +}
    +
    +/*---------------------------------------------------------------
    +                    DAC pad setting
    +---------------------------------------------------------------*/
    +/**
    + * @brief Power on the DAC pad and start outputting.
    + *
    + * @param channel DAC channel num
    + */
    +static inline void dac_ll_pad_power_on(dac_channel_t channel)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.xpd_pad_0 = 1;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.xpd_pad_1 = 1;
    +    }
    +}
    +
    +/**
    + * @brief Power down the DAC pad and stop outputting.
    + *
    + * @param channel DAC channel num
    + */
    +static inline void dac_ll_pad_power_down(dac_channel_t channel)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.xpd_pad_0 = 0;
    +        LP_DAC.pad_cfg.dbuf_ls_pad_0 = 0;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.xpd_pad_1 = 0;
    +        LP_DAC.pad_cfg.dbuf_ls_pad_1 = 0;
    +    }
    +}
    +
    +/**
    + * @brief Select the internal data source that drives a DAC channel output.
    + *
    + * @note  The hardware data-select bit only distinguishes DMA vs Sintx. Both
    + *        `DAC_DATA_SOURCE_COSINE` and `DAC_DATA_SOURCE_DIRECT` map onto the Sintx path.
    + *
    + * @param channel DAC channel num
    + * @param source  Data source, see `dac_data_source_t`
    + */
    +static inline void dac_ll_pad_set_data_source(dac_channel_t channel, dac_data_source_t source)
    +{
    +    const uint32_t sel = (source == DAC_DATA_SOURCE_DMA) ? 1 : 0;
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.data_output_cfg.pad_0_data_sel = sel;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.data_output_cfg.pad_1_data_sel = sel;
    +    }
    +}
    +
    +/**
    + * @brief Set the DAC output code through the Sintx (direct software output) path.
    + *
    + * @param channel DAC channel num
    + * @param code    Output code. Bit width depends on the DAC resolution and speed mode.
    + */
    +__attribute__((always_inline))
    +static inline void dac_ll_pad_set_output_code(dac_channel_t channel, uint16_t code)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.sintx_data.dc_1 = code;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.sintx_data.dc_2 = code;
    +    }
    +}
    +
    +/**
    + * @brief Enable or disable the high-speed mode of a DAC pad.
    + *
    + * @param channel  DAC channel num
    + * @param enable   true to enable, false to disable
    + */
    +static inline void dac_ll_pad_enable_high_speed(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.hs_mode_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.hs_mode_pad_1 = enable;
    +    }
    +}
    +
    +/**
    + * @brief Enable or bypass the analog output buffer of a DAC pad (low-speed mode only).
    + *
    + * @param channel DAC channel num
    + * @param enable  true: enable the analog buffer; false: bypass it
    + */
    +static inline void dac_ll_pad_enable_buffer(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.dbuf_ls_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.dbuf_ls_pad_1 = enable;
    +    }
    +}
    +
    +/**
    + * @brief Select the input code range supported by the DAC analog buffer.
    + *
    + * @note Only applicable in low-speed mode with the analog buffer enabled.
    + * @note Full-code-range mode reduces the output voltage swing
    + *
    + * @param channel DAC channel num
    + * @param full_code_range true: support input codes 0 to 4095 with reduced output voltage swing;
    + *                        false: use input codes 248 to 3848 for linear operation with wider output
    + *                        voltage swing. Codes outside this range may cause output saturation.
    + */
    +static inline void dac_ll_pad_set_buffer_code_range(dac_channel_t channel, bool full_code_range)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.dbuf_range_ls_pad_0 = full_code_range;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.dbuf_range_ls_pad_1 = full_code_range;
    +    }
    +}
    +
    +/*---------------------------------------------------------------
    +                    Controller setting
    +---------------------------------------------------------------*/
    +
    +/**
    + * @brief Enable/disable the synchronization operation between ADC and DAC.
    + *
    + * @note  ESP32-S31 has no equivalent register bit, keep this as a no-op for API compatibility.
    + */
    +static inline void dac_ll_sync_by_adc(bool enable)
    +{
    +    (void)enable;
    +}
    +
    +/**
    + * @brief Enable/disable the ADC mux of a DAC pad.
    + *
    + * @note  For internal testing only.
    + *
    + * @param channel DAC channel num
    + * @param enable  true to enable, false to disable
    + */
    +static inline void dac_ll_enable_adc_mux(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.en_adc_mux_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.en_adc_mux_pad_1 = enable;
    +    }
    +}
    +
    +/*---------------------------------------------------------------
    +                    Sample-hold setting
    +---------------------------------------------------------------*/
    +
    +/**
    + * @brief Enable/disable the sample-hold mode of a DAC pad.
    + *
    + * @param channel DAC channel num
    + * @param enable  true to enable, false to disable
    + */
    +static inline void dac_ll_sh_enable(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.dsamp_ls_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.dsamp_ls_pad_1 = enable;
    +    }
    +}
    +
    +/**
    + * @brief Set the sample-phase wait cycle.
    + *
    + * @note Clocked by clk_ls.
    + *
    + * @param channel DAC channel num
    + * @param cycle   Wait cycles
    + */
    +static inline void dac_ll_sh_set_sample_cycle(dac_channel_t channel, uint16_t cycle)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.sample_wait_cfg.wait_target_sample_pad_0 = cycle;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.sample_wait_cfg.wait_target_sample_pad_1 = cycle;
    +    }
    +}
    +
    +/**
    + * @brief Set the hold-phase wait cycle.
    + *
    + * @note Clocked by clk_ls.
    + *
    + * @param channel DAC channel num
    + * @param cycle   Wait cycles
    + */
    +static inline void dac_ll_sh_set_hold_cycle(dac_channel_t channel, uint16_t cycle)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.hold_wait_cfg.wait_target_hold_pad_0 = cycle;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.hold_wait_cfg.wait_target_hold_pad_1 = cycle;
    +    }
    +}
    +
    +/**
    + * @brief Set the refresh-phase wait cycle.
    + *
    + * @note Clocked by clk_ls.
    + *
    + * @param channel DAC channel num
    + * @param cycle   Wait cycles
    + */
    +static inline void dac_ll_sh_set_refresh_cycle(dac_channel_t channel, uint16_t cycle)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.refresh_wait_cfg.wait_target_refresh_pad_0 = cycle;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.refresh_wait_cfg.wait_target_refresh_pad_1 = cycle;
    +    }
    +}
    +
    +/*---------------------------------------------------------------
    +                    Calibration setting
    +---------------------------------------------------------------*/
    +/**
    + * @brief Enable/disable the calibration of a DAC pad buffer.
    + *
    + * @note Valid only when the analog buffer is enabled.
    + *
    + * @param channel DAC channel num
    + * @param enable  true to enable, false to disable
    + */
    +static inline void dac_ll_cali_enable(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.dcal_ls_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.dcal_ls_pad_1 = enable;
    +    }
    +}
    +
    +/**
    + * @brief Get the calibration comparison result of a DAC pad buffer.
    + *
    + * @param channel DAC channel num
    + * @return Calibration comparison result
    + */
    +static inline bool dac_ll_cali_get_comparison_result(dac_channel_t channel)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        return LP_DAC.cali.cali_out_pad_0;
    +    } else if (channel == DAC_CHAN_1) {
    +        return LP_DAC.cali.cali_out_pad_1;
    +    } else {
    +        HAL_ASSERT(false);
    +        return false;
    +    }
    +}
    +
    +/**
    + * @brief Set the calibration result of a DAC pad buffer.
    + *
    + * @param channel DAC channel num
    + * @param result Calibration result, 12-bit
    + */
    +static inline void dac_ll_cali_set_result(dac_channel_t channel, uint16_t result)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.cali_result.cali_result_pad_0 = result;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.cali_result.cali_result_pad_1 = result;
    +    }
    +}
    +
    +/**
    + * @brief Get the calibration result of a DAC pad buffer.
    + *
    + * @param channel DAC channel num
    + * @return Calibration result, 12-bit
    + */
    +static inline uint16_t dac_ll_cali_get_result(dac_channel_t channel)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        return LP_DAC.cali_result.cali_result_pad_0;
    +    } else if (channel == DAC_CHAN_1) {
    +        return LP_DAC.cali_result.cali_result_pad_1;
    +    } else {
    +        HAL_ASSERT(false);
    +        return 0;
    +    }
    +}
    +
    +/*---------------------------------------------------------------
    +                    Cosine (Sintx) path setting
    +---------------------------------------------------------------*/
    +/**
    + * @brief Enable the cosine wave generator (Sintx tone mode).
    + *
    + * @note  Starts the phase accumulator and the Sintx timer that pushes samples to the pad.
    + */
    +static inline void dac_ll_cw_enable_tone(void)
    +{
    +    LP_DAC.sintx_cfg.sw_tone = 1;
    +    LP_DAC.sintx_timer_cfg.sintx_timer_en = 1;
    +}
    +
    +/**
    + * @brief Enable the Sintx generator for direct (DC) software output.
    + *
    + * @note  The DC value written by `dac_ll_pad_set_output_code()` is pushed to the pad
    + *        by the Sintx timer; the phase accumulator is left disabled.
    + */
    +static inline void dac_ll_cw_enable_dc(void)
    +{
    +    LP_DAC.sintx_cfg.sw_tone = 0;
    +    LP_DAC.sintx_timer_cfg.sintx_timer_en = 1;
    +}
    +
    +/**
    + * @brief Disable the cosine wave / Sintx generator.
    + */
    +static inline void dac_ll_cw_disable(void)
    +{
    +    LP_DAC.sintx_cfg.sw_tone = 0;
    +    LP_DAC.sintx_timer_cfg.sintx_timer_en = 0;
    +}
    +
    +/**
    + * @brief Set the timer target of the cosine wave (Sintx) generator timer.
    + *
    + * @note timer_target: 24-bit, range 0 ~ 0xFFFFFF.
    + *       Effective divider is timer_target, except that 0 is treated as 1
    + *       (i.e. dac_hs_clk / max(timer_target, 1)).
    + */
    +static inline void dac_ll_cw_set_timer_target(uint32_t timer_target)
    +{
    +    LP_DAC.sintx_timer_cfg.sintx_timer_target = timer_target;
    +}
    +
    +/**
    + * @brief Set the step increment of the cosine wave generator.
    + *
    + * @note A 16-bit phase accumulator freq_acc is incremented by DAC_SW_FSTEP on every Sintx trigger edge.
    + *       The upper 8 bits of the accumulator (freq_acc[15:8]) form the angle index freq_idx.
    + * @note sintx output frequency = (dac_hs_clk / max(timer_target, 1)) * (fstep / 2^16)
    + */
    +static inline void dac_ll_cw_set_fstep(uint16_t fstep)
    +{
    +    LP_DAC.sintx_cfg.sw_fstep = fstep;
    +}
    +
    +/**
    + * @brief Set the attenuation of the cosine wave generator output.
    + *
    + * @param channel DAC channel num
    + * @param atten   Attenuation config
    + */
    +static inline void dac_ll_cw_set_atten(dac_channel_t channel, dac_cosine_atten_t atten)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.sintx_cfg.scale_1 = atten;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.sintx_cfg.scale_2 = atten;
    +    }
    +}
    +
    +/**
    + * @brief Set the phase of the cosine wave generator output.
    + *
    + * @note  On ESP32-S31 the sine LUT stores unsigned values, so phase 0/180 maps to 0/1 directly.
    + *
    + * @param channel DAC channel num
    + * @param phase   Phase value
    + */
    +static inline void dac_ll_cw_set_phase(dac_channel_t channel, dac_cosine_phase_t phase)
    +{
    +    uint8_t dac_inv = phase == DAC_COSINE_PHASE_180 ? 0x01 : 0x00;
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.sintx_cfg.inv_1 = dac_inv;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.sintx_cfg.inv_2 = dac_inv;
    +    }
    +}
    +
    +/**
    + * @brief Set the offset of the cosine wave generator output.
    + *
    + * @note  On ESP32-S31 the offset is a 12-bit unsigned value added to the scaled sample with saturation.
    + *
    + * @param channel DAC channel num
    + * @param offset  DC offset. Range: 0 ~ 4095 (LS) or 0 ~ 1023 (HS)
    + */
    +static inline void dac_ll_cw_set_offset(dac_channel_t channel, int16_t offset)

    offset parameter is now uint16_t offset

    wmrsouza wmrsouza commented on code on Nov 30, 2026 22:37 UTC
    Code Review
    components/esp_hal_ana_conv/esp32s31/include/hal/dac_ll.h:1
    @@ -0,0 +1,566 @@
    +/*
    + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
    + *
    + * SPDX-License-Identifier: Apache-2.0
    + */
    +
    +#pragma once
    +
    +#include <stdbool.h>
    +#include <stdint.h>
    +#include "hal/assert.h"
    +#include "soc/dac_struct.h"
    +#include "soc/lp_peri_clkrst_struct.h"
    +#include "soc/clk_tree_defs.h"
    +#include "hal/dac_types.h"
    +#include "hal/dac_types_private.h"
    +
    +#if SOC_DAC_SUPPORTED
    +
    +#define SOC_DAC_DC_VIA_SINTX           1

    Those symbols were moved to soc_caps.h

    wmrsouza wmrsouza commented on code on Nov 30, 2026 22:38 UTC
    Code Review
    components/soc/esp32s31/include/soc/soc_caps.h:1
    @@ -158,6 +158,13 @@
     /*!< ADC power control is shared by PWDET, TempSensor */
     #define SOC_ADC_SHARED_POWER                    1
     
    +/*-------------------------- DAC CAPS ----------------------------------------*/
    +#define SOC_DAC_SUPPORTED                       1

    Kconfig.soc_caps.in and soc_caps.h are now synced.

    wmrsouza wmrsouza commented on code on Nov 30, 2026 22:39 UTC
    Code Review
    components/esp_hw_support/periph_ctrl.c:1
    @@ -498,6 +501,15 @@ void non_shared_periph_module_enable(int periph)
     #endif
     #endif
     #endif
    +#if defined(ESP32_LP_DAC_MODULE) && SOC_DAC_SUPPORTED
    +#if ESP32_LP_DAC_MODULE >= 100
    +    case ESP32_LP_DAC_MODULE:
    +        dac_ll_reset_register();

    Done, thanks.

    sylvioalves sylvioalves commented on code on Dec 01, 2026 21:54 UTC
    Code Review
    components/esp_hal_ana_conv/esp32s31/include/hal/dac_ll.h:1
    @@ -0,0 +1,557 @@
    +/*
    + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
    + *
    + * SPDX-License-Identifier: Apache-2.0
    + */
    +
    +#pragma once
    +
    +#include <stdbool.h>
    +#include <stdint.h>
    +#include "hal/assert.h"
    +#include "soc/dac_struct.h"
    +#include "soc/lp_peri_clkrst_struct.h"
    +#include "soc/clk_tree_defs.h"
    +#include "hal/dac_types.h"
    +#include "hal/dac_types_private.h"
    +
    +#if SOC_DAC_SUPPORTED
    +
    +#ifdef __cplusplus
    +extern "C" {
    +#endif
    +
    +/*---------------------------------------------------------------
    +                    Clock setting
    +---------------------------------------------------------------*/
    +/**
    + * @brief Reset the DAC module
    + */
    +static inline void dac_ll_reset_register(void)
    +{
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_rst_en = 1;
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_rst_en = 0;
    +}
    +
    +/**
    + * @brief Select the source clock of the DAC functional clock (DAC_HS_CLK).
    + *
    + * @note  On ESP32-S31 both the Sintx (cosine) path and the GDMA path share this
    + *        functional clock, so the source applies to both.
    + *
    + * @param clk_src Clock source, see `soc_periph_dac_digi_clk_src_t`
    + */
    +static inline void dac_ll_clk_set_source(soc_periph_dac_digi_clk_src_t clk_src)
    +{
    +    switch (clk_src) {
    +    case DAC_DIGI_CLK_SRC_LP_FAST:
    +        LP_PERI_CLKRST.dac_ctrl.lp_dac_clk_sel = 0;
    +        break;
    +    case DAC_DIGI_CLK_SRC_XTAL:
    +        LP_PERI_CLKRST.dac_ctrl.lp_dac_clk_sel = 1;
    +        break;
    +    default:
    +        HAL_ASSERT(false);
    +    }
    +}
    +
    +/**
    + * @brief Enable or disable the DAC functional clock (DAC_HS_CLK).
    + *
    + * @note  The DAC functional clock (DAC_HS_CLK) gates the whole LP_DAC register block.
    + *        While it is disabled, NONE of the registers under `LP_DAC` can be accessed
    + *        (writes are dropped and reads return invalid data). Therefore this clock must
    + *        be enabled before configuring/accessing any `LP_DAC.*` register.
    + *
    + * @param enable true to enable, false to disable
    + */
    +static inline void dac_ll_clk_enable(bool enable)
    +{
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_clk_en = enable;
    +}
    +
    +/**
    + * @brief Set the divider from the source clock to DAC_HS_CLK.
    + *
    + * @note  DAC_HS_CLK = clock_source / (hs_div + 1)
    + */
    +static inline void dac_ll_clk_set_hs_div(uint8_t hs_div)
    +{
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_div_num = hs_div;
    +}
    +
    +/**
    + * @brief Get the divider from the source clock to DAC_HS_CLK.
    + */
    +static inline uint8_t dac_ll_clk_get_hs_div(void)
    +{
    +    return LP_PERI_CLKRST.dac_ctrl.lp_dac_div_num;
    +}
    +
    +/**
    + * @brief Set the internal divider from DAC_HS_CLK to the low-speed pad clock (clk_ls).
    + *
    + * @note  clk_ls = DAC_HS_CLK / (ls_div + 1)
    + */
    +static inline void dac_ll_clk_set_ls_div(uint16_t ls_div)
    +{
    +    LP_DAC.pad_cfg.div_num = ls_div;
    +}
    +
    +/**
    + * @brief Get the divider from DAC_HS_CLK to the low-speed pad clock (clk_ls).
    + */
    +static inline uint16_t dac_ll_clk_get_ls_div(void)
    +{
    +    return LP_DAC.pad_cfg.div_num;
    +}
    +
    +/*---------------------------------------------------------------
    +                    DAC pad setting
    +---------------------------------------------------------------*/
    +/**
    + * @brief Power on the DAC pad and start outputting.
    + *
    + * @param channel DAC channel num
    + */
    +static inline void dac_ll_pad_power_on(dac_channel_t channel)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.xpd_pad_0 = 1;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.xpd_pad_1 = 1;
    +    }
    +}
    +
    +/**
    + * @brief Power down the DAC pad and stop outputting.
    + *
    + * @param channel DAC channel num
    + */
    +static inline void dac_ll_pad_power_down(dac_channel_t channel)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.xpd_pad_0 = 0;
    +        LP_DAC.pad_cfg.dbuf_ls_pad_0 = 0;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.xpd_pad_1 = 0;
    +        LP_DAC.pad_cfg.dbuf_ls_pad_1 = 0;
    +    }
    +}
    +
    +/**
    + * @brief Select the internal data source that drives a DAC channel output.
    + *
    + * @note  The hardware data-select bit only distinguishes DMA vs Sintx. Both
    + *        `DAC_DATA_SOURCE_COSINE` and `DAC_DATA_SOURCE_DIRECT` map onto the Sintx path.
    + *
    + * @param channel DAC channel num
    + * @param source  Data source, see `dac_data_source_t`
    + */
    +static inline void dac_ll_pad_set_data_source(dac_channel_t channel, dac_data_source_t source)
    +{
    +    const uint32_t sel = (source == DAC_DATA_SOURCE_DMA) ? 1 : 0;
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.data_output_cfg.pad_0_data_sel = sel;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.data_output_cfg.pad_1_data_sel = sel;
    +    }
    +}
    +
    +/**
    + * @brief Set the DAC output code through the Sintx (direct software output) path.
    + *
    + * @param channel DAC channel num
    + * @param code    Output code. Bit width depends on the DAC resolution and speed mode.
    + */
    +__attribute__((always_inline))
    +static inline void dac_ll_pad_set_output_code(dac_channel_t channel, uint16_t code)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.sintx_data.dc_1 = code;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.sintx_data.dc_2 = code;
    +    }
    +}
    +
    +/**
    + * @brief Enable or disable the high-speed mode of a DAC pad.
    + *
    + * @param channel  DAC channel num
    + * @param enable   true to enable, false to disable
    + */
    +static inline void dac_ll_pad_enable_high_speed(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.hs_mode_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.hs_mode_pad_1 = enable;
    +    }
    +}
    +
    +/**
    + * @brief Enable or bypass the analog output buffer of a DAC pad (low-speed mode only).
    + *
    + * @param channel DAC channel num
    + * @param enable  true: enable the analog buffer; false: bypass it
    + */
    +static inline void dac_ll_pad_enable_buffer(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.dbuf_ls_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.dbuf_ls_pad_1 = enable;
    +    }
    +}
    +
    +/**
    + * @brief Select the output swing range of the analog buffer (only valid when the buffer is enabled).
    + *
    + * @param channel     DAC channel num
    + * @param full_range  true: full-scale swing; false: reduced swing range.
    + */
    +static inline void dac_ll_pad_set_buffer_range(dac_channel_t channel, bool full_range)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.dbuf_range_ls_pad_0 = full_range;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.dbuf_range_ls_pad_1 = full_range;
    +    }
    +}
    +
    +/*---------------------------------------------------------------
    +                    Controller setting
    +---------------------------------------------------------------*/
    +
    +/**
    + * @brief Enable/disable the synchronization operation between ADC and DAC.
    + *
    + * @note  ESP32-S31 has no equivalent register bit, keep this as a no-op for API compatibility.
    + */
    +static inline void dac_ll_sync_by_adc(bool enable)

    with SOC_DAC_SUPPORTED=1, adc_oneshot_hal.c now compiles s_disable_dac() for S31 and calls dac_ll_rtc_sync_by_adc(), but this LL only defines dac_ll_sync_by_adc, so every S31 build with CONFIG_ADC_ESP32 (e.g. tests/drivers/adc/adc_api on esp32s31_function_coreboard/hpcore) fails with an implicit declaration at adc_oneshot_hal.c:198. naming it dac_ll_rtc_sync_by_adc like the esp32/esp32s2 LLs in this hal fixes it, I checked that build

    static inline void dac_ll_rtc_sync_by_adc(bool enable)
    

    sylvioalves sylvioalves commented on code on Dec 01, 2026 21:54 UTC
    Code Review
    components/esp_hal_ana_conv/esp32s31/include/hal/dac_ll.h:1
    @@ -0,0 +1,557 @@
    +/*
    + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
    + *
    + * SPDX-License-Identifier: Apache-2.0
    + */
    +
    +#pragma once
    +
    +#include <stdbool.h>
    +#include <stdint.h>
    +#include "hal/assert.h"
    +#include "soc/dac_struct.h"
    +#include "soc/lp_peri_clkrst_struct.h"
    +#include "soc/clk_tree_defs.h"
    +#include "hal/dac_types.h"
    +#include "hal/dac_types_private.h"
    +
    +#if SOC_DAC_SUPPORTED
    +
    +#ifdef __cplusplus
    +extern "C" {
    +#endif
    +
    +/*---------------------------------------------------------------
    +                    Clock setting
    +---------------------------------------------------------------*/
    +/**
    + * @brief Reset the DAC module
    + */
    +static inline void dac_ll_reset_register(void)
    +{
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_rst_en = 1;
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_rst_en = 0;
    +}
    +
    +/**
    + * @brief Select the source clock of the DAC functional clock (DAC_HS_CLK).
    + *
    + * @note  On ESP32-S31 both the Sintx (cosine) path and the GDMA path share this
    + *        functional clock, so the source applies to both.
    + *
    + * @param clk_src Clock source, see `soc_periph_dac_digi_clk_src_t`
    + */
    +static inline void dac_ll_clk_set_source(soc_periph_dac_digi_clk_src_t clk_src)
    +{
    +    switch (clk_src) {
    +    case DAC_DIGI_CLK_SRC_LP_FAST:
    +        LP_PERI_CLKRST.dac_ctrl.lp_dac_clk_sel = 0;
    +        break;
    +    case DAC_DIGI_CLK_SRC_XTAL:
    +        LP_PERI_CLKRST.dac_ctrl.lp_dac_clk_sel = 1;
    +        break;
    +    default:
    +        HAL_ASSERT(false);
    +    }
    +}
    +
    +/**
    + * @brief Enable or disable the DAC functional clock (DAC_HS_CLK).
    + *
    + * @note  The DAC functional clock (DAC_HS_CLK) gates the whole LP_DAC register block.
    + *        While it is disabled, NONE of the registers under `LP_DAC` can be accessed
    + *        (writes are dropped and reads return invalid data). Therefore this clock must
    + *        be enabled before configuring/accessing any `LP_DAC.*` register.
    + *
    + * @param enable true to enable, false to disable
    + */
    +static inline void dac_ll_clk_enable(bool enable)
    +{
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_clk_en = enable;
    +}
    +
    +/**
    + * @brief Set the divider from the source clock to DAC_HS_CLK.
    + *
    + * @note  DAC_HS_CLK = clock_source / (hs_div + 1)
    + */
    +static inline void dac_ll_clk_set_hs_div(uint8_t hs_div)
    +{
    +    LP_PERI_CLKRST.dac_ctrl.lp_dac_div_num = hs_div;
    +}
    +
    +/**
    + * @brief Get the divider from the source clock to DAC_HS_CLK.
    + */
    +static inline uint8_t dac_ll_clk_get_hs_div(void)
    +{
    +    return LP_PERI_CLKRST.dac_ctrl.lp_dac_div_num;
    +}
    +
    +/**
    + * @brief Set the internal divider from DAC_HS_CLK to the low-speed pad clock (clk_ls).
    + *
    + * @note  clk_ls = DAC_HS_CLK / (ls_div + 1)
    + */
    +static inline void dac_ll_clk_set_ls_div(uint16_t ls_div)
    +{
    +    LP_DAC.pad_cfg.div_num = ls_div;
    +}
    +
    +/**
    + * @brief Get the divider from DAC_HS_CLK to the low-speed pad clock (clk_ls).
    + */
    +static inline uint16_t dac_ll_clk_get_ls_div(void)
    +{
    +    return LP_DAC.pad_cfg.div_num;
    +}
    +
    +/*---------------------------------------------------------------
    +                    DAC pad setting
    +---------------------------------------------------------------*/
    +/**
    + * @brief Power on the DAC pad and start outputting.
    + *
    + * @param channel DAC channel num
    + */
    +static inline void dac_ll_pad_power_on(dac_channel_t channel)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.xpd_pad_0 = 1;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.xpd_pad_1 = 1;
    +    }
    +}
    +
    +/**
    + * @brief Power down the DAC pad and stop outputting.
    + *
    + * @param channel DAC channel num
    + */
    +static inline void dac_ll_pad_power_down(dac_channel_t channel)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.xpd_pad_0 = 0;
    +        LP_DAC.pad_cfg.dbuf_ls_pad_0 = 0;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.xpd_pad_1 = 0;
    +        LP_DAC.pad_cfg.dbuf_ls_pad_1 = 0;
    +    }
    +}
    +
    +/**
    + * @brief Select the internal data source that drives a DAC channel output.
    + *
    + * @note  The hardware data-select bit only distinguishes DMA vs Sintx. Both
    + *        `DAC_DATA_SOURCE_COSINE` and `DAC_DATA_SOURCE_DIRECT` map onto the Sintx path.
    + *
    + * @param channel DAC channel num
    + * @param source  Data source, see `dac_data_source_t`
    + */
    +static inline void dac_ll_pad_set_data_source(dac_channel_t channel, dac_data_source_t source)
    +{
    +    const uint32_t sel = (source == DAC_DATA_SOURCE_DMA) ? 1 : 0;
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.data_output_cfg.pad_0_data_sel = sel;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.data_output_cfg.pad_1_data_sel = sel;
    +    }
    +}
    +
    +/**
    + * @brief Set the DAC output code through the Sintx (direct software output) path.
    + *
    + * @param channel DAC channel num
    + * @param code    Output code. Bit width depends on the DAC resolution and speed mode.
    + */
    +__attribute__((always_inline))
    +static inline void dac_ll_pad_set_output_code(dac_channel_t channel, uint16_t code)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.sintx_data.dc_1 = code;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.sintx_data.dc_2 = code;
    +    }
    +}
    +
    +/**
    + * @brief Enable or disable the high-speed mode of a DAC pad.
    + *
    + * @param channel  DAC channel num
    + * @param enable   true to enable, false to disable
    + */
    +static inline void dac_ll_pad_enable_high_speed(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.hs_mode_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.hs_mode_pad_1 = enable;
    +    }
    +}
    +
    +/**
    + * @brief Enable or bypass the analog output buffer of a DAC pad (low-speed mode only).
    + *
    + * @param channel DAC channel num
    + * @param enable  true: enable the analog buffer; false: bypass it
    + */
    +static inline void dac_ll_pad_enable_buffer(dac_channel_t channel, bool enable)
    +{
    +    if (channel == DAC_CHAN_0) {
    +        LP_DAC.pad_cfg.dbuf_ls_pad_0 = enable;
    +    } else if (channel == DAC_CHAN_1) {
    +        LP_DAC.pad_cfg.dbuf_ls_pad_1 = enable;
    +    }
    +}
    +
    +/**
    + * @brief Select the output swing range of the analog buffer (only valid when the buffer is enabled).
    + *
    + * @param channel     DAC channel num
    + * @param full_range  true: full-scale swing; false: reduced swing range.

    the new comment on dac_ll_pad_set_buffer_range() says false is the reduced swing, but buffered with false (what dac_esp32.c passes) measured 0.80 to 3.31 V on GPIO4 for codes 1024 to 4095, which is the wide swing the zephyr binding describes. anyone trusting the comment passes true for full scale and gets the other mode, so the previous wording (false = wider swing, codes 248..3848 linear) was the right one

     * @param full_range  true: input codes 0 to 4095 with reduced output swing;
     *                    false: wider output swing, codes 248 to 3848 are linear.
    

    sylvioalves sylvioalves commented on code on Dec 01, 2026 21:54 UTC
    Code Review
    components/esp_hal_ana_conv/esp32s31/dac_periph.c:1
    @@ -0,0 +1,15 @@
    +/*
    + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD

    dac_periph.c, dac_ll.h and dac_types_private.h are new files but use "Espressif Systems (Shanghai) CO LTD", so they don't carry the company's legal name. "Espressif Systems (Shanghai) Co., Ltd." in all three fixes it

    - * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
    + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) Co., Ltd.
    

    sylvioalves sylvioalves approved these changes on Dec 02, 2026 14:15 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    wmrsouza wmrsouza
    Labels
    risk: low confidence: 82.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 55.8% (MEDIUM) · Higher = larger blast radius
    55.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 82.8% · Lower = rushed or shallow review
    82.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 9.6% · Safe to merge
    9.6%