1 /**********************************************************************
\r
2 * $Id$ lpc18xx_i2s.c 2011-06-02
\r
4 * @file lpc18xx_i2s.c
\r
5 * @brief Contains all functions support for I2S firmware library
\r
8 * @date 02. June. 2011
\r
9 * @author NXP MCU SW Application Team
\r
11 * Copyright(C) 2011, NXP Semiconductor
\r
12 * All rights reserved.
\r
14 ***********************************************************************
\r
15 * Software that is described herein is for illustrative purposes only
\r
16 * which provides customers with programming information regarding the
\r
17 * products. This software is supplied "AS IS" without any warranties.
\r
18 * NXP Semiconductors assumes no responsibility or liability for the
\r
19 * use of the software, conveys no license or title under any patent,
\r
20 * copyright, or mask work right to the product. NXP Semiconductors
\r
21 * reserves the right to make changes in the software without
\r
22 * notification. NXP Semiconductors also make no representation or
\r
23 * warranty that such application will be suitable for the specified
\r
24 * use without further testing or modification.
\r
25 **********************************************************************/
\r
27 /* Peripheral group ----------------------------------------------------------- */
\r
32 /* Includes ------------------------------------------------------------------- */
\r
33 #include "lpc18xx_i2s.h"
\r
34 #include "lpc18xx_cgu.h"
\r
37 /* If this source file built with example, the LPC18xx FW library configuration
\r
38 * file in each example directory ("lpc18xx_libcfg.h") must be included,
\r
39 * otherwise the default FW library configuration file must be included instead
\r
41 #ifdef __BUILD_WITH_EXAMPLE__
\r
42 #include "lpc18xx_libcfg.h"
\r
44 #include "lpc18xx_libcfg_default.h"
\r
45 #endif /* __BUILD_WITH_EXAMPLE__ */
\r
50 /* Private Functions ---------------------------------------------------------- */
\r
52 static uint8_t i2s_GetWordWidth(LPC_I2Sn_Type *I2Sx, uint8_t TRMode);
\r
53 static uint8_t i2s_GetChannel(LPC_I2Sn_Type *I2Sx, uint8_t TRMode);
\r
55 /********************************************************************//**
\r
56 * @brief Get I2S wordwidth value
\r
57 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
58 * @param[in] TRMode is the I2S mode, should be:
\r
59 * - I2S_TX_MODE = 0 :transmit mode
\r
60 * - I2S_RX_MODE = 1 :receive mode
\r
61 * @return The wordwidth value, should be: 8,16 or 32
\r
62 *********************************************************************/
\r
63 static uint8_t i2s_GetWordWidth(LPC_I2Sn_Type *I2Sx, uint8_t TRMode) {
\r
66 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
67 CHECK_PARAM(PARAM_I2S_TRX(TRMode));
\r
69 if (TRMode == I2S_TX_MODE) {
\r
70 value = (I2Sx->DAO) & 0x03; /* get wordwidth bit */
\r
72 value = (I2Sx->DAI) & 0x03; /* get wordwidth bit */
\r
75 case I2S_WORDWIDTH_8:
\r
77 case I2S_WORDWIDTH_16:
\r
84 /********************************************************************//**
\r
85 * @brief Get I2S channel value
\r
86 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
87 * @param[in] TRMode is the I2S mode, should be:
\r
88 * - I2S_TX_MODE = 0 :transmit mode
\r
89 * - I2S_RX_MODE = 1 :receive mode
\r
90 * @return The channel value, should be: 1(mono) or 2(stereo)
\r
91 *********************************************************************/
\r
92 static uint8_t i2s_GetChannel(LPC_I2Sn_Type *I2Sx, uint8_t TRMode) {
\r
95 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
96 CHECK_PARAM(PARAM_I2S_TRX(TRMode));
\r
98 if (TRMode == I2S_TX_MODE) {
\r
99 value = (I2Sx->DAO) & 0x04; /* get bit[2] */
\r
101 value = (I2Sx->DAI) & 0x04; /* get bit[2] */
\r
104 if(value == I2S_MONO) return 1;
\r
108 /* End of Private Functions --------------------------------------------------- */
\r
111 /* Public Functions ----------------------------------------------------------- */
\r
112 /** @addtogroup I2S_Public_Functions
\r
116 /********************************************************************//**
\r
117 * @brief Initialize I2S
\r
118 * - Turn on power and clock
\r
119 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
121 *********************************************************************/
\r
122 void I2S_Init(LPC_I2Sn_Type *I2Sx) {
\r
123 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
125 // Turn on power and clock
\r
126 //CGU_ConfigPPWR(CGU_PCONP_PCI2S, ENABLE);
\r
127 I2Sx->DAI = I2Sx->DAO = 0x00;
\r
130 /********************************************************************//**
\r
131 * @brief Configuration I2S, setting:
\r
132 * - master/slave mode
\r
133 * - wordwidth value
\r
135 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
136 * @param[in] TRMode transmit/receive mode, should be:
\r
137 * - I2S_TX_MODE = 0 :transmit mode
\r
138 * - I2S_RX_MODE = 1 :receive mode
\r
139 * @param[in] ConfigStruct pointer to I2S_CFG_Type structure
\r
140 * which will be initialized.
\r
142 *********************************************************************/
\r
143 void I2S_Config(LPC_I2Sn_Type *I2Sx, uint8_t TRMode, I2S_CFG_Type* ConfigStruct)
\r
145 uint32_t bps, config;
\r
147 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
149 CHECK_PARAM(PARAM_I2S_WORDWIDTH(ConfigStruct->wordwidth));
\r
150 CHECK_PARAM(PARAM_I2S_CHANNEL(ConfigStruct->mono));
\r
151 CHECK_PARAM(PARAM_I2S_STOP(ConfigStruct->stop));
\r
152 CHECK_PARAM(PARAM_I2S_RESET(ConfigStruct->reset));
\r
153 CHECK_PARAM(PARAM_I2S_WS_SEL(ConfigStruct->ws_sel));
\r
154 CHECK_PARAM(PARAM_I2S_MUTE(ConfigStruct->mute));
\r
157 bps = (ConfigStruct->wordwidth +1)*8;
\r
159 /* Calculate audio config */
\r
160 config = (bps - 1)<<6 | (ConfigStruct->ws_sel)<<5 | (ConfigStruct->reset)<<4 |
\r
161 (ConfigStruct->stop)<<3 | (ConfigStruct->mono)<<2 | (ConfigStruct->wordwidth);
\r
163 if(TRMode == I2S_RX_MODE){
\r
164 I2Sx->DAI = config;
\r
166 I2Sx->DAO = config;
\r
170 /********************************************************************//**
\r
171 * @brief DeInitial both I2S transmit or receive
\r
172 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
174 *********************************************************************/
\r
175 void I2S_DeInit(LPC_I2Sn_Type *I2Sx) {
\r
176 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
178 // Turn off power and clock
\r
179 //CGU_ConfigPPWR(CGU_PCONP_PCI2S, DISABLE);
\r
182 /********************************************************************//**
\r
183 * @brief Get I2S Buffer Level
\r
184 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
185 * @param[in] TRMode Transmit/receive mode, should be:
\r
186 * - I2S_TX_MODE = 0 :transmit mode
\r
187 * - I2S_RX_MODE = 1 :receive mode
\r
188 * @return current level of Transmit/Receive Buffer
\r
189 *********************************************************************/
\r
190 uint8_t I2S_GetLevel(LPC_I2Sn_Type *I2Sx, uint8_t TRMode)
\r
192 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
193 CHECK_PARAM(PARAM_I2S_TRX(TRMode));
\r
195 if(TRMode == I2S_TX_MODE)
\r
197 return ((I2Sx->STATE >> 16) & 0xFF);
\r
201 return ((I2Sx->STATE >> 8) & 0xFF);
\r
205 /********************************************************************//**
\r
206 * @brief I2S Start: clear all STOP,RESET and MUTE bit, ready to operate
\r
207 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
209 *********************************************************************/
\r
210 void I2S_Start(LPC_I2Sn_Type *I2Sx)
\r
212 //Clear STOP,RESET and MUTE bit
\r
213 I2Sx->DAO &= ~I2S_DAI_RESET;
\r
214 I2Sx->DAI &= ~I2S_DAI_RESET;
\r
215 I2Sx->DAO &= ~I2S_DAI_STOP;
\r
216 I2Sx->DAI &= ~I2S_DAI_STOP;
\r
217 I2Sx->DAO &= ~I2S_DAI_MUTE;
\r
220 /********************************************************************//**
\r
221 * @brief I2S Send data
\r
222 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
223 * @param[in] BufferData pointer to uint32_t is the data will be send
\r
225 *********************************************************************/
\r
226 void I2S_Send(LPC_I2Sn_Type *I2Sx, uint32_t BufferData) {
\r
227 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
229 I2Sx->TXFIFO = BufferData;
\r
232 /********************************************************************//**
\r
233 * @brief I2S Receive Data
\r
234 * @param[in] I2Sx pointer to LPC_I2Sn_Type, should be: LPC_I2S
\r
235 * @return received value
\r
236 *********************************************************************/
\r
237 uint32_t I2S_Receive(LPC_I2Sn_Type* I2Sx) {
\r
238 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
240 return (I2Sx->RXFIFO);
\r
244 /********************************************************************//**
\r
246 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
247 * @param[in] TRMode is transmit/receive mode, should be:
\r
248 * - I2S_TX_MODE = 0 :transmit mode
\r
249 * - I2S_RX_MODE = 1 :receive mode
\r
251 *********************************************************************/
\r
252 void I2S_Pause(LPC_I2Sn_Type *I2Sx, uint8_t TRMode) {
\r
253 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
254 CHECK_PARAM(PARAM_I2S_TRX(TRMode));
\r
256 if (TRMode == I2S_TX_MODE) //Transmit mode
\r
258 I2Sx->DAO |= I2S_DAO_STOP;
\r
259 } else //Receive mode
\r
261 I2Sx->DAI |= I2S_DAI_STOP;
\r
265 /********************************************************************//**
\r
267 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
268 * @param[in] TRMode is transmit/receive mode, should be:
\r
269 * - I2S_TX_MODE = 0 :transmit mode
\r
270 * - I2S_RX_MODE = 1 :receive mode
\r
272 *********************************************************************/
\r
273 void I2S_Mute(LPC_I2Sn_Type *I2Sx, uint8_t TRMode) {
\r
274 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
275 CHECK_PARAM(PARAM_I2S_TRX(TRMode));
\r
277 if (TRMode == I2S_TX_MODE) //Transmit mode
\r
279 I2Sx->DAO |= I2S_DAO_MUTE;
\r
280 } else //Receive mode
\r
282 I2Sx->DAI |= I2S_DAI_MUTE;
\r
286 /********************************************************************//**
\r
288 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
289 * @param[in] TRMode is transmit/receive mode, should be:
\r
290 * - I2S_TX_MODE = 0 :transmit mode
\r
291 * - I2S_RX_MODE = 1 :receive mode
\r
293 *********************************************************************/
\r
294 void I2S_Stop(LPC_I2Sn_Type *I2Sx, uint8_t TRMode) {
\r
295 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
296 CHECK_PARAM(PARAM_I2S_TRX(TRMode));
\r
298 if (TRMode == I2S_TX_MODE) //Transmit mode
\r
300 I2Sx->DAO &= ~I2S_DAO_MUTE;
\r
301 I2Sx->DAO |= I2S_DAO_STOP;
\r
302 I2Sx->DAO |= I2S_DAO_RESET;
\r
303 } else //Receive mode
\r
305 I2Sx->DAI |= I2S_DAI_STOP;
\r
306 I2Sx->DAI |= I2S_DAI_RESET;
\r
310 /********************************************************************//**
\r
311 * @brief Set frequency for I2S
\r
312 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
313 * @param[in] Freq is the frequency for I2S will be set. It can range
\r
314 * from 16-96 kHz(16, 22.05, 32, 44.1, 48, 96kHz)
\r
315 * @param[in] TRMode is transmit/receive mode, should be:
\r
316 * - I2S_TX_MODE = 0 :transmit mode
\r
317 * - I2S_RX_MODE = 1 :receive mode
\r
318 * @return Status: ERROR or SUCCESS
\r
319 *********************************************************************/
\r
320 Status I2S_FreqConfig(LPC_I2Sn_Type *I2Sx, uint32_t Freq, uint8_t TRMode) {
\r
322 /* Calculate bit rate
\r
324 * bit_rate = channel*wordwidth - 1
\r
325 * 48kHz sample rate for 16 bit stereo date requires
\r
326 * a bit rate of 48000*16*2=1536MHz (MCLK)
\r
330 uint8_t bitrate, channel, wordwidth;
\r
334 uint16_t x_divide, y_divide;
\r
335 uint16_t ErrorOptimal = 0xFFFF;
\r
338 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
339 CHECK_PARAM(PRAM_I2S_FREQ(Freq));
\r
340 CHECK_PARAM(PARAM_I2S_TRX(TRMode));
\r
342 //LPC_CGU->BASE_VPB1_CLK = 0x08<<24 | AUTO_BLOCK;
\r
343 CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_APB1);
\r
344 i2sPclk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_I2S);
\r
345 if(TRMode == I2S_TX_MODE)
\r
347 channel = i2s_GetChannel(I2Sx,I2S_TX_MODE);
\r
348 wordwidth = i2s_GetWordWidth(I2Sx,I2S_TX_MODE);
\r
352 channel = i2s_GetChannel(I2Sx,I2S_RX_MODE);
\r
353 wordwidth = i2s_GetWordWidth(I2Sx,I2S_RX_MODE);
\r
355 bitrate = 2 * wordwidth - 1;
\r
357 /* Calculate X and Y divider
\r
358 * The MCLK rate for the I2S transmitter is determined by the value
\r
359 * in the I2STXRATE/I2SRXRATE register. The required I2STXRATE/I2SRXRATE
\r
360 * setting depends on the desired audio sample rate desired, the format
\r
361 * (stereo/mono) used, and the data size.
\r
363 * I2S_MCLK = PCLK * (X/Y) / 2
\r
365 * I2S_MCLK = Freq * bit_rate * I2Sx->TXBITRATE;
\r
366 * So: (X/Y) = (Freq * bit_rate * I2Sx->TXBITRATE)/PCLK*2
\r
367 * We use a loop function to chose the most suitable X,Y value
\r
370 /* divider is a fixed point number with 16 fractional bits */
\r
371 divider = ((uint64_t)(Freq *( bitrate+1) * 2)<<16) / i2sPclk;
\r
373 /* find N that make x/y <= 1 -> divider <= 2^16 */
\r
374 for(N=64;N>=0;N--){
\r
375 if((divider*N) < (1<<16)) break;
\r
378 if(N == 0) return ERROR;
\r
382 for (y = 255; y > 0; y--) {
\r
384 if(x & (0xFF000000)) continue;
\r
386 if(dif>0x8000) error = 0x10000-dif;
\r
393 else if (error < ErrorOptimal)
\r
395 ErrorOptimal = error;
\r
399 x_divide = ((uint64_t)y_divide * Freq *( bitrate+1)* N * 2)/i2sPclk;
\r
400 if(x_divide >= 256) x_divide = 0xFF;
\r
401 if(x_divide == 0) x_divide = 1;
\r
402 if (TRMode == I2S_TX_MODE)// Transmitter
\r
404 I2Sx->TXBITRATE = N;
\r
405 I2Sx->TXRATE = y_divide | (x_divide << 8);
\r
408 I2Sx->RXBITRATE = N;
\r
409 I2Sx->RXRATE = y_divide | (x_divide << 8);
\r
414 /********************************************************************//**
\r
415 * @brief I2S set bitrate
\r
416 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
417 * @param[in] bitrate value will be set, it can be calculate as follows:
\r
418 * bitrate = channel * wordwidth - 1
\r
419 * bitrate value should be in range: 0 .. 63
\r
420 * @param[in] TRMode is transmit/receive mode, should be:
\r
421 * - I2S_TX_MODE = 0 :transmit mode
\r
422 * - I2S_RX_MODE = 1 :receive mode
\r
424 *********************************************************************/
\r
425 void I2S_SetBitRate(LPC_I2Sn_Type *I2Sx, uint8_t bitrate, uint8_t TRMode)
\r
427 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
428 CHECK_PARAM(PARAM_I2S_BITRATE(bitrate));
\r
429 CHECK_PARAM(PARAM_I2S_TRX(TRMode));
\r
431 if(TRMode == I2S_TX_MODE)
\r
433 I2Sx->TXBITRATE = bitrate;
\r
437 I2Sx->RXBITRATE = bitrate;
\r
441 /********************************************************************//**
\r
442 * @brief Configuration operating mode for I2S
\r
443 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
444 * @param[in] ModeConfig pointer to I2S_MODEConf_Type will be used to
\r
446 * @param[in] TRMode is transmit/receive mode, should be:
\r
447 * - I2S_TX_MODE = 0 :transmit mode
\r
448 * - I2S_RX_MODE = 1 :receive mode
\r
450 *********************************************************************/
\r
451 void I2S_ModeConfig(LPC_I2Sn_Type *I2Sx, I2S_MODEConf_Type* ModeConfig,
\r
454 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
455 CHECK_PARAM(PARAM_I2S_CLKSEL(ModeConfig->clksel));
\r
456 CHECK_PARAM(PARAM_I2S_4PIN(ModeConfig->fpin));
\r
457 CHECK_PARAM(PARAM_I2S_MCLK(ModeConfig->mcena));
\r
458 CHECK_PARAM(PARAM_I2S_TRX(TRMode));
\r
460 if (TRMode == I2S_TX_MODE) {
\r
461 I2Sx->TXMODE &= ~0x0F; //clear bit 3:0 in I2STXMODE register
\r
462 if (ModeConfig->clksel == I2S_CLKSEL_MCLK) {
\r
463 I2Sx->TXMODE |= 0x02;
\r
465 if (ModeConfig->fpin == I2S_4PIN_ENABLE) {
\r
466 I2Sx->TXMODE |= (1 << 2);
\r
468 if (ModeConfig->mcena == I2S_MCLK_ENABLE) {
\r
469 I2Sx->TXMODE |= (1 << 3);
\r
472 I2Sx->RXMODE &= ~0x0F; //clear bit 3:0 in I2STXMODE register
\r
473 if (ModeConfig->clksel == I2S_CLKSEL_MCLK) {
\r
474 I2Sx->RXMODE |= 0x02;
\r
476 if (ModeConfig->fpin == I2S_4PIN_ENABLE) {
\r
477 I2Sx->RXMODE |= (1 << 2);
\r
479 if (ModeConfig->mcena == I2S_MCLK_ENABLE) {
\r
480 I2Sx->RXMODE |= (1 << 3);
\r
485 /********************************************************************//**
\r
486 * @brief Configure DMA operation for I2S
\r
487 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
488 * @param[in] DMAConfig pointer to I2S_DMAConf_Type will be used to configure
\r
489 * @param[in] TRMode is transmit/receive mode, should be:
\r
490 * - I2S_TX_MODE = 0 :transmit mode
\r
491 * - I2S_RX_MODE = 1 :receive mode
\r
493 *********************************************************************/
\r
494 void I2S_DMAConfig(LPC_I2Sn_Type *I2Sx, I2S_DMAConf_Type* DMAConfig,
\r
497 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
498 CHECK_PARAM(PARAM_I2S_DMA(DMAConfig->DMAIndex));
\r
499 CHECK_PARAM(PARAM_I2S_DMA_DEPTH(DMAConfig->depth));
\r
500 CHECK_PARAM(PARAM_I2S_TRX(TRMode));
\r
502 if (TRMode == I2S_RX_MODE) {
\r
503 if (DMAConfig->DMAIndex == I2S_DMA_1) {
\r
504 I2Sx->DMA1 = (DMAConfig->depth) << 8;
\r
506 I2Sx->DMA2 = (DMAConfig->depth) << 8;
\r
509 if (DMAConfig->DMAIndex == I2S_DMA_1) {
\r
510 I2Sx->DMA1 = (DMAConfig->depth) << 16;
\r
512 I2Sx->DMA2 = (DMAConfig->depth) << 16;
\r
517 /********************************************************************//**
\r
518 * @brief Enable/Disable DMA operation for I2S
\r
519 * @param[in] I2Sx: I2S peripheral selected, should be: LPC_I2S
\r
520 * @param[in] DMAIndex chose what DMA is used, should be:
\r
521 * - I2S_DMA_1 = 0 :DMA1
\r
522 * - I2S_DMA_2 = 1 :DMA2
\r
523 * @param[in] TRMode is transmit/receive mode, should be:
\r
524 * - I2S_TX_MODE = 0 :transmit mode
\r
525 * - I2S_RX_MODE = 1 :receive mode
\r
526 * @param[in] NewState is new state of DMA operation, should be:
\r
530 *********************************************************************/
\r
531 void I2S_DMACmd(LPC_I2Sn_Type *I2Sx, uint8_t DMAIndex, uint8_t TRMode,
\r
532 FunctionalState NewState)
\r
534 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
535 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
\r
536 CHECK_PARAM(PARAM_I2S_DMA(DMAIndex));
\r
537 CHECK_PARAM(PARAM_I2S_TRX(TRMode));
\r
539 if (TRMode == I2S_RX_MODE) {
\r
540 if (DMAIndex == I2S_DMA_1) {
\r
541 if (NewState == ENABLE)
\r
542 I2Sx->DMA1 |= 0x01;
\r
544 I2Sx->DMA1 &= ~0x01;
\r
546 if (NewState == ENABLE)
\r
547 I2Sx->DMA2 |= 0x01;
\r
549 I2Sx->DMA2 &= ~0x01;
\r
552 if (DMAIndex == I2S_DMA_1) {
\r
553 if (NewState == ENABLE)
\r
554 I2Sx->DMA1 |= 0x02;
\r
556 I2Sx->DMA1 &= ~0x02;
\r
558 if (NewState == ENABLE)
\r
559 I2Sx->DMA2 |= 0x02;
\r
561 I2Sx->DMA2 &= ~0x02;
\r
566 /********************************************************************//**
\r
567 * @brief Configure IRQ for I2S
\r
568 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
569 * @param[in] TRMode is transmit/receive mode, should be:
\r
570 * - I2S_TX_MODE = 0 :transmit mode
\r
571 * - I2S_RX_MODE = 1 :receive mode
\r
572 * @param[in] level is the FIFO level that triggers IRQ request
\r
574 *********************************************************************/
\r
575 void I2S_IRQConfig(LPC_I2Sn_Type *I2Sx, uint8_t TRMode, uint8_t level) {
\r
576 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
577 CHECK_PARAM(PARAM_I2S_TRX(TRMode));
\r
578 CHECK_PARAM(PARAM_I2S_IRQ_LEVEL(level));
\r
580 if (TRMode == I2S_RX_MODE) {
\r
581 I2Sx->IRQ |= (level << 8);
\r
583 I2Sx->IRQ |= (level << 16);
\r
587 /********************************************************************//**
\r
588 * @brief Enable/Disable IRQ for I2S
\r
589 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
590 * @param[in] TRMode is transmit/receive mode, should be:
\r
591 * - I2S_TX_MODE = 0 :transmit mode
\r
592 * - I2S_RX_MODE = 1 :receive mode
\r
593 * @param[in] NewState is new state of DMA operation, should be:
\r
597 *********************************************************************/
\r
598 void I2S_IRQCmd(LPC_I2Sn_Type *I2Sx, uint8_t TRMode, FunctionalState NewState) {
\r
599 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
600 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
\r
602 if (TRMode == I2S_RX_MODE) {
\r
603 if (NewState == ENABLE)
\r
606 I2Sx->IRQ &= ~0x01;
\r
610 if (NewState == ENABLE)
\r
613 I2Sx->IRQ &= ~0x02;
\r
617 /********************************************************************//**
\r
618 * @brief Get I2S interrupt status
\r
619 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
620 * @param[in] TRMode is transmit/receive mode, should be:
\r
621 * - I2S_TX_MODE = 0 :transmit mode
\r
622 * - I2S_RX_MODE = 1 :receive mode
\r
623 * @return FunctionState should be:
\r
624 * - ENABLE :interrupt is enable
\r
625 * - DISABLE :interrupt is disable
\r
626 *********************************************************************/
\r
627 FunctionalState I2S_GetIRQStatus(LPC_I2Sn_Type *I2Sx,uint8_t TRMode)
\r
629 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
630 if(TRMode == I2S_TX_MODE)
\r
631 return (FunctionalState)((I2Sx->IRQ >> 1)&0x01);
\r
633 return (FunctionalState)((I2Sx->IRQ)&0x01);
\r
636 /********************************************************************//**
\r
637 * @brief Get I2S interrupt depth
\r
638 * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
\r
639 * @param[in] TRMode is transmit/receive mode, should be:
\r
640 * - I2S_TX_MODE = 0 :transmit mode
\r
641 * - I2S_RX_MODE = 1 :receive mode
\r
642 * @return depth of FIFO level on which to create an irq request
\r
643 *********************************************************************/
\r
644 uint8_t I2S_GetIRQDepth(LPC_I2Sn_Type *I2Sx,uint8_t TRMode)
\r
646 CHECK_PARAM(PARAM_I2Sx(I2Sx));
\r
647 if(TRMode == I2S_TX_MODE)
\r
648 return (((I2Sx->IRQ)>>16)&0xFF);
\r
650 return (((I2Sx->IRQ)>>8)&0xFF);
\r
662 /* --------------------------------- End Of File ------------------------------ */
\r