Merge pull request #11198 from SteveCEvans/sce_rc2
[betaflight.git] / lib / main / STM32F4 / Drivers / STM32F4xx_HAL_Driver / Inc / stm32f4xx_hal_sai.h
blobb8e66699ddf7b05e370b95935e30749ea14e7503
1 /**
2 ******************************************************************************
3 * @file stm32f4xx_hal_sai.h
4 * @author MCD Application Team
5 * @version V1.7.1
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 __STM32F4xx_HAL_SAI_H
40 #define __STM32F4xx_HAL_SAI_H
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal_def.h"
49 /** @addtogroup STM32F4xx_HAL_Driver
50 * @{
52 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
53 defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || \
54 defined(STM32F423xx)
56 /** @addtogroup SAI
57 * @{
60 /* Exported types ------------------------------------------------------------*/
61 /** @defgroup SAI_Exported_Types SAI Exported Types
62 * @{
65 /**
66 * @brief HAL State structures definition
68 typedef enum
70 HAL_SAI_STATE_RESET = 0x00U, /*!< SAI not yet initialized or disabled */
71 HAL_SAI_STATE_READY = 0x01U, /*!< SAI initialized and ready for use */
72 HAL_SAI_STATE_BUSY = 0x02U, /*!< SAI internal process is ongoing */
73 HAL_SAI_STATE_BUSY_TX = 0x12U, /*!< Data transmission process is ongoing */
74 HAL_SAI_STATE_BUSY_RX = 0x22U, /*!< Data reception process is ongoing */
75 HAL_SAI_STATE_TIMEOUT = 0x03U, /*!< SAI timeout state */
76 HAL_SAI_STATE_ERROR = 0x04U /*!< SAI error state */
77 }HAL_SAI_StateTypeDef;
79 /**
80 * @brief SAI Callback prototype
82 typedef void (*SAIcallback)(void);
84 /** @defgroup SAI_Init_Structure_definition SAI Init Structure definition
85 * @brief SAI Init Structure definition
86 * @{
88 typedef struct
90 uint32_t AudioMode; /*!< Specifies the SAI Block audio Mode.
91 This parameter can be a value of @ref SAI_Block_Mode */
93 uint32_t Synchro; /*!< Specifies SAI Block synchronization
94 This parameter can be a value of @ref SAI_Block_Synchronization */
96 uint32_t SynchroExt; /*!< Specifies SAI external output synchronization, this setup is common
97 for BlockA and BlockB
98 This parameter can be a value of @ref SAI_Block_SyncExt
99 @note: If both audio blocks of same SAI are used, this parameter has
100 to be set to the same value for each audio block */
102 uint32_t OutputDrive; /*!< Specifies when SAI Block outputs are driven.
103 This parameter can be a value of @ref SAI_Block_Output_Drive
104 @note this value has to be set before enabling the audio block
105 but after the audio block configuration. */
107 uint32_t NoDivider; /*!< Specifies whether master clock will be divided or not.
108 This parameter can be a value of @ref SAI_Block_NoDivider
109 @note If bit NODIV in the SAI_xCR1 register is cleared, the frame length
110 should be aligned to a number equal to a power of 2, from 8 to 256.
111 If bit NODIV in the SAI_xCR1 register is set, the frame length can
112 take any of the values without constraint since the input clock of
113 the audio block should be equal to the bit clock.
114 There is no MCLK_x clock which can be output. */
116 uint32_t FIFOThreshold; /*!< Specifies SAI Block FIFO threshold.
117 This parameter can be a value of @ref SAI_Block_Fifo_Threshold */
119 uint32_t ClockSource; /*!< Specifies the SAI Block x Clock source.
120 This parameter is not used for STM32F446xx devices. */
122 uint32_t AudioFrequency; /*!< Specifies the audio frequency sampling.
123 This parameter can be a value of @ref SAI_Audio_Frequency */
125 uint32_t Mckdiv; /*!< Specifies the master clock divider, the parameter will be used if for
126 AudioFrequency the user choice
127 This parameter must be a number between Min_Data = 0 and Max_Data = 15 */
129 uint32_t MonoStereoMode; /*!< Specifies if the mono or stereo mode is selected.
130 This parameter can be a value of @ref SAI_Mono_Stereo_Mode */
132 uint32_t CompandingMode; /*!< Specifies the companding mode type.
133 This parameter can be a value of @ref SAI_Block_Companding_Mode */
135 uint32_t TriState; /*!< Specifies the companding mode type.
136 This parameter can be a value of @ref SAI_TRIState_Management */
138 /* This part of the structure is automatically filled if your are using the high level intialisation
139 function HAL_SAI_InitProtocol */
141 uint32_t Protocol; /*!< Specifies the SAI Block protocol.
142 This parameter can be a value of @ref SAI_Block_Protocol */
144 uint32_t DataSize; /*!< Specifies the SAI Block data size.
145 This parameter can be a value of @ref SAI_Block_Data_Size */
147 uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
148 This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission */
150 uint32_t ClockStrobing; /*!< Specifies the SAI Block clock strobing edge sensitivity.
151 This parameter can be a value of @ref SAI_Block_Clock_Strobing */
152 }SAI_InitTypeDef;
154 * @}
157 /** @defgroup SAI_Frame_Structure_definition SAI Frame Structure definition
158 * @brief SAI Frame Init structure definition
159 * @{
161 typedef struct
163 uint32_t FrameLength; /*!< Specifies the Frame length, the number of SCK clocks for each audio frame.
164 This parameter must be a number between Min_Data = 8 and Max_Data = 256.
165 @note If master clock MCLK_x pin is declared as an output, the frame length
166 should be aligned to a number equal to power of 2 in order to keep
167 in an audio frame, an integer number of MCLK pulses by bit Clock. */
169 uint32_t ActiveFrameLength; /*!< Specifies the Frame synchronization active level length.
170 This Parameter specifies the length in number of bit clock (SCK + 1)
171 of the active level of FS signal in audio frame.
172 This parameter must be a number between Min_Data = 1 and Max_Data = 128 */
174 uint32_t FSDefinition; /*!< Specifies the Frame synchronization definition.
175 This parameter can be a value of @ref SAI_Block_FS_Definition */
177 uint32_t FSPolarity; /*!< Specifies the Frame synchronization Polarity.
178 This parameter can be a value of @ref SAI_Block_FS_Polarity */
180 uint32_t FSOffset; /*!< Specifies the Frame synchronization Offset.
181 This parameter can be a value of @ref SAI_Block_FS_Offset */
182 }SAI_FrameInitTypeDef;
184 * @}
187 /** @defgroup SAI_Slot_Structure_definition SAI Slot Structure definition
188 * @brief SAI Block Slot Init Structure definition
189 * @{
191 typedef struct
193 uint32_t FirstBitOffset; /*!< Specifies the position of first data transfer bit in the slot.
194 This parameter must be a number between Min_Data = 0 and Max_Data = 24 */
196 uint32_t SlotSize; /*!< Specifies the Slot Size.
197 This parameter can be a value of @ref SAI_Block_Slot_Size */
199 uint32_t SlotNumber; /*!< Specifies the number of slot in the audio frame.
200 This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
202 uint32_t SlotActive; /*!< Specifies the slots in audio frame that will be activated.
203 This parameter can be a value of @ref SAI_Block_Slot_Active */
204 }SAI_SlotInitTypeDef;
207 * @}
210 /** @defgroup SAI_Handle_Structure_definition SAI Handle Structure definition
211 * @brief SAI handle Structure definition
212 * @{
214 typedef struct __SAI_HandleTypeDef
216 SAI_Block_TypeDef *Instance; /*!< SAI Blockx registers base address */
218 SAI_InitTypeDef Init; /*!< SAI communication parameters */
220 SAI_FrameInitTypeDef FrameInit; /*!< SAI Frame configuration parameters */
222 SAI_SlotInitTypeDef SlotInit; /*!< SAI Slot configuration parameters */
224 uint8_t *pBuffPtr; /*!< Pointer to SAI transfer Buffer */
226 uint16_t XferSize; /*!< SAI transfer size */
228 uint16_t XferCount; /*!< SAI transfer counter */
230 DMA_HandleTypeDef *hdmatx; /*!< SAI Tx DMA handle parameters */
232 DMA_HandleTypeDef *hdmarx; /*!< SAI Rx DMA handle parameters */
234 SAIcallback mutecallback;/*!< SAI mute callback */
236 void (*InterruptServiceRoutine)(struct __SAI_HandleTypeDef *hsai); /* function pointer for IRQ handler */
238 HAL_LockTypeDef Lock; /*!< SAI locking object */
240 __IO HAL_SAI_StateTypeDef State; /*!< SAI communication state */
242 __IO uint32_t ErrorCode; /*!< SAI Error code */
243 }SAI_HandleTypeDef;
245 * @}
249 * @}
252 /* Exported constants --------------------------------------------------------*/
254 /** @defgroup SAI_Exported_Constants SAI Exported Constants
255 * @{
258 /** @defgroup SAI_Error_Code SAI Error Code
259 * @{
261 #define HAL_SAI_ERROR_NONE 0x00000000U /*!< No error */
262 #define HAL_SAI_ERROR_OVR 0x00000001U /*!< Overrun Error */
263 #define HAL_SAI_ERROR_UDR 0x00000002U /*!< Underrun error */
264 #define HAL_SAI_ERROR_AFSDET 0x00000004U /*!< Anticipated Frame synchronisation detection */
265 #define HAL_SAI_ERROR_LFSDET 0x00000008U /*!< Late Frame synchronisation detection */
266 #define HAL_SAI_ERROR_CNREADY 0x00000010U /*!< codec not ready */
267 #define HAL_SAI_ERROR_WCKCFG 0x00000020U /*!< Wrong clock configuration */
268 #define HAL_SAI_ERROR_TIMEOUT 0x00000040U /*!< Timeout error */
269 #define HAL_SAI_ERROR_DMA 0x00000080U /*!< DMA error */
271 * @}
274 /** @defgroup SAI_Block_SyncExt SAI External synchronisation
275 * @{
277 #define SAI_SYNCEXT_DISABLE 0U
278 #define SAI_SYNCEXT_OUTBLOCKA_ENABLE 1U
279 #define SAI_SYNCEXT_OUTBLOCKB_ENABLE 2U
281 * @}
284 /** @defgroup SAI_Protocol SAI Supported protocol
285 * @{
287 #define SAI_I2S_STANDARD 0U
288 #define SAI_I2S_MSBJUSTIFIED 1U
289 #define SAI_I2S_LSBJUSTIFIED 2U
290 #define SAI_PCM_LONG 3U
291 #define SAI_PCM_SHORT 4U
293 * @}
296 /** @defgroup SAI_Protocol_DataSize SAI protocol data size
297 * @{
299 #define SAI_PROTOCOL_DATASIZE_16BIT 0U
300 #define SAI_PROTOCOL_DATASIZE_16BITEXTENDED 1U
301 #define SAI_PROTOCOL_DATASIZE_24BIT 2U
302 #define SAI_PROTOCOL_DATASIZE_32BIT 3U
304 * @}
307 /** @defgroup SAI_Audio_Frequency SAI Audio Frequency
308 * @{
310 #define SAI_AUDIO_FREQUENCY_192K 192000U
311 #define SAI_AUDIO_FREQUENCY_96K 96000U
312 #define SAI_AUDIO_FREQUENCY_48K 48000U
313 #define SAI_AUDIO_FREQUENCY_44K 44100U
314 #define SAI_AUDIO_FREQUENCY_32K 32000U
315 #define SAI_AUDIO_FREQUENCY_22K 22050U
316 #define SAI_AUDIO_FREQUENCY_16K 16000U
317 #define SAI_AUDIO_FREQUENCY_11K 11025U
318 #define SAI_AUDIO_FREQUENCY_8K 8000U
319 #define SAI_AUDIO_FREQUENCY_MCKDIV 0U
321 * @}
324 /** @defgroup SAI_Block_Mode SAI Block Mode
325 * @{
327 #define SAI_MODEMASTER_TX 0x00000000U
328 #define SAI_MODEMASTER_RX ((uint32_t)SAI_xCR1_MODE_0)
329 #define SAI_MODESLAVE_TX ((uint32_t)SAI_xCR1_MODE_1)
330 #define SAI_MODESLAVE_RX ((uint32_t)(SAI_xCR1_MODE_1 | SAI_xCR1_MODE_0))
332 * @}
335 /** @defgroup SAI_Block_Protocol SAI Block Protocol
336 * @{
338 #define SAI_FREE_PROTOCOL 0x00000000U
339 #define SAI_SPDIF_PROTOCOL ((uint32_t)SAI_xCR1_PRTCFG_0)
340 #define SAI_AC97_PROTOCOL ((uint32_t)SAI_xCR1_PRTCFG_1)
342 * @}
345 /** @defgroup SAI_Block_Data_Size SAI Block Data Size
346 * @{
348 #define SAI_DATASIZE_8 ((uint32_t)SAI_xCR1_DS_1)
349 #define SAI_DATASIZE_10 ((uint32_t)(SAI_xCR1_DS_1 | SAI_xCR1_DS_0))
350 #define SAI_DATASIZE_16 ((uint32_t)SAI_xCR1_DS_2)
351 #define SAI_DATASIZE_20 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_0))
352 #define SAI_DATASIZE_24 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_1))
353 #define SAI_DATASIZE_32 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_1 | SAI_xCR1_DS_0))
355 * @}
358 /** @defgroup SAI_Block_MSB_LSB_transmission SAI Block MSB LSB transmission
359 * @{
361 #define SAI_FIRSTBIT_MSB 0x00000000U
362 #define SAI_FIRSTBIT_LSB ((uint32_t)SAI_xCR1_LSBFIRST)
364 * @}
367 /** @defgroup SAI_Block_Clock_Strobing SAI Block Clock Strobing
368 * @{
370 #define SAI_CLOCKSTROBING_FALLINGEDGE 0U
371 #define SAI_CLOCKSTROBING_RISINGEDGE 1U
373 * @}
376 /** @defgroup SAI_Block_Synchronization SAI Block Synchronization
377 * @{
379 #define SAI_ASYNCHRONOUS 0U /*!< Asynchronous */
380 #define SAI_SYNCHRONOUS 1U /*!< Synchronous with other block of same SAI */
381 #define SAI_SYNCHRONOUS_EXT_SAI1 2U /*!< Synchronous with other SAI, SAI1 */
382 #define SAI_SYNCHRONOUS_EXT_SAI2 3U /*!< Synchronous with other SAI, SAI2 */
384 * @}
387 /** @defgroup SAI_Block_Output_Drive SAI Block Output Drive
388 * @{
390 #define SAI_OUTPUTDRIVE_DISABLE 0x00000000U
391 #define SAI_OUTPUTDRIVE_ENABLE ((uint32_t)SAI_xCR1_OUTDRIV)
393 * @}
396 /** @defgroup SAI_Block_NoDivider SAI Block NoDivider
397 * @{
399 #define SAI_MASTERDIVIDER_ENABLE 0x00000000U
400 #define SAI_MASTERDIVIDER_DISABLE ((uint32_t)SAI_xCR1_NODIV)
402 * @}
405 /** @defgroup SAI_Block_FS_Definition SAI Block FS Definition
406 * @{
408 #define SAI_FS_STARTFRAME 0x00000000U
409 #define SAI_FS_CHANNEL_IDENTIFICATION ((uint32_t)SAI_xFRCR_FSDEF)
411 * @}
414 /** @defgroup SAI_Block_FS_Polarity SAI Block FS Polarity
415 * @{
417 #define SAI_FS_ACTIVE_LOW 0x00000000U
418 #define SAI_FS_ACTIVE_HIGH ((uint32_t)SAI_xFRCR_FSPOL)
420 * @}
423 /** @defgroup SAI_Block_FS_Offset SAI Block FS Offset
424 * @{
426 #define SAI_FS_FIRSTBIT 0x00000000U
427 #define SAI_FS_BEFOREFIRSTBIT ((uint32_t)SAI_xFRCR_FSOFF)
429 * @}
432 /** @defgroup SAI_Block_Slot_Size SAI Block Slot Size
433 * @{
435 #define SAI_SLOTSIZE_DATASIZE 0x00000000U
436 #define SAI_SLOTSIZE_16B ((uint32_t)SAI_xSLOTR_SLOTSZ_0)
437 #define SAI_SLOTSIZE_32B ((uint32_t)SAI_xSLOTR_SLOTSZ_1)
439 * @}
442 /** @defgroup SAI_Block_Slot_Active SAI Block Slot Active
443 * @{
445 #define SAI_SLOT_NOTACTIVE 0x00000000U
446 #define SAI_SLOTACTIVE_0 0x00000001U
447 #define SAI_SLOTACTIVE_1 0x00000002U
448 #define SAI_SLOTACTIVE_2 0x00000004U
449 #define SAI_SLOTACTIVE_3 0x00000008U
450 #define SAI_SLOTACTIVE_4 0x00000010U
451 #define SAI_SLOTACTIVE_5 0x00000020U
452 #define SAI_SLOTACTIVE_6 0x00000040U
453 #define SAI_SLOTACTIVE_7 0x00000080U
454 #define SAI_SLOTACTIVE_8 0x00000100U
455 #define SAI_SLOTACTIVE_9 0x00000200U
456 #define SAI_SLOTACTIVE_10 0x00000400U
457 #define SAI_SLOTACTIVE_11 0x00000800U
458 #define SAI_SLOTACTIVE_12 0x00001000U
459 #define SAI_SLOTACTIVE_13 0x00002000U
460 #define SAI_SLOTACTIVE_14 0x00004000U
461 #define SAI_SLOTACTIVE_15 0x00008000U
462 #define SAI_SLOTACTIVE_ALL 0x0000FFFFU
464 * @}
467 /** @defgroup SAI_Mono_Stereo_Mode SAI Mono Stereo Mode
468 * @{
470 #define SAI_STEREOMODE 0x00000000U
471 #define SAI_MONOMODE ((uint32_t)SAI_xCR1_MONO)
473 * @}
476 /** @defgroup SAI_TRIState_Management SAI TRIState Management
477 * @{
479 #define SAI_OUTPUT_NOTRELEASED 0x00000000U
480 #define SAI_OUTPUT_RELEASED ((uint32_t)SAI_xCR2_TRIS)
482 * @}
485 /** @defgroup SAI_Block_Fifo_Threshold SAI Block Fifo Threshold
486 * @{
488 #define SAI_FIFOTHRESHOLD_EMPTY 0x00000000U
489 #define SAI_FIFOTHRESHOLD_1QF ((uint32_t)(SAI_xCR2_FTH_0))
490 #define SAI_FIFOTHRESHOLD_HF ((uint32_t)(SAI_xCR2_FTH_1))
491 #define SAI_FIFOTHRESHOLD_3QF ((uint32_t)(SAI_xCR2_FTH_1 | SAI_xCR2_FTH_0))
492 #define SAI_FIFOTHRESHOLD_FULL ((uint32_t)(SAI_xCR2_FTH_2))
494 * @}
497 /** @defgroup SAI_Block_Companding_Mode SAI Block Companding Mode
498 * @{
500 #define SAI_NOCOMPANDING 0x00000000U
501 #define SAI_ULAW_1CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1))
502 #define SAI_ALAW_1CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0))
503 #define SAI_ULAW_2CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_CPL))
504 #define SAI_ALAW_2CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0 | SAI_xCR2_CPL))
506 * @}
509 /** @defgroup SAI_Block_Mute_Value SAI Block Mute Value
510 * @{
512 #define SAI_ZERO_VALUE 0x00000000U
513 #define SAI_LAST_SENT_VALUE ((uint32_t)SAI_xCR2_MUTEVAL)
515 * @}
518 /** @defgroup SAI_Block_Interrupts_Definition SAI Block Interrupts Definition
519 * @{
521 #define SAI_IT_OVRUDR ((uint32_t)SAI_xIMR_OVRUDRIE)
522 #define SAI_IT_MUTEDET ((uint32_t)SAI_xIMR_MUTEDETIE)
523 #define SAI_IT_WCKCFG ((uint32_t)SAI_xIMR_WCKCFGIE)
524 #define SAI_IT_FREQ ((uint32_t)SAI_xIMR_FREQIE)
525 #define SAI_IT_CNRDY ((uint32_t)SAI_xIMR_CNRDYIE)
526 #define SAI_IT_AFSDET ((uint32_t)SAI_xIMR_AFSDETIE)
527 #define SAI_IT_LFSDET ((uint32_t)SAI_xIMR_LFSDETIE)
529 * @}
532 /** @defgroup SAI_Block_Flags_Definition SAI Block Flags Definition
533 * @{
535 #define SAI_FLAG_OVRUDR ((uint32_t)SAI_xSR_OVRUDR)
536 #define SAI_FLAG_MUTEDET ((uint32_t)SAI_xSR_MUTEDET)
537 #define SAI_FLAG_WCKCFG ((uint32_t)SAI_xSR_WCKCFG)
538 #define SAI_FLAG_FREQ ((uint32_t)SAI_xSR_FREQ)
539 #define SAI_FLAG_CNRDY ((uint32_t)SAI_xSR_CNRDY)
540 #define SAI_FLAG_AFSDET ((uint32_t)SAI_xSR_AFSDET)
541 #define SAI_FLAG_LFSDET ((uint32_t)SAI_xSR_LFSDET)
543 * @}
546 /** @defgroup SAI_Block_Fifo_Status_Level SAI Block Fifo Status Level
547 * @{
549 #define SAI_FIFOSTATUS_EMPTY 0x00000000U
550 #define SAI_FIFOSTATUS_LESS1QUARTERFULL 0x00010000U
551 #define SAI_FIFOSTATUS_1QUARTERFULL 0x00020000U
552 #define SAI_FIFOSTATUS_HALFFULL 0x00030000U
553 #define SAI_FIFOSTATUS_3QUARTERFULL 0x00040000U
554 #define SAI_FIFOSTATUS_FULL 0x00050000U
556 * @}
560 * @}
563 /* Exported macro ------------------------------------------------------------*/
565 /** @defgroup SAI_Exported_Macros SAI Exported Macros
566 * @brief macros to handle interrupts and specific configurations
567 * @{
570 /** @brief Reset SAI handle state
571 * @param __HANDLE__: specifies the SAI Handle.
572 * @retval NoneS
574 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SAI_STATE_RESET)
576 /** @brief Enable or disable the specified SAI interrupts.
577 * @param __HANDLE__: specifies the SAI Handle.
578 * @param __INTERRUPT__: specifies the interrupt source to enable or disable.
579 * This parameter can be one of the following values:
580 * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
581 * @arg SAI_IT_MUTEDET: Mute detection interrupt enable
582 * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
583 * @arg SAI_IT_FREQ: FIFO request interrupt enable
584 * @arg SAI_IT_CNRDY: Codec not ready interrupt enable
585 * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
586 * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
587 * @retval None
589 #define __HAL_SAI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR |= (__INTERRUPT__))
590 #define __HAL_SAI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR &= (~(__INTERRUPT__)))
592 /** @brief Check if the specified SAI interrupt source is enabled or disabled.
593 * @param __HANDLE__: specifies the SAI Handle.
594 * This parameter can be SAI where x: 1, 2, or 3 to select the SAI peripheral.
595 * @param __INTERRUPT__: specifies the SAI interrupt source to check.
596 * This parameter can be one of the following values:
597 * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
598 * @arg SAI_IT_MUTEDET: Mute detection interrupt enable
599 * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
600 * @arg SAI_IT_FREQ: FIFO request interrupt enable
601 * @arg SAI_IT_CNRDY: Codec not ready interrupt enable
602 * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
603 * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
604 * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
606 #define __HAL_SAI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IMR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
608 /** @brief Check whether the specified SAI flag is set or not.
609 * @param __HANDLE__: specifies the SAI Handle.
610 * @param __FLAG__: specifies the flag to check.
611 * This parameter can be one of the following values:
612 * @arg SAI_FLAG_OVRUDR: Overrun underrun flag.
613 * @arg SAI_FLAG_MUTEDET: Mute detection flag.
614 * @arg SAI_FLAG_WCKCFG: Wrong Clock Configuration flag.
615 * @arg SAI_FLAG_FREQ: FIFO request flag.
616 * @arg SAI_FLAG_CNRDY: Codec not ready flag.
617 * @arg SAI_FLAG_AFSDET: Anticipated frame synchronization detection flag.
618 * @arg SAI_FLAG_LFSDET: Late frame synchronization detection flag.
619 * @retval The new state of __FLAG__ (TRUE or FALSE).
621 #define __HAL_SAI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
623 /** @brief Clear the specified SAI pending flag.
624 * @param __HANDLE__: specifies the SAI Handle.
625 * @param __FLAG__: specifies the flag to check.
626 * This parameter can be any combination of the following values:
627 * @arg SAI_FLAG_OVRUDR: Clear Overrun underrun
628 * @arg SAI_FLAG_MUTEDET: Clear Mute detection
629 * @arg SAI_FLAG_WCKCFG: Clear Wrong Clock Configuration
630 * @arg SAI_FLAG_FREQ: Clear FIFO request
631 * @arg SAI_FLAG_CNRDY: Clear Codec not ready
632 * @arg SAI_FLAG_AFSDET: Clear Anticipated frame synchronization detection
633 * @arg SAI_FLAG_LFSDET: Clear Late frame synchronization detection
634 * @retval None
636 #define __HAL_SAI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__))
638 /** @brief Enable SAI
639 * @param __HANDLE__: specifies the SAI Handle.
640 * @retval None
642 #define __HAL_SAI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SAI_xCR1_SAIEN)
644 /** @brief Disable SAI
645 * @param __HANDLE__: specifies the SAI Handle.
646 * @retval None
648 #define __HAL_SAI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~SAI_xCR1_SAIEN)
651 * @}
654 /* Include RCC SAI Extension module */
655 #include "stm32f4xx_hal_sai_ex.h"
657 /* Exported functions --------------------------------------------------------*/
659 /** @addtogroup SAI_Exported_Functions
660 * @{
663 /* Initialization/de-initialization functions **********************************/
664 /** @addtogroup SAI_Exported_Functions_Group1
665 * @{
667 HAL_StatusTypeDef HAL_SAI_InitProtocol(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot);
668 HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai);
669 HAL_StatusTypeDef HAL_SAI_DeInit (SAI_HandleTypeDef *hsai);
670 void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai);
671 void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai);
674 * @}
677 /* I/O operation functions *****************************************************/
678 /** @addtogroup SAI_Exported_Functions_Group2
679 * @{
681 /* Blocking mode: Polling */
682 HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
683 HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
685 /* Non-Blocking mode: Interrupt */
686 HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
687 HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
689 /* Non-Blocking mode: DMA */
690 HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
691 HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
692 HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai);
693 HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai);
694 HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai);
696 /* Abort function */
697 HAL_StatusTypeDef HAL_SAI_Abort(SAI_HandleTypeDef *hsai);
699 /* Mute management */
700 HAL_StatusTypeDef HAL_SAI_EnableTxMuteMode(SAI_HandleTypeDef *hsai, uint16_t val);
701 HAL_StatusTypeDef HAL_SAI_DisableTxMuteMode(SAI_HandleTypeDef *hsai);
702 HAL_StatusTypeDef HAL_SAI_EnableRxMuteMode(SAI_HandleTypeDef *hsai, SAIcallback callback, uint16_t counter);
703 HAL_StatusTypeDef HAL_SAI_DisableRxMuteMode(SAI_HandleTypeDef *hsai);
705 /* SAI IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
706 void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai);
707 void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai);
708 void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai);
709 void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai);
710 void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai);
711 void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai);
713 * @}
716 /** @addtogroup SAI_Exported_Functions_Group3
717 * @{
719 /* Peripheral State functions ************************************************/
720 HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai);
721 uint32_t HAL_SAI_GetError(SAI_HandleTypeDef *hsai);
723 * @}
727 * @}
730 /* Private macros ------------------------------------------------------------*/
731 /** @addtogroup SAI_Private_Macros
732 * @{
734 #define IS_SAI_BLOCK_SYNCEXT(STATE) (((STATE) == SAI_SYNCEXT_DISABLE) ||\
735 ((STATE) == SAI_SYNCEXT_OUTBLOCKA_ENABLE) ||\
736 ((STATE) == SAI_SYNCEXT_OUTBLOCKB_ENABLE))
738 #define IS_SAI_SUPPORTED_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_I2S_STANDARD) ||\
739 ((PROTOCOL) == SAI_I2S_MSBJUSTIFIED) ||\
740 ((PROTOCOL) == SAI_I2S_LSBJUSTIFIED) ||\
741 ((PROTOCOL) == SAI_PCM_LONG) ||\
742 ((PROTOCOL) == SAI_PCM_SHORT))
744 #define IS_SAI_PROTOCOL_DATASIZE(DATASIZE) (((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BIT) ||\
745 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BITEXTENDED) ||\
746 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_24BIT) ||\
747 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_32BIT))
749 #define IS_SAI_AUDIO_FREQUENCY(AUDIO) (((AUDIO) == SAI_AUDIO_FREQUENCY_192K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_96K) || \
750 ((AUDIO) == SAI_AUDIO_FREQUENCY_48K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_44K) || \
751 ((AUDIO) == SAI_AUDIO_FREQUENCY_32K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_22K) || \
752 ((AUDIO) == SAI_AUDIO_FREQUENCY_16K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_11K) || \
753 ((AUDIO) == SAI_AUDIO_FREQUENCY_8K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_MCKDIV))
755 #define IS_SAI_BLOCK_MODE(MODE) (((MODE) == SAI_MODEMASTER_TX) || \
756 ((MODE) == SAI_MODEMASTER_RX) || \
757 ((MODE) == SAI_MODESLAVE_TX) || \
758 ((MODE) == SAI_MODESLAVE_RX))
760 #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_FREE_PROTOCOL) || \
761 ((PROTOCOL) == SAI_AC97_PROTOCOL) || \
762 ((PROTOCOL) == SAI_SPDIF_PROTOCOL))
764 #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DATASIZE_8) || \
765 ((DATASIZE) == SAI_DATASIZE_10) || \
766 ((DATASIZE) == SAI_DATASIZE_16) || \
767 ((DATASIZE) == SAI_DATASIZE_20) || \
768 ((DATASIZE) == SAI_DATASIZE_24) || \
769 ((DATASIZE) == SAI_DATASIZE_32))
771 #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FIRSTBIT_MSB) || \
772 ((BIT) == SAI_FIRSTBIT_LSB))
774 #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_CLOCKSTROBING_FALLINGEDGE) || \
775 ((CLOCK) == SAI_CLOCKSTROBING_RISINGEDGE))
777 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS) || \
778 ((SYNCHRO) == SAI_SYNCHRONOUS) || \
779 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI1) ||\
780 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI2))
782 #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OUTPUTDRIVE_DISABLE) || \
783 ((DRIVE) == SAI_OUTPUTDRIVE_ENABLE))
785 #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MASTERDIVIDER_ENABLE) || \
786 ((NODIVIDER) == SAI_MASTERDIVIDER_DISABLE))
788 #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63U)
790 #define IS_SAI_BLOCK_MUTE_VALUE(VALUE) (((VALUE) == SAI_ZERO_VALUE) || \
791 ((VALUE) == SAI_LAST_SENT_VALUE))
793 #define IS_SAI_BLOCK_COMPANDING_MODE(MODE) (((MODE) == SAI_NOCOMPANDING) || \
794 ((MODE) == SAI_ULAW_1CPL_COMPANDING) || \
795 ((MODE) == SAI_ALAW_1CPL_COMPANDING) || \
796 ((MODE) == SAI_ULAW_2CPL_COMPANDING) || \
797 ((MODE) == SAI_ALAW_2CPL_COMPANDING))
799 #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_FIFOTHRESHOLD_EMPTY) || \
800 ((THRESHOLD) == SAI_FIFOTHRESHOLD_1QF) || \
801 ((THRESHOLD) == SAI_FIFOTHRESHOLD_HF) || \
802 ((THRESHOLD) == SAI_FIFOTHRESHOLD_3QF) || \
803 ((THRESHOLD) == SAI_FIFOTHRESHOLD_FULL))
805 #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_OUTPUT_NOTRELEASED) ||\
806 ((STATE) == SAI_OUTPUT_RELEASED))
808 #define IS_SAI_MONO_STEREO_MODE(MODE) (((MODE) == SAI_MONOMODE) ||\
809 ((MODE) == SAI_STEREOMODE))
811 #define IS_SAI_SLOT_ACTIVE(ACTIVE) ((ACTIVE) <= SAI_SLOTACTIVE_ALL)
813 #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1U <= (NUMBER)) && ((NUMBER) <= 16U))
815 #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SLOTSIZE_DATASIZE) || \
816 ((SIZE) == SAI_SLOTSIZE_16B) || \
817 ((SIZE) == SAI_SLOTSIZE_32B))
819 #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24U)
821 #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FIRSTBIT) || \
822 ((OFFSET) == SAI_FS_BEFOREFIRSTBIT))
824 #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ACTIVE_LOW) || \
825 ((POLARITY) == SAI_FS_ACTIVE_HIGH))
827 #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_STARTFRAME) || \
828 ((DEFINITION) == SAI_FS_CHANNEL_IDENTIFICATION))
830 #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 15U)
832 #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8U <= (LENGTH)) && ((LENGTH) <= 256U))
834 #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1U <= (LENGTH)) && ((LENGTH) <= 128U))
838 * @}
841 /* Private functions ---------------------------------------------------------*/
842 /** @defgroup SAI_Private_Functions SAI Private Functions
843 * @{
847 * @}
851 * @}
854 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx || STM32F413xx || STM32F423xx */
857 * @}
860 #ifdef __cplusplus
862 #endif
864 #endif /* __STM32F4xx_HAL_SAI_H */
866 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/