11/*
2- * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
@@ -285,15 +285,21 @@ static inline void i2s_ll_tx_set_bck_div_num(i2s_dev_t *hw, uint32_t val)
285285 */
286286static inline void i2s_ll_tx_set_raw_clk_div (i2s_dev_t * hw , uint32_t div_int , uint32_t x , uint32_t y , uint32_t z , uint32_t yn1 )
287287{
288- /* Set the integer part of mclk division */
288+ /* Workaround for the double division issue.
289+ * The division coefficients must be set in particular sequence.
290+ * And it has to switch to a small division first before setting the target division. */
291+ HAL_FORCE_MODIFY_U32_REG_FIELD (hw -> tx_clkm_conf , tx_clkm_div_num , 2 );
292+ hw -> tx_clkm_div_conf .tx_clkm_div_yn1 = 0 ;
293+ hw -> tx_clkm_div_conf .tx_clkm_div_y = 1 ;
294+ hw -> tx_clkm_div_conf .tx_clkm_div_z = 0 ;
295+ hw -> tx_clkm_div_conf .tx_clkm_div_x = 0 ;
296+
297+ /* Set the target mclk division coefficients */
298+ hw -> tx_clkm_div_conf .tx_clkm_div_yn1 = yn1 ;
299+ hw -> tx_clkm_div_conf .tx_clkm_div_z = z ;
300+ hw -> tx_clkm_div_conf .tx_clkm_div_y = y ;
301+ hw -> tx_clkm_div_conf .tx_clkm_div_x = x ;
289302 HAL_FORCE_MODIFY_U32_REG_FIELD (hw -> tx_clkm_conf , tx_clkm_div_num , div_int );
290- /* Set the decimal part of the mclk division */
291- typeof (hw -> tx_clkm_div_conf ) div = {};
292- div .tx_clkm_div_x = x ;
293- div .tx_clkm_div_y = y ;
294- div .tx_clkm_div_z = z ;
295- div .tx_clkm_div_yn1 = yn1 ;
296- hw -> tx_clkm_div_conf .val = div .val ;
297303}
298304
299305/**
@@ -308,15 +314,21 @@ static inline void i2s_ll_tx_set_raw_clk_div(i2s_dev_t *hw, uint32_t div_int, ui
308314 */
309315static inline void i2s_ll_rx_set_raw_clk_div (i2s_dev_t * hw , uint32_t div_int , uint32_t x , uint32_t y , uint32_t z , uint32_t yn1 )
310316{
311- /* Set the integer part of mclk division */
317+ /* Workaround for the double division issue.
318+ * The division coefficients must be set in particular sequence.
319+ * And it has to switch to a small division first before setting the target division. */
320+ HAL_FORCE_MODIFY_U32_REG_FIELD (hw -> rx_clkm_conf , rx_clkm_div_num , 2 );
321+ hw -> rx_clkm_div_conf .rx_clkm_div_yn1 = 0 ;
322+ hw -> rx_clkm_div_conf .rx_clkm_div_y = 1 ;
323+ hw -> rx_clkm_div_conf .rx_clkm_div_z = 0 ;
324+ hw -> rx_clkm_div_conf .rx_clkm_div_x = 0 ;
325+
326+ /* Set the target mclk division coefficients */
327+ hw -> rx_clkm_div_conf .rx_clkm_div_yn1 = yn1 ;
328+ hw -> rx_clkm_div_conf .rx_clkm_div_z = z ;
329+ hw -> rx_clkm_div_conf .rx_clkm_div_y = y ;
330+ hw -> rx_clkm_div_conf .rx_clkm_div_x = x ;
312331 HAL_FORCE_MODIFY_U32_REG_FIELD (hw -> rx_clkm_conf , rx_clkm_div_num , div_int );
313- /* Set the decimal part of the mclk division */
314- typeof (hw -> rx_clkm_div_conf ) div = {};
315- div .rx_clkm_div_x = x ;
316- div .rx_clkm_div_y = y ;
317- div .rx_clkm_div_z = z ;
318- div .rx_clkm_div_yn1 = yn1 ;
319- hw -> rx_clkm_div_conf .val = div .val ;
320332}
321333
322334/**
@@ -327,12 +339,6 @@ static inline void i2s_ll_rx_set_raw_clk_div(i2s_dev_t *hw, uint32_t div_int, ui
327339 */
328340static inline void i2s_ll_tx_set_mclk (i2s_dev_t * hw , const hal_utils_clk_div_t * mclk_div )
329341{
330- /* Workaround for inaccurate clock while switching from a relatively low sample rate to a high sample rate
331- * Set to particular coefficients first then update to the target coefficients,
332- * otherwise the clock division might be inaccurate.
333- * the general idea is to set a value that impossible to calculate from the regular decimal */
334- i2s_ll_tx_set_raw_clk_div (hw , 7 , 317 , 7 , 3 , 0 );
335-
336342 uint32_t div_x = 0 ;
337343 uint32_t div_y = 0 ;
338344 uint32_t div_z = 0 ;
@@ -367,12 +373,6 @@ static inline void i2s_ll_rx_set_bck_div_num(i2s_dev_t *hw, uint32_t val)
367373 */
368374static inline void i2s_ll_rx_set_mclk (i2s_dev_t * hw , const hal_utils_clk_div_t * mclk_div )
369375{
370- /* Workaround for inaccurate clock while switching from a relatively low sample rate to a high sample rate
371- * Set to particular coefficients first then update to the target coefficients,
372- * otherwise the clock division might be inaccurate.
373- * the general idea is to set a value that impossible to calculate from the regular decimal */
374- i2s_ll_rx_set_raw_clk_div (hw , 7 , 317 , 7 , 3 , 0 );
375-
376376 uint32_t div_x = 0 ;
377377 uint32_t div_y = 0 ;
378378 uint32_t div_z = 0 ;
@@ -467,7 +467,7 @@ static inline void i2s_ll_rx_set_eof_num(i2s_dev_t *hw, int eof_num)
467467}
468468
469469/**
470- * @brief Congfigure TX chan bit and audio data bit
470+ * @brief Configure TX chan bit and audio data bit
471471 *
472472 * @param hw Peripheral I2S hardware instance address.
473473 * @param chan_bit The chan bit width
@@ -480,7 +480,7 @@ static inline void i2s_ll_tx_set_sample_bit(i2s_dev_t *hw, uint8_t chan_bit, int
480480}
481481
482482/**
483- * @brief Congfigure RX chan bit and audio data bit
483+ * @brief Configure RX chan bit and audio data bit
484484 *
485485 * @param hw Peripheral I2S hardware instance address.
486486 * @param chan_bit The chan bit width
@@ -880,23 +880,23 @@ static inline void i2s_ll_tx_set_pdm_fpfs(i2s_dev_t *hw, uint32_t fp, uint32_t f
880880}
881881
882882/**
883- * @brief Get I2S TX PDM fp configuration paramater
883+ * @brief Get I2S TX PDM fp configuration parameter
884884 *
885885 * @param hw Peripheral I2S hardware instance address.
886886 * @return
887- * - fp configuration paramater
887+ * - fp configuration parameter
888888 */
889889static inline uint32_t i2s_ll_tx_get_pdm_fp (i2s_dev_t * hw )
890890{
891891 return hw -> tx_pcm2pdm_conf1 .tx_pdm_fp ;
892892}
893893
894894/**
895- * @brief Get I2S TX PDM fs configuration paramater
895+ * @brief Get I2S TX PDM fs configuration parameter
896896 *
897897 * @param hw Peripheral I2S hardware instance address.
898898 * @return
899- * - fs configuration paramater
899+ * - fs configuration parameter
900900 */
901901static inline uint32_t i2s_ll_tx_get_pdm_fs (i2s_dev_t * hw )
902902{
@@ -922,7 +922,7 @@ static inline void i2s_ll_rx_enable_pdm(i2s_dev_t *hw, bool pdm_enable)
922922 * @brief Configura TX a/u-law decompress or compress
923923 *
924924 * @param hw Peripheral I2S hardware instance address.
925- * @param pcm_cfg PCM configuration paramater
925+ * @param pcm_cfg PCM configuration parameter
926926 */
927927static inline void i2s_ll_tx_set_pcm_type (i2s_dev_t * hw , i2s_pcm_compress_t pcm_cfg )
928928{
@@ -934,7 +934,7 @@ static inline void i2s_ll_tx_set_pcm_type(i2s_dev_t *hw, i2s_pcm_compress_t pcm_
934934 * @brief Configure RX a/u-law decompress or compress
935935 *
936936 * @param hw Peripheral I2S hardware instance address.
937- * @param pcm_cfg PCM configuration paramater
937+ * @param pcm_cfg PCM configuration parameter
938938 */
939939static inline void i2s_ll_rx_set_pcm_type (i2s_dev_t * hw , i2s_pcm_compress_t pcm_cfg )
940940{
@@ -1106,7 +1106,7 @@ static inline void i2s_ll_tx_pdm_dma_take_mode(i2s_dev_t *hw, bool is_mono, bool
11061106 * @param is_mono The DMA data only has one slot (mono) or contains two slots (stereo)
11071107 * @param is_copy Whether the un-selected slot copies the data from the selected one
11081108 * If not, the un-selected slot will transmit the data from 'conf_single_data'
1109- * @param mask The slot mask to selet the slot
1109+ * @param mask The slot mask to select the slot
11101110 */
11111111static inline void i2s_ll_tx_pdm_slot_mode (i2s_dev_t * hw , bool is_mono , bool is_copy , i2s_pdm_slot_mask_t mask )
11121112{
0 commit comments