パラメータを適応変化させる事により圧縮率を向上させた動的ライス・ゴロム符号を利用した可逆圧縮方式。圧縮ソフト、圧縮率のMATLABシミュレーションは詳細はInterface誌2011年8月号に掲載されるRX62Nマイコン連動特集にて掲載予定。
I2S_Example/lpc17xx_i2s.c@0:d920d64db582, 2011-03-30 (annotated)
- Committer:
- lynxeyed_atsu
- Date:
- Wed Mar 30 06:05:24 2011 +0000
- Revision:
- 0:d920d64db582
alpha
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lynxeyed_atsu | 0:d920d64db582 | 1 | /***********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 2 | * @file lpc17xx_i2s.c |
lynxeyed_atsu | 0:d920d64db582 | 3 | * @brief Contains all functions support for I2S firmware library on LPC17xx |
lynxeyed_atsu | 0:d920d64db582 | 4 | * @version 3.0 |
lynxeyed_atsu | 0:d920d64db582 | 5 | * @date 18. June. 2010 |
lynxeyed_atsu | 0:d920d64db582 | 6 | * @author NXP MCU SW Application Team |
lynxeyed_atsu | 0:d920d64db582 | 7 | ************************************************************************** |
lynxeyed_atsu | 0:d920d64db582 | 8 | * Software that is described herein is for illustrative purposes only |
lynxeyed_atsu | 0:d920d64db582 | 9 | * which provides customers with programming information regarding the |
lynxeyed_atsu | 0:d920d64db582 | 10 | * products. This software is supplied "AS IS" without any warranties. |
lynxeyed_atsu | 0:d920d64db582 | 11 | * NXP Semiconductors assumes no responsibility or liability for the |
lynxeyed_atsu | 0:d920d64db582 | 12 | * use of the software, conveys no license or title under any patent, |
lynxeyed_atsu | 0:d920d64db582 | 13 | * copyright, or mask work right to the product. NXP Semiconductors |
lynxeyed_atsu | 0:d920d64db582 | 14 | * reserves the right to make changes in the software without |
lynxeyed_atsu | 0:d920d64db582 | 15 | * notification. NXP Semiconductors also make no representation or |
lynxeyed_atsu | 0:d920d64db582 | 16 | * warranty that such application will be suitable for the specified |
lynxeyed_atsu | 0:d920d64db582 | 17 | * use without further testing or modification. |
lynxeyed_atsu | 0:d920d64db582 | 18 | **********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 19 | |
lynxeyed_atsu | 0:d920d64db582 | 20 | /* Peripheral group ----------------------------------------------------------- */ |
lynxeyed_atsu | 0:d920d64db582 | 21 | /** @addtogroup I2S |
lynxeyed_atsu | 0:d920d64db582 | 22 | * @{ |
lynxeyed_atsu | 0:d920d64db582 | 23 | */ |
lynxeyed_atsu | 0:d920d64db582 | 24 | |
lynxeyed_atsu | 0:d920d64db582 | 25 | /* Includes ------------------------------------------------------------------- */ |
lynxeyed_atsu | 0:d920d64db582 | 26 | //#include "mbed.h" |
lynxeyed_atsu | 0:d920d64db582 | 27 | #include "lpc17xx_i2s.h" |
lynxeyed_atsu | 0:d920d64db582 | 28 | #include "lpc17xx_clkpwr.h" |
lynxeyed_atsu | 0:d920d64db582 | 29 | #include "mbed.h" |
lynxeyed_atsu | 0:d920d64db582 | 30 | |
lynxeyed_atsu | 0:d920d64db582 | 31 | |
lynxeyed_atsu | 0:d920d64db582 | 32 | /* If this source file built with example, the LPC17xx FW library configuration |
lynxeyed_atsu | 0:d920d64db582 | 33 | * file in each example directory ("lpc17xx_libcfg.h") must be included, |
lynxeyed_atsu | 0:d920d64db582 | 34 | * otherwise the default FW library configuration file must be included instead |
lynxeyed_atsu | 0:d920d64db582 | 35 | */ |
lynxeyed_atsu | 0:d920d64db582 | 36 | #ifdef __BUILD_WITH_EXAMPLE__ |
lynxeyed_atsu | 0:d920d64db582 | 37 | #include "lpc17xx_libcfg.h" |
lynxeyed_atsu | 0:d920d64db582 | 38 | #else |
lynxeyed_atsu | 0:d920d64db582 | 39 | #include "lpc17xx_libcfg_default.h" |
lynxeyed_atsu | 0:d920d64db582 | 40 | #endif /* __BUILD_WITH_EXAMPLE__ */ |
lynxeyed_atsu | 0:d920d64db582 | 41 | |
lynxeyed_atsu | 0:d920d64db582 | 42 | |
lynxeyed_atsu | 0:d920d64db582 | 43 | #ifdef _I2S |
lynxeyed_atsu | 0:d920d64db582 | 44 | |
lynxeyed_atsu | 0:d920d64db582 | 45 | /* Private Functions ---------------------------------------------------------- */ |
lynxeyed_atsu | 0:d920d64db582 | 46 | |
lynxeyed_atsu | 0:d920d64db582 | 47 | static uint8_t i2s_GetWordWidth(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode); |
lynxeyed_atsu | 0:d920d64db582 | 48 | static uint8_t i2s_GetChannel(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode); |
lynxeyed_atsu | 0:d920d64db582 | 49 | |
lynxeyed_atsu | 0:d920d64db582 | 50 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 51 | * @brief Get I2S wordwidth value |
lynxeyed_atsu | 0:d920d64db582 | 52 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 53 | * @param[in] TRMode is the I2S mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 54 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 55 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 56 | * @return The wordwidth value, should be: 8,16 or 32 |
lynxeyed_atsu | 0:d920d64db582 | 57 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 58 | static uint8_t i2s_GetWordWidth(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) { |
lynxeyed_atsu | 0:d920d64db582 | 59 | uint8_t value; |
lynxeyed_atsu | 0:d920d64db582 | 60 | |
lynxeyed_atsu | 0:d920d64db582 | 61 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 62 | CHECK_PARAM(PARAM_I2S_TRX(TRMode)); |
lynxeyed_atsu | 0:d920d64db582 | 63 | |
lynxeyed_atsu | 0:d920d64db582 | 64 | if (TRMode == I2S_TX_MODE) { |
lynxeyed_atsu | 0:d920d64db582 | 65 | value = (I2Sx->I2SDAO) & 0x03; /* get wordwidth bit */ |
lynxeyed_atsu | 0:d920d64db582 | 66 | } else { |
lynxeyed_atsu | 0:d920d64db582 | 67 | value = (I2Sx->I2SDAI) & 0x03; /* get wordwidth bit */ |
lynxeyed_atsu | 0:d920d64db582 | 68 | } |
lynxeyed_atsu | 0:d920d64db582 | 69 | switch (value) { |
lynxeyed_atsu | 0:d920d64db582 | 70 | case I2S_WORDWIDTH_8: |
lynxeyed_atsu | 0:d920d64db582 | 71 | return 8; |
lynxeyed_atsu | 0:d920d64db582 | 72 | case I2S_WORDWIDTH_16: |
lynxeyed_atsu | 0:d920d64db582 | 73 | return 16; |
lynxeyed_atsu | 0:d920d64db582 | 74 | default: |
lynxeyed_atsu | 0:d920d64db582 | 75 | return 32; |
lynxeyed_atsu | 0:d920d64db582 | 76 | } |
lynxeyed_atsu | 0:d920d64db582 | 77 | } |
lynxeyed_atsu | 0:d920d64db582 | 78 | |
lynxeyed_atsu | 0:d920d64db582 | 79 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 80 | * @brief Get I2S channel value |
lynxeyed_atsu | 0:d920d64db582 | 81 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 82 | * @param[in] TRMode is the I2S mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 83 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 84 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 85 | * @return The channel value, should be: 1(mono) or 2(stereo) |
lynxeyed_atsu | 0:d920d64db582 | 86 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 87 | static uint8_t i2s_GetChannel(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) { |
lynxeyed_atsu | 0:d920d64db582 | 88 | uint8_t value; |
lynxeyed_atsu | 0:d920d64db582 | 89 | |
lynxeyed_atsu | 0:d920d64db582 | 90 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 91 | CHECK_PARAM(PARAM_I2S_TRX(TRMode)); |
lynxeyed_atsu | 0:d920d64db582 | 92 | |
lynxeyed_atsu | 0:d920d64db582 | 93 | if (TRMode == I2S_TX_MODE) { |
lynxeyed_atsu | 0:d920d64db582 | 94 | value = (I2Sx->I2SDAO) & 0x04; /* get bit[2] */ |
lynxeyed_atsu | 0:d920d64db582 | 95 | } else { |
lynxeyed_atsu | 0:d920d64db582 | 96 | value = (I2Sx->I2SDAI) & 0x04; /* get bit[2] */ |
lynxeyed_atsu | 0:d920d64db582 | 97 | } |
lynxeyed_atsu | 0:d920d64db582 | 98 | if(value == I2S_MONO) return 1; |
lynxeyed_atsu | 0:d920d64db582 | 99 | return 2; |
lynxeyed_atsu | 0:d920d64db582 | 100 | } |
lynxeyed_atsu | 0:d920d64db582 | 101 | |
lynxeyed_atsu | 0:d920d64db582 | 102 | /* End of Private Functions --------------------------------------------------- */ |
lynxeyed_atsu | 0:d920d64db582 | 103 | |
lynxeyed_atsu | 0:d920d64db582 | 104 | |
lynxeyed_atsu | 0:d920d64db582 | 105 | /* Public Functions ----------------------------------------------------------- */ |
lynxeyed_atsu | 0:d920d64db582 | 106 | /** @addtogroup I2S_Public_Functions |
lynxeyed_atsu | 0:d920d64db582 | 107 | * @{ |
lynxeyed_atsu | 0:d920d64db582 | 108 | */ |
lynxeyed_atsu | 0:d920d64db582 | 109 | |
lynxeyed_atsu | 0:d920d64db582 | 110 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 111 | * @brief Initialize I2S |
lynxeyed_atsu | 0:d920d64db582 | 112 | * - Turn on power and clock |
lynxeyed_atsu | 0:d920d64db582 | 113 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 114 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 115 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 116 | void I2S_Init(LPC_I2S_TypeDef *I2Sx) { |
lynxeyed_atsu | 0:d920d64db582 | 117 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 118 | |
lynxeyed_atsu | 0:d920d64db582 | 119 | // Turn on power and clock |
lynxeyed_atsu | 0:d920d64db582 | 120 | CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCI2S, ENABLE); |
lynxeyed_atsu | 0:d920d64db582 | 121 | LPC_I2S->I2SDAI = LPC_I2S->I2SDAO = 0x00; |
lynxeyed_atsu | 0:d920d64db582 | 122 | } |
lynxeyed_atsu | 0:d920d64db582 | 123 | |
lynxeyed_atsu | 0:d920d64db582 | 124 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 125 | * @brief Configuration I2S, setting: |
lynxeyed_atsu | 0:d920d64db582 | 126 | * - master/slave mode |
lynxeyed_atsu | 0:d920d64db582 | 127 | * - wordwidth value |
lynxeyed_atsu | 0:d920d64db582 | 128 | * - channel mode |
lynxeyed_atsu | 0:d920d64db582 | 129 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 130 | * @param[in] TRMode transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 131 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 132 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 133 | * @param[in] ConfigStruct pointer to I2S_CFG_Type structure |
lynxeyed_atsu | 0:d920d64db582 | 134 | * which will be initialized. |
lynxeyed_atsu | 0:d920d64db582 | 135 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 136 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 137 | void I2S_Config(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode, I2S_CFG_Type* ConfigStruct) |
lynxeyed_atsu | 0:d920d64db582 | 138 | { |
lynxeyed_atsu | 0:d920d64db582 | 139 | uint32_t bps, config; |
lynxeyed_atsu | 0:d920d64db582 | 140 | |
lynxeyed_atsu | 0:d920d64db582 | 141 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 142 | |
lynxeyed_atsu | 0:d920d64db582 | 143 | CHECK_PARAM(PARAM_I2S_WORDWIDTH(ConfigStruct->wordwidth)); |
lynxeyed_atsu | 0:d920d64db582 | 144 | CHECK_PARAM(PARAM_I2S_CHANNEL(ConfigStruct->mono)); |
lynxeyed_atsu | 0:d920d64db582 | 145 | CHECK_PARAM(PARAM_I2S_STOP(ConfigStruct->stop)); |
lynxeyed_atsu | 0:d920d64db582 | 146 | CHECK_PARAM(PARAM_I2S_RESET(ConfigStruct->reset)); |
lynxeyed_atsu | 0:d920d64db582 | 147 | CHECK_PARAM(PARAM_I2S_WS_SEL(ConfigStruct->ws_sel)); |
lynxeyed_atsu | 0:d920d64db582 | 148 | CHECK_PARAM(PARAM_I2S_MUTE(ConfigStruct->mute)); |
lynxeyed_atsu | 0:d920d64db582 | 149 | |
lynxeyed_atsu | 0:d920d64db582 | 150 | /* Setup clock */ |
lynxeyed_atsu | 0:d920d64db582 | 151 | bps = (ConfigStruct->wordwidth +1)*8; |
lynxeyed_atsu | 0:d920d64db582 | 152 | |
lynxeyed_atsu | 0:d920d64db582 | 153 | /* Calculate audio config */ |
lynxeyed_atsu | 0:d920d64db582 | 154 | config = (bps - 1)<<6 | (ConfigStruct->ws_sel)<<5 | (ConfigStruct->reset)<<4 | |
lynxeyed_atsu | 0:d920d64db582 | 155 | (ConfigStruct->stop)<<3 | (ConfigStruct->mono)<<2 | (ConfigStruct->wordwidth); |
lynxeyed_atsu | 0:d920d64db582 | 156 | |
lynxeyed_atsu | 0:d920d64db582 | 157 | if(TRMode == I2S_RX_MODE){ |
lynxeyed_atsu | 0:d920d64db582 | 158 | LPC_I2S->I2SDAI = config; |
lynxeyed_atsu | 0:d920d64db582 | 159 | }else{ |
lynxeyed_atsu | 0:d920d64db582 | 160 | LPC_I2S->I2SDAO = config; |
lynxeyed_atsu | 0:d920d64db582 | 161 | } |
lynxeyed_atsu | 0:d920d64db582 | 162 | } |
lynxeyed_atsu | 0:d920d64db582 | 163 | |
lynxeyed_atsu | 0:d920d64db582 | 164 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 165 | * @brief DeInitial both I2S transmit or receive |
lynxeyed_atsu | 0:d920d64db582 | 166 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 167 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 168 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 169 | void I2S_DeInit(LPC_I2S_TypeDef *I2Sx) { |
lynxeyed_atsu | 0:d920d64db582 | 170 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 171 | |
lynxeyed_atsu | 0:d920d64db582 | 172 | // Turn off power and clock |
lynxeyed_atsu | 0:d920d64db582 | 173 | CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCI2S, DISABLE); |
lynxeyed_atsu | 0:d920d64db582 | 174 | } |
lynxeyed_atsu | 0:d920d64db582 | 175 | |
lynxeyed_atsu | 0:d920d64db582 | 176 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 177 | * @brief Get I2S Buffer Level |
lynxeyed_atsu | 0:d920d64db582 | 178 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 179 | * @param[in] TRMode Transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 180 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 181 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 182 | * @return current level of Transmit/Receive Buffer |
lynxeyed_atsu | 0:d920d64db582 | 183 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 184 | uint8_t I2S_GetLevel(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) |
lynxeyed_atsu | 0:d920d64db582 | 185 | { |
lynxeyed_atsu | 0:d920d64db582 | 186 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 187 | CHECK_PARAM(PARAM_I2S_TRX(TRMode)); |
lynxeyed_atsu | 0:d920d64db582 | 188 | |
lynxeyed_atsu | 0:d920d64db582 | 189 | if(TRMode == I2S_TX_MODE) |
lynxeyed_atsu | 0:d920d64db582 | 190 | { |
lynxeyed_atsu | 0:d920d64db582 | 191 | return ((I2Sx->I2SSTATE >> 16) & 0xFF); |
lynxeyed_atsu | 0:d920d64db582 | 192 | } |
lynxeyed_atsu | 0:d920d64db582 | 193 | else |
lynxeyed_atsu | 0:d920d64db582 | 194 | { |
lynxeyed_atsu | 0:d920d64db582 | 195 | return ((I2Sx->I2SSTATE >> 8) & 0xFF); |
lynxeyed_atsu | 0:d920d64db582 | 196 | } |
lynxeyed_atsu | 0:d920d64db582 | 197 | } |
lynxeyed_atsu | 0:d920d64db582 | 198 | |
lynxeyed_atsu | 0:d920d64db582 | 199 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 200 | * @brief I2S Start: clear all STOP,RESET and MUTE bit, ready to operate |
lynxeyed_atsu | 0:d920d64db582 | 201 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 202 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 203 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 204 | void I2S_Start(LPC_I2S_TypeDef *I2Sx) |
lynxeyed_atsu | 0:d920d64db582 | 205 | { |
lynxeyed_atsu | 0:d920d64db582 | 206 | //Clear STOP,RESET and MUTE bit |
lynxeyed_atsu | 0:d920d64db582 | 207 | I2Sx->I2SDAO &= ~I2S_DAI_RESET; |
lynxeyed_atsu | 0:d920d64db582 | 208 | I2Sx->I2SDAI &= ~I2S_DAI_RESET; |
lynxeyed_atsu | 0:d920d64db582 | 209 | I2Sx->I2SDAO &= ~I2S_DAI_STOP; |
lynxeyed_atsu | 0:d920d64db582 | 210 | I2Sx->I2SDAI &= ~I2S_DAI_STOP; |
lynxeyed_atsu | 0:d920d64db582 | 211 | I2Sx->I2SDAO &= ~I2S_DAI_MUTE; |
lynxeyed_atsu | 0:d920d64db582 | 212 | } |
lynxeyed_atsu | 0:d920d64db582 | 213 | |
lynxeyed_atsu | 0:d920d64db582 | 214 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 215 | * @brief I2S Send data |
lynxeyed_atsu | 0:d920d64db582 | 216 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 217 | * @param[in] BufferData pointer to uint32_t is the data will be send |
lynxeyed_atsu | 0:d920d64db582 | 218 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 219 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 220 | void I2S_Send(LPC_I2S_TypeDef *I2Sx, uint32_t BufferData) { |
lynxeyed_atsu | 0:d920d64db582 | 221 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 222 | |
lynxeyed_atsu | 0:d920d64db582 | 223 | I2Sx->I2STXFIFO = BufferData; |
lynxeyed_atsu | 0:d920d64db582 | 224 | } |
lynxeyed_atsu | 0:d920d64db582 | 225 | |
lynxeyed_atsu | 0:d920d64db582 | 226 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 227 | * @brief I2S Receive Data |
lynxeyed_atsu | 0:d920d64db582 | 228 | * @param[in] I2Sx pointer to LPC_I2S_TypeDef |
lynxeyed_atsu | 0:d920d64db582 | 229 | * @return received value |
lynxeyed_atsu | 0:d920d64db582 | 230 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 231 | uint32_t I2S_Receive(LPC_I2S_TypeDef* I2Sx) { |
lynxeyed_atsu | 0:d920d64db582 | 232 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 233 | |
lynxeyed_atsu | 0:d920d64db582 | 234 | return (I2Sx->I2SRXFIFO); |
lynxeyed_atsu | 0:d920d64db582 | 235 | |
lynxeyed_atsu | 0:d920d64db582 | 236 | } |
lynxeyed_atsu | 0:d920d64db582 | 237 | |
lynxeyed_atsu | 0:d920d64db582 | 238 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 239 | * @brief I2S Pause |
lynxeyed_atsu | 0:d920d64db582 | 240 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 241 | * @param[in] TRMode is transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 242 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 243 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 244 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 245 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 246 | void I2S_Pause(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) { |
lynxeyed_atsu | 0:d920d64db582 | 247 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 248 | CHECK_PARAM(PARAM_I2S_TRX(TRMode)); |
lynxeyed_atsu | 0:d920d64db582 | 249 | |
lynxeyed_atsu | 0:d920d64db582 | 250 | if (TRMode == I2S_TX_MODE) //Transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 251 | { |
lynxeyed_atsu | 0:d920d64db582 | 252 | I2Sx->I2SDAO |= I2S_DAO_STOP; |
lynxeyed_atsu | 0:d920d64db582 | 253 | } else //Receive mode |
lynxeyed_atsu | 0:d920d64db582 | 254 | { |
lynxeyed_atsu | 0:d920d64db582 | 255 | I2Sx->I2SDAI |= I2S_DAI_STOP; |
lynxeyed_atsu | 0:d920d64db582 | 256 | } |
lynxeyed_atsu | 0:d920d64db582 | 257 | } |
lynxeyed_atsu | 0:d920d64db582 | 258 | |
lynxeyed_atsu | 0:d920d64db582 | 259 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 260 | * @brief I2S Mute |
lynxeyed_atsu | 0:d920d64db582 | 261 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 262 | * @param[in] TRMode is transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 263 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 264 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 265 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 266 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 267 | void I2S_Mute(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) { |
lynxeyed_atsu | 0:d920d64db582 | 268 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 269 | CHECK_PARAM(PARAM_I2S_TRX(TRMode)); |
lynxeyed_atsu | 0:d920d64db582 | 270 | |
lynxeyed_atsu | 0:d920d64db582 | 271 | if (TRMode == I2S_TX_MODE) //Transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 272 | { |
lynxeyed_atsu | 0:d920d64db582 | 273 | I2Sx->I2SDAO |= I2S_DAO_MUTE; |
lynxeyed_atsu | 0:d920d64db582 | 274 | } else //Receive mode |
lynxeyed_atsu | 0:d920d64db582 | 275 | { |
lynxeyed_atsu | 0:d920d64db582 | 276 | I2Sx->I2SDAI |= I2S_DAI_MUTE; |
lynxeyed_atsu | 0:d920d64db582 | 277 | } |
lynxeyed_atsu | 0:d920d64db582 | 278 | } |
lynxeyed_atsu | 0:d920d64db582 | 279 | |
lynxeyed_atsu | 0:d920d64db582 | 280 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 281 | * @brief I2S Stop |
lynxeyed_atsu | 0:d920d64db582 | 282 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 283 | * @param[in] TRMode is transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 284 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 285 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 286 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 287 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 288 | void I2S_Stop(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) { |
lynxeyed_atsu | 0:d920d64db582 | 289 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 290 | CHECK_PARAM(PARAM_I2S_TRX(TRMode)); |
lynxeyed_atsu | 0:d920d64db582 | 291 | |
lynxeyed_atsu | 0:d920d64db582 | 292 | if (TRMode == I2S_TX_MODE) //Transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 293 | { |
lynxeyed_atsu | 0:d920d64db582 | 294 | I2Sx->I2SDAO &= ~I2S_DAO_MUTE; |
lynxeyed_atsu | 0:d920d64db582 | 295 | I2Sx->I2SDAO |= I2S_DAO_STOP; |
lynxeyed_atsu | 0:d920d64db582 | 296 | I2Sx->I2SDAO |= I2S_DAO_RESET; |
lynxeyed_atsu | 0:d920d64db582 | 297 | } else //Receive mode |
lynxeyed_atsu | 0:d920d64db582 | 298 | { |
lynxeyed_atsu | 0:d920d64db582 | 299 | I2Sx->I2SDAI |= I2S_DAI_STOP; |
lynxeyed_atsu | 0:d920d64db582 | 300 | I2Sx->I2SDAI |= I2S_DAI_RESET; |
lynxeyed_atsu | 0:d920d64db582 | 301 | } |
lynxeyed_atsu | 0:d920d64db582 | 302 | } |
lynxeyed_atsu | 0:d920d64db582 | 303 | |
lynxeyed_atsu | 0:d920d64db582 | 304 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 305 | * @brief Set frequency for I2S |
lynxeyed_atsu | 0:d920d64db582 | 306 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 307 | * @param[in] Freq is the frequency for I2S will be set. It can range |
lynxeyed_atsu | 0:d920d64db582 | 308 | * from 16-96 kHz(16, 22.05, 32, 44.1, 48, 96kHz) |
lynxeyed_atsu | 0:d920d64db582 | 309 | * @param[in] TRMode is transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 310 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 311 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 312 | * @return Status: ERROR or SUCCESS |
lynxeyed_atsu | 0:d920d64db582 | 313 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 314 | Status I2S_FreqConfig(LPC_I2S_TypeDef *I2Sx, uint32_t Freq, uint8_t TRMode) { |
lynxeyed_atsu | 0:d920d64db582 | 315 | |
lynxeyed_atsu | 0:d920d64db582 | 316 | /* Calculate bit rate |
lynxeyed_atsu | 0:d920d64db582 | 317 | * The formula is: |
lynxeyed_atsu | 0:d920d64db582 | 318 | * bit_rate = channel*wordwidth - 1 |
lynxeyed_atsu | 0:d920d64db582 | 319 | * 48kHz sample rate for 16 bit stereo date requires |
lynxeyed_atsu | 0:d920d64db582 | 320 | * a bit rate of 48000*16*2=1536MHz (MCLK) |
lynxeyed_atsu | 0:d920d64db582 | 321 | */ |
lynxeyed_atsu | 0:d920d64db582 | 322 | uint32_t i2sPclk; |
lynxeyed_atsu | 0:d920d64db582 | 323 | uint64_t divider; |
lynxeyed_atsu | 0:d920d64db582 | 324 | uint8_t bitrate, channel, wordwidth; |
lynxeyed_atsu | 0:d920d64db582 | 325 | uint32_t x, y; |
lynxeyed_atsu | 0:d920d64db582 | 326 | uint16_t dif; |
lynxeyed_atsu | 0:d920d64db582 | 327 | uint16_t error; |
lynxeyed_atsu | 0:d920d64db582 | 328 | uint8_t x_divide, y_divide=0; |
lynxeyed_atsu | 0:d920d64db582 | 329 | uint16_t ErrorOptimal = 0xFFFF; |
lynxeyed_atsu | 0:d920d64db582 | 330 | |
lynxeyed_atsu | 0:d920d64db582 | 331 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 332 | CHECK_PARAM(PRAM_I2S_FREQ(Freq)); |
lynxeyed_atsu | 0:d920d64db582 | 333 | CHECK_PARAM(PARAM_I2S_TRX(TRMode)); |
lynxeyed_atsu | 0:d920d64db582 | 334 | |
lynxeyed_atsu | 0:d920d64db582 | 335 | i2sPclk = CLKPWR_GetPCLK(CLKPWR_PCLKSEL_I2S); |
lynxeyed_atsu | 0:d920d64db582 | 336 | printf("I2S_PCLK = %dHz\r\n",i2sPclk); |
lynxeyed_atsu | 0:d920d64db582 | 337 | if(TRMode == I2S_TX_MODE) |
lynxeyed_atsu | 0:d920d64db582 | 338 | { |
lynxeyed_atsu | 0:d920d64db582 | 339 | channel = i2s_GetChannel(I2Sx,I2S_TX_MODE); |
lynxeyed_atsu | 0:d920d64db582 | 340 | wordwidth = i2s_GetWordWidth(I2Sx,I2S_TX_MODE); |
lynxeyed_atsu | 0:d920d64db582 | 341 | } |
lynxeyed_atsu | 0:d920d64db582 | 342 | else |
lynxeyed_atsu | 0:d920d64db582 | 343 | { |
lynxeyed_atsu | 0:d920d64db582 | 344 | channel = i2s_GetChannel(I2Sx,I2S_RX_MODE); |
lynxeyed_atsu | 0:d920d64db582 | 345 | wordwidth = i2s_GetWordWidth(I2Sx,I2S_RX_MODE); |
lynxeyed_atsu | 0:d920d64db582 | 346 | } |
lynxeyed_atsu | 0:d920d64db582 | 347 | bitrate = channel * wordwidth - 1; |
lynxeyed_atsu | 0:d920d64db582 | 348 | if (TRMode == I2S_TX_MODE)// Transmitter |
lynxeyed_atsu | 0:d920d64db582 | 349 | { |
lynxeyed_atsu | 0:d920d64db582 | 350 | I2Sx->I2STXBITRATE = bitrate; |
lynxeyed_atsu | 0:d920d64db582 | 351 | } else //Receiver |
lynxeyed_atsu | 0:d920d64db582 | 352 | { |
lynxeyed_atsu | 0:d920d64db582 | 353 | I2Sx->I2SRXBITRATE = bitrate; |
lynxeyed_atsu | 0:d920d64db582 | 354 | } |
lynxeyed_atsu | 0:d920d64db582 | 355 | printf("TX CHANNEL= %d\r\n",i2s_GetChannel(I2Sx,I2S_TX_MODE)); |
lynxeyed_atsu | 0:d920d64db582 | 356 | printf("TX WORDWIDTH= %dbits \r\n",i2s_GetWordWidth(I2Sx,I2S_TX_MODE)); |
lynxeyed_atsu | 0:d920d64db582 | 357 | printf("I2STXBITRATE= %d,bitrate= %d \r\n",I2Sx->I2STXBITRATE,bitrate); |
lynxeyed_atsu | 0:d920d64db582 | 358 | /* Calculate X and Y divider |
lynxeyed_atsu | 0:d920d64db582 | 359 | * The MCLK rate for the I2S transmitter is determined by the value |
lynxeyed_atsu | 0:d920d64db582 | 360 | * in the I2STXRATE/I2SRXRATE register. The required I2STXRATE/I2SRXRATE |
lynxeyed_atsu | 0:d920d64db582 | 361 | * setting depends on the desired audio sample rate desired, the format |
lynxeyed_atsu | 0:d920d64db582 | 362 | * (stereo/mono) used, and the data size. |
lynxeyed_atsu | 0:d920d64db582 | 363 | * The formula is: |
lynxeyed_atsu | 0:d920d64db582 | 364 | * I2S_MCLK = PCLK * (X/Y) / 2 |
lynxeyed_atsu | 0:d920d64db582 | 365 | * We have: |
lynxeyed_atsu | 0:d920d64db582 | 366 | * I2S_MCLK = Freq * bit_rate; |
lynxeyed_atsu | 0:d920d64db582 | 367 | * So: (X/Y) = (Freq * bit_rate)/PCLK*2 |
lynxeyed_atsu | 0:d920d64db582 | 368 | * We use a loop function to chose the most suitable X,Y value |
lynxeyed_atsu | 0:d920d64db582 | 369 | */ |
lynxeyed_atsu | 0:d920d64db582 | 370 | |
lynxeyed_atsu | 0:d920d64db582 | 371 | divider = ((uint64_t)(Freq *( bitrate+1)/* * 2*/)<<16) / i2sPclk; |
lynxeyed_atsu | 0:d920d64db582 | 372 | for (y = 255; y > 0; y--) { |
lynxeyed_atsu | 0:d920d64db582 | 373 | x = y * divider; |
lynxeyed_atsu | 0:d920d64db582 | 374 | dif = x & 0xFFFF; |
lynxeyed_atsu | 0:d920d64db582 | 375 | if(dif>0x8000) error = 0x10000-dif; |
lynxeyed_atsu | 0:d920d64db582 | 376 | else error = dif; |
lynxeyed_atsu | 0:d920d64db582 | 377 | if (error == 0) |
lynxeyed_atsu | 0:d920d64db582 | 378 | { |
lynxeyed_atsu | 0:d920d64db582 | 379 | y_divide = y; |
lynxeyed_atsu | 0:d920d64db582 | 380 | break; |
lynxeyed_atsu | 0:d920d64db582 | 381 | } |
lynxeyed_atsu | 0:d920d64db582 | 382 | else if (error < ErrorOptimal) |
lynxeyed_atsu | 0:d920d64db582 | 383 | { |
lynxeyed_atsu | 0:d920d64db582 | 384 | ErrorOptimal = error; |
lynxeyed_atsu | 0:d920d64db582 | 385 | y_divide = y; |
lynxeyed_atsu | 0:d920d64db582 | 386 | } |
lynxeyed_atsu | 0:d920d64db582 | 387 | } |
lynxeyed_atsu | 0:d920d64db582 | 388 | //y_divide--;//for test |
lynxeyed_atsu | 0:d920d64db582 | 389 | x_divide = (y_divide * Freq *( bitrate+1)* 2)/i2sPclk; |
lynxeyed_atsu | 0:d920d64db582 | 390 | if (TRMode == I2S_TX_MODE)// Transmitter |
lynxeyed_atsu | 0:d920d64db582 | 391 | { |
lynxeyed_atsu | 0:d920d64db582 | 392 | I2Sx->I2STXRATE = y_divide | (x_divide << 8); |
lynxeyed_atsu | 0:d920d64db582 | 393 | } else //Receiver |
lynxeyed_atsu | 0:d920d64db582 | 394 | { |
lynxeyed_atsu | 0:d920d64db582 | 395 | I2Sx->I2SRXRATE = y_divide | (x_divide << 8); |
lynxeyed_atsu | 0:d920d64db582 | 396 | } |
lynxeyed_atsu | 0:d920d64db582 | 397 | |
lynxeyed_atsu | 0:d920d64db582 | 398 | printf("I2STXRATE=%d, x_divide=%d, y_divide=%d \r\n",I2Sx->I2STXRATE,x_divide,y_divide); |
lynxeyed_atsu | 0:d920d64db582 | 399 | return SUCCESS; |
lynxeyed_atsu | 0:d920d64db582 | 400 | } |
lynxeyed_atsu | 0:d920d64db582 | 401 | |
lynxeyed_atsu | 0:d920d64db582 | 402 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 403 | * @brief I2S set bitrate |
lynxeyed_atsu | 0:d920d64db582 | 404 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 405 | * @param[in] bitrate value will be set, it can be calculate as follows: |
lynxeyed_atsu | 0:d920d64db582 | 406 | * bitrate = channel * wordwidth - 1 |
lynxeyed_atsu | 0:d920d64db582 | 407 | * bitrate value should be in range: 0 .. 63 |
lynxeyed_atsu | 0:d920d64db582 | 408 | * @param[in] TRMode is transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 409 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 410 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 411 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 412 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 413 | void I2S_SetBitRate(LPC_I2S_TypeDef *I2Sx, uint8_t bitrate, uint8_t TRMode) |
lynxeyed_atsu | 0:d920d64db582 | 414 | { |
lynxeyed_atsu | 0:d920d64db582 | 415 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 416 | CHECK_PARAM(PARAM_I2S_BITRATE(bitrate)); |
lynxeyed_atsu | 0:d920d64db582 | 417 | CHECK_PARAM(PARAM_I2S_TRX(TRMode)); |
lynxeyed_atsu | 0:d920d64db582 | 418 | |
lynxeyed_atsu | 0:d920d64db582 | 419 | if(TRMode == I2S_TX_MODE) |
lynxeyed_atsu | 0:d920d64db582 | 420 | { |
lynxeyed_atsu | 0:d920d64db582 | 421 | I2Sx->I2STXBITRATE = bitrate; |
lynxeyed_atsu | 0:d920d64db582 | 422 | } |
lynxeyed_atsu | 0:d920d64db582 | 423 | else |
lynxeyed_atsu | 0:d920d64db582 | 424 | { |
lynxeyed_atsu | 0:d920d64db582 | 425 | I2Sx->I2SRXBITRATE = bitrate; |
lynxeyed_atsu | 0:d920d64db582 | 426 | } |
lynxeyed_atsu | 0:d920d64db582 | 427 | } |
lynxeyed_atsu | 0:d920d64db582 | 428 | |
lynxeyed_atsu | 0:d920d64db582 | 429 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 430 | * @brief Configuration operating mode for I2S |
lynxeyed_atsu | 0:d920d64db582 | 431 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 432 | * @param[in] ModeConfig pointer to I2S_MODEConf_Type will be used to |
lynxeyed_atsu | 0:d920d64db582 | 433 | * configure |
lynxeyed_atsu | 0:d920d64db582 | 434 | * @param[in] TRMode is transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 435 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 436 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 437 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 438 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 439 | void I2S_ModeConfig(LPC_I2S_TypeDef *I2Sx, I2S_MODEConf_Type* ModeConfig, |
lynxeyed_atsu | 0:d920d64db582 | 440 | uint8_t TRMode) |
lynxeyed_atsu | 0:d920d64db582 | 441 | { |
lynxeyed_atsu | 0:d920d64db582 | 442 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 443 | CHECK_PARAM(PARAM_I2S_CLKSEL(ModeConfig->clksel)); |
lynxeyed_atsu | 0:d920d64db582 | 444 | CHECK_PARAM(PARAM_I2S_4PIN(ModeConfig->fpin)); |
lynxeyed_atsu | 0:d920d64db582 | 445 | CHECK_PARAM(PARAM_I2S_MCLK(ModeConfig->mcena)); |
lynxeyed_atsu | 0:d920d64db582 | 446 | CHECK_PARAM(PARAM_I2S_TRX(TRMode)); |
lynxeyed_atsu | 0:d920d64db582 | 447 | |
lynxeyed_atsu | 0:d920d64db582 | 448 | if (TRMode == I2S_TX_MODE) { |
lynxeyed_atsu | 0:d920d64db582 | 449 | I2Sx->I2STXMODE &= ~0x0F; //clear bit 3:0 in I2STXMODE register |
lynxeyed_atsu | 0:d920d64db582 | 450 | if (ModeConfig->clksel == I2S_CLKSEL_MCLK) { |
lynxeyed_atsu | 0:d920d64db582 | 451 | I2Sx->I2STXMODE |= 0x02; |
lynxeyed_atsu | 0:d920d64db582 | 452 | } |
lynxeyed_atsu | 0:d920d64db582 | 453 | if (ModeConfig->fpin == I2S_4PIN_ENABLE) { |
lynxeyed_atsu | 0:d920d64db582 | 454 | I2Sx->I2STXMODE |= (1 << 2); |
lynxeyed_atsu | 0:d920d64db582 | 455 | } |
lynxeyed_atsu | 0:d920d64db582 | 456 | if (ModeConfig->mcena == I2S_MCLK_ENABLE) { |
lynxeyed_atsu | 0:d920d64db582 | 457 | I2Sx->I2STXMODE |= (1 << 3); |
lynxeyed_atsu | 0:d920d64db582 | 458 | } |
lynxeyed_atsu | 0:d920d64db582 | 459 | } else { |
lynxeyed_atsu | 0:d920d64db582 | 460 | I2Sx->I2SRXMODE &= ~0x0F; //clear bit 3:0 in I2STXMODE register |
lynxeyed_atsu | 0:d920d64db582 | 461 | if (ModeConfig->clksel == I2S_CLKSEL_MCLK) { |
lynxeyed_atsu | 0:d920d64db582 | 462 | I2Sx->I2SRXMODE |= 0x02; |
lynxeyed_atsu | 0:d920d64db582 | 463 | } |
lynxeyed_atsu | 0:d920d64db582 | 464 | if (ModeConfig->fpin == I2S_4PIN_ENABLE) { |
lynxeyed_atsu | 0:d920d64db582 | 465 | I2Sx->I2SRXMODE |= (1 << 2); |
lynxeyed_atsu | 0:d920d64db582 | 466 | } |
lynxeyed_atsu | 0:d920d64db582 | 467 | if (ModeConfig->mcena == I2S_MCLK_ENABLE) { |
lynxeyed_atsu | 0:d920d64db582 | 468 | I2Sx->I2SRXMODE |= (1 << 3); |
lynxeyed_atsu | 0:d920d64db582 | 469 | } |
lynxeyed_atsu | 0:d920d64db582 | 470 | } |
lynxeyed_atsu | 0:d920d64db582 | 471 | } |
lynxeyed_atsu | 0:d920d64db582 | 472 | |
lynxeyed_atsu | 0:d920d64db582 | 473 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 474 | * @brief Configure DMA operation for I2S |
lynxeyed_atsu | 0:d920d64db582 | 475 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 476 | * @param[in] DMAConfig pointer to I2S_DMAConf_Type will be used to configure |
lynxeyed_atsu | 0:d920d64db582 | 477 | * @param[in] TRMode is transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 478 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 479 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 480 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 481 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 482 | void I2S_DMAConfig(LPC_I2S_TypeDef *I2Sx, I2S_DMAConf_Type* DMAConfig, |
lynxeyed_atsu | 0:d920d64db582 | 483 | uint8_t TRMode) |
lynxeyed_atsu | 0:d920d64db582 | 484 | { |
lynxeyed_atsu | 0:d920d64db582 | 485 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 486 | CHECK_PARAM(PARAM_I2S_DMA(DMAConfig->DMAIndex)); |
lynxeyed_atsu | 0:d920d64db582 | 487 | CHECK_PARAM(PARAM_I2S_DMA_DEPTH(DMAConfig->depth)); |
lynxeyed_atsu | 0:d920d64db582 | 488 | CHECK_PARAM(PARAM_I2S_TRX(TRMode)); |
lynxeyed_atsu | 0:d920d64db582 | 489 | |
lynxeyed_atsu | 0:d920d64db582 | 490 | if (TRMode == I2S_RX_MODE) { |
lynxeyed_atsu | 0:d920d64db582 | 491 | if (DMAConfig->DMAIndex == I2S_DMA_1) { |
lynxeyed_atsu | 0:d920d64db582 | 492 | LPC_I2S->I2SDMA1 = (DMAConfig->depth) << 8; |
lynxeyed_atsu | 0:d920d64db582 | 493 | } else { |
lynxeyed_atsu | 0:d920d64db582 | 494 | LPC_I2S->I2SDMA2 = (DMAConfig->depth) << 8; |
lynxeyed_atsu | 0:d920d64db582 | 495 | } |
lynxeyed_atsu | 0:d920d64db582 | 496 | } else { |
lynxeyed_atsu | 0:d920d64db582 | 497 | if (DMAConfig->DMAIndex == I2S_DMA_1) { |
lynxeyed_atsu | 0:d920d64db582 | 498 | LPC_I2S->I2SDMA1 = (DMAConfig->depth) << 16; |
lynxeyed_atsu | 0:d920d64db582 | 499 | } else { |
lynxeyed_atsu | 0:d920d64db582 | 500 | LPC_I2S->I2SDMA2 = (DMAConfig->depth) << 16; |
lynxeyed_atsu | 0:d920d64db582 | 501 | } |
lynxeyed_atsu | 0:d920d64db582 | 502 | } |
lynxeyed_atsu | 0:d920d64db582 | 503 | } |
lynxeyed_atsu | 0:d920d64db582 | 504 | |
lynxeyed_atsu | 0:d920d64db582 | 505 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 506 | * @brief Enable/Disable DMA operation for I2S |
lynxeyed_atsu | 0:d920d64db582 | 507 | * @param[in] I2Sx: I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 508 | * @param[in] DMAIndex chose what DMA is used, should be: |
lynxeyed_atsu | 0:d920d64db582 | 509 | * - I2S_DMA_1 = 0: DMA1 |
lynxeyed_atsu | 0:d920d64db582 | 510 | * - I2S_DMA_2 = 1: DMA2 |
lynxeyed_atsu | 0:d920d64db582 | 511 | * @param[in] TRMode is transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 512 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 513 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 514 | * @param[in] NewState is new state of DMA operation, should be: |
lynxeyed_atsu | 0:d920d64db582 | 515 | * - ENABLE |
lynxeyed_atsu | 0:d920d64db582 | 516 | * - DISABLE |
lynxeyed_atsu | 0:d920d64db582 | 517 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 518 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 519 | void I2S_DMACmd(LPC_I2S_TypeDef *I2Sx, uint8_t DMAIndex, uint8_t TRMode, |
lynxeyed_atsu | 0:d920d64db582 | 520 | FunctionalState NewState) |
lynxeyed_atsu | 0:d920d64db582 | 521 | { |
lynxeyed_atsu | 0:d920d64db582 | 522 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 523 | CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState)); |
lynxeyed_atsu | 0:d920d64db582 | 524 | CHECK_PARAM(PARAM_I2S_DMA(DMAIndex)); |
lynxeyed_atsu | 0:d920d64db582 | 525 | CHECK_PARAM(PARAM_I2S_TRX(TRMode)); |
lynxeyed_atsu | 0:d920d64db582 | 526 | |
lynxeyed_atsu | 0:d920d64db582 | 527 | if (TRMode == I2S_RX_MODE) { |
lynxeyed_atsu | 0:d920d64db582 | 528 | if (DMAIndex == I2S_DMA_1) { |
lynxeyed_atsu | 0:d920d64db582 | 529 | if (NewState == ENABLE) |
lynxeyed_atsu | 0:d920d64db582 | 530 | I2Sx->I2SDMA1 |= 0x01; |
lynxeyed_atsu | 0:d920d64db582 | 531 | else |
lynxeyed_atsu | 0:d920d64db582 | 532 | I2Sx->I2SDMA1 &= ~0x01; |
lynxeyed_atsu | 0:d920d64db582 | 533 | } else { |
lynxeyed_atsu | 0:d920d64db582 | 534 | if (NewState == ENABLE) |
lynxeyed_atsu | 0:d920d64db582 | 535 | I2Sx->I2SDMA2 |= 0x01; |
lynxeyed_atsu | 0:d920d64db582 | 536 | else |
lynxeyed_atsu | 0:d920d64db582 | 537 | I2Sx->I2SDMA2 &= ~0x01; |
lynxeyed_atsu | 0:d920d64db582 | 538 | } |
lynxeyed_atsu | 0:d920d64db582 | 539 | } else { |
lynxeyed_atsu | 0:d920d64db582 | 540 | if (DMAIndex == I2S_DMA_1) { |
lynxeyed_atsu | 0:d920d64db582 | 541 | if (NewState == ENABLE) |
lynxeyed_atsu | 0:d920d64db582 | 542 | I2Sx->I2SDMA1 |= 0x02; |
lynxeyed_atsu | 0:d920d64db582 | 543 | else |
lynxeyed_atsu | 0:d920d64db582 | 544 | I2Sx->I2SDMA1 &= ~0x02; |
lynxeyed_atsu | 0:d920d64db582 | 545 | } else { |
lynxeyed_atsu | 0:d920d64db582 | 546 | if (NewState == ENABLE) |
lynxeyed_atsu | 0:d920d64db582 | 547 | I2Sx->I2SDMA2 |= 0x02; |
lynxeyed_atsu | 0:d920d64db582 | 548 | else |
lynxeyed_atsu | 0:d920d64db582 | 549 | I2Sx->I2SDMA2 &= ~0x02; |
lynxeyed_atsu | 0:d920d64db582 | 550 | } |
lynxeyed_atsu | 0:d920d64db582 | 551 | } |
lynxeyed_atsu | 0:d920d64db582 | 552 | } |
lynxeyed_atsu | 0:d920d64db582 | 553 | |
lynxeyed_atsu | 0:d920d64db582 | 554 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 555 | * @brief Configure IRQ for I2S |
lynxeyed_atsu | 0:d920d64db582 | 556 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 557 | * @param[in] TRMode is transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 558 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 559 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 560 | * @param[in] level is the FIFO level that triggers IRQ request |
lynxeyed_atsu | 0:d920d64db582 | 561 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 562 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 563 | void I2S_IRQConfig(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode, uint8_t level) { |
lynxeyed_atsu | 0:d920d64db582 | 564 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 565 | CHECK_PARAM(PARAM_I2S_TRX(TRMode)); |
lynxeyed_atsu | 0:d920d64db582 | 566 | CHECK_PARAM(PARAM_I2S_IRQ_LEVEL(level)); |
lynxeyed_atsu | 0:d920d64db582 | 567 | |
lynxeyed_atsu | 0:d920d64db582 | 568 | if (TRMode == I2S_RX_MODE) { |
lynxeyed_atsu | 0:d920d64db582 | 569 | I2Sx->I2SIRQ |= (level << 8); |
lynxeyed_atsu | 0:d920d64db582 | 570 | } else { |
lynxeyed_atsu | 0:d920d64db582 | 571 | I2Sx->I2SIRQ |= (level << 16); |
lynxeyed_atsu | 0:d920d64db582 | 572 | } |
lynxeyed_atsu | 0:d920d64db582 | 573 | } |
lynxeyed_atsu | 0:d920d64db582 | 574 | |
lynxeyed_atsu | 0:d920d64db582 | 575 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 576 | * @brief Enable/Disable IRQ for I2S |
lynxeyed_atsu | 0:d920d64db582 | 577 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 578 | * @param[in] TRMode is transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 579 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 580 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 581 | * @param[in] NewState is new state of DMA operation, should be: |
lynxeyed_atsu | 0:d920d64db582 | 582 | * - ENABLE |
lynxeyed_atsu | 0:d920d64db582 | 583 | * - DISABLE |
lynxeyed_atsu | 0:d920d64db582 | 584 | * @return none |
lynxeyed_atsu | 0:d920d64db582 | 585 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 586 | void I2S_IRQCmd(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode, FunctionalState NewState) { |
lynxeyed_atsu | 0:d920d64db582 | 587 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 588 | CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState)); |
lynxeyed_atsu | 0:d920d64db582 | 589 | |
lynxeyed_atsu | 0:d920d64db582 | 590 | if (TRMode == I2S_RX_MODE) { |
lynxeyed_atsu | 0:d920d64db582 | 591 | if (NewState == ENABLE) |
lynxeyed_atsu | 0:d920d64db582 | 592 | I2Sx->I2SIRQ |= 0x01; |
lynxeyed_atsu | 0:d920d64db582 | 593 | else |
lynxeyed_atsu | 0:d920d64db582 | 594 | I2Sx->I2SIRQ &= ~0x01; |
lynxeyed_atsu | 0:d920d64db582 | 595 | //Enable DMA |
lynxeyed_atsu | 0:d920d64db582 | 596 | |
lynxeyed_atsu | 0:d920d64db582 | 597 | } else { |
lynxeyed_atsu | 0:d920d64db582 | 598 | if (NewState == ENABLE) |
lynxeyed_atsu | 0:d920d64db582 | 599 | I2Sx->I2SIRQ |= 0x02; |
lynxeyed_atsu | 0:d920d64db582 | 600 | else |
lynxeyed_atsu | 0:d920d64db582 | 601 | I2Sx->I2SIRQ &= ~0x02; |
lynxeyed_atsu | 0:d920d64db582 | 602 | } |
lynxeyed_atsu | 0:d920d64db582 | 603 | } |
lynxeyed_atsu | 0:d920d64db582 | 604 | |
lynxeyed_atsu | 0:d920d64db582 | 605 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 606 | * @brief Get I2S interrupt status |
lynxeyed_atsu | 0:d920d64db582 | 607 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 608 | * @param[in] TRMode is transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 609 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 610 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 611 | * @return FunctionState should be: |
lynxeyed_atsu | 0:d920d64db582 | 612 | * - ENABLE: interrupt is enable |
lynxeyed_atsu | 0:d920d64db582 | 613 | * - DISABLE: interrupt is disable |
lynxeyed_atsu | 0:d920d64db582 | 614 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 615 | FunctionalState I2S_GetIRQStatus(LPC_I2S_TypeDef *I2Sx,uint8_t TRMode) |
lynxeyed_atsu | 0:d920d64db582 | 616 | { |
lynxeyed_atsu | 0:d920d64db582 | 617 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 618 | if(TRMode == I2S_TX_MODE) |
lynxeyed_atsu | 0:d920d64db582 | 619 | return (FunctionalState)((I2Sx->I2SIRQ >> 1)&0x01); |
lynxeyed_atsu | 0:d920d64db582 | 620 | else |
lynxeyed_atsu | 0:d920d64db582 | 621 | return (FunctionalState)((I2Sx->I2SIRQ)&0x01); |
lynxeyed_atsu | 0:d920d64db582 | 622 | } |
lynxeyed_atsu | 0:d920d64db582 | 623 | |
lynxeyed_atsu | 0:d920d64db582 | 624 | /********************************************************************//** |
lynxeyed_atsu | 0:d920d64db582 | 625 | * @brief Get I2S interrupt depth |
lynxeyed_atsu | 0:d920d64db582 | 626 | * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S |
lynxeyed_atsu | 0:d920d64db582 | 627 | * @param[in] TRMode is transmit/receive mode, should be: |
lynxeyed_atsu | 0:d920d64db582 | 628 | * - I2S_TX_MODE = 0: transmit mode |
lynxeyed_atsu | 0:d920d64db582 | 629 | * - I2S_RX_MODE = 1: receive mode |
lynxeyed_atsu | 0:d920d64db582 | 630 | * @return depth of FIFO level on which to create an irq request |
lynxeyed_atsu | 0:d920d64db582 | 631 | *********************************************************************/ |
lynxeyed_atsu | 0:d920d64db582 | 632 | uint8_t I2S_GetIRQDepth(LPC_I2S_TypeDef *I2Sx,uint8_t TRMode) |
lynxeyed_atsu | 0:d920d64db582 | 633 | { |
lynxeyed_atsu | 0:d920d64db582 | 634 | CHECK_PARAM(PARAM_I2Sx(I2Sx)); |
lynxeyed_atsu | 0:d920d64db582 | 635 | if(TRMode == I2S_TX_MODE) |
lynxeyed_atsu | 0:d920d64db582 | 636 | return (((I2Sx->I2SIRQ)>>16)&0xFF); |
lynxeyed_atsu | 0:d920d64db582 | 637 | else |
lynxeyed_atsu | 0:d920d64db582 | 638 | return (((I2Sx->I2SIRQ)>>8)&0xFF); |
lynxeyed_atsu | 0:d920d64db582 | 639 | } |
lynxeyed_atsu | 0:d920d64db582 | 640 | /** |
lynxeyed_atsu | 0:d920d64db582 | 641 | * @} |
lynxeyed_atsu | 0:d920d64db582 | 642 | */ |
lynxeyed_atsu | 0:d920d64db582 | 643 | |
lynxeyed_atsu | 0:d920d64db582 | 644 | #endif /* _I2S */ |
lynxeyed_atsu | 0:d920d64db582 | 645 | |
lynxeyed_atsu | 0:d920d64db582 | 646 | /** |
lynxeyed_atsu | 0:d920d64db582 | 647 | * @} |
lynxeyed_atsu | 0:d920d64db582 | 648 | */ |
lynxeyed_atsu | 0:d920d64db582 | 649 | |
lynxeyed_atsu | 0:d920d64db582 | 650 | /* --------------------------------- End Of File ------------------------------ */ |