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:
@@ -16,8 +16,11 @@
|
||||
#include "soc/system_struct.h"
|
||||
#include "hal/assert.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_DUTY_NUM_LSCH0_V)
|
||||
@@ -27,8 +30,13 @@
|
||||
#define LEDC_LL_OVF_CNT_MAX (LEDC_OVF_NUM_LSCH0_V + 1)
|
||||
#define LEDC_LL_FRACTIONAL_BITS (8)
|
||||
#define LEDC_LL_FRACTIONAL_MAX ((1 << LEDC_LL_FRACTIONAL_BITS) - 1)
|
||||
/// Get the mask of the fade end interrupt status register.
|
||||
#define LEDC_LL_FADE_END_INTR_MASK (0x3fUL << LEDC_DUTY_CHNG_END_LSCH0_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_LSCH0_INT_ENA_S)
|
||||
|
||||
#define LEDC_LL_EVENT_CHANNEL_DUTY_CHANGE_END(speed_mode, channel) BIT(LEDC_DUTY_CHNG_END_LSCH0_INT_ENA_S + (channel))
|
||||
#define LEDC_LL_EVENT_CHANNEL_OVF_CNT(speed_mode, channel) BIT(LEDC_OVF_CNT_LSCH0_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))
|
||||
|
||||
#define LEDC_LL_GLOBAL_CLOCKS { \
|
||||
LEDC_SLOW_CLK_APB, \
|
||||
@@ -525,62 +533,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, high-speed mode or low-speed mode
|
||||
* @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_LSCH0_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, high-speed mode or low-speed mode
|
||||
* @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_LSCH0_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, high-speed mode or low-speed mode
|
||||
* @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_LSCH0_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