mirror of
https://github.com/espressif/esp-idf.git
synced 2026-08-18 06:35:35 +03:00
feat(uart): add glitch filter functionality for UART
Closes https://github.com/espressif/esp-idf/issues/17847
This commit is contained in:
@@ -305,6 +305,35 @@ FORCE_INLINE_ATTR uint32_t uart_ll_get_baudrate(uart_dev_t *hw, uint32_t sclk_fr
|
||||
return ((sclk_freq << 4)) / (((div_reg.clkdiv_int << 4) | div_reg.clkdiv_frag) * sclk_div);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the UART glitch filter threshold. Any high pulse lasting shorter than this value will be ignored when the filter is enabled.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param glitch_filt_thrd The glitch filter threshold to be set (unit: ns)
|
||||
* @param sclk_freq Frequency of the clock source of UART, in Hz.
|
||||
*/
|
||||
FORCE_INLINE_ATTR void uart_ll_set_glitch_filt_thrd(uart_dev_t *hw, uint32_t glitch_filt_thrd, uint32_t sclk_freq)
|
||||
{
|
||||
uint32_t clk_cycles = 0;
|
||||
if (glitch_filt_thrd > 0) {
|
||||
uint32_t ref_clk_freq = sclk_freq / (UART_LL_PCR_REG_U32_GET(hw, sclk_conf, sclk_div_num) + 1);
|
||||
clk_cycles = ((uint64_t)glitch_filt_thrd * ref_clk_freq + 1000000000 - 1) / 1000000000; // round up to always filter something
|
||||
HAL_ASSERT(clk_cycles <= UART_GLITCH_FILT_V);
|
||||
}
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->rx_filt, glitch_filt, clk_cycles);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable the UART glitch filter
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param enable True to enable the filter, False to disable the filter
|
||||
*/
|
||||
FORCE_INLINE_ATTR void uart_ll_enable_glitch_filt(uart_dev_t *hw, bool enable)
|
||||
{
|
||||
hw->rx_filt.glitch_filt_en = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the UART interrupt based on the given mask.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user