lpc_i2s.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /**********************************************************************
  2. * $Id$ lpc_i2s.h 2011-06-02
  3. *//**
  4. * @file lpc_i2s.h
  5. * @brief Contains all macro definitions and function prototypes
  6. * support for I2S firmware library 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. /** @defgroup I2S I2S (Inter-IC Sound bus)
  34. * @ingroup LPC_CMSIS_FwLib_Drivers
  35. * @{
  36. */
  37. #ifndef __LPC_I2S_H_
  38. #define __LPC_I2S_H_
  39. /* Includes ------------------------------------------------------------------- */
  40. #include "LPC407x_8x_177x_8x.h"
  41. #include "lpc_types.h"
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif
  46. /* Public Macros -------------------------------------------------------------- */
  47. /** @defgroup I2S_Public_Macros I2S Public Macros
  48. * @{
  49. */
  50. /*********************************************************************//**
  51. * I2S configuration parameter defines
  52. **********************************************************************/
  53. /** I2S Wordwidth bit */
  54. #define I2S_WORDWIDTH_8 ((uint32_t)(0))
  55. #define I2S_WORDWIDTH_16 ((uint32_t)(1))
  56. #define I2S_WORDWIDTH_32 ((uint32_t)(3))
  57. /** I2S Channel bit */
  58. #define I2S_STEREO ((uint32_t)(0))
  59. #define I2S_MONO ((uint32_t)(1))
  60. /** I2S Master/Slave mode bit */
  61. #define I2S_MASTER_MODE ((uint8_t)(0))
  62. #define I2S_SLAVE_MODE ((uint8_t)(1))
  63. /** I2S Stop bit */
  64. #define I2S_STOP_ENABLE ((uint8_t)(1))
  65. #define I2S_STOP_DISABLE ((uint8_t)(0))
  66. /** I2S Reset bit */
  67. #define I2S_RESET_ENABLE ((uint8_t)(1))
  68. #define I2S_RESET_DISABLE ((uint8_t)(0))
  69. /** I2S Mute bit */
  70. #define I2S_MUTE_ENABLE ((uint8_t)(1))
  71. #define I2S_MUTE_DISABLE ((uint8_t)(0))
  72. /** I2S Transmit/Receive bit */
  73. #define I2S_TX_MODE ((uint8_t)(0))
  74. #define I2S_RX_MODE ((uint8_t)(1))
  75. /** I2S Clock Select bit */
  76. #define I2S_CLKSEL_FRDCLK ((uint8_t)(0))
  77. #define I2S_CLKSEL_MCLK ((uint8_t)(2))
  78. /** I2S 4-pin Mode bit */
  79. #define I2S_4PIN_ENABLE ((uint8_t)(1))
  80. #define I2S_4PIN_DISABLE ((uint8_t)(0))
  81. /** I2S MCLK Enable bit */
  82. #define I2S_MCLK_ENABLE ((uint8_t)(1))
  83. #define I2S_MCLK_DISABLE ((uint8_t)(0))
  84. /** I2S select DMA bit */
  85. #define I2S_DMA_1 ((uint8_t)(0))
  86. #define I2S_DMA_2 ((uint8_t)(1))
  87. /**
  88. * @}
  89. */
  90. /* Private Macros ------------------------------------------------------------- */
  91. /** @defgroup I2S_Private_Macros I2S Private Macros
  92. * @{
  93. */
  94. /*********************************************************************//**
  95. * Macro defines for DAO-Digital Audio Output register
  96. **********************************************************************/
  97. /** I2S wordwide - the number of bytes in data output - 8 bits*/
  98. #define I2S_DAO_WORDWIDTH_8 ((uint32_t)(0))
  99. /** I2S wordwide - the number of bytes in data output - 16 bits*/
  100. #define I2S_DAO_WORDWIDTH_16 ((uint32_t)(1))
  101. /** I2S wordwide - the number of bytes in data output - 32 bits*/
  102. #define I2S_DAO_WORDWIDTH_32 ((uint32_t)(3))
  103. /** I2S control mono or stereo format */
  104. #define I2S_DAO_MONO ((uint32_t)(1<<2))
  105. /** I2S control stop mode */
  106. #define I2S_DAO_STOP ((uint32_t)(1<<3))
  107. /** I2S control reset mode */
  108. #define I2S_DAO_RESET ((uint32_t)(1<<4))
  109. /** I2S control master/slave mode */
  110. #define I2S_DAO_SLAVE ((uint32_t)(1<<5))
  111. /** I2S word select half period minus one */
  112. #define I2S_DAO_WS_HALFPERIOD(n) ((uint32_t)(n<<6))
  113. /** I2S control mute mode */
  114. #define I2S_DAO_MUTE ((uint32_t)(1<<15))
  115. /*********************************************************************//**
  116. * Macro defines for DAI-Digital Audio Input register
  117. **********************************************************************/
  118. /** I2S wordwide - the number of bytes in data input - 8 bit*/
  119. #define I2S_DAI_WORDWIDTH_8 ((uint32_t)(0))
  120. /** I2S wordwide - the number of bytes in data input - 16 bit*/
  121. #define I2S_DAI_WORDWIDTH_16 ((uint32_t)(1))
  122. /** I2S wordwide - the number of bytes in data input - 32 bit*/
  123. #define I2S_DAI_WORDWIDTH_32 ((uint32_t)(3))
  124. /** I2S control mono or stereo format */
  125. #define I2S_DAI_MONO ((uint32_t)(1<<2))
  126. /** I2S control stop mode */
  127. #define I2S_DAI_STOP ((uint32_t)(1<<3))
  128. /** I2S control reset mode */
  129. #define I2S_DAI_RESET ((uint32_t)(1<<4))
  130. /** I2S control master/slave mode */
  131. #define I2S_DAI_SLAVE ((uint32_t)(1<<5))
  132. /** I2S word select half period minus one (9 bits)*/
  133. #define I2S_DAI_WS_HALFPERIOD(n) ((uint32_t)((n&0x1FF)<<6))
  134. /** I2S control mute mode */
  135. #define I2S_DAI_MUTE ((uint32_t)(1<<15))
  136. /*********************************************************************//**
  137. * Macro defines for STAT register (Status Feedback register)
  138. **********************************************************************/
  139. /** I2S Status Receive or Transmit Interrupt */
  140. #define I2S_STATE_IRQ ((uint32_t)(1))
  141. /** I2S Status Receive or Transmit DMA1 */
  142. #define I2S_STATE_DMA1 ((uint32_t)(1<<1))
  143. /** I2S Status Receive or Transmit DMA2 */
  144. #define I2S_STATE_DMA2 ((uint32_t)(1<<2))
  145. /** I2S Status Current level of the Receive FIFO (5 bits)*/
  146. #define I2S_STATE_RX_LEVEL(n) ((uint32_t)((n&1F)<<8))
  147. /** I2S Status Current level of the Transmit FIFO (5 bits)*/
  148. #define I2S_STATE_TX_LEVEL(n) ((uint32_t)((n&1F)<<16))
  149. /*********************************************************************//**
  150. * Macro defines for DMA1 register (DMA1 Configuration register)
  151. **********************************************************************/
  152. /** I2S control DMA1 for I2S receive */
  153. #define I2S_DMA1_RX_ENABLE ((uint32_t)(1))
  154. /** I2S control DMA1 for I2S transmit */
  155. #define I2S_DMA1_TX_ENABLE ((uint32_t)(1<<1))
  156. /** I2S set FIFO level that trigger a receive DMA request on DMA1 */
  157. #define I2S_DMA1_RX_DEPTH(n) ((uint32_t)((n&0x1F)<<8))
  158. /** I2S set FIFO level that trigger a transmit DMA request on DMA1 */
  159. #define I2S_DMA1_TX_DEPTH(n) ((uint32_t)((n&0x1F)<<16))
  160. /*********************************************************************//**
  161. * Macro defines for DMA2 register (DMA2 Configuration register)
  162. **********************************************************************/
  163. /** I2S control DMA2 for I2S receive */
  164. #define I2S_DMA2_RX_ENABLE ((uint32_t)(1))
  165. /** I2S control DMA1 for I2S transmit */
  166. #define I2S_DMA2_TX_ENABLE ((uint32_t)(1<<1))
  167. /** I2S set FIFO level that trigger a receive DMA request on DMA1 */
  168. #define I2S_DMA2_RX_DEPTH(n) ((uint32_t)((n&0x1F)<<8))
  169. /** I2S set FIFO level that trigger a transmit DMA request on DMA1 */
  170. #define I2S_DMA2_TX_DEPTH(n) ((uint32_t)((n&0x1F)<<16))
  171. /*********************************************************************//**
  172. * Macro defines for IRQ register (Interrupt Request Control register)
  173. **********************************************************************/
  174. /** I2S control I2S receive interrupt */
  175. #define I2S_IRQ_RX_ENABLE ((uint32_t)(1))
  176. /** I2S control I2S transmit interrupt */
  177. #define I2S_IRQ_TX_ENABLE ((uint32_t)(1<<1))
  178. /** I2S set the FIFO level on which to create an irq request */
  179. #define I2S_IRQ_RX_DEPTH(n) ((uint32_t)((n&0x1F)<<8))
  180. /** I2S set the FIFO level on which to create an irq request */
  181. #define I2S_IRQ_TX_DEPTH(n) ((uint32_t)((n&0x1F)<<16))
  182. /********************************************************************************//**
  183. * Macro defines for TXRATE/RXRATE register (Transmit/Receive Clock Rate register)
  184. *********************************************************************************/
  185. /** I2S Transmit MCLK rate denominator */
  186. #define I2S_TXRATE_Y_DIVIDER(n) ((uint32_t)(n&0xFF))
  187. /** I2S Transmit MCLK rate denominator */
  188. #define I2S_TXRATE_X_DIVIDER(n) ((uint32_t)((n&0xFF)<<8))
  189. /** I2S Receive MCLK rate denominator */
  190. #define I2S_RXRATE_Y_DIVIDER(n) ((uint32_t)(n&0xFF))
  191. /** I2S Receive MCLK rate denominator */
  192. #define I2S_RXRATE_X_DIVIDER(n) ((uint32_t)((n&0xFF)<<8))
  193. /*************************************************************************************//**
  194. * Macro defines for TXBITRATE & RXBITRATE register (Transmit/Receive Bit Rate register)
  195. **************************************************************************************/
  196. #define I2S_TXBITRATE(n) ((uint32_t)(n&0x3F))
  197. #define I2S_RXBITRATE(n) ((uint32_t)(n&0x3F))
  198. /**********************************************************************************//**
  199. * Macro defines for TXMODE/RXMODE register (Transmit/Receive Mode Control register)
  200. ************************************************************************************/
  201. /** I2S Transmit select clock source (2 bits)*/
  202. #define I2S_TXMODE_CLKSEL(n) ((uint32_t)(n&0x03))
  203. /** I2S Transmit control 4-pin mode */
  204. #define I2S_TXMODE_4PIN_ENABLE ((uint32_t)(1<<2))
  205. /** I2S Transmit control the TX_MCLK output */
  206. #define I2S_TXMODE_MCENA ((uint32_t)(1<<3))
  207. /** I2S Receive select clock source */
  208. #define I2S_RXMODE_CLKSEL(n) ((uint32_t)(n&0x03))
  209. /** I2S Receive control 4-pin mode */
  210. #define I2S_RXMODE_4PIN_ENABLE ((uint32_t)(1<<2))
  211. /** I2S Receive control the TX_MCLK output */
  212. #define I2S_RXMODE_MCENA ((uint32_t)(1<<3))
  213. /**
  214. * @}
  215. */
  216. /* Public Types --------------------------------------------------------------- */
  217. /** @defgroup I2S_Public_Types I2S Public Types
  218. * @{
  219. */
  220. /**
  221. * @brief I2S configuration structure definition
  222. */
  223. typedef struct {
  224. uint8_t wordwidth; /** the number of bytes in data as follow:
  225. -I2S_WORDWIDTH_8: 8 bit data
  226. -I2S_WORDWIDTH_16: 16 bit data
  227. -I2S_WORDWIDTH_32: 32 bit data */
  228. uint8_t mono; /** Set mono/stereo mode, should be:
  229. - I2S_STEREO: stereo mode
  230. - I2S_MONO: mono mode */
  231. uint8_t stop; /** Disables accesses on FIFOs, should be:
  232. - I2S_STOP_ENABLE: enable stop mode
  233. - I2S_STOP_DISABLE: disable stop mode */
  234. uint8_t reset; /** Asynchronously reset tje transmit channel and FIFO, should be:
  235. - I2S_RESET_ENABLE: enable reset mode
  236. - I2S_RESET_DISABLE: disable reset mode */
  237. uint8_t ws_sel; /** Set Master/Slave mode, should be:
  238. - I2S_MASTER_MODE: I2S master mode
  239. - I2S_SLAVE_MODE: I2S slave mode */
  240. uint8_t mute; /** MUTE mode: when true, the transmit channel sends only zeroes, shoule be:
  241. - I2S_MUTE_ENABLE: enable mute mode
  242. - I2S_MUTE_DISABLE: disable mute mode */
  243. uint8_t Reserved0[2];
  244. } I2S_CFG_Type;
  245. /**
  246. * @brief I2S DMA configuration structure definition
  247. */
  248. typedef struct {
  249. uint8_t DMAIndex; /** Select DMA1 or DMA2, should be:
  250. - I2S_DMA_1: DMA1
  251. - I2S_DMA_2: DMA2 */
  252. uint8_t depth; /** FIFO level that triggers a DMA request */
  253. uint8_t Reserved0[2];
  254. }I2S_DMAConf_Type;
  255. /**
  256. * @brief I2S mode configuration structure definition
  257. */
  258. typedef struct{
  259. uint8_t clksel; /** Clock source selection, should be:
  260. - I2S_CLKSEL_FRDCLK: Select the fractional rate divider clock output
  261. - I2S_CLKSEL_MCLK: Select the MCLK signal as the clock source */
  262. uint8_t fpin; /** Select four pin mode, should be:
  263. - I2S_4PIN_ENABLE: 4-pin enable
  264. - I2S_4PIN_DISABLE: 4-pin disable */
  265. uint8_t mcena; /** Select MCLK mode, should be:
  266. - I2S_MCLK_ENABLE: MCLK enable for output
  267. - I2S_MCLK_DISABLE: MCLK disable for output */
  268. uint8_t Reserved;
  269. }I2S_MODEConf_Type;
  270. /**
  271. * @}
  272. */
  273. /* Public Functions ----------------------------------------------------------- */
  274. /** @defgroup I2S_Public_Functions I2S Public Functions
  275. * @{
  276. */
  277. /* I2S Init/DeInit functions ---------*/
  278. void I2S_Init(LPC_I2S_TypeDef *I2Sx);
  279. void I2S_DeInit(LPC_I2S_TypeDef *I2Sx);
  280. /* I2S configuration functions --------*/
  281. void I2S_Config(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode, I2S_CFG_Type* ConfigStruct);
  282. Status I2S_FreqConfig(LPC_I2S_TypeDef *I2Sx, uint32_t Freq, uint8_t TRMode);
  283. void I2S_SetBitRate(LPC_I2S_TypeDef *I2Sx, uint8_t bitrate, uint8_t TRMode);
  284. void I2S_ModeConfig(LPC_I2S_TypeDef *I2Sx, I2S_MODEConf_Type* ModeConfig, uint8_t TRMode);
  285. uint8_t I2S_GetLevel(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode);
  286. /* I2S operate functions -------------*/
  287. void I2S_Send(LPC_I2S_TypeDef *I2Sx, uint32_t BufferData);
  288. uint32_t I2S_Receive(LPC_I2S_TypeDef* I2Sx);
  289. void I2S_Start(LPC_I2S_TypeDef *I2Sx);
  290. void I2S_Pause(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode);
  291. void I2S_Mute(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode);
  292. void I2S_Stop(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode);
  293. /* I2S DMA functions ----------------*/
  294. void I2S_DMAConfig(LPC_I2S_TypeDef *I2Sx, I2S_DMAConf_Type* DMAConfig, uint8_t TRMode);
  295. void I2S_DMACmd(LPC_I2S_TypeDef *I2Sx, uint8_t DMAIndex,uint8_t TRMode, FunctionalState NewState);
  296. /* I2S IRQ functions ----------------*/
  297. void I2S_IRQCmd(LPC_I2S_TypeDef *I2Sx,uint8_t TRMode, FunctionalState NewState);
  298. void I2S_IRQConfig(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode, uint8_t level);
  299. FunctionalState I2S_GetIRQStatus(LPC_I2S_TypeDef *I2Sx,uint8_t TRMode);
  300. uint8_t I2S_GetIRQDepth(LPC_I2S_TypeDef *I2Sx,uint8_t TRMode);
  301. /**
  302. * @}
  303. */
  304. #ifdef __cplusplus
  305. }
  306. #endif
  307. #endif /* __LPC_SSP_H_ */
  308. /**
  309. * @}
  310. */
  311. /* --------------------------------- End Of File ------------------------------ */