/********************************************************************//** * @brief Configuration I2S, setting: * - master/slave mode * - wordwidth value * - channel mode * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S0 or LPC_I2S1 * @param[in] TRMode transmit/receive mode, should be: * - I2S_TX_MODE = 0 :transmit mode * - I2S_RX_MODE = 1 :receive mode * @param[in] ConfigStruct pointer to I2S_CFG_Type structure * which will be initialized. * @return none *********************************************************************/ void I2S_Config(LPC_I2Sn_Type *I2Sx, uint8_t TRMode, I2S_CFG_Type* ConfigStruct) { uint32_t bps, config; CHECK_PARAM(PARAM_I2Sx(I2Sx)); CHECK_PARAM(PARAM_I2S_WORDWIDTH(ConfigStruct->wordwidth)); CHECK_PARAM(PARAM_I2S_CHANNEL(ConfigStruct->mono)); CHECK_PARAM(PARAM_I2S_STOP(ConfigStruct->stop)); CHECK_PARAM(PARAM_I2S_RESET(ConfigStruct->reset)); CHECK_PARAM(PARAM_I2S_WS_SEL(ConfigStruct->ws_sel)); CHECK_PARAM(PARAM_I2S_MUTE(ConfigStruct->mute)); /* Setup clock */ bps = (ConfigStruct->wordwidth +1)*8; /* Calculate audio config */ config = (bps - 1)<<6 | (ConfigStruct->ws_sel)<<5 | (ConfigStruct->reset)<<4 | (ConfigStruct->stop)<<3 | (ConfigStruct->mono)<<2 | (ConfigStruct->wordwidth); if(TRMode == I2S_RX_MODE){ I2Sx->DAI = config; }else{ I2Sx->DAO = config; } }
/********************************************************************//** * @brief Initialize I2S * - Turn on power and clock * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S0 or LPC_I2S1 * @return none *********************************************************************/ void I2S_Init(LPC_I2Sn_Type *I2Sx) { CHECK_PARAM(PARAM_I2Sx(I2Sx)); // Turn on power and clock //CGU_ConfigPPWR(CGU_PCONP_PCI2S, ENABLE); I2Sx->DAI = I2Sx->DAO = 0x00; }
/********************************************************************//** * @brief Get I2S channel value * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S * @param[in] TRMode is the I2S mode, should be: * - I2S_TX_MODE = 0: transmit mode * - I2S_RX_MODE = 1: receive mode * @return The channel value, should be: 1(mono) or 2(stereo) *********************************************************************/ static uint8_t i2s_GetChannel(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) { uint8_t value; CHECK_PARAM(PARAM_I2Sx(I2Sx)); CHECK_PARAM(PARAM_I2S_TRX(TRMode)); if (TRMode == I2S_TX_MODE) { value = ((I2Sx->I2SDAO) & 0x04)>>2; /* get bit[2] */ } else {
/********************************************************************//** * @brief Get I2S Buffer Level * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S0 or LPC_I2S1 * @param[in] TRMode Transmit/receive mode, should be: * - I2S_TX_MODE = 0 :transmit mode * - I2S_RX_MODE = 1 :receive mode * @return current level of Transmit/Receive Buffer *********************************************************************/ uint8_t I2S_GetLevel(LPC_I2Sn_Type *I2Sx, uint8_t TRMode) { CHECK_PARAM(PARAM_I2Sx(I2Sx)); CHECK_PARAM(PARAM_I2S_TRX(TRMode)); if(TRMode == I2S_TX_MODE) { return ((I2Sx->STATE >> 16) & 0xFF); } else { return ((I2Sx->STATE >> 8) & 0xFF);
/********************************************************************//** * @brief Get I2S channel value * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S0 or LPC_I2S1 * @param[in] TRMode is the I2S mode, should be: * - I2S_TX_MODE = 0 :transmit mode * - I2S_RX_MODE = 1 :receive mode * @return The channel value, should be: 1(mono) or 2(stereo) *********************************************************************/ static uint8_t i2s_GetChannel(LPC_I2Sn_Type *I2Sx, uint8_t TRMode) { uint8_t value; CHECK_PARAM(PARAM_I2Sx(I2Sx)); CHECK_PARAM(PARAM_I2S_TRX(TRMode)); if (TRMode == I2S_TX_MODE) { value = (I2Sx->DAO) & 0x04; /* get bit[2] */ } else { value = (I2Sx->DAI) & 0x04; /* get bit[2] */ } value >>= 2; if(value == I2S_MONO) return 1; return 2; }
/********************************************************************//** * @brief Get I2S wordwidth value * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S * @param[in] TRMode is the I2S mode, should be: * - I2S_TX_MODE = 0: transmit mode * - I2S_RX_MODE = 1: receive mode * @return The wordwidth value, should be: 8,16 or 32 *********************************************************************/ static uint8_t i2s_GetWordWidth(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) { uint8_t value; CHECK_PARAM(PARAM_I2Sx(I2Sx)); CHECK_PARAM(PARAM_I2S_TRX(TRMode)); if (TRMode == I2S_TX_MODE) { value = (I2Sx->I2SDAO) & 0x03; /* get wordwidth bit */ } else { value = (I2Sx->I2SDAI) & 0x03; /* get wordwidth bit */ } switch (value) { case I2S_WORDWIDTH_8: return 8; case I2S_WORDWIDTH_16: return 16; default: return 32; } }
/********************************************************************//** * @brief DeInitial both I2S transmit or receive * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S0 or LPC_I2S1 * @return none *********************************************************************/ void I2S_DeInit(LPC_I2Sn_Type *I2Sx) { CHECK_PARAM(PARAM_I2Sx(I2Sx)); // Turn off power and clock //CGU_ConfigPPWR(CGU_PCONP_PCI2S, DISABLE); }