refactor(ana_cmpr): use enum types in ll

This commit is contained in:
laokaiyao
2024-12-10 12:05:46 +08:00
parent b48b43880a
commit f731a53694
9 changed files with 60 additions and 40 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -9,6 +9,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#include "soc/clk_tree_defs.h" #include "soc/clk_tree_defs.h"
#include "hal/ana_cmpr_types.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -40,32 +41,6 @@ typedef enum {
ANA_CMPR_EXT_REF_CHAN, /*!< Analog Comparator external reference channel, which is used as the reference signal */ ANA_CMPR_EXT_REF_CHAN, /*!< Analog Comparator external reference channel, which is used as the reference signal */
} ana_cmpr_channel_type_t; } ana_cmpr_channel_type_t;
/**
* @brief Analog comparator interrupt type
*
*/
typedef enum {
ANA_CMPR_CROSS_DISABLE, /*!< Disable the cross event interrupt */
ANA_CMPR_CROSS_POS, /*!< Positive cross can trigger event interrupt */
ANA_CMPR_CROSS_NEG, /*!< Negative cross can trigger event interrupt */
ANA_CMPR_CROSS_ANY, /*!< Any cross can trigger event interrupt */
} ana_cmpr_cross_type_t;
/**
* @brief Analog comparator internal reference voltage
*
*/
typedef enum {
ANA_CMPR_REF_VOLT_0_PCT_VDD, /*!< Internal reference voltage equals to 0% VDD */
ANA_CMPR_REF_VOLT_10_PCT_VDD, /*!< Internal reference voltage equals to 10% VDD */
ANA_CMPR_REF_VOLT_20_PCT_VDD, /*!< Internal reference voltage equals to 20% VDD */
ANA_CMPR_REF_VOLT_30_PCT_VDD, /*!< Internal reference voltage equals to 30% VDD */
ANA_CMPR_REF_VOLT_40_PCT_VDD, /*!< Internal reference voltage equals to 40% VDD */
ANA_CMPR_REF_VOLT_50_PCT_VDD, /*!< Internal reference voltage equals to 50% VDD */
ANA_CMPR_REF_VOLT_60_PCT_VDD, /*!< Internal reference voltage equals to 60% VDD */
ANA_CMPR_REF_VOLT_70_PCT_VDD, /*!< Internal reference voltage equals to 70% VDD */
} ana_cmpr_ref_voltage_t;
/** /**
* @brief Analog comparator unit handle * @brief Analog comparator unit handle
* *

View File

@@ -9,6 +9,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "hal/misc.h" #include "hal/misc.h"
#include "hal/assert.h" #include "hal/assert.h"
#include "hal/ana_cmpr_types.h"
#include "soc/ana_cmpr_struct.h" #include "soc/ana_cmpr_struct.h"
#include "soc/soc_etm_source.h" #include "soc/soc_etm_source.h"
@@ -68,7 +69,7 @@ static inline float analog_cmpr_ll_get_internal_ref_voltage(analog_cmpr_dev_t *h
* @param hw Analog comparator register base address * @param hw Analog comparator register base address
* @param ref_src reference source, 0 for internal, 1 for external GPIO pad (GPIO10) * @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) static inline void analog_cmpr_ll_set_ref_source(analog_cmpr_dev_t *hw, ana_cmpr_ref_voltage_t ref_src)
{ {
hw->pad_comp_config->mode_comp_0 = ref_src; hw->pad_comp_config->mode_comp_0 = ref_src;
} }
@@ -85,7 +86,7 @@ static inline void analog_cmpr_ll_set_ref_source(analog_cmpr_dev_t *hw, uint32_t
* @return interrupt mask * @return interrupt mask
*/ */
__attribute__((always_inline)) __attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(analog_cmpr_dev_t *hw, uint8_t type) static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(analog_cmpr_dev_t *hw, ana_cmpr_cross_type_t type)
{ {
uint32_t unit = ANALOG_CMPR_LL_GET_UNIT(hw); uint32_t unit = ANALOG_CMPR_LL_GET_UNIT(hw);
uint32_t mask = 0; uint32_t mask = 0;

View File

@@ -9,6 +9,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "hal/misc.h" #include "hal/misc.h"
#include "hal/assert.h" #include "hal/assert.h"
#include "hal/ana_cmpr_types.h"
#include "soc/ana_cmpr_struct.h" #include "soc/ana_cmpr_struct.h"
#include "soc/soc_etm_source.h" #include "soc/soc_etm_source.h"
@@ -68,7 +69,7 @@ static inline float analog_cmpr_ll_get_internal_ref_voltage(analog_cmpr_dev_t *h
* @param hw Analog comparator register base address * @param hw Analog comparator register base address
* @param ref_src reference source, 0 for internal, 1 for external GPIO pad (GPIO10) * @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) static inline void analog_cmpr_ll_set_ref_source(analog_cmpr_dev_t *hw, ana_cmpr_ref_voltage_t ref_src)
{ {
hw->pad_comp_config->mode_comp_0 = ref_src; hw->pad_comp_config->mode_comp_0 = ref_src;
} }
@@ -85,7 +86,7 @@ static inline void analog_cmpr_ll_set_ref_source(analog_cmpr_dev_t *hw, uint32_t
* @return interrupt mask * @return interrupt mask
*/ */
__attribute__((always_inline)) __attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(analog_cmpr_dev_t *hw, uint8_t type) static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(analog_cmpr_dev_t *hw, ana_cmpr_cross_type_t type)
{ {
uint32_t unit = ANALOG_CMPR_LL_GET_UNIT(hw); uint32_t unit = ANALOG_CMPR_LL_GET_UNIT(hw);
uint32_t mask = 0; uint32_t mask = 0;

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -9,6 +9,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "hal/misc.h" #include "hal/misc.h"
#include "hal/assert.h" #include "hal/assert.h"
#include "hal/ana_cmpr_types.h"
#include "soc/ana_cmpr_struct.h" #include "soc/ana_cmpr_struct.h"
#define ANALOG_CMPR_LL_GET_HW(unit) (&ANALOG_CMPR[unit]) #define ANALOG_CMPR_LL_GET_HW(unit) (&ANALOG_CMPR[unit])
@@ -60,7 +61,7 @@ static inline uint32_t analog_cmpr_ll_get_internal_ref_voltage(analog_cmpr_dev_t
* @param hw Analog comparator register base address * @param hw Analog comparator register base address
* @param ref_src reference source, 0 for internal, 1 for external GPIO pad (GPIO10) * @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) static inline void analog_cmpr_ll_set_ref_source(analog_cmpr_dev_t *hw, ana_cmpr_ref_voltage_t ref_src)
{ {
hw->pad_comp_config->mode_comp = ref_src; hw->pad_comp_config->mode_comp = ref_src;
} }
@@ -91,7 +92,7 @@ static inline void analog_cmpr_ll_set_cross_type(analog_cmpr_dev_t *hw, uint8_t
* @return interrupt mask * @return interrupt mask
*/ */
__attribute__((always_inline)) __attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(analog_cmpr_dev_t *hw, uint8_t type) static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(analog_cmpr_dev_t *hw, ana_cmpr_cross_type_t type)
{ {
(void)type; (void)type;
return ANALOG_CMPR_LL_EVENT_CROSS; return ANALOG_CMPR_LL_EVENT_CROSS;

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -9,6 +9,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "hal/misc.h" #include "hal/misc.h"
#include "hal/assert.h" #include "hal/assert.h"
#include "hal/ana_cmpr_types.h"
#include "soc/ana_cmpr_struct.h" #include "soc/ana_cmpr_struct.h"
#include "soc/soc_etm_source.h" #include "soc/soc_etm_source.h"
@@ -68,7 +69,7 @@ static inline float analog_cmpr_ll_get_internal_ref_voltage(analog_cmpr_dev_t *h
* @param hw Analog comparator register base address * @param hw Analog comparator register base address
* @param ref_src reference source, 0 for internal, 1 for external GPIO pad (GPIO10) * @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) static inline void analog_cmpr_ll_set_ref_source(analog_cmpr_dev_t *hw, ana_cmpr_ref_voltage_t ref_src)
{ {
hw->pad_comp_config->mode_comp = ref_src; hw->pad_comp_config->mode_comp = ref_src;
} }
@@ -85,7 +86,7 @@ static inline void analog_cmpr_ll_set_ref_source(analog_cmpr_dev_t *hw, uint32_t
* @return interrupt mask * @return interrupt mask
*/ */
__attribute__((always_inline)) __attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(analog_cmpr_dev_t *hw, uint8_t type) static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(analog_cmpr_dev_t *hw, ana_cmpr_cross_type_t type)
{ {
uint32_t unit = ANALOG_CMPR_LL_GET_UNIT(hw); uint32_t unit = ANALOG_CMPR_LL_GET_UNIT(hw);
uint32_t mask = 0; uint32_t mask = 0;

View File

@@ -0,0 +1,41 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Analog comparator interrupt type
*
*/
typedef enum {
ANA_CMPR_CROSS_DISABLE, /*!< Disable the cross event interrupt */
ANA_CMPR_CROSS_POS, /*!< Positive cross can trigger event interrupt */
ANA_CMPR_CROSS_NEG, /*!< Negative cross can trigger event interrupt */
ANA_CMPR_CROSS_ANY, /*!< Any cross can trigger event interrupt */
} ana_cmpr_cross_type_t;
/**
* @brief Analog comparator internal reference voltage
*
*/
typedef enum {
ANA_CMPR_REF_VOLT_0_PCT_VDD, /*!< Internal reference voltage equals to 0% VDD */
ANA_CMPR_REF_VOLT_10_PCT_VDD, /*!< Internal reference voltage equals to 10% VDD */
ANA_CMPR_REF_VOLT_20_PCT_VDD, /*!< Internal reference voltage equals to 20% VDD */
ANA_CMPR_REF_VOLT_30_PCT_VDD, /*!< Internal reference voltage equals to 30% VDD */
ANA_CMPR_REF_VOLT_40_PCT_VDD, /*!< Internal reference voltage equals to 40% VDD */
ANA_CMPR_REF_VOLT_50_PCT_VDD, /*!< Internal reference voltage equals to 50% VDD */
ANA_CMPR_REF_VOLT_60_PCT_VDD, /*!< Internal reference voltage equals to 60% VDD */
ANA_CMPR_REF_VOLT_70_PCT_VDD, /*!< Internal reference voltage equals to 70% VDD */
} ana_cmpr_ref_voltage_t;
#ifdef __cplusplus
}
#endif

View File

@@ -11,7 +11,7 @@ const ana_cmpr_periph_t ana_cmpr_periph[SOC_ANA_CMPR_NUM] = {
[0] = { [0] = {
.src_gpio = ANA_CMPR0_SRC_GPIO, .src_gpio = ANA_CMPR0_SRC_GPIO,
.ext_ref_gpio = ANA_CMPR0_EXT_REF_GPIO, .ext_ref_gpio = ANA_CMPR0_EXT_REF_GPIO,
.intr_src = ETS_GPIO_NMI_SOURCE, .intr_src = ETS_GPIO_EXT_SOURCE,
}, },
}; };

View File

@@ -47,7 +47,7 @@ typedef enum {
ETS_CACHE_INTR_SOURCE, ETS_CACHE_INTR_SOURCE,
ETS_CPU_PERI_TIMEOUT_INTR_SOURCE, ETS_CPU_PERI_TIMEOUT_INTR_SOURCE,
ETS_GPIO_INTR_SOURCE, /**< interrupt of GPIO, level*/ ETS_GPIO_INTR_SOURCE, /**< interrupt of GPIO, level*/
ETS_GPIO_NMI_SOURCE, /**< interrupt of GPIO, NMI*/ ETS_GPIO_EXT_SOURCE, /**< interrupt of GPIO, EXT (analog comparator)*/
ETS_PAU_INTR_SOURCE, ETS_PAU_INTR_SOURCE,
ETS_HP_PERI_TIMEOUT_INTR_SOURCE, ETS_HP_PERI_TIMEOUT_INTR_SOURCE,
ETS_MODEM_PERI_TIMEOUT_INTR_SOURCE, ETS_MODEM_PERI_TIMEOUT_INTR_SOURCE,

View File

@@ -39,7 +39,7 @@ const char *const esp_isr_names[] = {
[ETS_CACHE_INTR_SOURCE] = "CACHE", [ETS_CACHE_INTR_SOURCE] = "CACHE",
[ETS_CPU_PERI_TIMEOUT_INTR_SOURCE] = "CPU_PERI_TIMEOUT", [ETS_CPU_PERI_TIMEOUT_INTR_SOURCE] = "CPU_PERI_TIMEOUT",
[ETS_GPIO_INTR_SOURCE] = "GPIO_INTR", [ETS_GPIO_INTR_SOURCE] = "GPIO_INTR",
[ETS_GPIO_NMI_SOURCE] = "GPIO_NMI", [ETS_GPIO_EXT_SOURCE] = "GPIO_EXT",
[ETS_PAU_INTR_SOURCE] = "PAU", [ETS_PAU_INTR_SOURCE] = "PAU",
[ETS_HP_PERI_TIMEOUT_INTR_SOURCE] = "HP_PERI_TIMEOUT", [ETS_HP_PERI_TIMEOUT_INTR_SOURCE] = "HP_PERI_TIMEOUT",
[ETS_MODEM_PERI_TIMEOUT_INTR_SOURCE] = "MODEM_PERI_TIMEOUT", [ETS_MODEM_PERI_TIMEOUT_INTR_SOURCE] = "MODEM_PERI_TIMEOUT",