mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
refactor(ledc): refactored some LEDC LL functions
This commit is contained in:
@@ -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_GAMMA_RANGE0_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 (0x3fUL << 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) (0x3fUL << 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) \
|
||||
@@ -496,12 +504,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_range(ledc_dev_t *hw, ledc_mode_t speed_mode, ledc_channel_t channel_num, uint8_t range, uint32_t dir, uint32_t cycle, uint32_t scale, uint32_t step)
|
||||
{
|
||||
HAL_ASSERT(range < SOC_LEDC_GAMMA_CURVE_FADE_RANGE_MAX);
|
||||
ledc_channel_gamma_fade_param_t range_param = {
|
||||
.duty_inc = dir,
|
||||
.duty_cycle = cycle,
|
||||
.scale = scale,
|
||||
.duty_num = step,
|
||||
};
|
||||
ledc_channel_gamma_fade_param_t range_param = {};
|
||||
range_param.duty_inc = dir;
|
||||
range_param.duty_cycle = cycle;
|
||||
range_param.scale = scale;
|
||||
range_param.duty_num = step;
|
||||
LEDC_GAMMA_RAM.channel[channel_num].entry[range].val = range_param.val;
|
||||
}
|
||||
|
||||
@@ -608,62 +615,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-5), 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-5), 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user