Merge pull request #10592 from iNavFlight/MrD_Update-parameter-description
[inav.git] / lib / main / STM32F7 / Drivers / STM32F7xx_HAL_Driver / Inc / stm32f7xx_hal_sai.h
blob09c32bee7656cc07cfc9f720ad9aa66a17d2da0c
1 /**
2 ******************************************************************************
3 * @file stm32f7xx_hal_sai.h
4 * @author MCD Application Team
5 * @version V1.2.2
6 * @date 14-April-2017
7 * @brief Header file of SAI HAL module.
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
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.
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.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F7xx_HAL_SAI_H
40 #define __STM32F7xx_HAL_SAI_H
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
47 /* Includes ------------------------------------------------------------------*/
48 #include "stm32f7xx_hal_def.h"
50 /** @addtogroup STM32F7xx_HAL_Driver
51 * @{
54 /** @addtogroup SAI
55 * @{
58 /* Exported types ------------------------------------------------------------*/
59 /** @defgroup SAI_Exported_Types SAI Exported Types
60 * @{
63 /**
64 * @brief HAL State structures definition
66 typedef enum
68 HAL_SAI_STATE_RESET = 0x00U, /*!< SAI not yet initialized or disabled */
69 HAL_SAI_STATE_READY = 0x01U, /*!< SAI initialized and ready for use */
70 HAL_SAI_STATE_BUSY = 0x02U, /*!< SAI internal process is ongoing */
71 HAL_SAI_STATE_BUSY_TX = 0x12U, /*!< Data transmission process is ongoing */
72 HAL_SAI_STATE_BUSY_RX = 0x22U, /*!< Data reception process is ongoing */
73 }HAL_SAI_StateTypeDef;
75 /**
76 * @brief SAI Callback prototype
78 typedef void (*SAIcallback)(void);
80 /** @defgroup SAI_Init_Structure_definition SAI Init Structure definition
81 * @brief SAI Init Structure definition
82 * @{
84 typedef struct
86 uint32_t AudioMode; /*!< Specifies the SAI Block audio Mode.
87 This parameter can be a value of @ref SAI_Block_Mode */
89 uint32_t Synchro; /*!< Specifies SAI Block synchronization
90 This parameter can be a value of @ref SAI_Block_Synchronization */
92 uint32_t SynchroExt; /*!< Specifies SAI external output synchronization, this setup is common
93 for BlockA and BlockB
94 This parameter can be a value of @ref SAI_Block_SyncExt
95 @note: If both audio blocks of same SAI are used, this parameter has
96 to be set to the same value for each audio block */
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. */
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. */
112 uint32_t FIFOThreshold; /*!< Specifies SAI Block FIFO threshold.
113 This parameter can be a value of @ref SAI_Block_Fifo_Threshold */
115 uint32_t AudioFrequency; /*!< Specifies the audio frequency sampling.
116 This parameter can be a value of @ref SAI_Audio_Frequency */
118 uint32_t Mckdiv; /*!< Specifies the master clock divider, the parameter will be used if for
119 AudioFrequency the user choice
120 This parameter must be a number between Min_Data = 0 and Max_Data = 15 */
122 uint32_t MonoStereoMode; /*!< Specifies if the mono or stereo mode is selected.
123 This parameter can be a value of @ref SAI_Mono_Stereo_Mode */
125 uint32_t CompandingMode; /*!< Specifies the companding mode type.
126 This parameter can be a value of @ref SAI_Block_Companding_Mode */
128 uint32_t TriState; /*!< Specifies the companding mode type.
129 This parameter can be a value of @ref SAI_TRIState_Management */
131 /* This part of the structure is automatically filled if your are using the high level initialisation
132 function HAL_SAI_InitProtocol */
134 uint32_t Protocol; /*!< Specifies the SAI Block protocol.
135 This parameter can be a value of @ref SAI_Block_Protocol */
137 uint32_t DataSize; /*!< Specifies the SAI Block data size.
138 This parameter can be a value of @ref SAI_Block_Data_Size */
140 uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
141 This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission */
143 uint32_t ClockStrobing; /*!< Specifies the SAI Block clock strobing edge sensitivity.
144 This parameter can be a value of @ref SAI_Block_Clock_Strobing */
145 }SAI_InitTypeDef;
147 * @}
150 /** @defgroup SAI_Frame_Structure_definition SAI Frame Structure definition
151 * @brief SAI Frame Init structure definition
152 * @{
154 typedef struct
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. */
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 */
168 uint32_t FSDefinition; /*!< Specifies the Frame synchronization definition.
169 This parameter can be a value of @ref SAI_Block_FS_Definition */
171 uint32_t FSPolarity; /*!< Specifies the Frame synchronization Polarity.
172 This parameter can be a value of @ref SAI_Block_FS_Polarity */
174 uint32_t FSOffset; /*!< Specifies the Frame synchronization Offset.
175 This parameter can be a value of @ref SAI_Block_FS_Offset */
177 }SAI_FrameInitTypeDef;
179 * @}
182 /** @defgroup SAI_Slot_Structure_definition SAI Slot Structure definition
183 * @brief SAI Block Slot Init Structure definition
184 * @{
186 typedef struct
188 uint32_t FirstBitOffset; /*!< Specifies the position of first data transfer bit in the slot.
189 This parameter must be a number between Min_Data = 0 and Max_Data = 24 */
191 uint32_t SlotSize; /*!< Specifies the Slot Size.
192 This parameter can be a value of @ref SAI_Block_Slot_Size */
194 uint32_t SlotNumber; /*!< Specifies the number of slot in the audio frame.
195 This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
197 uint32_t SlotActive; /*!< Specifies the slots in audio frame that will be activated.
198 This parameter can be a value of @ref SAI_Block_Slot_Active */
199 }SAI_SlotInitTypeDef;
201 * @}
204 /** @defgroup SAI_Handle_Structure_definition SAI Handle Structure definition
205 * @brief SAI handle Structure definition
206 * @{
208 typedef struct __SAI_HandleTypeDef
210 SAI_Block_TypeDef *Instance; /*!< SAI Blockx registers base address */
212 SAI_InitTypeDef Init; /*!< SAI communication parameters */
214 SAI_FrameInitTypeDef FrameInit; /*!< SAI Frame configuration parameters */
216 SAI_SlotInitTypeDef SlotInit; /*!< SAI Slot configuration parameters */
218 uint8_t *pBuffPtr; /*!< Pointer to SAI transfer Buffer */
220 uint16_t XferSize; /*!< SAI transfer size */
222 uint16_t XferCount; /*!< SAI transfer counter */
224 DMA_HandleTypeDef *hdmatx; /*!< SAI Tx DMA handle parameters */
226 DMA_HandleTypeDef *hdmarx; /*!< SAI Rx DMA handle parameters */
228 SAIcallback mutecallback; /*!< SAI mute callback */
230 void (*InterruptServiceRoutine)(struct __SAI_HandleTypeDef *hsai); /* function pointer for IRQ handler */
232 HAL_LockTypeDef Lock; /*!< SAI locking object */
234 __IO HAL_SAI_StateTypeDef State; /*!< SAI communication state */
236 __IO uint32_t ErrorCode; /*!< SAI Error code */
237 }SAI_HandleTypeDef;
239 * @}
243 * @}
246 /* Exported constants --------------------------------------------------------*/
248 /** @defgroup SAI_Exported_Constants SAI Exported Constants
249 * @{
252 /** @defgroup SAI_Error_Code SAI Error Code
253 * @{
255 #define HAL_SAI_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
256 #define HAL_SAI_ERROR_OVR ((uint32_t)0x00000001U) /*!< Overrun Error */
257 #define HAL_SAI_ERROR_UDR ((uint32_t)0x00000002U) /*!< Underrun error */
258 #define HAL_SAI_ERROR_AFSDET ((uint32_t)0x00000004U) /*!< Anticipated Frame synchronisation detection */
259 #define HAL_SAI_ERROR_LFSDET ((uint32_t)0x00000008U) /*!< Late Frame synchronisation detection */
260 #define HAL_SAI_ERROR_CNREADY ((uint32_t)0x00000010U) /*!< codec not ready */
261 #define HAL_SAI_ERROR_WCKCFG ((uint32_t)0x00000020U) /*!< Wrong clock configuration */
262 #define HAL_SAI_ERROR_TIMEOUT ((uint32_t)0x00000040U) /*!< Timeout error */
263 #define HAL_SAI_ERROR_DMA ((uint32_t)0x00000080U) /*!< DMA error */
265 * @}
268 /** @defgroup SAI_Block_SyncExt SAI External synchronisation
269 * @{
271 #define SAI_SYNCEXT_DISABLE 0
272 #define SAI_SYNCEXT_OUTBLOCKA_ENABLE 1
273 #define SAI_SYNCEXT_OUTBLOCKB_ENABLE 2
275 * @}
278 /** @defgroup SAI_Protocol SAI Supported protocol
279 * @{
281 #define SAI_I2S_STANDARD 0
282 #define SAI_I2S_MSBJUSTIFIED 1
283 #define SAI_I2S_LSBJUSTIFIED 2
284 #define SAI_PCM_LONG 3
285 #define SAI_PCM_SHORT 4
287 * @}
290 /** @defgroup SAI_Protocol_DataSize SAI protocol data size
291 * @{
293 #define SAI_PROTOCOL_DATASIZE_16BIT 0
294 #define SAI_PROTOCOL_DATASIZE_16BITEXTENDED 1
295 #define SAI_PROTOCOL_DATASIZE_24BIT 2
296 #define SAI_PROTOCOL_DATASIZE_32BIT 3
298 * @}
301 /** @defgroup SAI_Audio_Frequency SAI Audio Frequency
302 * @{
304 #define SAI_AUDIO_FREQUENCY_192K ((uint32_t)192000U)
305 #define SAI_AUDIO_FREQUENCY_96K ((uint32_t)96000U)
306 #define SAI_AUDIO_FREQUENCY_48K ((uint32_t)48000U)
307 #define SAI_AUDIO_FREQUENCY_44K ((uint32_t)44100U)
308 #define SAI_AUDIO_FREQUENCY_32K ((uint32_t)32000U)
309 #define SAI_AUDIO_FREQUENCY_22K ((uint32_t)22050U)
310 #define SAI_AUDIO_FREQUENCY_16K ((uint32_t)16000U)
311 #define SAI_AUDIO_FREQUENCY_11K ((uint32_t)11025U)
312 #define SAI_AUDIO_FREQUENCY_8K ((uint32_t)8000U)
313 #define SAI_AUDIO_FREQUENCY_MCKDIV ((uint32_t)0U)
315 * @}
318 /** @defgroup SAI_Block_Mode SAI Block Mode
319 * @{
321 #define SAI_MODEMASTER_TX ((uint32_t)0x00000000U)
322 #define SAI_MODEMASTER_RX ((uint32_t)SAI_xCR1_MODE_0)
323 #define SAI_MODESLAVE_TX ((uint32_t)SAI_xCR1_MODE_1)
324 #define SAI_MODESLAVE_RX ((uint32_t)(SAI_xCR1_MODE_1 | SAI_xCR1_MODE_0))
327 * @}
330 /** @defgroup SAI_Block_Protocol SAI Block Protocol
331 * @{
333 #define SAI_FREE_PROTOCOL ((uint32_t)0x00000000U)
334 #define SAI_SPDIF_PROTOCOL ((uint32_t)SAI_xCR1_PRTCFG_0)
335 #define SAI_AC97_PROTOCOL ((uint32_t)SAI_xCR1_PRTCFG_1)
337 * @}
340 /** @defgroup SAI_Block_Data_Size SAI Block Data Size
341 * @{
343 #define SAI_DATASIZE_8 ((uint32_t)SAI_xCR1_DS_1)
344 #define SAI_DATASIZE_10 ((uint32_t)(SAI_xCR1_DS_1 | SAI_xCR1_DS_0))
345 #define SAI_DATASIZE_16 ((uint32_t)SAI_xCR1_DS_2)
346 #define SAI_DATASIZE_20 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_0))
347 #define SAI_DATASIZE_24 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_1))
348 #define SAI_DATASIZE_32 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_1 | SAI_xCR1_DS_0))
350 * @}
353 /** @defgroup SAI_Block_MSB_LSB_transmission SAI Block MSB LSB transmission
354 * @{
356 #define SAI_FIRSTBIT_MSB ((uint32_t)0x00000000U)
357 #define SAI_FIRSTBIT_LSB ((uint32_t)SAI_xCR1_LSBFIRST)
359 * @}
362 /** @defgroup SAI_Block_Clock_Strobing SAI Block Clock Strobing
363 * @{
365 #define SAI_CLOCKSTROBING_FALLINGEDGE 0
366 #define SAI_CLOCKSTROBING_RISINGEDGE 1
368 * @}
371 /** @defgroup SAI_Block_Synchronization SAI Block Synchronization
372 * @{
374 #define SAI_ASYNCHRONOUS 0 /*!< Asynchronous */
375 #define SAI_SYNCHRONOUS 1 /*!< Synchronous with other block of same SAI */
376 #define SAI_SYNCHRONOUS_EXT_SAI1 2 /*!< Synchronous with other SAI, SAI1 */
377 #define SAI_SYNCHRONOUS_EXT_SAI2 3 /*!< Synchronous with other SAI, SAI2 */
379 * @}
382 /** @defgroup SAI_Block_Output_Drive SAI Block Output Drive
383 * @{
385 #define SAI_OUTPUTDRIVE_DISABLE ((uint32_t)0x00000000U)
386 #define SAI_OUTPUTDRIVE_ENABLE ((uint32_t)SAI_xCR1_OUTDRIV)
388 * @}
391 /** @defgroup SAI_Block_NoDivider SAI Block NoDivider
392 * @{
394 #define SAI_MASTERDIVIDER_ENABLE ((uint32_t)0x00000000U)
395 #define SAI_MASTERDIVIDER_DISABLE ((uint32_t)SAI_xCR1_NODIV)
397 * @}
401 /** @defgroup SAI_Block_FS_Definition SAI Block FS Definition
402 * @{
404 #define SAI_FS_STARTFRAME ((uint32_t)0x00000000U)
405 #define SAI_FS_CHANNEL_IDENTIFICATION ((uint32_t)SAI_xFRCR_FSDEF)
407 * @}
410 /** @defgroup SAI_Block_FS_Polarity SAI Block FS Polarity
411 * @{
413 #define SAI_FS_ACTIVE_LOW ((uint32_t)0x00000000U)
414 #define SAI_FS_ACTIVE_HIGH ((uint32_t)SAI_xFRCR_FSPOL)
416 * @}
419 /** @defgroup SAI_Block_FS_Offset SAI Block FS Offset
420 * @{
422 #define SAI_FS_FIRSTBIT ((uint32_t)0x00000000U)
423 #define SAI_FS_BEFOREFIRSTBIT ((uint32_t)SAI_xFRCR_FSOFF)
425 * @}
429 /** @defgroup SAI_Block_Slot_Size SAI Block Slot Size
430 * @{
432 #define SAI_SLOTSIZE_DATASIZE ((uint32_t)0x00000000U)
433 #define SAI_SLOTSIZE_16B ((uint32_t)SAI_xSLOTR_SLOTSZ_0)
434 #define SAI_SLOTSIZE_32B ((uint32_t)SAI_xSLOTR_SLOTSZ_1)
436 * @}
439 /** @defgroup SAI_Block_Slot_Active SAI Block Slot Active
440 * @{
442 #define SAI_SLOT_NOTACTIVE ((uint32_t)0x00000000U)
443 #define SAI_SLOTACTIVE_0 ((uint32_t)0x00000001U)
444 #define SAI_SLOTACTIVE_1 ((uint32_t)0x00000002U)
445 #define SAI_SLOTACTIVE_2 ((uint32_t)0x00000004U)
446 #define SAI_SLOTACTIVE_3 ((uint32_t)0x00000008U)
447 #define SAI_SLOTACTIVE_4 ((uint32_t)0x00000010U)
448 #define SAI_SLOTACTIVE_5 ((uint32_t)0x00000020U)
449 #define SAI_SLOTACTIVE_6 ((uint32_t)0x00000040U)
450 #define SAI_SLOTACTIVE_7 ((uint32_t)0x00000080U)
451 #define SAI_SLOTACTIVE_8 ((uint32_t)0x00000100U)
452 #define SAI_SLOTACTIVE_9 ((uint32_t)0x00000200U)
453 #define SAI_SLOTACTIVE_10 ((uint32_t)0x00000400U)
454 #define SAI_SLOTACTIVE_11 ((uint32_t)0x00000800U)
455 #define SAI_SLOTACTIVE_12 ((uint32_t)0x00001000U)
456 #define SAI_SLOTACTIVE_13 ((uint32_t)0x00002000U)
457 #define SAI_SLOTACTIVE_14 ((uint32_t)0x00004000U)
458 #define SAI_SLOTACTIVE_15 ((uint32_t)0x00008000U)
459 #define SAI_SLOTACTIVE_ALL ((uint32_t)0x0000FFFFU)
461 * @}
464 /** @defgroup SAI_Mono_Stereo_Mode SAI Mono Stereo Mode
465 * @{
467 #define SAI_STEREOMODE ((uint32_t)0x00000000U)
468 #define SAI_MONOMODE ((uint32_t)SAI_xCR1_MONO)
470 * @}
473 /** @defgroup SAI_TRIState_Management SAI TRIState Management
474 * @{
476 #define SAI_OUTPUT_NOTRELEASED ((uint32_t)0x00000000U)
477 #define SAI_OUTPUT_RELEASED ((uint32_t)SAI_xCR2_TRIS)
479 * @}
482 /** @defgroup SAI_Block_Fifo_Threshold SAI Block Fifo Threshold
483 * @{
485 #define SAI_FIFOTHRESHOLD_EMPTY ((uint32_t)0x00000000U)
486 #define SAI_FIFOTHRESHOLD_1QF ((uint32_t)(SAI_xCR2_FTH_0))
487 #define SAI_FIFOTHRESHOLD_HF ((uint32_t)(SAI_xCR2_FTH_1))
488 #define SAI_FIFOTHRESHOLD_3QF ((uint32_t)(SAI_xCR2_FTH_1 | SAI_xCR2_FTH_0))
489 #define SAI_FIFOTHRESHOLD_FULL ((uint32_t)(SAI_xCR2_FTH_2))
491 * @}
494 /** @defgroup SAI_Block_Companding_Mode SAI Block Companding Mode
495 * @{
497 #define SAI_NOCOMPANDING ((uint32_t)0x00000000U)
498 #define SAI_ULAW_1CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1))
499 #define SAI_ALAW_1CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0))
500 #define SAI_ULAW_2CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_CPL))
501 #define SAI_ALAW_2CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0 | SAI_xCR2_CPL))
503 * @}
506 /** @defgroup SAI_Block_Mute_Value SAI Block Mute Value
507 * @{
509 #define SAI_ZERO_VALUE ((uint32_t)0x00000000U)
510 #define SAI_LAST_SENT_VALUE ((uint32_t)SAI_xCR2_MUTEVAL)
512 * @}
515 /** @defgroup SAI_Block_Interrupts_Definition SAI Block Interrupts Definition
516 * @{
518 #define SAI_IT_OVRUDR ((uint32_t)SAI_xIMR_OVRUDRIE)
519 #define SAI_IT_MUTEDET ((uint32_t)SAI_xIMR_MUTEDETIE)
520 #define SAI_IT_WCKCFG ((uint32_t)SAI_xIMR_WCKCFGIE)
521 #define SAI_IT_FREQ ((uint32_t)SAI_xIMR_FREQIE)
522 #define SAI_IT_CNRDY ((uint32_t)SAI_xIMR_CNRDYIE)
523 #define SAI_IT_AFSDET ((uint32_t)SAI_xIMR_AFSDETIE)
524 #define SAI_IT_LFSDET ((uint32_t)SAI_xIMR_LFSDETIE)
526 * @}
529 /** @defgroup SAI_Block_Flags_Definition SAI Block Flags Definition
530 * @{
532 #define SAI_FLAG_OVRUDR ((uint32_t)SAI_xSR_OVRUDR)
533 #define SAI_FLAG_MUTEDET ((uint32_t)SAI_xSR_MUTEDET)
534 #define SAI_FLAG_WCKCFG ((uint32_t)SAI_xSR_WCKCFG)
535 #define SAI_FLAG_FREQ ((uint32_t)SAI_xSR_FREQ)
536 #define SAI_FLAG_CNRDY ((uint32_t)SAI_xSR_CNRDY)
537 #define SAI_FLAG_AFSDET ((uint32_t)SAI_xSR_AFSDET)
538 #define SAI_FLAG_LFSDET ((uint32_t)SAI_xSR_LFSDET)
540 * @}
543 /** @defgroup SAI_Block_Fifo_Status_Level SAI Block Fifo Status Level
544 * @{
546 #define SAI_FIFOSTATUS_EMPTY ((uint32_t)0x00000000U)
547 #define SAI_FIFOSTATUS_LESS1QUARTERFULL ((uint32_t)0x00010000U)
548 #define SAI_FIFOSTATUS_1QUARTERFULL ((uint32_t)0x00020000U)
549 #define SAI_FIFOSTATUS_HALFFULL ((uint32_t)0x00030000U)
550 #define SAI_FIFOSTATUS_3QUARTERFULL ((uint32_t)0x00040000U)
551 #define SAI_FIFOSTATUS_FULL ((uint32_t)0x00050000U)
553 * @}
557 * @}
560 /* Exported macro ------------------------------------------------------------*/
562 /** @defgroup SAI_Exported_Macros SAI Exported Macros
563 * @brief macros to handle interrupts and specific configurations
564 * @{
567 /** @brief Reset SAI handle state.
568 * @param __HANDLE__: specifies the SAI Handle.
569 * @retval None
571 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SAI_STATE_RESET)
573 /** @brief Enable or disable the specified SAI interrupts.
574 * @param __HANDLE__: specifies the SAI Handle.
575 * @param __INTERRUPT__: specifies the interrupt source to enable or disable.
576 * This parameter can be one of the following values:
577 * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
578 * @arg SAI_IT_MUTEDET: Mute detection interrupt enable
579 * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
580 * @arg SAI_IT_FREQ: FIFO request interrupt enable
581 * @arg SAI_IT_CNRDY: Codec not ready interrupt enable
582 * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
583 * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
584 * @retval None
586 #define __HAL_SAI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR |= (__INTERRUPT__))
587 #define __HAL_SAI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR &= (~(__INTERRUPT__)))
589 /** @brief Check whether the specified SAI interrupt source is enabled or not.
590 * @param __HANDLE__: specifies the SAI Handle.
591 * @param __INTERRUPT__: specifies the SAI interrupt source to check.
592 * This parameter can be one of the following values:
593 * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
594 * @arg SAI_IT_MUTEDET: Mute detection interrupt enable
595 * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
596 * @arg SAI_IT_FREQ: FIFO request interrupt enable
597 * @arg SAI_IT_CNRDY: Codec not ready interrupt enable
598 * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
599 * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
600 * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
602 #define __HAL_SAI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IMR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
604 /** @brief Check whether the specified SAI flag is set or not.
605 * @param __HANDLE__: specifies the SAI Handle.
606 * @param __FLAG__: specifies the flag to check.
607 * This parameter can be one of the following values:
608 * @arg SAI_FLAG_OVRUDR: Overrun underrun flag.
609 * @arg SAI_FLAG_MUTEDET: Mute detection flag.
610 * @arg SAI_FLAG_WCKCFG: Wrong Clock Configuration flag.
611 * @arg SAI_FLAG_FREQ: FIFO request flag.
612 * @arg SAI_FLAG_CNRDY: Codec not ready flag.
613 * @arg SAI_FLAG_AFSDET: Anticipated frame synchronization detection flag.
614 * @arg SAI_FLAG_LFSDET: Late frame synchronization detection flag.
615 * @retval The new state of __FLAG__ (TRUE or FALSE).
617 #define __HAL_SAI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
619 /** @brief Clear the specified SAI pending flag.
620 * @param __HANDLE__: specifies the SAI Handle.
621 * @param __FLAG__: specifies the flag to check.
622 * This parameter can be any combination of the following values:
623 * @arg SAI_FLAG_OVRUDR: Clear Overrun underrun
624 * @arg SAI_FLAG_MUTEDET: Clear Mute detection
625 * @arg SAI_FLAG_WCKCFG: Clear Wrong Clock Configuration
626 * @arg SAI_FLAG_FREQ: Clear FIFO request
627 * @arg SAI_FLAG_CNRDY: Clear Codec not ready
628 * @arg SAI_FLAG_AFSDET: Clear Anticipated frame synchronization detection
629 * @arg SAI_FLAG_LFSDET: Clear Late frame synchronization detection
631 * @retval None
633 #define __HAL_SAI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__))
635 #define __HAL_SAI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SAI_xCR1_SAIEN)
636 #define __HAL_SAI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~SAI_xCR1_SAIEN)
639 * @}
642 /* Exported functions --------------------------------------------------------*/
644 /** @addtogroup SAI_Exported_Functions
645 * @{
648 /* Initialization/de-initialization functions ********************************/
650 /** @addtogroup SAI_Exported_Functions_Group1
651 * @{
653 HAL_StatusTypeDef HAL_SAI_InitProtocol(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot);
654 HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai);
655 HAL_StatusTypeDef HAL_SAI_DeInit (SAI_HandleTypeDef *hsai);
656 void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai);
657 void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai);
660 * @}
663 /* I/O operation functions ***************************************************/
665 /** @addtogroup SAI_Exported_Functions_Group2
666 * @{
668 /* Blocking mode: Polling */
669 HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
670 HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
672 /* Non-Blocking mode: Interrupt */
673 HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
674 HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
676 /* Non-Blocking mode: DMA */
677 HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
678 HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
679 HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai);
680 HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai);
681 HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai);
683 /* Abort function */
684 HAL_StatusTypeDef HAL_SAI_Abort(SAI_HandleTypeDef *hsai);
686 /* Mute management */
687 HAL_StatusTypeDef HAL_SAI_EnableTxMuteMode(SAI_HandleTypeDef *hsai, uint16_t val);
688 HAL_StatusTypeDef HAL_SAI_DisableTxMuteMode(SAI_HandleTypeDef *hsai);
689 HAL_StatusTypeDef HAL_SAI_EnableRxMuteMode(SAI_HandleTypeDef *hsai, SAIcallback callback, uint16_t counter);
690 HAL_StatusTypeDef HAL_SAI_DisableRxMuteMode(SAI_HandleTypeDef *hsai);
692 /* SAI IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
693 void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai);
694 void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai);
695 void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai);
696 void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai);
697 void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai);
698 void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai);
700 * @}
703 /** @addtogroup SAI_Exported_Functions_Group3
704 * @{
706 /* Peripheral State functions ************************************************/
707 HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai);
708 uint32_t HAL_SAI_GetError(SAI_HandleTypeDef *hsai);
710 * @}
714 * @}
717 /* Private macros ------------------------------------------------------------*/
718 /** @addtogroup SAI_Private_Macros
719 * @{
721 #define IS_SAI_BLOCK_SYNCEXT(STATE) (((STATE) == SAI_SYNCEXT_DISABLE) ||\
722 ((STATE) == SAI_SYNCEXT_OUTBLOCKA_ENABLE) ||\
723 ((STATE) == SAI_SYNCEXT_OUTBLOCKB_ENABLE))
725 #define IS_SAI_SUPPORTED_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_I2S_STANDARD) ||\
726 ((PROTOCOL) == SAI_I2S_MSBJUSTIFIED) ||\
727 ((PROTOCOL) == SAI_I2S_LSBJUSTIFIED) ||\
728 ((PROTOCOL) == SAI_PCM_LONG) ||\
729 ((PROTOCOL) == SAI_PCM_SHORT))
731 #define IS_SAI_PROTOCOL_DATASIZE(DATASIZE) (((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BIT) ||\
732 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BITEXTENDED) ||\
733 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_24BIT) ||\
734 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_32BIT))
736 #define IS_SAI_AUDIO_FREQUENCY(AUDIO) (((AUDIO) == SAI_AUDIO_FREQUENCY_192K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_96K) || \
737 ((AUDIO) == SAI_AUDIO_FREQUENCY_48K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_44K) || \
738 ((AUDIO) == SAI_AUDIO_FREQUENCY_32K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_22K) || \
739 ((AUDIO) == SAI_AUDIO_FREQUENCY_16K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_11K) || \
740 ((AUDIO) == SAI_AUDIO_FREQUENCY_8K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_MCKDIV))
742 #define IS_SAI_BLOCK_MODE(MODE) (((MODE) == SAI_MODEMASTER_TX) || \
743 ((MODE) == SAI_MODEMASTER_RX) || \
744 ((MODE) == SAI_MODESLAVE_TX) || \
745 ((MODE) == SAI_MODESLAVE_RX))
747 #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_FREE_PROTOCOL) || \
748 ((PROTOCOL) == SAI_AC97_PROTOCOL) || \
749 ((PROTOCOL) == SAI_SPDIF_PROTOCOL))
751 #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DATASIZE_8) || \
752 ((DATASIZE) == SAI_DATASIZE_10) || \
753 ((DATASIZE) == SAI_DATASIZE_16) || \
754 ((DATASIZE) == SAI_DATASIZE_20) || \
755 ((DATASIZE) == SAI_DATASIZE_24) || \
756 ((DATASIZE) == SAI_DATASIZE_32))
758 #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FIRSTBIT_MSB) || \
759 ((BIT) == SAI_FIRSTBIT_LSB))
761 #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_CLOCKSTROBING_FALLINGEDGE) || \
762 ((CLOCK) == SAI_CLOCKSTROBING_RISINGEDGE))
764 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS) || \
765 ((SYNCHRO) == SAI_SYNCHRONOUS) || \
766 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI1) || \
767 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI2))
769 #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OUTPUTDRIVE_DISABLE) || \
770 ((DRIVE) == SAI_OUTPUTDRIVE_ENABLE))
772 #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MASTERDIVIDER_ENABLE) || \
773 ((NODIVIDER) == SAI_MASTERDIVIDER_DISABLE))
775 #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63)
777 #define IS_SAI_BLOCK_MUTE_VALUE(VALUE) (((VALUE) == SAI_ZERO_VALUE) || \
778 ((VALUE) == SAI_LAST_SENT_VALUE))
780 #define IS_SAI_BLOCK_COMPANDING_MODE(MODE) (((MODE) == SAI_NOCOMPANDING) || \
781 ((MODE) == SAI_ULAW_1CPL_COMPANDING) || \
782 ((MODE) == SAI_ALAW_1CPL_COMPANDING) || \
783 ((MODE) == SAI_ULAW_2CPL_COMPANDING) || \
784 ((MODE) == SAI_ALAW_2CPL_COMPANDING))
786 #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_FIFOTHRESHOLD_EMPTY) || \
787 ((THRESHOLD) == SAI_FIFOTHRESHOLD_1QF) || \
788 ((THRESHOLD) == SAI_FIFOTHRESHOLD_HF) || \
789 ((THRESHOLD) == SAI_FIFOTHRESHOLD_3QF) || \
790 ((THRESHOLD) == SAI_FIFOTHRESHOLD_FULL))
792 #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_OUTPUT_NOTRELEASED) ||\
793 ((STATE) == SAI_OUTPUT_RELEASED))
795 #define IS_SAI_MONO_STEREO_MODE(MODE) (((MODE) == SAI_MONOMODE) ||\
796 ((MODE) == SAI_STEREOMODE))
798 #define IS_SAI_SLOT_ACTIVE(ACTIVE) ((ACTIVE) <= SAI_SLOTACTIVE_ALL)
800 #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1 <= (NUMBER)) && ((NUMBER) <= 16))
802 #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SLOTSIZE_DATASIZE) || \
803 ((SIZE) == SAI_SLOTSIZE_16B) || \
804 ((SIZE) == SAI_SLOTSIZE_32B))
806 #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24)
808 #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FIRSTBIT) || \
809 ((OFFSET) == SAI_FS_BEFOREFIRSTBIT))
811 #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ACTIVE_LOW) || \
812 ((POLARITY) == SAI_FS_ACTIVE_HIGH))
814 #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_STARTFRAME) || \
815 ((DEFINITION) == SAI_FS_CHANNEL_IDENTIFICATION))
817 #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 15)
819 #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8 <= (LENGTH)) && ((LENGTH) <= 256))
821 #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1 <= (LENGTH)) && ((LENGTH) <= 128))
824 * @}
827 /* Private functions ---------------------------------------------------------*/
828 /** @defgroup SAI_Private_Functions SAI Private Functions
829 * @{
833 * @}
837 * @}
841 * @}
844 #ifdef __cplusplus
846 #endif
848 #endif /* __STM32F7xx_HAL_SAI_H */
850 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/