/* Configure I2S for Audio Format input */ Status Chip_I2S_TxConfig(LPC_I2S_T *pI2S, I2S_AUDIO_FORMAT_T *format) { uint32_t temp=0; uint16_t xDiv, yDiv; uint32_t N; if (getClkDiv(pI2S, format, &xDiv, &yDiv, &N) == ERROR) { return ERROR; } //temp = pI2S->DAO & (~(I2S_DAO_WORDWIDTH_MASK | I2S_DAO_MONO | I2S_DAO_SLAVE | I2S_DAO_WS_HALFPERIOD_MASK)); /*if (format->WordWidth <= 8) { temp |= I2S_WORDWIDTH_8; } else if (format->WordWidth <= 16) { temp |= I2S_WORDWIDTH_16; } else { temp |= I2S_WORDWIDTH_32; }*/ temp |= I2S_WORDWIDTH_32; pI2S->DAO = I2S_DAO_WS_HALFPERIOD(format->WordWidth - 1); temp |=I2S_STEREO; //(format->ChannelNumber) == 1 ? I2S_MONO : I2S_STEREO; temp |= I2S_MASTER_MODE; temp |= I2S_DAO_WS_HALFPERIOD(format->WordWidth - 1); pI2S->DAO = temp; pI2S->TXMODE = I2S_TXMODE_CLKSEL(0); pI2S->TXBITRATE = N-1; pI2S->TXRATE = yDiv | (xDiv << 8); return SUCCESS; } /* Configure I2S for Audio Format input */ Status Chip_I2S_RxConfig(LPC_I2S_T *pI2S, I2S_AUDIO_FORMAT_T *format) { uint32_t temp; uint16_t xDiv, yDiv; uint32_t N; if (getClkDiv(pI2S, format, &xDiv, &yDiv, &N) == ERROR) { return ERROR; } temp = pI2S->DAI & (~(I2S_DAI_WORDWIDTH_MASK | I2S_DAI_MONO | I2S_DAI_SLAVE | I2S_DAI_WS_HALFPERIOD_MASK)); if (format->WordWidth <= 8) { temp |= I2S_WORDWIDTH_8; } else if (format->WordWidth <= 16) { temp |= I2S_WORDWIDTH_16; } else { temp |= I2S_WORDWIDTH_32; } temp |= (format->ChannelNumber) == 1 ? I2S_MONO : I2S_STEREO; temp |= I2S_MASTER_MODE; temp |= I2S_DAI_WS_HALFPERIOD(format->WordWidth - 1); pI2S->DAI = temp; pI2S->RXMODE = I2S_RXMODE_CLKSEL(0); pI2S->RXBITRATE = N - 1; pI2S->RXRATE = yDiv | (xDiv << 8); return SUCCESS; } |