refactor(ledc): refactored some LEDC LL functions

This commit is contained in:
Song Ruo Jing
2026-04-01 21:34:52 +08:00
parent 32d31d72a3
commit 88b62b19fd
41 changed files with 890 additions and 846 deletions
@@ -19,8 +19,11 @@
#include "soc/soc_caps.h"
#include "soc/soc_etm_source.h"
#define LEDC_LL_GET(attr) (LEDC_LL_ ## attr)
#define LEDC_LL_GET_HW(group_id) ((group_id == 0) ? &LEDC : NULL)
#define LEDC_LL_GROUP_NUM (1)
#define LEDC_LL_CHANNEL_SUPPORT_OVF_CNT 1
#define LEDC_LL_DUTY_NUM_MAX (LEDC_CH0_FADE_PARAM_DUTY_NUM_V)
@@ -31,8 +34,13 @@
#define LEDC_LL_FRACTIONAL_BITS (8)
#define LEDC_LL_FRACTIONAL_MAX ((1 << LEDC_LL_FRACTIONAL_BITS) - 1)
#define LEDC_LL_GLOBAL_CLOCKS SOC_LEDC_CLKS
/// Get the mask of the fade end interrupt status register.
#define LEDC_LL_FADE_END_INTR_MASK (0xffUL << LEDC_DUTY_CHNG_END_CH0_INT_ENA_S)
/// Get the mask of the duty change end interrupt status register.
#define LEDC_LL_DUTY_CHANGE_END_INTR_MASK(speed_mode) (0xffUL << LEDC_DUTY_CHNG_END_CH0_INT_ENA_S)
#define LEDC_LL_EVENT_CHANNEL_DUTY_CHANGE_END(speed_mode, channel) BIT(LEDC_DUTY_CHNG_END_CH0_INT_ENA_S + (channel))
#define LEDC_LL_EVENT_CHANNEL_OVF_CNT(speed_mode, channel) BIT(LEDC_OVF_CNT_CH0_INT_ENA_S + (channel))
#define LEDC_LL_EVENT_CHANNEL_MASK(speed_mode, channel) (LEDC_LL_EVENT_CHANNEL_DUTY_CHANGE_END(speed_mode, channel) | LEDC_LL_EVENT_CHANNEL_OVF_CNT(speed_mode, channel))
// Channel tasks: ID, enable register and bit
#define LEDC_LL_ETM_CHANNEL_TASK_ID(group, channel, task) \
@@ -499,12 +507,11 @@ static inline void ledc_ll_get_duty(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc
*/
static inline void ledc_ll_set_fade_param(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc_channel_t channel_num, uint32_t dir, uint32_t cycle, uint32_t scale, uint32_t step)
{
ledc_chn_fade_param_reg_t fade_param = {
.duty_inc = dir,
.duty_cycle = cycle,
.scale = scale,
.duty_num = step,
};
ledc_chn_fade_param_reg_t fade_param = {};
fade_param.duty_inc = dir;
fade_param.duty_cycle = cycle;
fade_param.scale = scale;
fade_param.duty_num = step;
hw->channel_fade_param_group[speed_mode].channel[channel_num].fade_param.val = fade_param.val;
}
@@ -555,62 +562,58 @@ static inline void ledc_ll_set_idle_level(ledc_dev_t *hw, ledc_mode_t speed_mode
}
/**
* @brief Set fade end interrupt enable
* @brief Enable LEDC interrupt for specific event mask
*
* @param hw Beginning address of the peripheral registers
* @param speed_mode LEDC speed_mode, low-speed mode only
* @param channel_num LEDC channel index (0-7), select from ledc_channel_t
* @param fade_end_intr_en The fade end interrupt enable status
*
* @return None
* @param mask Interrupt enable mask
* @param enable True to enable, False to disable
*/
static inline void ledc_ll_set_fade_end_intr(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc_channel_t channel_num, bool fade_end_intr_en)
__attribute__((always_inline))
static inline void ledc_ll_enable_interrupt(ledc_dev_t *hw, uint32_t mask, bool enable)
{
uint32_t value = hw->int_ena.val;
uint32_t int_en_base = LEDC_DUTY_CHNG_END_CH0_INT_ENA_S;
hw->int_ena.val = fade_end_intr_en ? (value | BIT(int_en_base + channel_num)) : (value & (~(BIT(int_en_base + channel_num))));
if (enable) {
hw->int_ena.val |= mask;
} else {
hw->int_ena.val &= ~mask;
}
}
/**
* @brief Get fade end interrupt status
* @brief Get interrupt status.
*
* @param hw Beginning address of the peripheral registers
* @param speed_mode LEDC speed_mode, low-speed mode only
* @param intr_status The fade end interrupt status
*
* @return None
* @return Interrupt status.
*/
static inline void ledc_ll_get_fade_end_intr_status(ledc_dev_t *hw, ledc_mode_t speed_mode, uint32_t *intr_status)
__attribute__((always_inline))
static inline uint32_t ledc_ll_get_intr_status(ledc_dev_t *hw)
{
uint32_t value = hw->int_st.val;
uint32_t int_en_base = LEDC_DUTY_CHNG_END_CH0_INT_ENA_S;
*intr_status = (value >> int_en_base) & 0xff;
return hw->int_st.val;
}
/**
* @brief Get the address of the fade end interrupt status register.
* @brief Get the address of the interrupt status register.
*
* @param hw Beginning address of the peripheral registers
* @return Pointer to the fade end interrupt status register.
* @return Pointer to the interrupt status register.
*/
static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw)
static inline volatile void* ledc_ll_get_intr_status_reg(ledc_dev_t *hw)
{
return &hw->int_st.val;
return (volatile void *)&hw->int_st;
}
/**
* @brief Clear fade end interrupt status
* @brief Clear interrupt status.
*
* @param hw Beginning address of the peripheral registers
* @param speed_mode LEDC speed_mode, low-speed mode only
* @param channel_num LEDC channel index (0-7), select from ledc_channel_t
* @param intr_mask Interrupt status mask to clear
*
* @return None
*/
static inline void ledc_ll_clear_fade_end_intr_status(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc_channel_t channel_num)
__attribute__((always_inline))
static inline void ledc_ll_clear_intr_status(ledc_dev_t *hw, uint32_t intr_mask)
{
uint32_t int_en_base = LEDC_DUTY_CHNG_END_CH0_INT_ENA_S;
hw->int_clr.val = BIT(int_en_base + channel_num);
hw->int_clr.val = intr_mask;
}
/**