34static uint32_t I2S_GetSourceClockFreq(
I2S_T *i2s)
36 uint32_t u32Freq, u32ClkSrcSel;
88uint32_t
I2S_Open(
I2S_T *i2s, uint32_t u32MasterSlave, uint32_t u32SampleRate, uint32_t u32WordWidth, uint32_t u32Channels, uint32_t u32DataFormat, uint32_t u32AudioInterface)
91 uint32_t u32BitRate, u32SrcClk;
94 SYS->IPRST_CTL2 &= ~SYS_IPRST_CTL2_I2S_RST_Msk;
98 u32SrcClk = I2S_GetSourceClockFreq(i2s);
100 u32BitRate = u32SampleRate * (((u32WordWidth>>4) & 0x3) + 1) * 16;
101 u8Divider = ((u32SrcClk/u32BitRate) >> 1) - 1;
102 i2s->
CLKDIV = (i2s->
CLKDIV & ~I2S_CLKDIV_BCLK_DIV_Msk) | (u8Divider << 8);
105 u32BitRate = u32SrcClk / (2*(u8Divider+1));
106 u32SampleRate = u32BitRate / ((((u32WordWidth>>4) & 0x3) + 1) * 16);
110 return u32SampleRate;
120 i2s->
CTRL &= ~I2S_CTRL_I2SEN_Msk;
132 i2s->
INTEN |= u32Mask;
144 i2s->
INTEN &= ~u32Mask;
156 uint32_t u32SrcClk, u32Reg;
158 u32SrcClk = I2S_GetSourceClockFreq(i2s);
159 if (u32BusClock == u32SrcClk)
162 u8Divider = (u32SrcClk/u32BusClock) >> 1;
164 i2s->
CLKDIV = (i2s->
CLKDIV & ~I2S_CLKDIV_MCLK_DIV_Msk) | u8Divider;
173 return ((u32SrcClk >> 1) / u32Reg);
183 i2s->
CTRL &= ~I2S_CTRL_MCLKEN_Msk;
Nano100 series peripheral access layer header file. This file contains all the peripheral register's ...
#define I2S_CTRL_I2SEN_Msk
#define I2S_CTRL_RXTH_Pos
#define I2S_CTRL_MCLKEN_Msk
#define I2S_CTRL_TXTH_Pos
#define SYS_IPRST_CTL2_I2S_RST_Msk
#define I2S_CTRL_RXTH_Msk
#define I2S_CLKDIV_MCLK_DIV_Msk
#define I2S_CTRL_TXTH_Msk
#define CLK_CLKSEL2_I2S_S_PLL
#define CLK_CLKSEL2_I2S_S_HIRC
#define CLK_CLKSEL2_I2S_S_HXT
uint32_t CLK_GetPLLClockFreq(void)
This function get PLL frequency. The frequency unit is Hz.
#define CLK_CLKSEL2_I2S_S_Msk
#define I2S_FIFO_TX_LEVEL_WORD_4
#define I2S_FIFO_RX_LEVEL_WORD_4
void I2S_SetFIFO(I2S_T *i2s, uint32_t u32TxThreshold, uint32_t u32RxThreshold)
Configure FIFO threshold setting.
uint32_t I2S_Open(I2S_T *i2s, uint32_t u32MasterSlave, uint32_t u32SampleRate, uint32_t u32WordWidth, uint32_t u32Channels, uint32_t u32DataFormat, uint32_t u32AudioInterface)
This function configures some parameters of I2S interface for general purpose use....
void I2S_DisableInt(I2S_T *i2s, uint32_t u32Mask)
This function disables the interrupt according to the mask parameter.
void I2S_DisableMCLK(I2S_T *i2s)
Disable MCLK .
uint32_t I2S_EnableMCLK(I2S_T *i2s, uint32_t u32BusClock)
Enable MCLK .
void I2S_EnableInt(I2S_T *i2s, uint32_t u32Mask)
This function enables the interrupt according to the mask parameter.
void I2S_Close(I2S_T *i2s)
Disable I2S function and I2S clock.
#define CLK
Pointer to CLK register structure.
#define SYS
Pointer to SYS register structure.