i2s: add basic examples for STD/TDM/PDM mode

This commit is contained in:
laokaiyao
2022-06-20 20:30:31 +08:00
parent 92b4e134bb
commit 90866e99fb
64 changed files with 1616 additions and 409 deletions

View File

@@ -218,6 +218,40 @@ static inline void i2s_ll_tx_set_bck_div_num(i2s_dev_t *hw, uint32_t val)
hw->tx_conf1.tx_bck_div_num = val - 1;
}
/**
* @brief Set I2S tx raw clock division
*
* @param hw Peripheral I2S hardware instance address.
* @param x div x
* @param y div y
* @param z div z
* @param yn1 yn1
*/
static inline void i2s_ll_tx_set_raw_clk_div(i2s_dev_t *hw, uint32_t x, uint32_t y, uint32_t z, uint32_t yn1)
{
hw->tx_clkm_div_conf.tx_clkm_div_x = x;
hw->tx_clkm_div_conf.tx_clkm_div_y = y;
hw->tx_clkm_div_conf.tx_clkm_div_z = z;
hw->tx_clkm_div_conf.tx_clkm_div_yn1 = yn1;
}
/**
* @brief Set I2S rx raw clock division
*
* @param hw Peripheral I2S hardware instance address.
* @param x div x
* @param y div y
* @param z div z
* @param yn1 yn1
*/
static inline void i2s_ll_rx_set_raw_clk_div(i2s_dev_t *hw, uint32_t x, uint32_t y, uint32_t z, uint32_t yn1)
{
hw->rx_clkm_div_conf.rx_clkm_div_x = x;
hw->rx_clkm_div_conf.rx_clkm_div_y = y;
hw->rx_clkm_div_conf.rx_clkm_div_z = z;
hw->rx_clkm_div_conf.rx_clkm_div_yn1 = yn1;
}
/**
* @brief Configure I2S TX module clock divider
*
@@ -272,7 +306,7 @@ finish:
hw->tx_clkm_div_conf.tx_clkm_div_yn1 = 1;
} else {
hw->tx_clkm_div_conf.tx_clkm_div_x = denominator / numerator - 1;
hw->tx_clkm_div_conf.tx_clkm_div_y = denominator % numerator + 1;
hw->tx_clkm_div_conf.tx_clkm_div_y = denominator % numerator;
hw->tx_clkm_div_conf.tx_clkm_div_z = numerator;
hw->tx_clkm_div_conf.tx_clkm_div_yn1 = 0;
}
@@ -346,7 +380,7 @@ finish:
hw->rx_clkm_div_conf.rx_clkm_div_yn1 = 1;
} else {
hw->rx_clkm_div_conf.rx_clkm_div_x = denominator / numerator - 1;
hw->rx_clkm_div_conf.rx_clkm_div_y = denominator % numerator + 1;
hw->rx_clkm_div_conf.rx_clkm_div_y = denominator % numerator;
hw->rx_clkm_div_conf.rx_clkm_div_z = numerator;
hw->rx_clkm_div_conf.rx_clkm_div_yn1 = 0;
}
@@ -607,6 +641,29 @@ static inline void i2s_ll_rx_select_slot(i2s_dev_t *hw, i2s_std_slot_mask_t slot
}
}
/**
* @brief PDM slot mode
*
* @param hw Peripheral I2S hardware instance address.
* @param mod Channel mode
* while tx_ws_idle_pol = 0:
* 0: stereo
* 1: Both slots transmit left
* 2: Both slots transmit right
* 3: Left transmits `conf_single_data` right transmits data
* 4: Right transmits `conf_single_data` left transmits data
* while tx_ws_idle_pol = 1:
0: stereo
* 1: Both slots transmit right
* 2: Both slots transmit left
* 3: Right transmits `conf_single_data` left transmits data
* 4: Left transmits `conf_single_data` right transmits data
*/
static inline void i2s_ll_tx_set_pdm_chan_mod(i2s_dev_t *hw, uint32_t mod)
{
hw->tx_conf.tx_chan_mod = mod;
}
/**
* @brief Set TX WS signal pol level
*
@@ -772,18 +829,6 @@ static inline void i2s_ll_tx_enable_pdm_hp_filter(i2s_dev_t *hw, bool enable)
hw->tx_pcm2pdm_conf.tx_pdm_hp_bypass = !enable;
}
/**
* @brief Enable I2S TX PDM sigma-delta codec
*
* @param hw Peripheral I2S hardware instance address.
* @param dither I2S TX PDM sigmadelta dither value
*/
static inline void i2s_ll_tx_enable_pdm_sd_codec(i2s_dev_t *hw, bool enable)
{
hw->tx_pcm2pdm_conf.tx_pdm_dac_2out_en = enable;
hw->tx_pcm2pdm_conf.tx_pdm_dac_mode_en = enable;
}
/**
* @brief Set I2S TX PDM sigma-delta codec dither
*
@@ -1010,6 +1055,73 @@ static inline void i2s_ll_share_bck_ws(i2s_dev_t *hw, bool ena)
hw->tx_conf.sig_loopback = ena;
}
/**
* @brief PDM TX DMA data take mode
*
* @param hw Peripheral I2S hardware instance address.
* @param is_mono The DMA data only has one slot (mono) or contains two slots (stereo)
* @param is_fst_valid Whether take the DMA data at the first half period
* Only take effet when 'is_mono' is true
*/
static inline void i2s_ll_tx_pdm_dma_take_mode(i2s_dev_t *hw, bool is_mono, bool is_fst_valid)
{
hw->tx_conf.tx_mono = is_mono;
hw->tx_conf.tx_mono_fst_vld = is_fst_valid;
}
/**
* @brief PDM TX slot mode
* @note Mode Left Slot Right Slot Chan Mode WS Pol
* -----------------------------------------------------------------
* Stereo Left Right 0 x
* -----------------------------------------------------------------
* Mono Left Left 1 0
* Mono Right Right 2 0
* Mono Single Right 3 0
* Mono Left Single 4 0
* -----------------------------------------------------------------
* Mono Right Right 1 1
* Mono Left Left 2 1
* Mono Left Single 3 1
* Mono Single Right 4 1
*
* @param hw Peripheral I2S hardware instance address.
* @param is_mono The DMA data only has one slot (mono) or contains two slots (stereo)
* @param is_copy Whether the un-selected slot copies the data from the selected one
* If not, the un-selected slot will transmit the data from 'conf_single_data'
* @param mask The slot mask to selet the slot
*/
static inline void i2s_ll_tx_pdm_slot_mode(i2s_dev_t *hw, bool is_mono, bool is_copy, i2s_pdm_slot_mask_t mask)
{
if (is_mono) {
/* The default tx_ws_idle_pol is false */
if (is_copy) {
hw->tx_conf.tx_chan_mod = mask == I2S_PDM_SLOT_LEFT ? 1 : 2;
} else {
hw->tx_conf.tx_chan_mod = mask == I2S_PDM_SLOT_LEFT ? 4 : 3;
}
} else {
hw->tx_conf.tx_chan_mod = 0;
}
}
/**
* @brief PDM TX line mode
* @note Mode DAC Mode 2 lines output
* -------------------------------------------
* PDM codec 0 1
* DAC 1-line 1 0
* DAC 2-line 1 1
*
* @param hw Peripheral I2S hardware instance address.
* @param line_mode PDM TX line mode
*/
static inline void i2s_ll_tx_pdm_line_mode(i2s_dev_t *hw, i2s_pdm_tx_line_mode_t line_mode)
{
hw->tx_pcm2pdm_conf.tx_pdm_dac_mode_en = line_mode > I2S_PDM_TX_ONE_LINE_CODEC;
hw->tx_pcm2pdm_conf.tx_pdm_dac_2out_en = line_mode != I2S_PDM_TX_ONE_LINE_DAC;
}
#ifdef __cplusplus
}
#endif