feat(ana_cmpr): refactor driver implemnetation for new ip

esp32h4 and esp32s31 has a new IP design WRT the ana cmpr module
This commit is contained in:
morris
2026-04-19 21:47:30 +08:00
parent a87de1d5c5
commit 45d2c0c486
13 changed files with 313 additions and 246 deletions
@@ -37,11 +37,10 @@ extern "C" {
#define ANALOG_CMPR_LL_GET_HW(unit) (&ANALOG_CMPR[unit])
#define ANALOG_CMPR_LL_NEG_CROSS_MASK(unit, src_chan) (1UL << ((unit) * 3 + 0))
#define ANALOG_CMPR_LL_POS_CROSS_MASK(unit, src_chan) (1UL << ((unit) * 3 + 1))
#define ANALOG_CMPR_LL_ANY_CROSS_MASK(unit, src_chan) (1UL << ((unit) * 3 + 2))
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_MASK(unit, src_chan) | ANALOG_CMPR_LL_ANY_CROSS_MASK(unit, src_chan))
#define ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) 0x01
#define ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan) 0x02
#define ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan))
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit) 0x07
#define ANALOG_CMPR_LL_ETM_SOURCE(unit, src_chan, type) (GPIO_EVT_ZERO_DET_POS0 + (unit) * 2 + (type))
@@ -59,13 +58,13 @@ static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(uint32_t unit_id, ui
uint32_t mask = 0;
switch (type) {
case ANA_CMPR_CROSS_POS:
mask |= ANALOG_CMPR_LL_POS_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit_id, src_chan);
break;
case ANA_CMPR_CROSS_NEG:
mask |= ANALOG_CMPR_LL_NEG_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit_id, src_chan);
break;
case ANA_CMPR_CROSS_ANY:
mask |= ANALOG_CMPR_LL_ANY_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit_id, src_chan);
break;
default:
break;
@@ -160,7 +159,7 @@ static inline void analog_cmpr_ll_enable_intr(analog_cmpr_dev_t *hw, uint32_t ma
__attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_status(analog_cmpr_dev_t *hw)
{
return hw->int_st->val;
return (hw->int_st->val) & ANALOG_CMPR_LL_ALL_INTR_MASK(0);
}
/**
@@ -37,11 +37,10 @@ extern "C" {
#define ANALOG_CMPR_LL_GET_HW(unit) (&ANALOG_CMPR[unit])
#define ANALOG_CMPR_LL_NEG_CROSS_MASK(unit, src_chan) (1UL << ((unit) * 3 + 0))
#define ANALOG_CMPR_LL_POS_CROSS_MASK(unit, src_chan) (1UL << ((unit) * 3 + 1))
#define ANALOG_CMPR_LL_ANY_CROSS_MASK(unit, src_chan) (1UL << ((unit) * 3 + 2))
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_MASK(unit, src_chan) | ANALOG_CMPR_LL_ANY_CROSS_MASK(unit, src_chan))
#define ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) 0x01
#define ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan) 0x02
#define ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan))
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit) 0x07
#define ANALOG_CMPR_LL_ETM_SOURCE(unit, src_chan, type) (GPIO_EVT_ZERO_DET_POS0 + (unit) * 2 + (type))
@@ -59,13 +58,13 @@ static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(uint32_t unit_id, ui
uint32_t mask = 0;
switch (type) {
case ANA_CMPR_CROSS_POS:
mask |= ANALOG_CMPR_LL_POS_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit_id, src_chan);
break;
case ANA_CMPR_CROSS_NEG:
mask |= ANALOG_CMPR_LL_NEG_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit_id, src_chan);
break;
case ANA_CMPR_CROSS_ANY:
mask |= ANALOG_CMPR_LL_ANY_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit_id, src_chan);
break;
default:
break;
@@ -160,7 +159,7 @@ static inline void analog_cmpr_ll_enable_intr(analog_cmpr_dev_t *hw, uint32_t ma
__attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_status(analog_cmpr_dev_t *hw)
{
return hw->int_st->val;
return hw->int_st->val & ANALOG_CMPR_LL_ALL_INTR_MASK(0);
}
/**
@@ -28,9 +28,9 @@
#define ANALOG_CMPR_LL_SRC_CHANNEL_NUM 1
#define ANALOG_CMPR_LL_GET_HW(unit) (&ANALOG_CMPR[unit])
#define ANALOG_CMPR_LL_EVENT_CROSS (1 << 0)
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_EVENT_CROSS)
#define ANALOG_CMPR_LL_CROSS_INTR_MASK 0x01
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit) ANALOG_CMPR_LL_CROSS_INTR_MASK
#ifdef __cplusplus
extern "C" {
@@ -50,7 +50,7 @@ static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(uint32_t unit_id, ui
(void)type;
(void)unit_id;
(void)src_chan;
return ANALOG_CMPR_LL_EVENT_CROSS;
return ANALOG_CMPR_LL_CROSS_INTR_MASK;
}
/**
@@ -156,7 +156,7 @@ static inline void analog_cmpr_ll_enable_intr(analog_cmpr_dev_t *hw, uint32_t ma
__attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_status(analog_cmpr_dev_t *hw)
{
return hw->int_st->val;
return hw->int_st->val & ANALOG_CMPR_LL_ALL_INTR_MASK(0);
}
/**
@@ -36,11 +36,10 @@ extern "C" {
#define ANALOG_CMPR_LL_GET_HW(unit) (&ANALOG_CMPR[unit])
#define ANALOG_CMPR_LL_NEG_CROSS_MASK(unit, src_chan) (1UL << ((unit) * 3 + 0))
#define ANALOG_CMPR_LL_POS_CROSS_MASK(unit, src_chan) (1UL << ((unit) * 3 + 1))
#define ANALOG_CMPR_LL_ANY_CROSS_MASK(unit, src_chan) (1UL << ((unit) * 3 + 2))
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_MASK(unit, src_chan) | ANALOG_CMPR_LL_ANY_CROSS_MASK(unit, src_chan))
#define ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) 0x01
#define ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan) 0x02
#define ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan))
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit) 0x07
/**
* @brief Get the interrupt mask from the given cross type
@@ -56,13 +55,13 @@ static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(uint32_t unit_id, ui
uint32_t mask = 0;
switch (type) {
case ANA_CMPR_CROSS_POS:
mask |= ANALOG_CMPR_LL_POS_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit_id, src_chan);
break;
case ANA_CMPR_CROSS_NEG:
mask |= ANALOG_CMPR_LL_NEG_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit_id, src_chan);
break;
case ANA_CMPR_CROSS_ANY:
mask |= ANALOG_CMPR_LL_ANY_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit_id, src_chan);
break;
default:
break;
@@ -157,7 +156,7 @@ static inline void analog_cmpr_ll_enable_intr(analog_cmpr_dev_t *hw, uint32_t ma
__attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_status(analog_cmpr_dev_t *hw)
{
return hw->int_st->val;
return hw->int_st->val & ANALOG_CMPR_LL_ALL_INTR_MASK(0);
}
/**
@@ -41,13 +41,12 @@ typedef zero_dev_t analog_cmpr_dev_t;
#define ANALOG_CMPR_LL_GET_HW(unit) (&ZERO_DET)
#define ANALOG_CMPR_LL_NEG_CROSS_MASK(unit, src_chan) (1UL << ((2 - (src_chan)) * 3 + 0))
#define ANALOG_CMPR_LL_POS_CROSS_MASK(unit, src_chan) (1UL << ((2 - (src_chan)) * 3 + 1))
#define ANALOG_CMPR_LL_ANY_CROSS_MASK(unit, src_chan) (1UL << ((2 - (src_chan)) * 3 + 2))
#define ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) (1UL << ((2 - (src_chan)) * 3 + 0))
#define ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan) (1UL << ((2 - (src_chan)) * 3 + 1))
#define ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan))
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit) 0x1FF
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_MASK(unit, src_chan) | ANALOG_CMPR_LL_ANY_CROSS_MASK(unit, src_chan))
#define ANALOG_CMPR_LL_ETM_SOURCE(unit, src_chan, type) (ZERO_DET_EVT_CHANNEL_1_POS + (src_chan) + ((type) * ANALOG_CMPR_LL_SRC_CHANNEL_NUM))
#define ANALOG_CMPR_LL_ETM_SOURCE(unit, src_chan, type) (ZERO_DET_EVT_CHANNEL_1_POS + (src_chan) + ((type) * ANALOG_CMPR_LL_SRC_CHANNEL_NUM))
/**
* @brief Enable the bus clock for Analog Comparator module
@@ -143,13 +142,13 @@ static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(uint32_t unit_id, ui
uint32_t mask = 0;
switch (type) {
case ANA_CMPR_CROSS_POS:
mask |= ANALOG_CMPR_LL_POS_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit_id, src_chan);
break;
case ANA_CMPR_CROSS_NEG:
mask |= ANALOG_CMPR_LL_NEG_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit_id, src_chan);
break;
case ANA_CMPR_CROSS_ANY:
mask |= ANALOG_CMPR_LL_ANY_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit_id, src_chan);
break;
default:
break;
@@ -244,7 +243,7 @@ static inline void analog_cmpr_ll_enable_intr(analog_cmpr_dev_t *hw, uint32_t ma
__attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_status(analog_cmpr_dev_t *hw)
{
return hw->det_int_st.val;
return hw->det_int_st.val & ANALOG_CMPR_LL_ALL_INTR_MASK(0);
}
/**
@@ -38,13 +38,12 @@ 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_NEG_CROSS_MASK(unit, src_chan) (1UL << ((unit) * 3 + 0))
#define ANALOG_CMPR_LL_POS_CROSS_MASK(unit, src_chan) (1UL << ((unit) * 3 + 1))
#define ANALOG_CMPR_LL_ANY_CROSS_MASK(unit, src_chan) (1UL << ((unit) * 3 + 2))
#define ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) (1UL << ((unit) * 3 + 0))
#define ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan) (1UL << ((unit) * 3 + 1))
#define ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan))
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit) (0x07 << ((unit) * 3))
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_MASK(unit, src_chan) | ANALOG_CMPR_LL_ANY_CROSS_MASK(unit, src_chan))
#define ANALOG_CMPR_LL_ETM_SOURCE(unit, src_chan, type) (GPIO_EVT_ZERO_DET_POS0 + (unit) * 2 + (type))
#define ANALOG_CMPR_LL_ETM_SOURCE(unit, src_chan, type) (GPIO_EVT_ZERO_DET_POS0 + (unit) * 2 + (type))
/**
* @brief Get the interrupt mask from the given cross type
@@ -60,13 +59,13 @@ static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(uint32_t unit_id, ui
uint32_t mask = 0;
switch (type) {
case ANA_CMPR_CROSS_POS:
mask |= ANALOG_CMPR_LL_POS_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit_id, src_chan);
break;
case ANA_CMPR_CROSS_NEG:
mask |= ANALOG_CMPR_LL_NEG_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit_id, src_chan);
break;
case ANA_CMPR_CROSS_ANY:
mask |= ANALOG_CMPR_LL_ANY_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit_id, src_chan);
break;
default:
break;
@@ -161,7 +160,8 @@ static inline void analog_cmpr_ll_enable_intr(analog_cmpr_dev_t *hw, uint32_t ma
__attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_status(analog_cmpr_dev_t *hw)
{
return hw->int_st->val;
int unit_id = ANALOG_CMPR_LL_GET_UNIT(hw);
return hw->int_st->val & ANALOG_CMPR_LL_ALL_INTR_MASK(unit_id);
}
/**
@@ -41,13 +41,12 @@ typedef zero_det_dev_t analog_cmpr_dev_t;
#define ANALOG_CMPR_LL_GET_HW(unit) (&ZERO_DET)
#define ANALOG_CMPR_LL_NEG_CROSS_MASK(unit, src_chan) (1UL << ((2 - (src_chan)) * 3 + 0))
#define ANALOG_CMPR_LL_POS_CROSS_MASK(unit, src_chan) (1UL << ((2 - (src_chan)) * 3 + 1))
#define ANALOG_CMPR_LL_ANY_CROSS_MASK(unit, src_chan) (1UL << ((2 - (src_chan)) * 3 + 2))
#define ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) (1UL << ((2 - (src_chan)) * 3 + 0))
#define ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan) (1UL << ((2 - (src_chan)) * 3 + 1))
#define ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan))
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit) 0x1FF
#define ANALOG_CMPR_LL_ALL_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_MASK(unit, src_chan) | ANALOG_CMPR_LL_ANY_CROSS_MASK(unit, src_chan))
#define ANALOG_CMPR_LL_ETM_SOURCE(unit, src_chan, type) (ZERO_DET_EVT_CHANNEL_1_POS + (src_chan) + ((type) * ANALOG_CMPR_LL_SRC_CHANNEL_NUM))
#define ANALOG_CMPR_LL_ETM_SOURCE(unit, src_chan, type) (ZERO_DET_EVT_CHANNEL_1_POS + (src_chan) + ((type) * ANALOG_CMPR_LL_SRC_CHANNEL_NUM))
/**
* @brief Enable the bus clock for Analog Comparator module
@@ -143,13 +142,13 @@ static inline uint32_t analog_cmpr_ll_get_intr_mask_by_type(uint32_t unit_id, ui
uint32_t mask = 0;
switch (type) {
case ANA_CMPR_CROSS_POS:
mask |= ANALOG_CMPR_LL_POS_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit_id, src_chan);
break;
case ANA_CMPR_CROSS_NEG:
mask |= ANALOG_CMPR_LL_NEG_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit_id, src_chan);
break;
case ANA_CMPR_CROSS_ANY:
mask |= ANALOG_CMPR_LL_ANY_CROSS_MASK(unit_id, src_chan);
mask |= ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit_id, src_chan);
break;
default:
break;
@@ -244,7 +243,7 @@ static inline void analog_cmpr_ll_enable_intr(analog_cmpr_dev_t *hw, uint32_t ma
__attribute__((always_inline))
static inline uint32_t analog_cmpr_ll_get_intr_status(analog_cmpr_dev_t *hw)
{
return hw->int_st.val;
return hw->int_st.val & ANALOG_CMPR_LL_ALL_INTR_MASK(0);
}
/**