]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/ThirdParty/CMSISv2p10_LPC18xx_DriverLib/inc/lpc18xx_i2s.h
Update copyright date ready for tagging V10.1.0.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / ThirdParty / CMSISv2p10_LPC18xx_DriverLib / inc / lpc18xx_i2s.h
1 /**********************************************************************\r
2 * $Id$          lpc18xx_i2s.h           2011-06-02\r
3 *//**\r
4 * @file         lpc18xx_i2s.h\r
5 * @brief        Contains all macro definitions and function prototypes\r
6 *                       support for I2S firmware library on LPC18xx\r
7 * @version      1.0\r
8 * @date         02. June. 2011\r
9 * @author       NXP MCU SW Application Team\r
10 *\r
11 * Copyright(C) 2011, NXP Semiconductor\r
12 * All rights reserved.\r
13 *\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
26 \r
27 /* Peripheral group ----------------------------------------------------------- */\r
28 /** @defgroup I2S I2S (Inter-IC Sound)\r
29  * @ingroup LPC1800CMSIS_FwLib_Drivers\r
30  * @{\r
31  */\r
32 \r
33 #ifndef LPC18XX_I2S_H_\r
34 #define LPC18XX_I2S_H_\r
35 \r
36 /* Includes ------------------------------------------------------------------- */\r
37 #include "LPC18xx.h"\r
38 #include "lpc_types.h"\r
39 \r
40 \r
41 #ifdef __cplusplus\r
42 extern "C"\r
43 {\r
44 #endif\r
45 \r
46 /* Private Macros ------------------------------------------------------------- */\r
47 /** @defgroup I2S_Private_Macros I2S Private Macros\r
48  * @{\r
49  */\r
50 \r
51 /*********************************************************************//**\r
52  * I2S configuration parameter defines\r
53  **********************************************************************/\r
54 /** I2S Wordwidth bit */\r
55 #define I2S_WORDWIDTH_8         ((uint32_t)(0))\r
56 #define I2S_WORDWIDTH_16        ((uint32_t)(1))\r
57 #define I2S_WORDWIDTH_32        ((uint32_t)(3))\r
58 /** I2S Channel bit */\r
59 #define I2S_STEREO                      ((uint32_t)(0))\r
60 #define I2S_MONO                        ((uint32_t)(1))\r
61 /** I2S Master/Slave mode bit */\r
62 #define I2S_MASTER_MODE         ((uint8_t)(0))\r
63 #define I2S_SLAVE_MODE          ((uint8_t)(1))\r
64 /** I2S Stop bit */\r
65 #define I2S_STOP_ENABLE         ((uint8_t)(1))\r
66 #define I2S_STOP_DISABLE        ((uint8_t)(0))\r
67 /** I2S Reset bit */\r
68 #define I2S_RESET_ENABLE        ((uint8_t)(1))\r
69 #define I2S_RESET_DISABLE       ((uint8_t)(0))\r
70 /** I2S Mute bit */\r
71 #define I2S_MUTE_ENABLE         ((uint8_t)(1))\r
72 #define I2S_MUTE_DISABLE        ((uint8_t)(0))\r
73 /** I2S Transmit/Receive bit */\r
74 #define I2S_TX_MODE                     ((uint8_t)(0))\r
75 #define I2S_RX_MODE                     ((uint8_t)(1))\r
76 /** I2S Clock Select bit */\r
77 #define I2S_CLKSEL_FRDCLK       ((uint8_t)(0))\r
78 #define I2S_CLKSEL_MCLK         ((uint8_t)(2))\r
79 /** I2S 4-pin Mode bit */\r
80 #define I2S_4PIN_ENABLE         ((uint8_t)(1))\r
81 #define I2S_4PIN_DISABLE        ((uint8_t)(0))\r
82 /** I2S MCLK Enable bit */\r
83 #define I2S_MCLK_ENABLE         ((uint8_t)(1))\r
84 #define I2S_MCLK_DISABLE        ((uint8_t)(0))\r
85 /** I2S select DMA bit */\r
86 #define I2S_DMA_1                       ((uint8_t)(0))\r
87 #define I2S_DMA_2                       ((uint8_t)(1))\r
88 \r
89 /*********************************************************************//**\r
90  * Macro defines for DAO-Digital Audio Output register\r
91  **********************************************************************/\r
92 /** I2S wordwide - the number of bytes in data*/\r
93 #define I2S_DAO_WORDWIDTH_8             ((uint32_t)(0))         /** 8 bit       */\r
94 #define I2S_DAO_WORDWIDTH_16    ((uint32_t)(1))         /** 16 bit      */\r
95 #define I2S_DAO_WORDWIDTH_32    ((uint32_t)(3))         /** 32 bit      */\r
96 /** I2S control mono or stereo format */\r
97 #define I2S_DAO_MONO                    ((uint32_t)(1<<2))\r
98 /** I2S control stop mode */\r
99 #define I2S_DAO_STOP                    ((uint32_t)(1<<3))\r
100 /** I2S control reset mode */\r
101 #define I2S_DAO_RESET                   ((uint32_t)(1<<4))\r
102 /** I2S control master/slave mode */\r
103 #define I2S_DAO_SLAVE                   ((uint32_t)(1<<5))\r
104 /** I2S word select half period minus one */\r
105 #define I2S_DAO_WS_HALFPERIOD(n)        ((uint32_t)(n<<6))\r
106 /** I2S control mute mode */\r
107 #define I2S_DAO_MUTE                    ((uint32_t)(1<<15))\r
108 \r
109 /*********************************************************************//**\r
110  * Macro defines for DAI-Digital Audio Input register\r
111 **********************************************************************/\r
112 /** I2S wordwide - the number of bytes in data*/\r
113 #define I2S_DAI_WORDWIDTH_8             ((uint32_t)(0))         /** 8 bit       */\r
114 #define I2S_DAI_WORDWIDTH_16    ((uint32_t)(1))         /** 16 bit      */\r
115 #define I2S_DAI_WORDWIDTH_32    ((uint32_t)(3))         /** 32 bit      */\r
116 /** I2S control mono or stereo format */\r
117 #define I2S_DAI_MONO                    ((uint32_t)(1<<2))\r
118 /** I2S control stop mode */\r
119 #define I2S_DAI_STOP                    ((uint32_t)(1<<3))\r
120 /** I2S control reset mode */\r
121 #define I2S_DAI_RESET                   ((uint32_t)(1<<4))\r
122 /** I2S control master/slave mode */\r
123 #define I2S_DAI_SLAVE                   ((uint32_t)(1<<5))\r
124 /** I2S word select half period minus one (9 bits)*/\r
125 #define I2S_DAI_WS_HALFPERIOD(n)        ((uint32_t)((n&0x1FF)<<6))\r
126 /** I2S control mute mode */\r
127 #define I2S_DAI_MUTE                    ((uint32_t)(1<<15))\r
128 \r
129 /*********************************************************************//**\r
130  * Macro defines for STAT register (Status Feedback register)\r
131 **********************************************************************/\r
132 /** I2S Status Receive or Transmit Interrupt */\r
133 #define I2S_STATE_IRQ           ((uint32_t)(1))\r
134 /** I2S Status Receive or Transmit DMA1 */\r
135 #define I2S_STATE_DMA1          ((uint32_t)(1<<1))\r
136 /** I2S Status Receive or Transmit DMA2 */\r
137 #define I2S_STATE_DMA2          ((uint32_t)(1<<2))\r
138 /** I2S Status Current level of the Receive FIFO (5 bits)*/\r
139 #define I2S_STATE_RX_LEVEL(n)   ((uint32_t)((n&1F)<<8))\r
140 /** I2S Status Current level of the Transmit FIFO (5 bits)*/\r
141 #define I2S_STATE_TX_LEVEL(n)   ((uint32_t)((n&1F)<<16))\r
142 \r
143 /*********************************************************************//**\r
144  * Macro defines for DMA1 register (DMA1 Configuration register)\r
145 **********************************************************************/\r
146 /** I2S control DMA1 for I2S receive */\r
147 #define I2S_DMA1_RX_ENABLE              ((uint32_t)(1))\r
148 /** I2S control DMA1 for I2S transmit */\r
149 #define I2S_DMA1_TX_ENABLE              ((uint32_t)(1<<1))\r
150 /** I2S set FIFO level that trigger a receive DMA request on DMA1 */\r
151 #define I2S_DMA1_RX_DEPTH(n)    ((uint32_t)((n&0x1F)<<8))\r
152 /** I2S set FIFO level that trigger a transmit DMA request on DMA1 */\r
153 #define I2S_DMA1_TX_DEPTH(n)    ((uint32_t)((n&0x1F)<<16))\r
154 \r
155 /*********************************************************************//**\r
156  * Macro defines for DMA2 register (DMA2 Configuration register)\r
157 **********************************************************************/\r
158 /** I2S control DMA2 for I2S receive */\r
159 #define I2S_DMA2_RX_ENABLE              ((uint32_t)(1))\r
160 /** I2S control DMA1 for I2S transmit */\r
161 #define I2S_DMA2_TX_ENABLE              ((uint32_t)(1<<1))\r
162 /** I2S set FIFO level that trigger a receive DMA request on DMA1 */\r
163 #define I2S_DMA2_RX_DEPTH(n)    ((uint32_t)((n&0x1F)<<8))\r
164 /** I2S set FIFO level that trigger a transmit DMA request on DMA1 */\r
165 #define I2S_DMA2_TX_DEPTH(n)    ((uint32_t)((n&0x1F)<<16))\r
166 \r
167 /*********************************************************************//**\r
168 * Macro defines for IRQ register (Interrupt Request Control register)\r
169 **********************************************************************/\r
170 /** I2S control I2S receive interrupt */\r
171 #define I2S_IRQ_RX_ENABLE               ((uint32_t)(1))\r
172 /** I2S control I2S transmit interrupt */\r
173 #define I2S_IRQ_TX_ENABLE               ((uint32_t)(1<<1))\r
174 /** I2S set the FIFO level on which to create an irq request */\r
175 #define I2S_IRQ_RX_DEPTH(n)             ((uint32_t)((n&0x1F)<<8))\r
176 /** I2S set the FIFO level on which to create an irq request */\r
177 #define I2S_IRQ_TX_DEPTH(n)             ((uint32_t)((n&0x1F)<<16))\r
178 \r
179 /********************************************************************************//**\r
180  * Macro defines for TXRATE/RXRATE register (Transmit/Receive Clock Rate register)\r
181 *********************************************************************************/\r
182 /** I2S Transmit MCLK rate denominator */\r
183 #define I2S_TXRATE_Y_DIVIDER(n) ((uint32_t)(n&0xFF))\r
184 /** I2S Transmit MCLK rate denominator */\r
185 #define I2S_TXRATE_X_DIVIDER(n) ((uint32_t)((n&0xFF)<<8))\r
186 /** I2S Receive MCLK rate denominator */\r
187 #define I2S_RXRATE_Y_DIVIDER(n) ((uint32_t)(n&0xFF))\r
188 /** I2S Receive MCLK rate denominator */\r
189 #define I2S_RXRATE_X_DIVIDER(n) ((uint32_t)((n&0xFF)<<8))\r
190 \r
191 /*************************************************************************************//**\r
192  * Macro defines for TXBITRATE & RXBITRATE register (Transmit/Receive Bit Rate register)\r
193 **************************************************************************************/\r
194 #define I2S_TXBITRATE(n)        ((uint32_t)(n&0x3F))\r
195 #define I2S_RXBITRATE(n)        ((uint32_t)(n&0x3F))\r
196 \r
197 /**********************************************************************************//**\r
198  * Macro defines for TXMODE/RXMODE register (Transmit/Receive Mode Control register)\r
199 ************************************************************************************/\r
200 /** I2S Transmit select clock source (2 bits)*/\r
201 #define I2S_TXMODE_CLKSEL(n)    ((uint32_t)(n&0x03))\r
202 /** I2S Transmit control 4-pin mode */\r
203 #define I2S_TXMODE_4PIN_ENABLE  ((uint32_t)(1<<2))\r
204 /** I2S Transmit control the TX_MCLK output */\r
205 #define I2S_TXMODE_MCENA                ((uint32_t)(1<<3))\r
206 /** I2S Receive select clock source */\r
207 #define I2S_RXMODE_CLKSEL(n)    ((uint32_t)(n&0x03))\r
208 /** I2S Receive control 4-pin mode */\r
209 #define I2S_RXMODE_4PIN_ENABLE  ((uint32_t)(1<<2))\r
210 /** I2S Receive control the TX_MCLK output */\r
211 #define I2S_RXMODE_MCENA                ((uint32_t)(1<<3))\r
212 \r
213 \r
214 /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */\r
215 /** Macro to determine if it is valid I2S peripheral */\r
216 #define PARAM_I2Sx(n)   ((((uint32_t *)n)==((uint32_t *)LPC_I2S0)) || (((uint32_t *)n)==((uint32_t *)LPC_I2S1)))\r
217 /** Macro to check Data to send valid */\r
218 #define PRAM_I2S_FREQ(freq)             ((freq>=8000)&&(freq <= 96000))\r
219 /* Macro check I2S word width type */\r
220 #define PARAM_I2S_WORDWIDTH(n)  ((n==I2S_WORDWIDTH_8)||(n==I2S_WORDWIDTH_16)\\r
221 ||(n==I2S_WORDWIDTH_32))\r
222 /* Macro check I2S channel type */\r
223 #define PARAM_I2S_CHANNEL(n)    ((n==I2S_STEREO)||(n==I2S_MONO))\r
224 /* Macro check I2S master/slave mode */\r
225 #define PARAM_I2S_WS_SEL(n)             ((n==I2S_MASTER_MODE)||(n==I2S_SLAVE_MODE))\r
226 /* Macro check I2S stop mode */\r
227 #define PARAM_I2S_STOP(n)       ((n==I2S_STOP_ENABLE)||(n==I2S_STOP_DISABLE))\r
228 /* Macro check I2S reset mode */\r
229 #define PARAM_I2S_RESET(n)      ((n==I2S_RESET_ENABLE)||(n==I2S_RESET_DISABLE))\r
230 /* Macro check I2S reset mode */\r
231 #define PARAM_I2S_MUTE(n)       ((n==I2S_MUTE_ENABLE)||(n==I2S_MUTE_DISABLE))\r
232 /* Macro check I2S transmit/receive mode */\r
233 #define PARAM_I2S_TRX(n)                ((n==I2S_TX_MODE)||(n==I2S_RX_MODE))\r
234 /* Macro check I2S clock select mode */\r
235 #define PARAM_I2S_CLKSEL(n)             ((n==I2S_CLKSEL_FRDCLK)||(n==I2S_CLKSEL_MCLK))\r
236 /* Macro check I2S 4-pin mode */\r
237 #define PARAM_I2S_4PIN(n)       ((n==I2S_4PIN_ENABLE)||(n==I2S_4PIN_DISABLE))\r
238 /* Macro check I2S MCLK mode */\r
239 #define PARAM_I2S_MCLK(n)       ((n==I2S_MCLK_ENABLE)||(n==I2S_MCLK_DISABLE))\r
240 /* Macro check I2S DMA mode */\r
241 #define PARAM_I2S_DMA(n)                ((n==I2S_DMA_1)||(n==I2S_DMA_2))\r
242 /* Macro check I2S DMA depth value */\r
243 #define PARAM_I2S_DMA_DEPTH(n)  ((n<=31))\r
244 /* Macro check I2S irq level value */\r
245 #define PARAM_I2S_IRQ_LEVEL(n)  ((n<=31))\r
246 /* Macro check I2S half-period value */\r
247 #define PARAM_I2S_HALFPERIOD(n) ((n>0)&&(n<512))\r
248 /* Macro check I2S bit-rate value */\r
249 #define PARAM_I2S_BITRATE(n)    ((n<=63))\r
250 /**\r
251  * @}\r
252  */\r
253 \r
254 \r
255 \r
256 /* Public Types --------------------------------------------------------------- */\r
257 /** @defgroup I2S_Public_Types I2S Public Types\r
258  * @{\r
259  */\r
260 \r
261 /**\r
262  * @brief I2S configuration structure definition\r
263  */\r
264 typedef struct {\r
265         uint8_t wordwidth;              /** the number of bytes in data as follow:\r
266                                                                 -I2S_WORDWIDTH_8: 8 bit data\r
267                                                                 -I2S_WORDWIDTH_16: 16 bit data\r
268                                                                 -I2S_WORDWIDTH_32: 32 bit data */\r
269         uint8_t mono;                   /** Set mono/stereo mode, should be:\r
270                                                                 - I2S_STEREO: stereo mode\r
271                                                                 - I2S_MONO: mono mode */\r
272         uint8_t stop;                   /** Disables accesses on FIFOs, should be:\r
273                                                                 - I2S_STOP_ENABLE: enable stop mode\r
274                                                                 - I2S_STOP_DISABLE: disable stop mode */\r
275         uint8_t reset;                  /** Asynchronously reset tje transmit channel and FIFO, should be:\r
276                                                                 - I2S_RESET_ENABLE: enable reset mode\r
277                                                                 - I2S_RESET_DISABLE: disable reset mode */\r
278         uint8_t ws_sel;                 /** Set Master/Slave mode, should be:\r
279                                                                 - I2S_MASTER_MODE: I2S master mode\r
280                                                                 - I2S_SLAVE_MODE: I2S slave mode */\r
281         uint8_t mute;                   /** MUTE mode: when true, the transmit channel sends only zeroes, shoule be:\r
282                                                                 - I2S_MUTE_ENABLE: enable mute mode\r
283                                                                 - I2S_MUTE_DISABLE: disable mute mode */\r
284         uint8_t Reserved0[2];\r
285 } I2S_CFG_Type;\r
286 \r
287 /**\r
288  * @brief I2S DMA configuration structure definition\r
289  */\r
290 typedef struct {\r
291         uint8_t DMAIndex;               /** Select DMA1 or DMA2, should be:\r
292                                                                 - I2S_DMA_1: DMA1\r
293                                                                 - I2S_DMA_2: DMA2 */\r
294         uint8_t depth;                  /** FIFO level that triggers a DMA request */\r
295         uint8_t Reserved0[2];\r
296 }I2S_DMAConf_Type;\r
297 \r
298 /**\r
299  * @brief I2S mode configuration structure definition\r
300  */\r
301 typedef struct{\r
302         uint8_t clksel;                 /** Clock source selection, should be:\r
303                                                                 - I2S_CLKSEL_FRDCLK: Select the fractional rate divider clock output\r
304                                                                 - I2S_CLKSEL_MCLK: Select the MCLK signal as the clock source */\r
305         uint8_t fpin;                   /** Select four pin mode, should be:\r
306                                                                 - I2S_4PIN_ENABLE: 4-pin enable\r
307                                                                 - I2S_4PIN_DISABLE: 4-pin disable */\r
308         uint8_t mcena;                  /** Select MCLK mode, should be:\r
309                                                                 - I2S_MCLK_ENABLE: MCLK enable for output\r
310                                                                 - I2S_MCLK_DISABLE: MCLK disable for output */\r
311         uint8_t Reserved;\r
312 }I2S_MODEConf_Type;\r
313 \r
314 \r
315 /**\r
316  * @}\r
317  */\r
318 \r
319 \r
320 /* Public Functions ----------------------------------------------------------- */\r
321 /** @defgroup I2S_Public_Functions I2S Public Functions\r
322  * @{\r
323  */\r
324 /* I2S Init/DeInit functions ---------*/\r
325 void I2S_Init(LPC_I2Sn_Type *I2Sx);\r
326 void I2S_DeInit(LPC_I2Sn_Type *I2Sx);\r
327 \r
328 /* I2S configuration functions --------*/\r
329 void I2S_Config(LPC_I2Sn_Type *I2Sx, uint8_t TRMode, I2S_CFG_Type* ConfigStruct);\r
330 Status I2S_FreqConfig(LPC_I2Sn_Type *I2Sx, uint32_t Freq, uint8_t TRMode);\r
331 void I2S_SetBitRate(LPC_I2Sn_Type *I2Sx, uint8_t bitrate, uint8_t TRMode);\r
332 void I2S_ModeConfig(LPC_I2Sn_Type *I2Sx, I2S_MODEConf_Type* ModeConfig, uint8_t TRMode);\r
333 uint8_t I2S_GetLevel(LPC_I2Sn_Type *I2Sx, uint8_t TRMode);\r
334 \r
335 /* I2S operate functions -------------*/\r
336 void I2S_Send(LPC_I2Sn_Type *I2Sx, uint32_t BufferData);\r
337 uint32_t I2S_Receive(LPC_I2Sn_Type* I2Sx);\r
338 void I2S_Start(LPC_I2Sn_Type *I2Sx);\r
339 void I2S_Pause(LPC_I2Sn_Type *I2Sx, uint8_t TRMode);\r
340 void I2S_Mute(LPC_I2Sn_Type *I2Sx, uint8_t TRMode);\r
341 void I2S_Stop(LPC_I2Sn_Type *I2Sx, uint8_t TRMode);\r
342 \r
343 /* I2S DMA functions ----------------*/\r
344 void I2S_DMAConfig(LPC_I2Sn_Type *I2Sx, I2S_DMAConf_Type* DMAConfig, uint8_t TRMode);\r
345 void I2S_DMACmd(LPC_I2Sn_Type *I2Sx, uint8_t DMAIndex,uint8_t TRMode, FunctionalState NewState);\r
346 \r
347 /* I2S IRQ functions ----------------*/\r
348 void I2S_IRQCmd(LPC_I2Sn_Type *I2Sx,uint8_t TRMode, FunctionalState NewState);\r
349 void I2S_IRQConfig(LPC_I2Sn_Type *I2Sx, uint8_t TRMode, uint8_t level);\r
350 FunctionalState I2S_GetIRQStatus(LPC_I2Sn_Type *I2Sx,uint8_t TRMode);\r
351 uint8_t I2S_GetIRQDepth(LPC_I2Sn_Type *I2Sx,uint8_t TRMode);\r
352 \r
353 /**\r
354  * @}\r
355  */\r
356 \r
357 \r
358 #ifdef __cplusplus\r
359 }\r
360 #endif\r
361 \r
362 \r
363 #endif /* LPC18XX_I2S_H_ */\r
364 \r
365 /**\r
366  * @}\r
367  */\r
368 \r
369 /* --------------------------------- End Of File ------------------------------ */\r