]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_sai.h
Merge commit '4d116a04e94cf0d19317d5b44e4fa9f34a3e5594'
[max/tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F4 / stm32f4xx_hal_sai.h
1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_sai.h
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    19-June-2014
7   * @brief   Header file of SAI HAL module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12   *
13   * Redistribution and use in source and binary forms, with or without modification,
14   * are permitted provided that the following conditions are met:
15   *   1. Redistributions of source code must retain the above copyright notice,
16   *      this list of conditions and the following disclaimer.
17   *   2. Redistributions in binary form must reproduce the above copyright notice,
18   *      this list of conditions and the following disclaimer in the documentation
19   *      and/or other materials provided with the distribution.
20   *   3. Neither the name of STMicroelectronics nor the names of its contributors
21   *      may be used to endorse or promote products derived from this software
22   *      without specific prior written permission.
23   *
24   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34   *
35   ******************************************************************************
36   */ 
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_HAL_SAI_H
40 #define __STM32F4xx_HAL_SAI_H
41
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45
46 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
47
48 /* Includes ------------------------------------------------------------------*/
49 #include "stm32f4xx_hal_def.h"  
50
51 /** @addtogroup STM32F4xx_HAL_Driver
52   * @{
53   */
54
55 /** @addtogroup SAI
56   * @{
57   */ 
58
59 /* Exported types ------------------------------------------------------------*/ 
60
61 /** 
62   * @brief  SAI Init Structure definition  
63   */
64 typedef struct
65 {                                    
66   uint32_t Protocol;        /*!< Specifies the SAI Block protocol.
67                                  This parameter can be a value of @ref SAI_Block_Protocol             */
68                                       
69   uint32_t AudioMode;       /*!< Specifies the SAI Block audio Mode. 
70                                  This parameter can be a value of @ref SAI_Block_Mode                 */
71
72   uint32_t DataSize;        /*!< Specifies the SAI Block data size.
73                                  This parameter can be a value of @ref SAI_Block_Data_Size            */
74
75   uint32_t FirstBit;        /*!< Specifies whether data transfers start from MSB or LSB bit.
76                                  This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission */
77
78   uint32_t ClockStrobing;   /*!< Specifies the SAI Block clock strobing edge sensitivity.
79                                  This parameter can be a value of @ref SAI_Block_Clock_Strobing       */
80
81   uint32_t Synchro;         /*!< Specifies SAI Block synchronization
82                                  This parameter can be a value of @ref SAI_Block_Synchronization      */
83  
84   uint32_t OutputDrive;     /*!< Specifies when SAI Block outputs are driven.
85                                  This parameter can be a value of @ref SAI_Block_Output_Drive
86                                  @note this value has to be set before enabling the audio block  
87                                        but after the audio block configuration.                       */
88
89   uint32_t NoDivider;       /*!< Specifies whether master clock will be divided or not.
90                                  This parameter can be a value of @ref SAI_Block_NoDivider
91                                  @note: If bit NODIV in the SAI_xCR1 register is cleared, the frame length 
92                                         should be aligned to a number equal to a power of 2, from 8 to 256.
93                                         If bit NODIV in the SAI_xCR1 register is set, the frame length can 
94                                         take any of the values without constraint since the input clock of 
95                                         the audio block should be equal to the bit clock.
96                                         There is no MCLK_x clock which can be output.                 */
97   
98   uint32_t FIFOThreshold;   /*!< Specifies SAI Block FIFO threshold.
99                                  This parameter can be a value of @ref SAI_Block_Fifo_Threshold       */
100
101   uint32_t ClockSource;     /*!< Specifies the SAI Block x Clock source.    
102                                  This parameter can be a value of @ref SAI_Clock_Source 
103                                  @note: If ClockSource is equal to SAI_CLKSource_Ext, the PLLI2S 
104                                        and PLLSAI divisions factors will be ignored.                  */ 
105                                      
106   uint32_t AudioFrequency;  /*!< Specifies the audio frequency sampling.     
107                                  This parameter can be a value of @ref SAI_Audio_Frequency            */
108                                                                                                                               
109 }SAI_InitTypeDef;
110
111 /** 
112   * @brief  SAI Block Frame Init structure definition  
113   */
114  
115 typedef struct
116 {
117
118   uint32_t FrameLength;         /*!< Specifies the Frame length, the number of SCK clocks for each audio frame.
119                                      This parameter must be a number between Min_Data = 8 and Max_Data = 256.
120                                      @note: If master clock MCLK_x pin is declared as an output, the frame length
121                                             should be aligned to a number equal to power of 2 in order to keep 
122                                             in an audio frame, an integer number of MCLK pulses by bit Clock. */                                               
123                                                                             
124   uint32_t ActiveFrameLength;  /*!< Specifies the Frame synchronization active level length.
125                                     This Parameter specifies the length in number of bit clock (SCK + 1)  
126                                     of the active level of FS signal in audio frame.
127                                     This parameter must be a number between Min_Data = 1 and Max_Data = 128   */
128                                          
129   uint32_t FSDefinition;       /*!< Specifies the Frame synchronization definition.
130                                     This parameter can be a value of @ref SAI_Block_FS_Definition             */
131                                          
132   uint32_t FSPolarity;         /*!< Specifies the Frame synchronization Polarity.
133                                     This parameter can be a value of @ref SAI_Block_FS_Polarity               */
134
135   uint32_t FSOffset;           /*!< Specifies the Frame synchronization Offset.
136                                     This parameter can be a value of @ref SAI_Block_FS_Offset                 */
137
138 }SAI_FrameInitTypeDef;
139
140 /**
141   * @brief   SAI Block Slot Init Structure definition
142   */    
143
144 typedef struct
145 {
146   uint32_t FirstBitOffset;  /*!< Specifies the position of first data transfer bit in the slot.
147                                  This parameter must be a number between Min_Data = 0 and Max_Data = 24 */
148
149   uint32_t SlotSize;        /*!< Specifies the Slot Size.
150                                  This parameter can be a value of @ref SAI_Block_Slot_Size              */
151
152   uint32_t SlotNumber;      /*!< Specifies the number of slot in the audio frame.
153                                  This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
154
155   uint32_t SlotActive;      /*!< Specifies the slots in audio frame that will be activated.
156                                  This parameter can be a value of @ref SAI_Block_Slot_Active            */
157 }SAI_SlotInitTypeDef;
158
159 /** 
160   * @brief  HAL State structures definition  
161   */ 
162 typedef enum
163 {
164   HAL_SAI_STATE_RESET      = 0x00,  /*!< SAI not yet initialized or disabled                */
165   HAL_SAI_STATE_READY      = 0x01,  /*!< SAI initialized and ready for use                  */
166   HAL_SAI_STATE_BUSY       = 0x02,  /*!< SAI internal process is ongoing                    */
167   HAL_SAI_STATE_BUSY_TX    = 0x12,  /*!< Data transmission process is ongoing               */ 
168   HAL_SAI_STATE_BUSY_RX    = 0x22,  /*!< Data reception process is ongoing                  */  
169   HAL_SAI_STATE_TIMEOUT    = 0x03,  /*!< SAI timeout state                                  */
170   HAL_SAI_STATE_ERROR      = 0x04   /*!< SAI error state                                    */
171                                                                         
172 }HAL_SAI_StateTypeDef;
173
174 /** 
175   * @brief  SAI handle Structure definition  
176   */
177 typedef struct
178 {
179   SAI_Block_TypeDef         *Instance;  /*!< SAI Blockx registers base address        */
180
181   SAI_InitTypeDef           Init;       /*!< SAI communication parameters             */
182
183   SAI_FrameInitTypeDef      FrameInit;  /*!< SAI Frame configuration parameters       */
184
185   SAI_SlotInitTypeDef       SlotInit;   /*!< SAI Slot configuration parameters        */
186
187   uint16_t                  *pTxBuffPtr; /*!< Pointer to SAI Tx transfer Buffer       */
188
189   uint16_t                  TxXferSize;  /*!< SAI Tx transfer size                    */
190
191   uint16_t                  TxXferCount; /*!< SAI Tx transfer counter                 */
192
193   uint16_t                  *pRxBuffPtr; /*!< Pointer to SAI Rx transfer buffer       */
194
195   uint16_t                  RxXferSize;  /*!< SAI Rx transfer size                    */
196
197   uint16_t                  RxXferCount; /*!< SAI Rx transfer counter                 */
198
199   DMA_HandleTypeDef         *hdmatx;     /*!< SAI Tx DMA handle parameters            */
200
201   DMA_HandleTypeDef         *hdmarx;     /*!< SAI Rx DMA handle parameters            */
202
203   HAL_LockTypeDef           Lock;        /*!< SAI locking object                      */
204
205   __IO HAL_SAI_StateTypeDef State;       /*!< SAI communication state                 */
206
207   __IO uint32_t             ErrorCode;   /*!< SAI Error code                          */
208 }SAI_HandleTypeDef;
209
210 /* Exported constants --------------------------------------------------------*/
211
212 /** @defgroup SAI_Exported_Constants
213   * @{
214   */
215 /** @defgroup SAI Error Code 
216   * @{
217   */ 
218 #define HAL_SAI_ERROR_NONE      ((uint32_t)0x00000000)     /*!< No error             */
219 #define HAL_SAI_ERROR_OVR       ((uint32_t)0x00000001)     /*!< Overrun Error        */
220 #define HAL_SAI_ERROR_UDR       ((uint32_t)0x00000002)     /*!< Underrun error       */
221 #define HAL_SAI_ERROR_TIMEOUT   ((uint32_t)0x00000020)     /*!< Timeout error        */
222 /**
223   * @}
224   */
225
226 /** @defgroup SAI_Clock_Source
227   * @{
228   */
229 #define SAI_CLKSOURCE_PLLSAI             ((uint32_t)RCC_SAIACLKSOURCE_PLLSAI)
230 #define SAI_CLKSOURCE_PLLI2S             ((uint32_t)RCC_SAIACLKSOURCE_PLLI2S)
231 #define SAI_CLKSOURCE_EXT                ((uint32_t)RCC_SAIACLKSOURCE_EXT)
232
233 #define IS_SAI_CLK_SOURCE(SOURCE) (((SOURCE) == SAI_CLKSOURCE_PLLSAI) ||\
234                                    ((SOURCE) == SAI_CLKSOURCE_PLLI2S) ||\
235                                    ((SOURCE) == SAI_CLKSOURCE_EXT))
236 /**
237   * @}
238   */
239
240 /** @defgroup SAI_Audio_Frequency
241   * @{
242   */
243 #define SAI_AUDIO_FREQUENCY_192K          ((uint32_t)192000)
244 #define SAI_AUDIO_FREQUENCY_96K           ((uint32_t)96000)
245 #define SAI_AUDIO_FREQUENCY_48K           ((uint32_t)48000)
246 #define SAI_AUDIO_FREQUENCY_44K           ((uint32_t)44100)
247 #define SAI_AUDIO_FREQUENCY_32K           ((uint32_t)32000)
248 #define SAI_AUDIO_FREQUENCY_22K           ((uint32_t)22050)
249 #define SAI_AUDIO_FREQUENCY_16K           ((uint32_t)16000)
250 #define SAI_AUDIO_FREQUENCY_11K           ((uint32_t)11025)
251 #define SAI_AUDIO_FREQUENCY_8K            ((uint32_t)8000)    
252
253 #define IS_SAI_AUDIO_FREQUENCY(AUDIO) (((AUDIO) == SAI_AUDIO_FREQUENCY_192K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_96K) || \
254                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_48K)  || ((AUDIO) == SAI_AUDIO_FREQUENCY_44K) || \
255                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_32K)  || ((AUDIO) == SAI_AUDIO_FREQUENCY_22K) || \
256                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_16K)  || ((AUDIO) == SAI_AUDIO_FREQUENCY_11K) || \
257                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_8K))
258 /**
259   * @}
260   */
261
262 /** @defgroup SAI_Block_Mode 
263   * @{
264   */
265 #define SAI_MODEMASTER_TX         ((uint32_t)0x00000000)
266 #define SAI_MODEMASTER_RX         ((uint32_t)0x00000001)
267 #define SAI_MODESLAVE_TX          ((uint32_t)0x00000002)
268 #define SAI_MODESLAVE_RX          ((uint32_t)0x00000003)
269 #define IS_SAI_BLOCK_MODE(MODE)    (((MODE) == SAI_MODEMASTER_TX) || \
270                                     ((MODE) == SAI_MODEMASTER_RX) || \
271                                     ((MODE) == SAI_MODESLAVE_TX)  || \
272                                     ((MODE) == SAI_MODESLAVE_RX))
273 /**
274   * @}
275   */
276
277 /** @defgroup SAI_Block_Protocol 
278   * @{
279   */
280
281 #define SAI_FREE_PROTOCOL                 ((uint32_t)0x00000000)
282 #define SAI_AC97_PROTOCOL                 ((uint32_t)SAI_xCR1_PRTCFG_1)
283
284 #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_FREE_PROTOCOL)  || \
285                                          ((PROTOCOL) == SAI_AC97_PROTOCOL))
286 /**
287   * @}
288   */
289
290 /** @defgroup SAI_Block_Data_Size 
291   * @{
292   */
293 #define SAI_DATASIZE_8                   ((uint32_t)0x00000040)
294 #define SAI_DATASIZE_10                  ((uint32_t)0x00000060)
295 #define SAI_DATASIZE_16                  ((uint32_t)0x00000080)
296 #define SAI_DATASIZE_20                  ((uint32_t)0x000000A0)
297 #define SAI_DATASIZE_24                  ((uint32_t)0x000000C0)
298 #define SAI_DATASIZE_32                  ((uint32_t)0x000000E0)
299
300 #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DATASIZE_8)  || \
301                                          ((DATASIZE) == SAI_DATASIZE_10) || \
302                                          ((DATASIZE) == SAI_DATASIZE_16) || \
303                                          ((DATASIZE) == SAI_DATASIZE_20) || \
304                                          ((DATASIZE) == SAI_DATASIZE_24) || \
305                                          ((DATASIZE) == SAI_DATASIZE_32))
306 /**
307   * @}
308   */ 
309
310 /** @defgroup SAI_Block_MSB_LSB_transmission 
311   * @{
312   */
313
314 #define SAI_FIRSTBIT_MSB                  ((uint32_t)0x00000000)
315 #define SAI_FIRSTBIT_LSB                  ((uint32_t)SAI_xCR1_LSBFIRST)
316
317 #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FIRSTBIT_MSB) || \
318                                      ((BIT) == SAI_FIRSTBIT_LSB))
319 /**
320   * @}
321   */
322
323 /** @defgroup SAI_Block_Clock_Strobing 
324   * @{
325   */
326 #define SAI_CLOCKSTROBING_FALLINGEDGE     ((uint32_t)0x00000000)
327 #define SAI_CLOCKSTROBING_RISINGEDGE      ((uint32_t)SAI_xCR1_CKSTR)
328
329 #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_CLOCKSTROBING_FALLINGEDGE) || \
330                                             ((CLOCK) == SAI_CLOCKSTROBING_RISINGEDGE))
331 /**
332   * @}
333   */
334
335 /** @defgroup SAI_Block_Synchronization 
336   * @{
337   */
338 #define SAI_ASYNCHRONOUS                  ((uint32_t)0x00000000)
339 #define SAI_SYNCHRONOUS                   ((uint32_t)SAI_xCR1_SYNCEN_0)
340
341 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS) || \
342                                        ((SYNCHRO) == SAI_SYNCHRONOUS))
343 /**
344   * @}
345   */ 
346
347 /** @defgroup SAI_Block_Output_Drive 
348   * @{
349   */
350 #define SAI_OUTPUTDRIVE_DISABLED          ((uint32_t)0x00000000)
351 #define SAI_OUTPUTDRIVE_ENABLED           ((uint32_t)SAI_xCR1_OUTDRIV)
352
353 #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OUTPUTDRIVE_DISABLED) || \
354                                           ((DRIVE) == SAI_OUTPUTDRIVE_ENABLED))
355 /**
356   * @}
357   */ 
358
359 /** @defgroup SAI_Block_NoDivider 
360   * @{
361   */
362 #define SAI_MASTERDIVIDER_ENABLED         ((uint32_t)0x00000000)
363 #define SAI_MASTERDIVIDER_DISABLED        ((uint32_t)SAI_xCR1_NODIV)
364
365 #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MASTERDIVIDER_ENABLED) || \
366                                            ((NODIVIDER) == SAI_MASTERDIVIDER_DISABLED))
367 /**
368   * @}
369   */
370   
371 /** @defgroup SAI_Block_Master_Divider 
372   * @{
373   */
374 #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 15)
375 /**
376   * @}
377   */
378   
379 /** @defgroup SAI_Block_Frame_Length 
380   * @{
381   */
382 #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8 <= (LENGTH)) && ((LENGTH) <= 256))
383 /**
384   * @}
385   */
386     
387 /** @defgroup SAI_Block_Active_FrameLength 
388   * @{
389   */
390 #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1 <= (LENGTH)) && ((LENGTH) <= 128))
391 /**
392   * @}
393   */
394
395 /** @defgroup SAI_Block_FS_Definition 
396   * @{
397   */
398 #define SAI_FS_STARTFRAME                 ((uint32_t)0x00000000)
399 #define SAI_FS_CHANNEL_IDENTIFICATION     ((uint32_t)SAI_xFRCR_FSDEF)
400
401 #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_STARTFRAME) || \
402                                                 ((DEFINITION) == SAI_FS_CHANNEL_IDENTIFICATION))
403 /**
404   * @}
405   */
406
407 /** @defgroup SAI_Block_FS_Polarity 
408   * @{
409   */
410 #define SAI_FS_ACTIVE_LOW                  ((uint32_t)0x00000000)
411 #define SAI_FS_ACTIVE_HIGH                 ((uint32_t)SAI_xFRCR_FSPO)
412
413 #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ACTIVE_LOW) || \
414                                             ((POLARITY) == SAI_FS_ACTIVE_HIGH))
415 /**
416   * @}
417   */
418             
419 /** @defgroup SAI_Block_FS_Offset 
420   * @{
421   */
422 #define SAI_FS_FIRSTBIT                   ((uint32_t)0x00000000)
423 #define SAI_FS_BEFOREFIRSTBIT             ((uint32_t)SAI_xFRCR_FSOFF)
424
425 #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FIRSTBIT) || \
426                                         ((OFFSET) == SAI_FS_BEFOREFIRSTBIT))
427 /**
428   * @}
429   */
430   
431 /** @defgroup SAI_Block_Slot_FirstBit_Offset
432   * @{
433   */
434 #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24)
435 /**
436   * @}
437   */
438
439   /** @defgroup SAI_Block_Slot_Size
440   * @{
441   */
442 #define SAI_SLOTSIZE_DATASIZE             ((uint32_t)0x00000000)  
443 #define SAI_SLOTSIZE_16B                  ((uint32_t)SAI_xSLOTR_SLOTSZ_0)
444 #define SAI_SLOTSIZE_32B                  ((uint32_t)SAI_xSLOTR_SLOTSZ_1)
445
446 #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SLOTSIZE_DATASIZE) || \
447                                       ((SIZE) == SAI_SLOTSIZE_16B)      || \
448                                       ((SIZE) == SAI_SLOTSIZE_32B))
449 /**
450   * @}
451   */
452
453 /** @defgroup SAI_Block_Slot_Number
454   * @{
455   */
456 #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1 <= (NUMBER)) && ((NUMBER) <= 16))
457 /**
458   * @}
459   */
460   
461 /** @defgroup SAI_Block_Slot_Active
462   * @{
463   */
464 #define SAI_SLOT_NOTACTIVE           ((uint32_t)0x00000000)
465 #define SAI_SLOTACTIVE_0             ((uint32_t)0x00010000)
466 #define SAI_SLOTACTIVE_1             ((uint32_t)0x00020000)
467 #define SAI_SLOTACTIVE_2             ((uint32_t)0x00040000)
468 #define SAI_SLOTACTIVE_3             ((uint32_t)0x00080000)
469 #define SAI_SLOTACTIVE_4             ((uint32_t)0x00100000)
470 #define SAI_SLOTACTIVE_5             ((uint32_t)0x00200000)
471 #define SAI_SLOTACTIVE_6             ((uint32_t)0x00400000)
472 #define SAI_SLOTACTIVE_7             ((uint32_t)0x00800000)
473 #define SAI_SLOTACTIVE_8             ((uint32_t)0x01000000)
474 #define SAI_SLOTACTIVE_9             ((uint32_t)0x02000000)
475 #define SAI_SLOTACTIVE_10            ((uint32_t)0x04000000)
476 #define SAI_SLOTACTIVE_11            ((uint32_t)0x08000000)
477 #define SAI_SLOTACTIVE_12            ((uint32_t)0x10000000)
478 #define SAI_SLOTACTIVE_13            ((uint32_t)0x20000000)
479 #define SAI_SLOTACTIVE_14            ((uint32_t)0x40000000)
480 #define SAI_SLOTACTIVE_15            ((uint32_t)0x80000000)
481 #define SAI_SLOTACTIVE_ALL           ((uint32_t)0xFFFF0000)
482
483 #define IS_SAI_SLOT_ACTIVE(ACTIVE) ((ACTIVE) != 0)
484
485 /**
486   * @}
487   */
488
489 /** @defgroup SAI_Mono_Stereo_Mode
490   * @{
491   */
492 #define SAI_MONOMODE                      ((uint32_t)SAI_xCR1_MONO)
493 #define SAI_STREOMODE                     ((uint32_t)0x00000000)
494
495 #define IS_SAI_BLOCK_MONO_STREO_MODE(MODE) (((MODE) == SAI_MONOMODE) ||\
496                                             ((MODE) == SAI_STREOMODE))
497 /**
498   * @}
499   */
500
501 /** @defgroup SAI_TRIState_Management
502   * @{
503   */
504 #define SAI_OUTPUT_NOTRELEASED              ((uint32_t)0x00000000)
505 #define SAI_OUTPUT_RELEASED                 ((uint32_t)SAI_xCR2_TRIS)
506
507 #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_OUTPUT_NOTRELEASED) ||\
508                                                  ((STATE) == SAI_OUTPUT_RELEASED))
509 /**
510   * @}
511   */
512
513 /** @defgroup SAI_Block_Fifo_Threshold 
514   * @{
515   */
516 #define SAI_FIFOTHRESHOLD_EMPTY  ((uint32_t)0x00000000)
517 #define SAI_FIFOTHRESHOLD_1QF    ((uint32_t)0x00000001)
518 #define SAI_FIFOTHRESHOLD_HF     ((uint32_t)0x00000002) 
519 #define SAI_FIFOTHRESHOLD_3QF    ((uint32_t)0x00000003)
520 #define SAI_FIFOTHRESHOLD_FULL   ((uint32_t)0x00000004)
521
522 #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_FIFOTHRESHOLD_EMPTY)   || \
523                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_1QF)     || \
524                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_HF)      || \
525                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_3QF)     || \
526                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_FULL))
527 /**
528   * @}
529   */
530   
531 /** @defgroup SAI_Block_Companding_Mode
532   * @{
533   */
534 #define SAI_NOCOMPANDING                  ((uint32_t)0x00000000)
535 #define SAI_ULAW_1CPL_COMPANDING          ((uint32_t)0x00008000)
536 #define SAI_ALAW_1CPL_COMPANDING          ((uint32_t)0x0000C000)
537 #define SAI_ULAW_2CPL_COMPANDING          ((uint32_t)0x0000A000)
538 #define SAI_ALAW_2CPL_COMPANDING          ((uint32_t)0x0000E000)
539
540 #define IS_SAI_BLOCK_COMPANDING_MODE(MODE)    (((MODE) == SAI_NOCOMPANDING)         || \
541                                                ((MODE) == SAI_ULAW_1CPL_COMPANDING) || \
542                                                ((MODE) == SAI_ALAW_1CPL_COMPANDING) || \
543                                                ((MODE) == SAI_ULAW_2CPL_COMPANDING) || \
544                                                ((MODE) == SAI_ALAW_2CPL_COMPANDING))
545 /**
546   * @}
547   */
548
549 /** @defgroup SAI_Block_Mute_Value
550   * @{
551   */
552 #define SAI_ZERO_VALUE                     ((uint32_t)0x00000000)
553 #define SAI_LAST_SENT_VALUE                 ((uint32_t)SAI_xCR2_MUTEVAL)
554
555 #define IS_SAI_BLOCK_MUTE_VALUE(VALUE)    (((VALUE) == SAI_ZERO_VALUE)     || \
556                                            ((VALUE) == SAI_LAST_SENT_VALUE))
557 /**
558   * @}
559   */
560
561 /** @defgroup SAI_Block_Mute_Frame_Counter
562   * @{
563   */ 
564 #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63)
565 /**
566   * @}
567   */
568
569 /** @defgroup SAI_Block_Interrupts_Definition 
570   * @{
571   */
572 #define SAI_IT_OVRUDR                     ((uint32_t)SAI_xIMR_OVRUDRIE)
573 #define SAI_IT_MUTEDET                    ((uint32_t)SAI_xIMR_MUTEDETIE)
574 #define SAI_IT_WCKCFG                     ((uint32_t)SAI_xIMR_WCKCFGIE)
575 #define SAI_IT_FREQ                       ((uint32_t)SAI_xIMR_FREQIE)
576 #define SAI_IT_CNRDY                      ((uint32_t)SAI_xIMR_CNRDYIE)
577 #define SAI_IT_AFSDET                     ((uint32_t)SAI_xIMR_AFSDETIE)
578 #define SAI_IT_LFSDET                     ((uint32_t)SAI_xIMR_LFSDETIE)
579
580 #define IS_SAI_BLOCK_CONFIG_IT(IT) (((IT) == SAI_IT_OVRUDR)  || \
581                                     ((IT) == SAI_IT_MUTEDET) || \
582                                     ((IT) == SAI_IT_WCKCFG)  || \
583                                     ((IT) == SAI_IT_FREQ)    || \
584                                     ((IT) == SAI_IT_CNRDY)   || \
585                                     ((IT) == SAI_IT_AFSDET)  || \
586                                     ((IT) == SAI_IT_LFSDET))
587 /**
588   * @}
589   */
590
591 /** @defgroup SAI_Block_Flags_Definition 
592   * @{
593   */
594 #define SAI_FLAG_OVRUDR                   ((uint32_t)SAI_xSR_OVRUDR)
595 #define SAI_FLAG_MUTEDET                  ((uint32_t)SAI_xSR_MUTEDET)
596 #define SAI_FLAG_WCKCFG                   ((uint32_t)SAI_xSR_WCKCFG)
597 #define SAI_FLAG_FREQ                     ((uint32_t)SAI_xSR_FREQ)
598 #define SAI_FLAG_CNRDY                    ((uint32_t)SAI_xSR_CNRDY)
599 #define SAI_FLAG_AFSDET                   ((uint32_t)SAI_xSR_AFSDET)
600 #define SAI_FLAG_LFSDET                   ((uint32_t)SAI_xSR_LFSDET)
601
602 #define IS_SAI_BLOCK_GET_FLAG(FLAG) (((FLAG) == SAI_FLAG_OVRUDR)  || \
603                                     ((FLAG) == SAI_FLAG_MUTEDET)  || \
604                                     ((FLAG) == SAI_FLAG_WCKCFG)   || \
605                                     ((FLAG) == SAI_FLAG_FREQ)     || \
606                                     ((FLAG) == SAI_FLAG_CNRDY)    || \
607                                     ((FLAG) == SAI_FLAG_AFSDET)   || \
608                                     ((FLAG) == SAI_FLAG_LFSDET))
609                                    
610 #define IS_SAI_BLOCK_CLEAR_FLAG(FLAG) (((FLAG) == SAI_FLAG_OVRUDR)  || \
611                                        ((FLAG) == SAI_FLAG_MUTEDET) || \
612                                        ((FLAG) == SAI_FLAG_WCKCFG)  || \
613                                        ((FLAG) == SAI_FLAG_FREQ)    || \
614                                        ((FLAG) == SAI_FLAG_CNRDY)   || \
615                                        ((FLAG) == SAI_FLAG_AFSDET)  || \
616                                        ((FLAG) == SAI_FLAG_LFSDET))
617 /**
618   * @}
619   */
620   
621 /** @defgroup SAI_Block_Fifo_Status_Level 
622   * @{
623   */
624 #define SAI_FIFOStatus_Empty              ((uint32_t)0x00000000)
625 #define SAI_FIFOStatus_Less1QuarterFull   ((uint32_t)0x00010000)
626 #define SAI_FIFOStatus_1QuarterFull       ((uint32_t)0x00020000)
627 #define SAI_FIFOStatus_HalfFull           ((uint32_t)0x00030000) 
628 #define SAI_FIFOStatus_3QuartersFull      ((uint32_t)0x00040000)
629 #define SAI_FIFOStatus_Full               ((uint32_t)0x00050000)
630
631 #define IS_SAI_BLOCK_FIFO_STATUS(STATUS) (((STATUS) == SAI_FIFOStatus_Less1QuarterFull ) || \
632                                           ((STATUS) == SAI_FIFOStatus_HalfFull)          || \
633                                           ((STATUS) == SAI_FIFOStatus_1QuarterFull)      || \
634                                           ((STATUS) == SAI_FIFOStatus_3QuartersFull)     || \
635                                           ((STATUS) == SAI_FIFOStatus_Full)              || \
636                                           ((STATUS) == SAI_FIFOStatus_Empty)) 
637 /**
638   * @}
639   */
640
641   
642 /**
643   * @}
644   */
645   
646 /* Exported macro ------------------------------------------------------------*/
647 /** @brief Reset SAI handle state
648   * @param  __HANDLE__: specifies the SAI Handle.
649   * @retval None
650   */
651 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SAI_STATE_RESET)
652
653 /** @brief  Enable or disable the specified SAI interrupts.
654   * @param  __HANDLE__: specifies the SAI Handle.
655   * @param  __INTERRUPT__: specifies the interrupt source to enable or disable.
656   *         This parameter can be one of the following values:
657   *            @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable                              
658   *            @arg SAI_IT_MUTEDET: Mute detection interrupt enable                               
659   *            @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable                    
660   *            @arg SAI_IT_FREQ: FIFO request interrupt enable                                  
661   *            @arg SAI_IT_CNRDY: Codec not ready interrupt enable                               
662   *            @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable   
663   *            @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enabl
664   * @retval None
665   */
666   
667 #define __HAL_SAI_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->IMR |= (__INTERRUPT__))
668 #define __HAL_SAI_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((__HANDLE__)->Instance->IMR &= (~(__INTERRUPT__)))
669  
670 /** @brief  Check if the specified SAI interrupt source is enabled or disabled.
671   * @param  __HANDLE__: specifies the SAI Handle.
672   *         This parameter can be SAI where x: 1, 2, or 3 to select the SAI peripheral.
673   * @param  __INTERRUPT__: specifies the SAI interrupt source to check.
674   *         This parameter can be one of the following values:
675   *            @arg SAI_IT_TXE: Tx buffer empty interrupt enable.
676   *            @arg SAI_IT_RXNE: Rx buffer not empty interrupt enable.
677   *            @arg SAI_IT_ERR: Error interrupt enable.
678   * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
679   */
680 #define __HAL_SAI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IMR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
681
682 /** @brief  Check whether the specified SAI flag is set or not.
683   * @param  __HANDLE__: specifies the SAI Handle.
684   * @param  __FLAG__: specifies the flag to check.
685   *         This parameter can be one of the following values:
686   *            @arg SAI_FLAG_OVRUDR: Overrun underrun flag.
687   *            @arg SAI_FLAG_MUTEDET: Mute detection flag.
688   *            @arg SAI_FLAG_WCKCFG: Wrong Clock Configuration flag.
689   *            @arg SAI_FLAG_FREQ: FIFO request flag.
690   *            @arg SAI_FLAG_CNRDY: Codec not ready flag.
691   *            @arg SAI_FLAG_AFSDET: Anticipated frame synchronization detection flag.
692   *            @arg SAI_FLAG_LFSDET: Late frame synchronization detection flag.  
693   * @retval The new state of __FLAG__ (TRUE or FALSE).
694   */
695 #define __HAL_SAI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
696
697 /** @brief  Clears the specified SAI pending flag.
698   * @param  __HANDLE__: specifies the SAI Handle.
699   * @param  __FLAG__: specifies the flag to check.
700   *          This parameter can be any combination of the following values:
701   *            @arg SAI_FLAG_OVRUDR: Clear Overrun underrun  
702   *            @arg SAI_FLAG_MUTEDET: Clear Mute detection 
703   *            @arg SAI_FLAG_WCKCFG: Clear Wrong Clock Configuration  
704   *            @arg SAI_FLAG_FREQ: Clear FIFO request   
705   *            @arg SAI_FLAG_CNRDY: Clear Codec not ready
706   *            @arg SAI_FLAG_AFSDET: Clear Anticipated frame synchronization detection
707   *            @arg SAI_FLAG_LFSDET: Clear Late frame synchronization detection
708   *   
709   * @retval None
710   */
711 #define __HAL_SAI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__))                                        
712
713 #define __HAL_SAI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |=  SAI_xCR1_SAIEN)
714 #define __HAL_SAI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &=  ~SAI_xCR1_SAIEN)
715                                                                                
716 /* Exported functions --------------------------------------------------------*/
717
718 /* Initialization/de-initialization functions  **********************************/
719 HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai);
720 HAL_StatusTypeDef HAL_SAI_DeInit (SAI_HandleTypeDef *hsai);
721 void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai);
722 void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai);
723
724 /* I/O operation functions  *****************************************************/
725 /* Blocking mode: Polling */
726 HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size, uint32_t Timeout);
727 HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size, uint32_t Timeout);
728
729 /* Non-Blocking mode: Interrupt */
730 HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size);
731 HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size);
732
733 /* Non-Blocking mode: DMA */
734 HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size);
735 HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size);
736 HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai);
737 HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai);
738 HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai);
739
740 /* SAI IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
741 void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai);
742 void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai);
743 void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai);
744 void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai);
745 void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai);
746 void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai);
747
748 /* Peripheral State functions  **************************************************/
749 HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai);
750 uint32_t HAL_SAI_GetError(SAI_HandleTypeDef *hsai);
751
752 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
753 /**
754   * @}
755   */ 
756
757 /**
758   * @}
759   */
760   
761 #ifdef __cplusplus
762 }
763 #endif
764
765 #endif /* __STM32F4xx_HAL_SAI_H */
766
767 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/