lpc_i2s.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /**********************************************************************
  2. * $Id$ lpc_i2s.c 2011-06-02
  3. *//**
  4. * @file lpc_i2s.c
  5. * @brief Contains all functions support for I2S firmware library
  6. * on LPC
  7. * @version 1.0
  8. * @date 02. June. 2011
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2011, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @addtogroup I2S
  34. * @{
  35. */
  36. #ifdef __BUILD_WITH_EXAMPLE__
  37. #include "lpc_libcfg.h"
  38. #else
  39. #include "lpc_libcfg_default.h"
  40. #endif /* __BUILD_WITH_EXAMPLE__ */
  41. #ifdef _I2S
  42. /* Includes ------------------------------------------------------------------- */
  43. #include "lpc_i2s.h"
  44. #include "lpc_clkpwr.h"
  45. /* definitions ---------------------------------------------------------- */
  46. #define I2S_IS_ENABLED(x) ((x)? ENABLE:DISABLE)
  47. /* Private Functions ---------------------------------------------------------- */
  48. static uint8_t i2s_GetWordWidth(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode);
  49. static uint8_t i2s_GetChannel(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode);
  50. /********************************************************************//**
  51. * @brief Get I2S wordwidth value
  52. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  53. * @param[in] TRMode is the I2S mode, should be:
  54. * - I2S_TX_MODE = 0: transmit mode
  55. * - I2S_RX_MODE = 1: receive mode
  56. * @return The wordwidth value, should be: 8,16 or 32
  57. *********************************************************************/
  58. static uint8_t i2s_GetWordWidth(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) {
  59. uint8_t value;
  60. if (TRMode == I2S_TX_MODE) {
  61. value = (I2Sx->DAO) & 0x03; /* get wordwidth bit */
  62. } else {
  63. value = (I2Sx->DAI) & 0x03; /* get wordwidth bit */
  64. }
  65. switch (value) {
  66. case I2S_WORDWIDTH_8:
  67. return 8;
  68. case I2S_WORDWIDTH_16:
  69. return 16;
  70. default:
  71. return 32;
  72. }
  73. }
  74. /********************************************************************//**
  75. * @brief Get I2S channel value
  76. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  77. * @param[in] TRMode is the I2S mode, should be:
  78. * - I2S_TX_MODE = 0: transmit mode
  79. * - I2S_RX_MODE = 1: receive mode
  80. * @return The channel value, should be: 1(mono) or 2(stereo)
  81. *********************************************************************/
  82. static uint8_t i2s_GetChannel(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) {
  83. uint8_t value;
  84. if (TRMode == I2S_TX_MODE) {
  85. value = ((I2Sx->DAO) & 0x04)>>2; /* get bit[2] */
  86. } else {
  87. value = ((I2Sx->DAI) & 0x04)>>2; /* get bit[2] */
  88. }
  89. if(value == I2S_MONO) return 1;
  90. return 2;
  91. }
  92. /* End of Private Functions --------------------------------------------------- */
  93. /* Public Functions ----------------------------------------------------------- */
  94. /** @addtogroup I2S_Public_Functions
  95. * @{
  96. */
  97. /********************************************************************//**
  98. * @brief Initialize I2S
  99. * - Turn on power and clock
  100. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  101. * @return none
  102. *********************************************************************/
  103. void I2S_Init(LPC_I2S_TypeDef *I2Sx) {
  104. // Turn on power and clock
  105. CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCI2S, ENABLE);
  106. LPC_I2S->DAI = LPC_I2S->DAO = 0x00;
  107. }
  108. /********************************************************************//**
  109. * @brief Configuration I2S, setting:
  110. * - master/slave mode
  111. * - wordwidth value
  112. * - channel mode
  113. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  114. * @param[in] TRMode transmit/receive mode, should be:
  115. * - I2S_TX_MODE = 0: transmit mode
  116. * - I2S_RX_MODE = 1: receive mode
  117. * @param[in] ConfigStruct pointer to I2S_CFG_Type structure
  118. * which will be initialized.
  119. * @return none
  120. *********************************************************************/
  121. void I2S_Config(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode, I2S_CFG_Type* ConfigStruct)
  122. {
  123. uint32_t bps, config;
  124. /* Setup clock */
  125. bps = (ConfigStruct->wordwidth +1)*8;
  126. /* Calculate audio config */
  127. config = (bps - 1)<<6 | (ConfigStruct->ws_sel)<<5 | (ConfigStruct->reset)<<4 |
  128. (ConfigStruct->stop)<<3 | (ConfigStruct->mono)<<2 | (ConfigStruct->wordwidth);
  129. if(TRMode == I2S_RX_MODE){
  130. LPC_I2S->DAI = config;
  131. }else{
  132. LPC_I2S->DAO = config;
  133. }
  134. }
  135. /********************************************************************//**
  136. * @brief DeInitial both I2S transmit or receive
  137. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  138. * @return none
  139. *********************************************************************/
  140. void I2S_DeInit(LPC_I2S_TypeDef *I2Sx) {
  141. // Turn off power and clock
  142. CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCI2S, DISABLE);
  143. }
  144. /********************************************************************//**
  145. * @brief Get I2S Buffer Level
  146. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  147. * @param[in] TRMode Transmit/receive mode, should be:
  148. * - I2S_TX_MODE = 0: transmit mode
  149. * - I2S_RX_MODE = 1: receive mode
  150. * @return current level of Transmit/Receive Buffer
  151. *********************************************************************/
  152. uint8_t I2S_GetLevel(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode)
  153. {
  154. if(TRMode == I2S_TX_MODE)
  155. {
  156. return ((I2Sx->STATE >> 16) & 0xFF);
  157. }
  158. else
  159. {
  160. return ((I2Sx->STATE >> 8) & 0xFF);
  161. }
  162. }
  163. /********************************************************************//**
  164. * @brief I2S Start: clear all STOP,RESET and MUTE bit, ready to operate
  165. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  166. * @return none
  167. *********************************************************************/
  168. void I2S_Start(LPC_I2S_TypeDef *I2Sx)
  169. {
  170. //Clear STOP,RESET and MUTE bit
  171. I2Sx->DAO &= ~I2S_DAI_RESET;
  172. I2Sx->DAI &= ~I2S_DAI_RESET;
  173. I2Sx->DAO &= ~I2S_DAI_STOP;
  174. I2Sx->DAI &= ~I2S_DAI_STOP;
  175. I2Sx->DAO &= ~I2S_DAI_MUTE;
  176. }
  177. /********************************************************************//**
  178. * @brief I2S Send data
  179. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  180. * @param[in] BufferData pointer to uint32_t is the data will be send
  181. * @return none
  182. *********************************************************************/
  183. void I2S_Send(LPC_I2S_TypeDef *I2Sx, uint32_t BufferData)
  184. {
  185. I2Sx->TXFIFO = BufferData;
  186. }
  187. /********************************************************************//**
  188. * @brief I2S Receive Data
  189. * @param[in] I2Sx pointer to LPC_I2S_TypeDef
  190. * @return received value
  191. *********************************************************************/
  192. uint32_t I2S_Receive(LPC_I2S_TypeDef* I2Sx)
  193. {
  194. return (I2Sx->RXFIFO);
  195. }
  196. /********************************************************************//**
  197. * @brief I2S Pause
  198. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  199. * @param[in] TRMode is transmit/receive mode, should be:
  200. * - I2S_TX_MODE = 0: transmit mode
  201. * - I2S_RX_MODE = 1: receive mode
  202. * @return none
  203. *********************************************************************/
  204. void I2S_Pause(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) {
  205. if (TRMode == I2S_TX_MODE) //Transmit mode
  206. {
  207. I2Sx->DAO |= I2S_DAO_STOP;
  208. } else //Receive mode
  209. {
  210. I2Sx->DAI |= I2S_DAI_STOP;
  211. }
  212. }
  213. /********************************************************************//**
  214. * @brief I2S Mute
  215. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  216. * @param[in] TRMode is transmit/receive mode, should be:
  217. * - I2S_TX_MODE = 0: transmit mode
  218. * - I2S_RX_MODE = 1: receive mode
  219. * @return none
  220. *********************************************************************/
  221. void I2S_Mute(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) {
  222. if (TRMode == I2S_TX_MODE) //Transmit mode
  223. {
  224. I2Sx->DAO |= I2S_DAO_MUTE;
  225. } else //Receive mode
  226. {
  227. I2Sx->DAI |= I2S_DAI_MUTE;
  228. }
  229. }
  230. /********************************************************************//**
  231. * @brief I2S Stop
  232. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  233. * @param[in] TRMode is transmit/receive mode, should be:
  234. * - I2S_TX_MODE = 0: transmit mode
  235. * - I2S_RX_MODE = 1: receive mode
  236. * @return none
  237. *********************************************************************/
  238. void I2S_Stop(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) {
  239. if (TRMode == I2S_TX_MODE) //Transmit mode
  240. {
  241. I2Sx->DAO &= ~I2S_DAO_MUTE;
  242. I2Sx->DAO |= I2S_DAO_STOP;
  243. I2Sx->DAO |= I2S_DAO_RESET;
  244. } else //Receive mode
  245. {
  246. I2Sx->DAI |= I2S_DAI_STOP;
  247. I2Sx->DAI |= I2S_DAI_RESET;
  248. }
  249. }
  250. /********************************************************************//**
  251. * @brief Set frequency for I2S
  252. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  253. * @param[in] Freq is the frequency for I2S will be set. It can range
  254. * from 16-96 kHz(16, 22.05, 32, 44.1, 48, 96kHz)
  255. * @param[in] TRMode is transmit/receive mode, should be:
  256. * - I2S_TX_MODE = 0: transmit mode
  257. * - I2S_RX_MODE = 1: receive mode
  258. * @return Status: ERROR or SUCCESS
  259. *********************************************************************/
  260. Status I2S_FreqConfig(LPC_I2S_TypeDef *I2Sx, uint32_t Freq, uint8_t TRMode) {
  261. uint32_t cclk;
  262. uint8_t channel, wordwidth;
  263. uint32_t x, y;
  264. uint64_t divider;
  265. uint16_t dif;
  266. uint16_t x_divide, y_divide;
  267. uint16_t err, ErrorOptimal = 0xFFFF;
  268. uint32_t N;
  269. //get cclk
  270. cclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU);
  271. if(TRMode == I2S_TX_MODE)
  272. {
  273. channel = i2s_GetChannel(I2Sx,I2S_TX_MODE);
  274. wordwidth = i2s_GetWordWidth(I2Sx,I2S_TX_MODE);
  275. }
  276. else
  277. {
  278. channel = i2s_GetChannel(I2Sx,I2S_RX_MODE);
  279. wordwidth = i2s_GetWordWidth(I2Sx,I2S_RX_MODE);
  280. }
  281. /* Calculate X and Y divider
  282. * The MCLK rate for the I2S transmitter is determined by the value
  283. * in the I2STXRATE/I2SRXRATE register. The required I2STXRATE/I2SRXRATE
  284. * setting depends on the desired audio sample rate desired, the format
  285. * (stereo/mono) used, and the data size.
  286. * The formula is:
  287. * I2S_MCLK = CCLK * (X/Y) / 2
  288. * We have:
  289. * I2S_MCLK = Freq * channel*wordwidth * (I2Sx->TXBITRATE+1);
  290. * So: (X/Y) = (Freq * channel*wordwidth * (I2Sx->TXBITRATE+1))/CCLK*2
  291. * We use a loop function to chose the most suitable X,Y value
  292. */
  293. /* divider is a fixed point number with 16 fractional bits */
  294. divider = (((uint64_t)Freq *channel*wordwidth * 2)<<16) / cclk;
  295. /* find N that make x/y <= 1 -> divider <= 2^16 */
  296. for(N=64;N>0;N--){
  297. if((divider*N) < (1<<16)) break;
  298. }
  299. if(N == 0) return ERROR;
  300. divider *= N;
  301. for (y = 255; y > 0; y--) {
  302. x = y * divider;
  303. if(x & (0xFF000000)) continue;
  304. dif = x & 0xFFFF;
  305. if(dif>0x8000) err = 0x10000-dif;
  306. else err = dif;
  307. if (err == 0)
  308. {
  309. y_divide = y;
  310. break;
  311. }
  312. else if (err < ErrorOptimal)
  313. {
  314. ErrorOptimal = err;
  315. y_divide = y;
  316. }
  317. }
  318. x_divide = ((uint64_t)y_divide * Freq *(channel*wordwidth)* N * 2)/cclk;
  319. if(x_divide >= 256) x_divide = 0xFF;
  320. if(x_divide == 0) x_divide = 1;
  321. if (TRMode == I2S_TX_MODE)// Transmitter
  322. {
  323. I2Sx->TXBITRATE = N-1;
  324. I2Sx->TXRATE = y_divide | (x_divide << 8);
  325. } else //Receiver
  326. {
  327. I2Sx->RXBITRATE = N-1;
  328. I2Sx->TXRATE = y_divide | (x_divide << 8);
  329. }
  330. return SUCCESS;
  331. }
  332. /********************************************************************//**
  333. * @brief I2S set bitrate
  334. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  335. * @param[in] bitrate value will be set
  336. * bitrate value should be in range: 0 .. 63
  337. * @param[in] TRMode is transmit/receive mode, should be:
  338. * - I2S_TX_MODE = 0: transmit mode
  339. * - I2S_RX_MODE = 1: receive mode
  340. * @return none
  341. *********************************************************************/
  342. void I2S_SetBitRate(LPC_I2S_TypeDef *I2Sx, uint8_t bitrate, uint8_t TRMode)
  343. {
  344. if(TRMode == I2S_TX_MODE)
  345. {
  346. I2Sx->TXBITRATE = bitrate;
  347. }
  348. else
  349. {
  350. I2Sx->RXBITRATE = bitrate;
  351. }
  352. }
  353. /********************************************************************//**
  354. * @brief Configuration operating mode for I2S
  355. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  356. * @param[in] ModeConfig pointer to I2S_MODEConf_Type will be used to
  357. * configure
  358. * @param[in] TRMode is transmit/receive mode, should be:
  359. * - I2S_TX_MODE = 0: transmit mode
  360. * - I2S_RX_MODE = 1: receive mode
  361. * @return none
  362. *********************************************************************/
  363. void I2S_ModeConfig(LPC_I2S_TypeDef *I2Sx, I2S_MODEConf_Type* ModeConfig,
  364. uint8_t TRMode)
  365. {
  366. if (TRMode == I2S_TX_MODE) {
  367. I2Sx->TXMODE &= ~0x0F; //clear bit 3:0 in I2STXMODE register
  368. if (ModeConfig->clksel == I2S_CLKSEL_MCLK) {
  369. I2Sx->TXMODE |= 0x02;
  370. }
  371. if (ModeConfig->fpin == I2S_4PIN_ENABLE) {
  372. I2Sx->TXMODE |= (1 << 2);
  373. }
  374. if (ModeConfig->mcena == I2S_MCLK_ENABLE) {
  375. I2Sx->TXMODE |= (1 << 3);
  376. }
  377. } else {
  378. I2Sx->RXMODE &= ~0x0F; //clear bit 3:0 in I2STXMODE register
  379. if (ModeConfig->clksel == I2S_CLKSEL_MCLK) {
  380. I2Sx->RXMODE |= 0x02;
  381. }
  382. if (ModeConfig->fpin == I2S_4PIN_ENABLE) {
  383. I2Sx->RXMODE |= (1 << 2);
  384. }
  385. if (ModeConfig->mcena == I2S_MCLK_ENABLE) {
  386. I2Sx->RXMODE |= (1 << 3);
  387. }
  388. }
  389. }
  390. /********************************************************************//**
  391. * @brief Configure DMA operation for I2S
  392. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  393. * @param[in] DMAConfig pointer to I2S_DMAConf_Type will be used to configure
  394. * @param[in] TRMode is transmit/receive mode, should be:
  395. * - I2S_TX_MODE = 0: transmit mode
  396. * - I2S_RX_MODE = 1: receive mode
  397. * @return none
  398. *********************************************************************/
  399. void I2S_DMAConfig(LPC_I2S_TypeDef *I2Sx, I2S_DMAConf_Type* DMAConfig,
  400. uint8_t TRMode)
  401. {
  402. if (TRMode == I2S_RX_MODE) {
  403. if (DMAConfig->DMAIndex == I2S_DMA_1) {
  404. LPC_I2S->DMA1 = (DMAConfig->depth) << 8;
  405. } else {
  406. LPC_I2S->DMA2 = (DMAConfig->depth) << 8;
  407. }
  408. } else {
  409. if (DMAConfig->DMAIndex == I2S_DMA_1) {
  410. LPC_I2S->DMA1 = (DMAConfig->depth) << 16;
  411. } else {
  412. LPC_I2S->DMA2 = (DMAConfig->depth) << 16;
  413. }
  414. }
  415. }
  416. /********************************************************************//**
  417. * @brief Enable/Disable DMA operation for I2S
  418. * @param[in] I2Sx: I2S peripheral selected, should be: LPC_I2S
  419. * @param[in] DMAIndex chose what DMA is used, should be:
  420. * - I2S_DMA_1 = 0: DMA1
  421. * - I2S_DMA_2 = 1: DMA2
  422. * @param[in] TRMode is transmit/receive mode, should be:
  423. * - I2S_TX_MODE = 0: transmit mode
  424. * - I2S_RX_MODE = 1: receive mode
  425. * @param[in] NewState is new state of DMA operation, should be:
  426. * - ENABLE
  427. * - DISABLE
  428. * @return none
  429. *********************************************************************/
  430. void I2S_DMACmd(LPC_I2S_TypeDef *I2Sx, uint8_t DMAIndex, uint8_t TRMode,
  431. FunctionalState NewState)
  432. {
  433. if (TRMode == I2S_RX_MODE) {
  434. if (DMAIndex == I2S_DMA_1) {
  435. if (NewState == ENABLE)
  436. I2Sx->DMA1 |= 0x01;
  437. else
  438. I2Sx->DMA1 &= ~0x01;
  439. } else {
  440. if (NewState == ENABLE)
  441. I2Sx->DMA2 |= 0x01;
  442. else
  443. I2Sx->DMA2 &= ~0x01;
  444. }
  445. } else {
  446. if (DMAIndex == I2S_DMA_1) {
  447. if (NewState == ENABLE)
  448. I2Sx->DMA1 |= 0x02;
  449. else
  450. I2Sx->DMA1 &= ~0x02;
  451. } else {
  452. if (NewState == ENABLE)
  453. I2Sx->DMA2 |= 0x02;
  454. else
  455. I2Sx->DMA2 &= ~0x02;
  456. }
  457. }
  458. }
  459. /********************************************************************//**
  460. * @brief Configure IRQ for I2S
  461. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  462. * @param[in] TRMode is transmit/receive mode, should be:
  463. * - I2S_TX_MODE = 0: transmit mode
  464. * - I2S_RX_MODE = 1: receive mode
  465. * @param[in] level is the FIFO level that triggers IRQ request
  466. * @return none
  467. *********************************************************************/
  468. void I2S_IRQConfig(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode, uint8_t level) {
  469. if (TRMode == I2S_RX_MODE) {
  470. I2Sx->IRQ |= (level << 8);
  471. } else {
  472. I2Sx->IRQ |= (level << 16);
  473. }
  474. }
  475. /********************************************************************//**
  476. * @brief Enable/Disable IRQ for I2S
  477. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  478. * @param[in] TRMode is transmit/receive mode, should be:
  479. * - I2S_TX_MODE = 0: transmit mode
  480. * - I2S_RX_MODE = 1: receive mode
  481. * @param[in] NewState is new state of DMA operation, should be:
  482. * - ENABLE
  483. * - DISABLE
  484. * @return none
  485. *********************************************************************/
  486. void I2S_IRQCmd(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode, FunctionalState NewState) {
  487. if (TRMode == I2S_RX_MODE) {
  488. if (NewState == ENABLE)
  489. I2Sx->IRQ |= 0x01;
  490. else
  491. I2Sx->IRQ &= ~0x01;
  492. //Enable DMA
  493. } else {
  494. if (NewState == ENABLE)
  495. I2Sx->IRQ |= 0x02;
  496. else
  497. I2Sx->IRQ &= ~0x02;
  498. }
  499. }
  500. /********************************************************************//**
  501. * @brief Get I2S interrupt status
  502. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  503. * @param[in] TRMode is transmit/receive mode, should be:
  504. * - I2S_TX_MODE = 0: transmit mode
  505. * - I2S_RX_MODE = 1: receive mode
  506. * @return FunctionState should be:
  507. * - ENABLE: interrupt is enable
  508. * - DISABLE: interrupt is disable
  509. *********************************************************************/
  510. FunctionalState I2S_GetIRQStatus(LPC_I2S_TypeDef *I2Sx,uint8_t TRMode)
  511. {
  512. if(TRMode == I2S_TX_MODE)
  513. return I2S_IS_ENABLED((I2Sx->IRQ >> 1)&0x01);
  514. else
  515. return I2S_IS_ENABLED((I2Sx->IRQ)&0x01);
  516. }
  517. /********************************************************************//**
  518. * @brief Get I2S interrupt depth
  519. * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
  520. * @param[in] TRMode is transmit/receive mode, should be:
  521. * - I2S_TX_MODE = 0: transmit mode
  522. * - I2S_RX_MODE = 1: receive mode
  523. * @return depth of FIFO level on which to create an irq request
  524. *********************************************************************/
  525. uint8_t I2S_GetIRQDepth(LPC_I2S_TypeDef *I2Sx,uint8_t TRMode)
  526. {
  527. if(TRMode == I2S_TX_MODE)
  528. return (((I2Sx->IRQ)>>16)&0xFF);
  529. else
  530. return (((I2Sx->IRQ)>>8)&0xFF);
  531. }
  532. /**
  533. * @}
  534. */
  535. #endif /*_I2S*/
  536. /**
  537. * @}
  538. */
  539. /* --------------------------------- End Of File ------------------------------ */