Merge branch 'feature/support_ana_cmpr_on_c61' into 'master'

feat(ana_cmpr): support analog comparator on C61

Closes IDF-11082

See merge request espressif/esp-idf!35480
master
Kevin (Lao Kaiyao) 2024-12-09 20:22:19 +08:00
commit 8077b5c7e2
15 zmienionych plików z 308 dodań i 30 usunięć

Wyświetl plik

@ -1,2 +1,2 @@
| Supported Targets | ESP32-H2 | ESP32-P4 |
| ----------------- | -------- | -------- |
| Supported Targets | ESP32-C61 | ESP32-H2 | ESP32-P4 |
| ----------------- | --------- | -------- | -------- |

Wyświetl plik

@ -6,6 +6,7 @@ from pytest_embedded import Dut
@pytest.mark.esp32h2
@pytest.mark.esp32p4
@pytest.mark.esp32c61
@pytest.mark.generic
@pytest.mark.parametrize(
'config',

Wyświetl plik

@ -0,0 +1,169 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdbool.h>
#include "hal/misc.h"
#include "hal/assert.h"
#include "soc/ana_cmpr_struct.h"
#include "soc/soc_etm_source.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ANALOG_CMPR_LL_GET_HW(unit) (&ANALOG_CMPR[unit])
#define ANALOG_CMPR_LL_GET_UNIT(hw) (0)
#define ANALOG_CMPR_LL_EVENT_CROSS (1 << 0)
#define ANALOG_CMPR_LL_NEG_CROSS_MASK(unit) (1UL << ((int)unit * 3))
#define ANALOG_CMPR_LL_POS_CROSS_MASK(unit) (1UL << ((int)unit * 3 + 1))
#define ANALOG_CMPR_LL_ETM_SOURCE(unit, type) (GPIO_EVT_ZERO_DET_POS0 + (unit) * 2 + (type))
/**
* @brief Enable analog comparator
*
* @param hw Analog comparator register base address
* @param en True to enable, False to disable
*/
static inline void analog_cmpr_ll_enable(analog_cmpr_dev_t *hw, bool en)
{
hw->pad_comp_config->xpd_comp_0 = en;
}
/**
* @brief Set the voltage of the internal reference
*
* @param hw Analog comparator register base address
* @param volt_level The voltage level of the internal reference, range [0.0V, 0.7VDD], step 0.1VDD
*/
__attribute__((always_inline))
static inline void analog_cmpr_ll_set_internal_ref_voltage(analog_cmpr_dev_t *hw, uint32_t volt_level)
{
hw->pad_comp_config->dref_comp_0 = volt_level;
}
/**
* @brief Get the voltage of the internal reference
*
* @param hw Analog comparator register base address
* @return The voltage of the internal reference
*/
static inline float analog_cmpr_ll_get_internal_ref_voltage(analog_cmpr_dev_t *hw)
{
return hw->pad_comp_config->dref_comp_0 * 0.1F;
}
/**
* @brief The reference voltage comes from internal or external
*
* @note Also see `analog_cmpr_ll_set_internal_ref_voltage` to use the internal reference voltage
*
* @param hw Analog comparator register base address
* @param ref_src reference source, 0 for internal, 1 for external GPIO pad (GPIO10)
*/
static inline void analog_cmpr_ll_set_ref_source(analog_cmpr_dev_t *hw, uint32_t ref_src)
{
hw->pad_comp_config->mode_comp_0 = ref_src;
}
/**
* @brief Get the interrupt mask by trigger type
*
* @param hw Analog comparator register base address
* @param type The type of cross interrupt
* - 0: disable interrupt
* - 1: enable positive cross interrupt (input analog goes from low to high and across the reference voltage)
* - 2: enable negative cross interrupt (input analog goes from high to low and across the reference voltage)
* - 3: enable any positive or negative cross interrupt
* @return interrupt mask
*/
__attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(analog_cmpr_dev_t *hw, uint8_t type)
{
uint32_t unit = ANALOG_CMPR_LL_GET_UNIT(hw);
uint32_t mask = 0;
if (type & 0x01) {
mask |= ANALOG_CMPR_LL_POS_CROSS_MASK(unit);
}
if (type & 0x02) {
mask |= ANALOG_CMPR_LL_NEG_CROSS_MASK(unit);
}
return mask;
}
/**
* @brief Set the debounce cycle for the cross detection
*
* @note When the comparator detects a cross, it will wait for the debounce cycle to make sure the cross is stable.
*
* @param hw Analog comparator register base address
* @param cycle The debounce cycle
*/
__attribute__((always_inline))
static inline void analog_cmpr_ll_set_debounce_cycle(analog_cmpr_dev_t *hw, uint32_t cycle)
{
hw->pad_comp_filter->zero_det_filter_cnt_0 = cycle;
}
/**
* @brief Enable comparator interrupt
*
* @param hw Analog comparator register base address
* @param mask Interrupt mask
* @param enable True to enable, False to disable
*/
static inline void analog_cmpr_ll_enable_intr(analog_cmpr_dev_t *hw, uint32_t mask, bool enable)
{
uint32_t val = hw->int_ena->val;
if (enable) {
val |= mask;
} else {
val &= ~mask;
}
hw->int_ena->val = val;
}
/**
* @brief Get comparator interrupt status
*
* @param hw Analog comparator register base address
*/
__attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_status(analog_cmpr_dev_t *hw)
{
return hw->int_st->val;
}
/**
* @brief Clear comparator interrupt status
*
* @param hw Analog comparator register base address
* @param mask Interrupt status word
*/
__attribute__((always_inline))
static inline void analog_cmpr_ll_clear_intr(analog_cmpr_dev_t *hw, uint32_t mask)
{
hw->int_clr->val = mask;
}
/**
* @brief Get the interrupt status register address
*
* @param hw Analog comparator register base address
* @return The interrupt status register address
*/
static inline volatile void *analog_cmpr_ll_get_intr_status_reg(analog_cmpr_dev_t *hw)
{
return hw->int_st;
}
#ifdef __cplusplus
}
#endif

Wyświetl plik

@ -19,7 +19,6 @@ extern "C" {
#define ANALOG_CMPR_LL_GET_HW(unit) (&ANALOG_CMPR[unit])
#define ANALOG_CMPR_LL_GET_UNIT(hw) ((hw) == (&ANALOG_CMPR[0]) ? 0 : 1)
#define ANALOG_CMPR_LL_EVENT_CROSS (1 << 0)
#define ANALOG_CMPR_LL_ETM_EVENTS_PER_UNIT (2)
#define ANALOG_CMPR_LL_NEG_CROSS_MASK(unit) (1UL << ((int)unit * 3))
#define ANALOG_CMPR_LL_POS_CROSS_MASK(unit) (1UL << ((int)unit * 3 + 1))

Wyświetl plik

@ -0,0 +1,26 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "soc/ana_cmpr_periph.h"
#include "soc/ana_cmpr_struct.h"
const ana_cmpr_periph_t ana_cmpr_periph[SOC_ANA_CMPR_NUM] = {
[0] = {
.src_gpio = ANA_CMPR0_SRC_GPIO,
.ext_ref_gpio = ANA_CMPR0_EXT_REF_GPIO,
.intr_src = ETS_GPIO_INTERRUPT_EXT_SOURCE,
},
};
analog_cmpr_dev_t ANALOG_CMPR[SOC_ANA_CMPR_NUM] = {
[0] = {
.pad_comp_config = &GPIO_EXT.pad_comp_config_0,
.pad_comp_filter = &GPIO_EXT.pad_comp_filter_0,
.int_st = &GPIO_EXT.int_st,
.int_ena = &GPIO_EXT.int_ena,
.int_clr = &GPIO_EXT.int_clr,
},
};

Wyświetl plik

@ -7,6 +7,10 @@ config SOC_ADC_SUPPORTED
bool
default y
config SOC_ANA_CMPR_SUPPORTED
bool
default y
config SOC_DEDICATED_GPIO_SUPPORTED
bool
default y
@ -471,6 +475,18 @@ config SOC_DEDIC_PERIPH_ALWAYS_ENABLE
bool
default y
config SOC_ANA_CMPR_NUM
int
default 1
config SOC_ANA_CMPR_CAN_DISTINGUISH_EDGE
bool
default y
config SOC_ANA_CMPR_SUPPORT_ETM
bool
default y
config SOC_I2C_NUM
int
default 1

Wyświetl plik

@ -0,0 +1,10 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#define ANA_CMPR0_EXT_REF_GPIO 8 /*!< The GPIO that can be used as external reference voltage */
#define ANA_CMPR0_SRC_GPIO 9 /*!< The GPIO that used for inputting the source signal to compare */

Wyświetl plik

@ -0,0 +1,36 @@
/**
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/* NOTE: this file is created manually for compatibility */
#pragma once
#include <stdint.h>
#include "soc/gpio_ext_struct.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief The Analog Comparator Device struct
* @note The field in it are register pointers, which point to the physical address
* of the corresponding configuration register
* @note see 'ana_cmpr_periph.c' for the device instance
*/
typedef struct {
volatile gpio_ext_pad_comp_config_0_reg_t *pad_comp_config;
volatile gpio_ext_pad_comp_filter_0_reg_t *pad_comp_filter;
volatile gpio_ext_int_st_reg_t *int_st;
volatile gpio_ext_int_ena_reg_t *int_ena;
volatile gpio_ext_int_clr_reg_t *int_clr;
} analog_cmpr_dev_t;
extern analog_cmpr_dev_t ANALOG_CMPR[1];
#ifdef __cplusplus
}
#endif

Wyświetl plik

@ -278,6 +278,23 @@ typedef enum {
GLITCH_FILTER_CLK_SRC_DEFAULT = SOC_MOD_CLK_PLL_F80M, /*!< Select PLL_F80M clock as the default clock choice */
} soc_periph_glitch_filter_clk_src_t;
///////////////////////////////////////////////////Analog Comparator////////////////////////////////////////////////////
/**
* @brief Array initializer for all supported clock sources of Analog Comparator
*/
#define SOC_ANA_CMPR_CLKS {SOC_MOD_CLK_PLL_F80M, SOC_MOD_CLK_RC_FAST, SOC_MOD_CLK_XTAL}
/**
* @brief Analog Comparator clock source
*/
typedef enum {
ANA_CMPR_CLK_SRC_XTAL = SOC_MOD_CLK_XTAL, /*!< Select XTAL clock as the source clock */
ANA_CMPR_CLK_SRC_RC_FAST = SOC_MOD_CLK_RC_FAST, /*!< Select RC_FAST clock as the source clock */
ANA_CMPR_CLK_SRC_PLL_F80M = SOC_MOD_CLK_PLL_F80M, /*!< Select PLL_F80M clock as the source clock */
ANA_CMPR_CLK_SRC_DEFAULT = SOC_MOD_CLK_PLL_F80M, /*!< Select PLL_F80M as the default clock choice */
} soc_periph_ana_cmpr_clk_src_t;
//////////////////////////////////////////////////ADC///////////////////////////////////////////////////////////////////
/**

Wyświetl plik

@ -18,6 +18,7 @@
/*-------------------------- COMMON CAPS ---------------------------------------*/
#define SOC_ADC_SUPPORTED 1
#define SOC_ANA_CMPR_SUPPORTED 1
#define SOC_DEDICATED_GPIO_SUPPORTED 1
#define SOC_UART_SUPPORTED 1
#define SOC_GDMA_SUPPORTED 1
@ -211,6 +212,11 @@
#define SOC_DEDIC_GPIO_IN_CHANNELS_NUM (8) /*!< 8 inward channels on each CPU core */
#define SOC_DEDIC_PERIPH_ALWAYS_ENABLE (1) /*!< The dedicated GPIO (a.k.a. fast GPIO) is featured by some customized CPU instructions, which is always enabled */
/*------------------------- Analog Comparator CAPS ---------------------------*/
#define SOC_ANA_CMPR_NUM (1U)
#define SOC_ANA_CMPR_CAN_DISTINGUISH_EDGE (1) // Support positive/negative/any cross interrupt
#define SOC_ANA_CMPR_SUPPORT_ETM (1)
/*-------------------------- I2C CAPS ----------------------------------------*/
// ESP32-C61 has 1 I2C
#define SOC_I2C_NUM (1U)

Wyświetl plik

@ -45,7 +45,6 @@ api-reference/peripherals/usb_device.rst
api-reference/peripherals/dac.rst
api-reference/peripherals/touch_element.rst
api-reference/peripherals/ppa.rst
api-reference/peripherals/ana_cmpr.rst
api-reference/peripherals/camera_driver.rst
api-reference/peripherals/spi_features.rst
api-reference/peripherals/sdio_slave.rst

Wyświetl plik

@ -3,8 +3,8 @@ Analog Comparator
:link_to_translation:`zh_CN:[中文]`
{IDF_TARGET_ANA_CMPR_SRC_CHAN0: default="NOT UPDATED", esp32h2="GPIO11", esp32p4="GPIO52"}
{IDF_TARGET_ANA_CMPR_EXT_REF_CHAN0: default="NOT UPDATED", esp32h2="GPIO10", esp32p4="GPIO51"}
{IDF_TARGET_ANA_CMPR_SRC_CHAN0: default="NOT UPDATED", esp32h2="GPIO11", esp32p4="GPIO52", esp32c61="GPIO9"}
{IDF_TARGET_ANA_CMPR_EXT_REF_CHAN0: default="NOT UPDATED", esp32h2="GPIO10", esp32p4="GPIO51", esp32c61="GPIO8"}
{IDF_TARGET_ANA_CMPR_SRC_CHAN1: default="NOT UPDATED", esp32p4="GPIO54"}
{IDF_TARGET_ANA_CMPR_EXT_REF_CHAN1: default="NOT UPDATED", esp32p4="GPIO53"}
@ -36,17 +36,16 @@ Functional Overview
The following sections of this document cover the typical steps to install and operate an analog comparator unit:
- :ref:`anacmpr-resource-allocation` - covers which parameters should be set up to get a unit handle and how to recycle the resources when it finishes working.
- :ref:`anacmpr-further-configurations` - covers the other configurations that might need to specify and what they are used for.
- :ref:`anacmpr-enable-and-disable-unit` - covers how to enable and disable the unit.
- :ref:`anacmpr-power-management` - describes how different source clock selections can affect power consumption.
- :ref:`anacmpr-iram-safe` - lists which functions are supposed to work even when the cache is disabled.
- :ref:`anacmpr-thread-safety` - lists which APIs are guaranteed to be thread safe by the driver.
- :ref:`anacmpr-kconfig-options` - lists the supported Kconfig options that can be used to make a different effect on driver behavior.
.. list::
.. only:: SOC_ANA_CMPR_SUPPORT_ETM
- :ref:`anacmpr-etm-events` - covers how to create an analog comparator cross event.
- :ref:`anacmpr-resource-allocation` - covers which parameters should be set up to get a unit handle and how to recycle the resources when it finishes working.
- :ref:`anacmpr-further-configurations` - covers the other configurations that might need to specify and what they are used for.
- :ref:`anacmpr-enable-and-disable-unit` - covers how to enable and disable the unit.
- :ref:`anacmpr-power-management` - describes how different source clock selections can affect power consumption.
- :ref:`anacmpr-iram-safe` - lists which functions are supposed to work even when the cache is disabled.
- :ref:`anacmpr-thread-safety` - lists which APIs are guaranteed to be thread safe by the driver.
- :ref:`anacmpr-kconfig-options` - lists the supported Kconfig options that can be used to make a different effect on driver behavior.
:SOC_ANA_CMPR_SUPPORT_ETM: - :ref:`anacmpr-etm-events` - covers how to create an analog comparator cross event.
.. _anacmpr-resource-allocation:

Wyświetl plik

@ -3,8 +3,8 @@
:link_to_translation:`en:[English]`
{IDF_TARGET_ANA_CMPR_SRC_CHAN0: default="未更新", esp32h2="GPIO11", esp32p4="GPIO52"}
{IDF_TARGET_ANA_CMPR_EXT_REF_CHAN0: default="未更新", esp32h2="GPIO10", esp32p4="GPIO51"}
{IDF_TARGET_ANA_CMPR_SRC_CHAN0: default="未更新", esp32h2="GPIO11", esp32p4="GPIO52", esp32c61="GPIO9"}
{IDF_TARGET_ANA_CMPR_EXT_REF_CHAN0: default="未更新", esp32h2="GPIO10", esp32p4="GPIO51", esp32c61="GPIO8"}
{IDF_TARGET_ANA_CMPR_SRC_CHAN1: default="未更新", esp32p4="GPIO54"}
{IDF_TARGET_ANA_CMPR_EXT_REF_CHAN1: default="未更新", esp32p4="GPIO53"}
@ -36,17 +36,16 @@
本文中的以下章节涵盖了安装及操作模拟比较器单元的基本步骤:
- :ref:`anacmpr-resource-allocation` - 涵盖了应设置哪些参数以获取单元句柄,以及完成工作后如何回收资源。
- :ref:`anacmpr-further-configurations` - 涵盖了可能需要指定的其他配置及其用途。
- :ref:`anacmpr-enable-and-disable-unit` - 涵盖了如何启用和禁用单元。
- :ref:`anacmpr-power-management` - 描述了不同时钟源对功耗的影响。
- :ref:`anacmpr-iram-safe` - 列出了在 cache 被禁用时也能起效的函数。
- :ref:`anacmpr-thread-safety` - 列出了驱动程序中线程安全的 API。
- :ref:`anacmpr-kconfig-options` - 列出了支持的 Kconfig 选项,这些选项可以对驱动程序产生不同影响。
.. list::
.. only:: SOC_ANA_CMPR_SUPPORT_ETM
- :ref:`anacmpr-etm-events` - 介绍了如何创建一个模拟比较器跨越事件。
- :ref:`anacmpr-resource-allocation` - 涵盖了应设置哪些参数以获取单元句柄,以及完成工作后如何回收资源。
- :ref:`anacmpr-further-configurations` - 涵盖了可能需要指定的其他配置及其用途。
- :ref:`anacmpr-enable-and-disable-unit` - 涵盖了如何启用和禁用单元。
- :ref:`anacmpr-power-management` - 描述了不同时钟源对功耗的影响。
- :ref:`anacmpr-iram-safe` - 列出了在 cache 被禁用时也能起效的函数。
- :ref:`anacmpr-thread-safety` - 列出了驱动程序中线程安全的 API。
- :ref:`anacmpr-kconfig-options` - 列出了支持的 Kconfig 选项,这些选项可以对驱动程序产生不同影响。
:SOC_ANA_CMPR_SUPPORT_ETM: - :ref:`anacmpr-etm-events` - 介绍了如何创建一个模拟比较器跨越事件。
.. _anacmpr-resource-allocation:

Wyświetl plik

@ -1,5 +1,5 @@
| Supported Targets | ESP32-H2 | ESP32-P4 |
| ----------------- | -------- | -------- |
| Supported Targets | ESP32-C61 | ESP32-H2 | ESP32-P4 |
| ----------------- | --------- | -------- | -------- |
# Analog Comparator Example

Wyświetl plik

@ -6,6 +6,7 @@ from pytest_embedded import Dut
@pytest.mark.esp32h2
@pytest.mark.esp32p4
@pytest.mark.esp32c61
@pytest.mark.generic
@pytest.mark.parametrize(
'config',