source: asp3_wo_tecs/trunk/arch/arm_m_gcc/stm32f4xx_stm32cube/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_sai.h@ 303

Last change on this file since 303 was 303, checked in by ertl-honda, 7 years ago

nucleo_f401re依存部の追加

File size: 38.0 KB
Line 
1/**
2 ******************************************************************************
3 * @file stm32f4xx_hal_sai.h
4 * @author MCD Application Team
5 * @version V1.4.1
6 * @date 09-October-2015
7 * @brief Header file of SAI HAL module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2015 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/* Includes ------------------------------------------------------------------*/
47#include "stm32f4xx_hal_def.h"
48
49/** @addtogroup STM32F4xx_HAL_Driver
50 * @{
51 */
52#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
53 defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
54
55/** @addtogroup SAI
56 * @{
57 */
58
59/* Exported types ------------------------------------------------------------*/
60/** @defgroup SAI_Exported_Types SAI Exported Types
61 * @{
62 */
63
64/**
65 * @brief HAL State structures definition
66 */
67typedef enum
68{
69 HAL_SAI_STATE_RESET = 0x00, /*!< SAI not yet initialized or disabled */
70 HAL_SAI_STATE_READY = 0x01, /*!< SAI initialized and ready for use */
71 HAL_SAI_STATE_BUSY = 0x02, /*!< SAI internal process is ongoing */
72 HAL_SAI_STATE_BUSY_TX = 0x12, /*!< Data transmission process is ongoing */
73 HAL_SAI_STATE_BUSY_RX = 0x22, /*!< Data reception process is ongoing */
74 HAL_SAI_STATE_TIMEOUT = 0x03, /*!< SAI timeout state */
75 HAL_SAI_STATE_ERROR = 0x04 /*!< SAI error state */
76}HAL_SAI_StateTypeDef;
77
78/**
79 * @brief SAI Callback prototype
80 */
81typedef void (*SAIcallback)(void);
82
83/**
84 * @brief SAI Init Structure definition
85 */
86typedef struct
87{
88 uint32_t AudioMode; /*!< Specifies the SAI Block audio Mode.
89 This parameter can be a value of @ref SAI_Block_Mode */
90
91 uint32_t Synchro; /*!< Specifies SAI Block synchronization
92 This parameter can be a value of @ref SAI_Block_Synchronization */
93
94 uint32_t SynchroExt; /*!< Specifies SAI Block synchronization, this setup is common
95 for BLOCKA and BLOCKB
96 This parameter can be a value of @ref SAI_Block_SyncExt */
97
98 uint32_t OutputDrive; /*!< Specifies when SAI Block outputs are driven.
99 This parameter can be a value of @ref SAI_Block_Output_Drive
100 @note this value has to be set before enabling the audio block
101 but after the audio block configuration. */
102
103 uint32_t NoDivider; /*!< Specifies whether master clock will be divided or not.
104 This parameter can be a value of @ref SAI_Block_NoDivider
105 @note: If bit NODIV in the SAI_xCR1 register is cleared, the frame length
106 should be aligned to a number equal to a power of 2, from 8 to 256.
107 If bit NODIV in the SAI_xCR1 register is set, the frame length can
108 take any of the values without constraint since the input clock of
109 the audio block should be equal to the bit clock.
110 There is no MCLK_x clock which can be output. */
111
112 uint32_t FIFOThreshold; /*!< Specifies SAI Block FIFO threshold.
113 This parameter can be a value of @ref SAI_Block_Fifo_Threshold */
114
115 uint32_t ClockSource; /*!< Specifies the SAI Block x Clock source.
116 This parameter is not used for STM32F446xx devices. */
117
118 uint32_t AudioFrequency; /*!< Specifies the audio frequency sampling.
119 This parameter can be a value of @ref SAI_Audio_Frequency */
120
121 uint32_t Mckdiv; /*!< Specifies the master clock divider, the parameter will be used if for
122 AudioFrequency the user choice
123 This parameter must be a number between Min_Data = 0 and Max_Data = 15 */
124
125 uint32_t MonoStereoMode; /*!< Specifies if the mono or stereo mode is selected.
126 This parameter can be a value of @ref SAI_Mono_Stereo_Mode */
127
128 uint32_t CompandingMode; /*!< Specifies the companding mode type.
129 This parameter can be a value of @ref SAI_Block_Companding_Mode */
130
131 uint32_t TriState; /*!< Specifies the companding mode type.
132 This parameter can be a value of @ref SAI_TRIState_Management */
133
134 /* This part of the structure is automatically filled if your are using the high level intialisation
135 function HAL_SAI_InitProtocol */
136
137 uint32_t Protocol; /*!< Specifies the SAI Block protocol.
138 This parameter can be a value of @ref SAI_Block_Protocol */
139
140 uint32_t DataSize; /*!< Specifies the SAI Block data size.
141 This parameter can be a value of @ref SAI_Block_Data_Size */
142
143 uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
144 This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission */
145
146 uint32_t ClockStrobing; /*!< Specifies the SAI Block clock strobing edge sensitivity.
147 This parameter can be a value of @ref SAI_Block_Clock_Strobing */
148}SAI_InitTypeDef;
149
150/**
151 * @brief SAI Block Frame Init structure definition
152 */
153
154typedef struct
155{
156
157 uint32_t FrameLength; /*!< Specifies the Frame length, the number of SCK clocks for each audio frame.
158 This parameter must be a number between Min_Data = 8 and Max_Data = 256.
159 @note: If master clock MCLK_x pin is declared as an output, the frame length
160 should be aligned to a number equal to power of 2 in order to keep
161 in an audio frame, an integer number of MCLK pulses by bit Clock. */
162
163 uint32_t ActiveFrameLength; /*!< Specifies the Frame synchronization active level length.
164 This Parameter specifies the length in number of bit clock (SCK + 1)
165 of the active level of FS signal in audio frame.
166 This parameter must be a number between Min_Data = 1 and Max_Data = 128 */
167
168 uint32_t FSDefinition; /*!< Specifies the Frame synchronization definition.
169 This parameter can be a value of @ref SAI_Block_FS_Definition */
170
171 uint32_t FSPolarity; /*!< Specifies the Frame synchronization Polarity.
172 This parameter can be a value of @ref SAI_Block_FS_Polarity */
173
174 uint32_t FSOffset; /*!< Specifies the Frame synchronization Offset.
175 This parameter can be a value of @ref SAI_Block_FS_Offset */
176
177}SAI_FrameInitTypeDef;
178
179/**
180 * @brief SAI Block Slot Init Structure definition
181 */
182
183typedef struct
184{
185 uint32_t FirstBitOffset; /*!< Specifies the position of first data transfer bit in the slot.
186 This parameter must be a number between Min_Data = 0 and Max_Data = 24 */
187
188 uint32_t SlotSize; /*!< Specifies the Slot Size.
189 This parameter can be a value of @ref SAI_Block_Slot_Size */
190
191 uint32_t SlotNumber; /*!< Specifies the number of slot in the audio frame.
192 This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
193
194 uint32_t SlotActive; /*!< Specifies the slots in audio frame that will be activated.
195 This parameter can be a value of @ref SAI_Block_Slot_Active */
196}SAI_SlotInitTypeDef;
197
198/**
199 * @brief SAI handle Structure definition
200 */
201typedef struct __SAI_HandleTypeDef
202{
203 SAI_Block_TypeDef *Instance; /*!< SAI Blockx registers base address */
204
205 SAI_InitTypeDef Init; /*!< SAI communication parameters */
206
207 SAI_FrameInitTypeDef FrameInit; /*!< SAI Frame configuration parameters */
208
209 SAI_SlotInitTypeDef SlotInit; /*!< SAI Slot configuration parameters */
210
211 uint8_t *pBuffPtr; /*!< Pointer to SAI transfer Buffer */
212
213 uint16_t XferSize; /*!< SAI transfer size */
214
215 uint16_t XferCount; /*!< SAI transfer counter */
216
217 DMA_HandleTypeDef *hdmatx; /*!< SAI Tx DMA handle parameters */
218
219 DMA_HandleTypeDef *hdmarx; /*!< SAI Rx DMA handle parameters */
220
221 SAIcallback mutecallback;/*!< SAI mute callback */
222
223 void (*InterruptServiceRoutine)(struct __SAI_HandleTypeDef *hsai); /* function pointer for IRQ handler */
224
225 HAL_LockTypeDef Lock; /*!< SAI locking object */
226
227 __IO HAL_SAI_StateTypeDef State; /*!< SAI communication state */
228
229 __IO uint32_t ErrorCode; /*!< SAI Error code */
230}SAI_HandleTypeDef;
231
232/**
233 * @}
234 */
235
236/* Exported constants --------------------------------------------------------*/
237
238/** @defgroup SAI_Exported_Constants SAI Exported Constants
239 * @{
240 */
241
242/** @defgroup SAI_Error_Code SAI Error Code
243 * @{
244 */
245#define HAL_SAI_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */
246#define HAL_SAI_ERROR_OVR ((uint32_t)0x00000001) /*!< Overrun Error */
247#define HAL_SAI_ERROR_UDR ((uint32_t)0x00000002) /*!< Underrun error */
248#define HAL_SAI_ERROR_AFSDET ((uint32_t)0x00000004) /*!< Anticipated Frame synchronisation detection */
249#define HAL_SAI_ERROR_LFSDET ((uint32_t)0x00000008) /*!< Late Frame synchronisation detection */
250#define HAL_SAI_ERROR_CNREADY ((uint32_t)0x00000010) /*!< codec not ready */
251#define HAL_SAI_ERROR_WCKCFG ((uint32_t)0x00000020) /*!< Wrong clock configuration */
252#define HAL_SAI_ERROR_TIMEOUT ((uint32_t)0x00000040) /*!< Timeout error */
253/**
254 * @}
255 */
256
257/** @defgroup SAI_Block_SyncExt SAI External synchronisation
258 * @{
259 */
260#define SAI_SYNCEXT_DISABLE ((uint32_t)0x00000000)
261#define SAI_SYNCEXT_IN_ENABLE ((uint32_t)0x00000001)
262#define SAI_SYNCEXT_OUTBLOCKA_ENABLE ((uint32_t)0x00000002)
263#define SAI_SYNCEXT_OUTBLOCKB_ENABLE ((uint32_t)0x00000004)
264/**
265 * @}
266 */
267
268/** @defgroup SAI_Protocol SAI Supported protocol
269 * @{
270 */
271#define SAI_I2S_STANDARD ((uint32_t)0x00000000)
272#define SAI_I2S_MSBJUSTIFIED ((uint32_t)0x00000001)
273#define SAI_I2S_LSBJUSTIFIED ((uint32_t)0x00000002)
274#define SAI_PCM_LONG ((uint32_t)0x00000004)
275#define SAI_PCM_SHORT ((uint32_t)0x00000008)
276/**
277 * @}
278 */
279
280/** @defgroup SAI_Protocol_DataSize SAI protocol data size
281 * @{
282 */
283#define SAI_PROTOCOL_DATASIZE_16BIT ((uint32_t)0x00000000)
284#define SAI_PROTOCOL_DATASIZE_16BITEXTENDED ((uint32_t)0x00000001)
285#define SAI_PROTOCOL_DATASIZE_24BIT ((uint32_t)0x00000002)
286#define SAI_PROTOCOL_DATASIZE_32BIT ((uint32_t)0x00000004)
287/**
288 * @}
289 */
290
291/** @defgroup SAI_Clock_Source SAI Clock Source
292 * @{
293 */
294#define SAI_CLKSOURCE_PLLSAI ((uint32_t)0x00000000)
295#define SAI_CLKSOURCE_PLLI2S ((uint32_t)0x00100000)
296#define SAI_CLKSOURCE_EXT ((uint32_t)0x00200000)
297#define SAI_CLKSOURCE_NA ((uint32_t)0x00400000) /*!< No applicable for STM32F446xx */
298/**
299 * @}
300 */
301
302/** @defgroup SAI_Audio_Frequency SAI Audio Frequency
303 * @{
304 */
305#define SAI_AUDIO_FREQUENCY_192K ((uint32_t)192000)
306#define SAI_AUDIO_FREQUENCY_96K ((uint32_t)96000)
307#define SAI_AUDIO_FREQUENCY_48K ((uint32_t)48000)
308#define SAI_AUDIO_FREQUENCY_44K ((uint32_t)44100)
309#define SAI_AUDIO_FREQUENCY_32K ((uint32_t)32000)
310#define SAI_AUDIO_FREQUENCY_22K ((uint32_t)22050)
311#define SAI_AUDIO_FREQUENCY_16K ((uint32_t)16000)
312#define SAI_AUDIO_FREQUENCY_11K ((uint32_t)11025)
313#define SAI_AUDIO_FREQUENCY_8K ((uint32_t)8000)
314#define SAI_AUDIO_FREQUENCY_MCKDIV ((uint32_t)0)
315
316/**
317 * @}
318 */
319
320/** @defgroup SAI_Block_Mode SAI Block Mode
321 * @{
322 */
323#define SAI_MODEMASTER_TX ((uint32_t)0x00000000)
324#define SAI_MODEMASTER_RX ((uint32_t)SAI_xCR1_MODE_0)
325#define SAI_MODESLAVE_TX ((uint32_t)SAI_xCR1_MODE_1)
326#define SAI_MODESLAVE_RX ((uint32_t)(SAI_xCR1_MODE_1 | SAI_xCR1_MODE_0))
327
328/**
329 * @}
330 */
331
332/** @defgroup SAI_Block_Protocol SAI Block Protocol
333 * @{
334 */
335#define SAI_FREE_PROTOCOL ((uint32_t)0x00000000)
336#define SAI_SPDIF_PROTOCOL ((uint32_t)SAI_xCR1_PRTCFG_0)
337#define SAI_AC97_PROTOCOL ((uint32_t)SAI_xCR1_PRTCFG_1)
338
339/**
340 * @}
341 */
342
343/** @defgroup SAI_Block_Data_Size SAI Block Data Size
344 * @{
345 */
346#define SAI_DATASIZE_8 ((uint32_t)SAI_xCR1_DS_1)
347#define SAI_DATASIZE_10 ((uint32_t)(SAI_xCR1_DS_1 | SAI_xCR1_DS_0))
348#define SAI_DATASIZE_16 ((uint32_t)SAI_xCR1_DS_2)
349#define SAI_DATASIZE_20 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_0))
350#define SAI_DATASIZE_24 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_1))
351#define SAI_DATASIZE_32 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_1 | SAI_xCR1_DS_0))
352
353/**
354 * @}
355 */
356
357/** @defgroup SAI_Block_MSB_LSB_transmission SAI Block MSB LSB transmission
358 * @{
359 */
360#define SAI_FIRSTBIT_MSB ((uint32_t)0x00000000)
361#define SAI_FIRSTBIT_LSB ((uint32_t)SAI_xCR1_LSBFIRST)
362
363/**
364 * @}
365 */
366
367/** @defgroup SAI_Block_Clock_Strobing SAI Block Clock Strobing
368 * @{
369 */
370#define SAI_CLOCKSTROBING_FALLINGEDGE ((uint32_t)0x00000000)
371#define SAI_CLOCKSTROBING_RISINGEDGE ((uint32_t)SAI_xCR1_CKSTR)
372
373/**
374 * @}
375 */
376
377/** @defgroup SAI_Block_Synchronization SAI Block Synchronization
378 * @{
379 */
380#define SAI_ASYNCHRONOUS ((uint32_t)0x00000000)
381#define SAI_SYNCHRONOUS ((uint32_t)SAI_xCR1_SYNCEN_0)
382#define SAI_SYNCHRONOUS_EXT ((uint32_t)SAI_xCR1_SYNCEN_1)
383
384/**
385 * @}
386 */
387
388/** @defgroup SAI_Block_Output_Drive SAI Block Output Drive
389 * @{
390 */
391#define SAI_OUTPUTDRIVE_DISABLE ((uint32_t)0x00000000)
392#define SAI_OUTPUTDRIVE_ENABLE ((uint32_t)SAI_xCR1_OUTDRIV)
393
394/**
395 * @}
396 */
397
398/** @defgroup SAI_Block_NoDivider SAI Block NoDivider
399 * @{
400 */
401#define SAI_MASTERDIVIDER_ENABLE ((uint32_t)0x00000000)
402#define SAI_MASTERDIVIDER_DISABLE ((uint32_t)SAI_xCR1_NODIV)
403
404/**
405 * @}
406 */
407
408
409/** @defgroup SAI_Block_FS_Definition SAI Block FS Definition
410 * @{
411 */
412#define SAI_FS_STARTFRAME ((uint32_t)0x00000000)
413#define SAI_FS_CHANNEL_IDENTIFICATION ((uint32_t)SAI_xFRCR_FSDEF)
414
415/**
416 * @}
417 */
418
419/** @defgroup SAI_Block_FS_Polarity SAI Block FS Polarity
420 * @{
421 */
422#define SAI_FS_ACTIVE_LOW ((uint32_t)0x00000000)
423#define SAI_FS_ACTIVE_HIGH ((uint32_t)SAI_xFRCR_FSPO)
424
425/**
426 * @}
427 */
428
429/** @defgroup SAI_Block_FS_Offset SAI Block FS Offset
430 * @{
431 */
432#define SAI_FS_FIRSTBIT ((uint32_t)0x00000000)
433#define SAI_FS_BEFOREFIRSTBIT ((uint32_t)SAI_xFRCR_FSOFF)
434
435/**
436 * @}
437 */
438
439
440 /** @defgroup SAI_Block_Slot_Size SAI Block Slot Size
441 * @{
442 */
443#define SAI_SLOTSIZE_DATASIZE ((uint32_t)0x00000000)
444#define SAI_SLOTSIZE_16B ((uint32_t)SAI_xSLOTR_SLOTSZ_0)
445#define SAI_SLOTSIZE_32B ((uint32_t)SAI_xSLOTR_SLOTSZ_1)
446/**
447 * @}
448 */
449
450/** @defgroup SAI_Block_Slot_Active SAI Block Slot Active
451 * @{
452 */
453#define SAI_SLOT_NOTACTIVE ((uint32_t)0x00000000)
454#define SAI_SLOTACTIVE_0 ((uint32_t)0x00010000)
455#define SAI_SLOTACTIVE_1 ((uint32_t)0x00020000)
456#define SAI_SLOTACTIVE_2 ((uint32_t)0x00040000)
457#define SAI_SLOTACTIVE_3 ((uint32_t)0x00080000)
458#define SAI_SLOTACTIVE_4 ((uint32_t)0x00100000)
459#define SAI_SLOTACTIVE_5 ((uint32_t)0x00200000)
460#define SAI_SLOTACTIVE_6 ((uint32_t)0x00400000)
461#define SAI_SLOTACTIVE_7 ((uint32_t)0x00800000)
462#define SAI_SLOTACTIVE_8 ((uint32_t)0x01000000)
463#define SAI_SLOTACTIVE_9 ((uint32_t)0x02000000)
464#define SAI_SLOTACTIVE_10 ((uint32_t)0x04000000)
465#define SAI_SLOTACTIVE_11 ((uint32_t)0x08000000)
466#define SAI_SLOTACTIVE_12 ((uint32_t)0x10000000)
467#define SAI_SLOTACTIVE_13 ((uint32_t)0x20000000)
468#define SAI_SLOTACTIVE_14 ((uint32_t)0x40000000)
469#define SAI_SLOTACTIVE_15 ((uint32_t)0x80000000)
470#define SAI_SLOTACTIVE_ALL ((uint32_t)0xFFFF0000)
471
472/**
473 * @}
474 */
475
476/** @defgroup SAI_Mono_Stereo_Mode SAI Mono Stereo Mode
477 * @{
478 */
479#define SAI_STEREOMODE ((uint32_t)0x00000000)
480#define SAI_MONOMODE ((uint32_t)SAI_xCR1_MONO)
481
482/**
483 * @}
484 */
485
486/** @defgroup SAI_TRIState_Management SAI TRIState Management
487 * @{
488 */
489#define SAI_OUTPUT_NOTRELEASED ((uint32_t)0x00000000)
490#define SAI_OUTPUT_RELEASED ((uint32_t)SAI_xCR2_TRIS)
491
492/**
493 * @}
494 */
495
496/** @defgroup SAI_Block_Fifo_Threshold SAI Block Fifo Threshold
497 * @{
498 */
499#define SAI_FIFOTHRESHOLD_EMPTY ((uint32_t)0x00000000)
500#define SAI_FIFOTHRESHOLD_1QF ((uint32_t)SAI_xCR2_FTH_0)
501#define SAI_FIFOTHRESHOLD_HF ((uint32_t)SAI_xCR2_FTH_1)
502#define SAI_FIFOTHRESHOLD_3QF ((uint32_t)(SAI_xCR2_FTH_1 | SAI_xCR2_FTH_0))
503#define SAI_FIFOTHRESHOLD_FULL ((uint32_t)SAI_xCR2_FTH_2)
504
505/**
506 * @}
507 */
508
509/** @defgroup SAI_Block_Companding_Mode SAI Block Companding Mode
510 * @{
511 */
512#define SAI_NOCOMPANDING ((uint32_t)0x00000000)
513#define SAI_ULAW_1CPL_COMPANDING ((uint32_t)SAI_xCR2_COMP_1)
514#define SAI_ALAW_1CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0))
515#define SAI_ULAW_2CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_CPL))
516#define SAI_ALAW_2CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0 | SAI_xCR2_CPL))
517
518/**
519 * @}
520 */
521
522/** @defgroup SAI_Block_Mute_Value SAI Block Mute Value
523 * @{
524 */
525#define SAI_ZERO_VALUE ((uint32_t)0x00000000)
526#define SAI_LAST_SENT_VALUE ((uint32_t)SAI_xCR2_MUTEVAL)
527
528/**
529 * @}
530 */
531
532
533/** @defgroup SAI_Block_Interrupts_Definition SAI Block Interrupts Definition
534 * @{
535 */
536#define SAI_IT_OVRUDR ((uint32_t)SAI_xIMR_OVRUDRIE)
537#define SAI_IT_MUTEDET ((uint32_t)SAI_xIMR_MUTEDETIE)
538#define SAI_IT_WCKCFG ((uint32_t)SAI_xIMR_WCKCFGIE)
539#define SAI_IT_FREQ ((uint32_t)SAI_xIMR_FREQIE)
540#define SAI_IT_CNRDY ((uint32_t)SAI_xIMR_CNRDYIE)
541#define SAI_IT_AFSDET ((uint32_t)SAI_xIMR_AFSDETIE)
542#define SAI_IT_LFSDET ((uint32_t)SAI_xIMR_LFSDETIE)
543
544/**
545 * @}
546 */
547
548/** @defgroup SAI_Block_Flags_Definition SAI Block Flags Definition
549 * @{
550 */
551#define SAI_FLAG_OVRUDR ((uint32_t)SAI_xSR_OVRUDR)
552#define SAI_FLAG_MUTEDET ((uint32_t)SAI_xSR_MUTEDET)
553#define SAI_FLAG_WCKCFG ((uint32_t)SAI_xSR_WCKCFG)
554#define SAI_FLAG_FREQ ((uint32_t)SAI_xSR_FREQ)
555#define SAI_FLAG_CNRDY ((uint32_t)SAI_xSR_CNRDY)
556#define SAI_FLAG_AFSDET ((uint32_t)SAI_xSR_AFSDET)
557#define SAI_FLAG_LFSDET ((uint32_t)SAI_xSR_LFSDET)
558
559/**
560 * @}
561 */
562
563/** @defgroup SAI_Block_Fifo_Status_Level SAI Block Fifo Status Level
564 * @{
565 */
566#define SAI_FIFOSTATUS_EMPTY ((uint32_t)0x00000000)
567#define SAI_FIFOSTATUS_LESS1QUARTERFULL ((uint32_t)0x00010000)
568#define SAI_FIFOSTATUS_1QUARTERFULL ((uint32_t)0x00020000)
569#define SAI_FIFOSTATUS_HALFFULL ((uint32_t)0x00030000)
570#define SAI_FIFOSTATUS_3QUARTERFULL ((uint32_t)0x00040000)
571#define SAI_FIFOSTATUS_FULL ((uint32_t)0x00050000)
572
573/**
574 * @}
575 */
576
577/**
578 * @}
579 */
580
581/* Exported macro ------------------------------------------------------------*/
582
583/** @defgroup SAI_Exported_Macros SAI Exported Macros
584 * @brief macros to handle interrupts and specific configurations
585 * @{
586 */
587
588/** @brief Reset SAI handle state
589 * @param __HANDLE__: specifies the SAI Handle.
590 * @retval None
591 */
592#define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SAI_STATE_RESET)
593
594/** @brief Enable or disable the specified SAI interrupts.
595 * @param __HANDLE__: specifies the SAI Handle.
596 * @param __INTERRUPT__: specifies the interrupt source to enable or disable.
597 * This parameter can be one of the following values:
598 * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
599 * @arg SAI_IT_MUTEDET: Mute detection interrupt enable
600 * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
601 * @arg SAI_IT_FREQ: FIFO request interrupt enable
602 * @arg SAI_IT_CNRDY: Codec not ready interrupt enable
603 * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
604 * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enabl
605 * @retval None
606 */
607
608#define __HAL_SAI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR |= (__INTERRUPT__))
609#define __HAL_SAI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR &= (~(__INTERRUPT__)))
610
611/** @brief Check if the specified SAI interrupt source is enabled or disabled.
612 * @param __HANDLE__: specifies the SAI Handle.
613 * This parameter can be SAI where x: 1, 2, or 3 to select the SAI peripheral.
614 * @param __INTERRUPT__: specifies the SAI interrupt source to check.
615 * This parameter can be one of the following values:
616 * @arg SAI_IT_TXE: Tx buffer empty interrupt enable.
617 * @arg SAI_IT_RXNE: Rx buffer not empty interrupt enable.
618 * @arg SAI_IT_ERR: Error interrupt enable.
619 * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
620 */
621#define __HAL_SAI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IMR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
622
623/** @brief Check whether the specified SAI flag is set or not.
624 * @param __HANDLE__: specifies the SAI Handle.
625 * @param __FLAG__: specifies the flag to check.
626 * This parameter can be one of the following values:
627 * @arg SAI_FLAG_OVRUDR: Overrun underrun flag.
628 * @arg SAI_FLAG_MUTEDET: Mute detection flag.
629 * @arg SAI_FLAG_WCKCFG: Wrong Clock Configuration flag.
630 * @arg SAI_FLAG_FREQ: FIFO request flag.
631 * @arg SAI_FLAG_CNRDY: Codec not ready flag.
632 * @arg SAI_FLAG_AFSDET: Anticipated frame synchronization detection flag.
633 * @arg SAI_FLAG_LFSDET: Late frame synchronization detection flag.
634 * @retval The new state of __FLAG__ (TRUE or FALSE).
635 */
636#define __HAL_SAI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
637
638/** @brief Clears the specified SAI pending flag.
639 * @param __HANDLE__: specifies the SAI Handle.
640 * @param __FLAG__: specifies the flag to check.
641 * This parameter can be any combination of the following values:
642 * @arg SAI_FLAG_OVRUDR: Clear Overrun underrun
643 * @arg SAI_FLAG_MUTEDET: Clear Mute detection
644 * @arg SAI_FLAG_WCKCFG: Clear Wrong Clock Configuration
645 * @arg SAI_FLAG_FREQ: Clear FIFO request
646 * @arg SAI_FLAG_CNRDY: Clear Codec not ready
647 * @arg SAI_FLAG_AFSDET: Clear Anticipated frame synchronization detection
648 * @arg SAI_FLAG_LFSDET: Clear Late frame synchronization detection
649 *
650 * @retval None
651 */
652#define __HAL_SAI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__))
653
654#define __HAL_SAI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SAI_xCR1_SAIEN)
655#define __HAL_SAI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~SAI_xCR1_SAIEN)
656
657 /**
658 * @}
659 */
660
661/* Include RCC SAI Extension module */
662#include "stm32f4xx_hal_sai_ex.h"
663
664/* Exported functions --------------------------------------------------------*/
665
666/** @addtogroup SAI_Exported_Functions
667 * @{
668 */
669
670/* Initialization/de-initialization functions **********************************/
671/** @addtogroup SAI_Exported_Functions_Group1
672 * @{
673 */
674HAL_StatusTypeDef HAL_SAI_InitProtocol(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot);
675HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai);
676HAL_StatusTypeDef HAL_SAI_DeInit (SAI_HandleTypeDef *hsai);
677void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai);
678void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai);
679
680/**
681 * @}
682 */
683
684/* I/O operation functions *****************************************************/
685/** @addtogroup SAI_Exported_Functions_Group2
686 * @{
687 */
688/* Blocking mode: Polling */
689HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
690HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
691
692/* Non-Blocking mode: Interrupt */
693HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
694HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
695
696/* Non-Blocking mode: DMA */
697HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
698HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
699HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai);
700HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai);
701HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai);
702
703/* Abort function */
704HAL_StatusTypeDef HAL_SAI_Abort(SAI_HandleTypeDef *hsai);
705
706/* Mute management */
707HAL_StatusTypeDef HAL_SAI_EnableTxMuteMode(SAI_HandleTypeDef *hsai, uint16_t val);
708HAL_StatusTypeDef HAL_SAI_DisableTxMuteMode(SAI_HandleTypeDef *hsai);
709HAL_StatusTypeDef HAL_SAI_EnableRxMuteMode(SAI_HandleTypeDef *hsai, SAIcallback callback, uint16_t counter);
710HAL_StatusTypeDef HAL_SAI_DisableRxMuteMode(SAI_HandleTypeDef *hsai);
711
712/* SAI IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
713void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai);
714void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai);
715void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai);
716void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai);
717void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai);
718void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai);
719/**
720 * @}
721 */
722
723/** @addtogroup SAI_Exported_Functions_Group3
724 * @{
725 */
726/* Peripheral State functions **************************************************/
727HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai);
728uint32_t HAL_SAI_GetError(SAI_HandleTypeDef *hsai);
729/**
730 * @}
731 */
732
733/**
734 * @}
735 */
736
737/* Private types -------------------------------------------------------------*/
738/** @defgroup SAI_Private_Types SAI Private Types
739 * @{
740 */
741
742/**
743 * @}
744 */
745
746/* Private variables ---------------------------------------------------------*/
747/** @defgroup SAI_Private_Variables SAI Private Variables
748 * @{
749 */
750
751/**
752 * @}
753 */
754
755/* Private constants ---------------------------------------------------------*/
756/** @defgroup SAI_Private_Constants SAI Private Constants
757 * @{
758 */
759
760/**
761 * @}
762 */
763
764/* Private macros ------------------------------------------------------------*/
765/** @addtogroup SAI_Private_Macros
766 * @{
767 */
768#define IS_SAI_BLOCK_SYNCEXT(STATE) (((STATE) == SAI_SYNCEXT_DISABLE) ||\
769 ((STATE) == SAI_SYNCEXT_IN_ENABLE) ||\
770 ((STATE) == SAI_SYNCEXT_OUTBLOCKA_ENABLE) ||\
771 ((STATE) == SAI_SYNCEXT_OUTBLOCKB_ENABLE))
772
773#define IS_SAI_SUPPORTED_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_I2S_STANDARD) ||\
774 ((PROTOCOL) == SAI_I2S_MSBJUSTIFIED) ||\
775 ((PROTOCOL) == SAI_I2S_LSBJUSTIFIED) ||\
776 ((PROTOCOL) == SAI_PCM_LONG) ||\
777 ((PROTOCOL) == SAI_PCM_SHORT))
778
779#define IS_SAI_PROTOCOL_DATASIZE(DATASIZE) (((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BIT) ||\
780 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BITEXTENDED) ||\
781 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_24BIT) ||\
782 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_32BIT))
783
784#define IS_SAI_CLK_SOURCE(SOURCE) (((SOURCE) == SAI_CLKSOURCE_PLLSAI) ||\
785 ((SOURCE) == SAI_CLKSOURCE_PLLI2S) ||\
786 ((SOURCE) == SAI_CLKSOURCE_EXT))
787
788#define IS_SAI_AUDIO_FREQUENCY(AUDIO) (((AUDIO) == SAI_AUDIO_FREQUENCY_192K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_96K) || \
789 ((AUDIO) == SAI_AUDIO_FREQUENCY_48K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_44K) || \
790 ((AUDIO) == SAI_AUDIO_FREQUENCY_32K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_22K) || \
791 ((AUDIO) == SAI_AUDIO_FREQUENCY_16K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_11K) || \
792 ((AUDIO) == SAI_AUDIO_FREQUENCY_8K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_MCKDIV))
793
794#define IS_SAI_BLOCK_MODE(MODE) (((MODE) == SAI_MODEMASTER_TX) || \
795 ((MODE) == SAI_MODEMASTER_RX) || \
796 ((MODE) == SAI_MODESLAVE_TX) || \
797 ((MODE) == SAI_MODESLAVE_RX))
798
799#define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_FREE_PROTOCOL) || \
800 ((PROTOCOL) == SAI_AC97_PROTOCOL) || \
801 ((PROTOCOL) == SAI_SPDIF_PROTOCOL))
802
803#define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DATASIZE_8) || \
804 ((DATASIZE) == SAI_DATASIZE_10) || \
805 ((DATASIZE) == SAI_DATASIZE_16) || \
806 ((DATASIZE) == SAI_DATASIZE_20) || \
807 ((DATASIZE) == SAI_DATASIZE_24) || \
808 ((DATASIZE) == SAI_DATASIZE_32))
809
810#define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FIRSTBIT_MSB) || \
811 ((BIT) == SAI_FIRSTBIT_LSB))
812
813#define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_CLOCKSTROBING_FALLINGEDGE) || \
814 ((CLOCK) == SAI_CLOCKSTROBING_RISINGEDGE))
815
816#define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS) || \
817 ((SYNCHRO) == SAI_SYNCHRONOUS) || \
818 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT))
819
820#define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OUTPUTDRIVE_DISABLE) || \
821 ((DRIVE) == SAI_OUTPUTDRIVE_ENABLE))
822
823#define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MASTERDIVIDER_ENABLE) || \
824 ((NODIVIDER) == SAI_MASTERDIVIDER_DISABLE))
825
826#define IS_SAI_BLOCK_FIFO_STATUS(STATUS) (((STATUS) == SAI_FIFOSTATUS_LESS1QUARTERFULL ) || \
827 ((STATUS) == SAI_FIFOSTATUS_HALFFULL) || \
828 ((STATUS) == SAI_FIFOSTATUS_1QUARTERFULL) || \
829 ((STATUS) == SAI_FIFOSTATUS_3QUARTERFULL) || \
830 ((STATUS) == SAI_FIFOSTATUS_FULL) || \
831 ((STATUS) == SAI_FIFOSTATUS_EMPTY))
832
833#define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63)
834
835#define IS_SAI_BLOCK_MUTE_VALUE(VALUE) (((VALUE) == SAI_ZERO_VALUE) || \
836 ((VALUE) == SAI_LAST_SENT_VALUE))
837
838#define IS_SAI_BLOCK_COMPANDING_MODE(MODE) (((MODE) == SAI_NOCOMPANDING) || \
839 ((MODE) == SAI_ULAW_1CPL_COMPANDING) || \
840 ((MODE) == SAI_ALAW_1CPL_COMPANDING) || \
841 ((MODE) == SAI_ULAW_2CPL_COMPANDING) || \
842 ((MODE) == SAI_ALAW_2CPL_COMPANDING))
843
844#define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_FIFOTHRESHOLD_EMPTY) || \
845 ((THRESHOLD) == SAI_FIFOTHRESHOLD_1QF) || \
846 ((THRESHOLD) == SAI_FIFOTHRESHOLD_HF) || \
847 ((THRESHOLD) == SAI_FIFOTHRESHOLD_3QF) || \
848 ((THRESHOLD) == SAI_FIFOTHRESHOLD_FULL))
849
850#define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_OUTPUT_NOTRELEASED) ||\
851 ((STATE) == SAI_OUTPUT_RELEASED))
852
853#define IS_SAI_MONO_STEREO_MODE(MODE) (((MODE) == SAI_MONOMODE) ||\
854 ((MODE) == SAI_STEREOMODE))
855
856#define IS_SAI_SLOT_ACTIVE(ACTIVE) ((((ACTIVE) >> 16 ) > 0) && (((ACTIVE) >> 16 ) <= (SAI_SLOTACTIVE_ALL >> 16)))
857
858#define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1 <= (NUMBER)) && ((NUMBER) <= 16))
859
860#define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SLOTSIZE_DATASIZE) || \
861 ((SIZE) == SAI_SLOTSIZE_16B) || \
862 ((SIZE) == SAI_SLOTSIZE_32B))
863
864#define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24)
865
866#define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FIRSTBIT) || \
867 ((OFFSET) == SAI_FS_BEFOREFIRSTBIT))
868
869#define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ACTIVE_LOW) || \
870 ((POLARITY) == SAI_FS_ACTIVE_HIGH))
871
872#define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_STARTFRAME) || \
873 ((DEFINITION) == SAI_FS_CHANNEL_IDENTIFICATION))
874
875#define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 15)
876
877#define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8 <= (LENGTH)) && ((LENGTH) <= 256))
878
879#define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1 <= (LENGTH)) && ((LENGTH) <= 128))
880
881/**
882 * @}
883 */
884
885/* Private functions ---------------------------------------------------------*/
886/** @defgroup SAI_Private_Functions SAI Private Functions
887 * @{
888 */
889
890/**
891 * @}
892 */
893
894#endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
895/**
896 * @}
897 */
898
899/**
900 * @}
901 */
902
903#ifdef __cplusplus
904}
905#endif
906
907#endif /* __STM32F4xx_HAL_SAI_H */
908
909/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.