2 ******************************************************************************
3 * @file stm32f7xx_hal_sai.h
4 * @author MCD Application Team
5 * @brief Header file of SAI HAL module.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef __STM32F7xx_HAL_SAI_H
22 #define __STM32F7xx_HAL_SAI_H
29 /* Includes ------------------------------------------------------------------*/
30 #include "stm32f7xx_hal_def.h"
32 /** @addtogroup STM32F7xx_HAL_Driver
40 /* Exported types ------------------------------------------------------------*/
41 /** @defgroup SAI_Exported_Types SAI Exported Types
46 * @brief HAL State structures definition
50 HAL_SAI_STATE_RESET
= 0x00U
, /*!< SAI not yet initialized or disabled */
51 HAL_SAI_STATE_READY
= 0x01U
, /*!< SAI initialized and ready for use */
52 HAL_SAI_STATE_BUSY
= 0x02U
, /*!< SAI internal process is ongoing */
53 HAL_SAI_STATE_BUSY_TX
= 0x12U
, /*!< Data transmission process is ongoing */
54 HAL_SAI_STATE_BUSY_RX
= 0x22U
, /*!< Data reception process is ongoing */
55 }HAL_SAI_StateTypeDef
;
58 * @brief SAI Callback prototype
60 typedef void (*SAIcallback
)(void);
62 /** @defgroup SAI_Init_Structure_definition SAI Init Structure definition
63 * @brief SAI Init Structure definition
68 uint32_t AudioMode
; /*!< Specifies the SAI Block audio Mode.
69 This parameter can be a value of @ref SAI_Block_Mode */
71 uint32_t Synchro
; /*!< Specifies SAI Block synchronization
72 This parameter can be a value of @ref SAI_Block_Synchronization */
74 uint32_t SynchroExt
; /*!< Specifies SAI external output synchronization, this setup is common
76 This parameter can be a value of @ref SAI_Block_SyncExt
77 @note: If both audio blocks of same SAI are used, this parameter has
78 to be set to the same value for each audio block */
80 uint32_t OutputDrive
; /*!< Specifies when SAI Block outputs are driven.
81 This parameter can be a value of @ref SAI_Block_Output_Drive
82 @note this value has to be set before enabling the audio block
83 but after the audio block configuration. */
85 uint32_t NoDivider
; /*!< Specifies whether master clock will be divided or not.
86 This parameter can be a value of @ref SAI_Block_NoDivider
87 @note: If bit NODIV in the SAI_xCR1 register is cleared, the frame length
88 should be aligned to a number equal to a power of 2, from 8 to 256.
89 If bit NODIV in the SAI_xCR1 register is set, the frame length can
90 take any of the values without constraint since the input clock of
91 the audio block should be equal to the bit clock.
92 There is no MCLK_x clock which can be output. */
94 uint32_t FIFOThreshold
; /*!< Specifies SAI Block FIFO threshold.
95 This parameter can be a value of @ref SAI_Block_Fifo_Threshold */
97 uint32_t AudioFrequency
; /*!< Specifies the audio frequency sampling.
98 This parameter can be a value of @ref SAI_Audio_Frequency */
100 uint32_t Mckdiv
; /*!< Specifies the master clock divider, the parameter will be used if for
101 AudioFrequency the user choice
102 This parameter must be a number between Min_Data = 0 and Max_Data = 15 */
104 uint32_t MonoStereoMode
; /*!< Specifies if the mono or stereo mode is selected.
105 This parameter can be a value of @ref SAI_Mono_Stereo_Mode */
107 uint32_t CompandingMode
; /*!< Specifies the companding mode type.
108 This parameter can be a value of @ref SAI_Block_Companding_Mode */
110 uint32_t TriState
; /*!< Specifies the companding mode type.
111 This parameter can be a value of @ref SAI_TRIState_Management */
113 /* This part of the structure is automatically filled if your are using the high level initialisation
114 function HAL_SAI_InitProtocol */
116 uint32_t Protocol
; /*!< Specifies the SAI Block protocol.
117 This parameter can be a value of @ref SAI_Block_Protocol */
119 uint32_t DataSize
; /*!< Specifies the SAI Block data size.
120 This parameter can be a value of @ref SAI_Block_Data_Size */
122 uint32_t FirstBit
; /*!< Specifies whether data transfers start from MSB or LSB bit.
123 This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission */
125 uint32_t ClockStrobing
; /*!< Specifies the SAI Block clock strobing edge sensitivity.
126 This parameter can be a value of @ref SAI_Block_Clock_Strobing */
132 /** @defgroup SAI_Frame_Structure_definition SAI Frame Structure definition
133 * @brief SAI Frame Init structure definition
139 uint32_t FrameLength
; /*!< Specifies the Frame length, the number of SCK clocks for each audio frame.
140 This parameter must be a number between Min_Data = 8 and Max_Data = 256.
141 @note: If master clock MCLK_x pin is declared as an output, the frame length
142 should be aligned to a number equal to power of 2 in order to keep
143 in an audio frame, an integer number of MCLK pulses by bit Clock. */
145 uint32_t ActiveFrameLength
; /*!< Specifies the Frame synchronization active level length.
146 This Parameter specifies the length in number of bit clock (SCK + 1)
147 of the active level of FS signal in audio frame.
148 This parameter must be a number between Min_Data = 1 and Max_Data = 128 */
150 uint32_t FSDefinition
; /*!< Specifies the Frame synchronization definition.
151 This parameter can be a value of @ref SAI_Block_FS_Definition */
153 uint32_t FSPolarity
; /*!< Specifies the Frame synchronization Polarity.
154 This parameter can be a value of @ref SAI_Block_FS_Polarity */
156 uint32_t FSOffset
; /*!< Specifies the Frame synchronization Offset.
157 This parameter can be a value of @ref SAI_Block_FS_Offset */
159 }SAI_FrameInitTypeDef
;
164 /** @defgroup SAI_Slot_Structure_definition SAI Slot Structure definition
165 * @brief SAI Block Slot Init Structure definition
170 uint32_t FirstBitOffset
; /*!< Specifies the position of first data transfer bit in the slot.
171 This parameter must be a number between Min_Data = 0 and Max_Data = 24 */
173 uint32_t SlotSize
; /*!< Specifies the Slot Size.
174 This parameter can be a value of @ref SAI_Block_Slot_Size */
176 uint32_t SlotNumber
; /*!< Specifies the number of slot in the audio frame.
177 This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
179 uint32_t SlotActive
; /*!< Specifies the slots in audio frame that will be activated.
180 This parameter can be a value of @ref SAI_Block_Slot_Active */
181 }SAI_SlotInitTypeDef
;
186 /** @defgroup SAI_Handle_Structure_definition SAI Handle Structure definition
187 * @brief SAI handle Structure definition
190 typedef struct __SAI_HandleTypeDef
192 SAI_Block_TypeDef
*Instance
; /*!< SAI Blockx registers base address */
194 SAI_InitTypeDef Init
; /*!< SAI communication parameters */
196 SAI_FrameInitTypeDef FrameInit
; /*!< SAI Frame configuration parameters */
198 SAI_SlotInitTypeDef SlotInit
; /*!< SAI Slot configuration parameters */
200 uint8_t *pBuffPtr
; /*!< Pointer to SAI transfer Buffer */
202 uint16_t XferSize
; /*!< SAI transfer size */
204 uint16_t XferCount
; /*!< SAI transfer counter */
206 DMA_HandleTypeDef
*hdmatx
; /*!< SAI Tx DMA handle parameters */
208 DMA_HandleTypeDef
*hdmarx
; /*!< SAI Rx DMA handle parameters */
210 SAIcallback mutecallback
; /*!< SAI mute callback */
212 void (*InterruptServiceRoutine
)(struct __SAI_HandleTypeDef
*hsai
); /* function pointer for IRQ handler */
214 HAL_LockTypeDef Lock
; /*!< SAI locking object */
216 __IO HAL_SAI_StateTypeDef State
; /*!< SAI communication state */
218 __IO
uint32_t ErrorCode
; /*!< SAI Error code */
220 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
221 void (*RxCpltCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI receive complete callback */
222 void (*RxHalfCpltCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI receive half complete callback */
223 void (*TxCpltCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI transmit complete callback */
224 void (*TxHalfCpltCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI transmit half complete callback */
225 void (*ErrorCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI error callback */
226 void (*MspInitCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI MSP init callback */
227 void (*MspDeInitCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI MSP de-init callback */
234 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
236 * @brief SAI callback ID enumeration definition
240 HAL_SAI_RX_COMPLETE_CB_ID
= 0x00U
, /*!< SAI receive complete callback ID */
241 HAL_SAI_RX_HALFCOMPLETE_CB_ID
= 0x01U
, /*!< SAI receive half complete callback ID */
242 HAL_SAI_TX_COMPLETE_CB_ID
= 0x02U
, /*!< SAI transmit complete callback ID */
243 HAL_SAI_TX_HALFCOMPLETE_CB_ID
= 0x03U
, /*!< SAI transmit half complete callback ID */
244 HAL_SAI_ERROR_CB_ID
= 0x04U
, /*!< SAI error callback ID */
245 HAL_SAI_MSPINIT_CB_ID
= 0x05U
, /*!< SAI MSP init callback ID */
246 HAL_SAI_MSPDEINIT_CB_ID
= 0x06U
/*!< SAI MSP de-init callback ID */
247 } HAL_SAI_CallbackIDTypeDef
;
250 * @brief SAI callback pointer definition
252 typedef void (*pSAI_CallbackTypeDef
)(SAI_HandleTypeDef
*hsai
);
259 /* Exported constants --------------------------------------------------------*/
261 /** @defgroup SAI_Exported_Constants SAI Exported Constants
265 /** @defgroup SAI_Error_Code SAI Error Code
268 #define HAL_SAI_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
269 #define HAL_SAI_ERROR_OVR ((uint32_t)0x00000001U) /*!< Overrun Error */
270 #define HAL_SAI_ERROR_UDR ((uint32_t)0x00000002U) /*!< Underrun error */
271 #define HAL_SAI_ERROR_AFSDET ((uint32_t)0x00000004U) /*!< Anticipated Frame synchronisation detection */
272 #define HAL_SAI_ERROR_LFSDET ((uint32_t)0x00000008U) /*!< Late Frame synchronisation detection */
273 #define HAL_SAI_ERROR_CNREADY ((uint32_t)0x00000010U) /*!< codec not ready */
274 #define HAL_SAI_ERROR_WCKCFG ((uint32_t)0x00000020U) /*!< Wrong clock configuration */
275 #define HAL_SAI_ERROR_TIMEOUT ((uint32_t)0x00000040U) /*!< Timeout error */
276 #define HAL_SAI_ERROR_DMA ((uint32_t)0x00000080U) /*!< DMA error */
277 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
278 #define HAL_SAI_ERROR_INVALID_CALLBACK 0x00000100U /*!< Invalid callback error */
284 /** @defgroup SAI_Block_SyncExt SAI External synchronisation
287 #define SAI_SYNCEXT_DISABLE 0
288 #define SAI_SYNCEXT_OUTBLOCKA_ENABLE 1
289 #define SAI_SYNCEXT_OUTBLOCKB_ENABLE 2
294 /** @defgroup SAI_Protocol SAI Supported protocol
297 #define SAI_I2S_STANDARD 0
298 #define SAI_I2S_MSBJUSTIFIED 1
299 #define SAI_I2S_LSBJUSTIFIED 2
300 #define SAI_PCM_LONG 3
301 #define SAI_PCM_SHORT 4
306 /** @defgroup SAI_Protocol_DataSize SAI protocol data size
309 #define SAI_PROTOCOL_DATASIZE_16BIT 0
310 #define SAI_PROTOCOL_DATASIZE_16BITEXTENDED 1
311 #define SAI_PROTOCOL_DATASIZE_24BIT 2
312 #define SAI_PROTOCOL_DATASIZE_32BIT 3
317 /** @defgroup SAI_Audio_Frequency SAI Audio Frequency
320 #define SAI_AUDIO_FREQUENCY_192K ((uint32_t)192000U)
321 #define SAI_AUDIO_FREQUENCY_96K ((uint32_t)96000U)
322 #define SAI_AUDIO_FREQUENCY_48K ((uint32_t)48000U)
323 #define SAI_AUDIO_FREQUENCY_44K ((uint32_t)44100U)
324 #define SAI_AUDIO_FREQUENCY_32K ((uint32_t)32000U)
325 #define SAI_AUDIO_FREQUENCY_22K ((uint32_t)22050U)
326 #define SAI_AUDIO_FREQUENCY_16K ((uint32_t)16000U)
327 #define SAI_AUDIO_FREQUENCY_11K ((uint32_t)11025U)
328 #define SAI_AUDIO_FREQUENCY_8K ((uint32_t)8000U)
329 #define SAI_AUDIO_FREQUENCY_MCKDIV ((uint32_t)0U)
334 /** @defgroup SAI_Block_Mode SAI Block Mode
337 #define SAI_MODEMASTER_TX ((uint32_t)0x00000000U)
338 #define SAI_MODEMASTER_RX ((uint32_t)SAI_xCR1_MODE_0)
339 #define SAI_MODESLAVE_TX ((uint32_t)SAI_xCR1_MODE_1)
340 #define SAI_MODESLAVE_RX ((uint32_t)(SAI_xCR1_MODE_1 | SAI_xCR1_MODE_0))
346 /** @defgroup SAI_Block_Protocol SAI Block Protocol
349 #define SAI_FREE_PROTOCOL ((uint32_t)0x00000000U)
350 #define SAI_SPDIF_PROTOCOL ((uint32_t)SAI_xCR1_PRTCFG_0)
351 #define SAI_AC97_PROTOCOL ((uint32_t)SAI_xCR1_PRTCFG_1)
356 /** @defgroup SAI_Block_Data_Size SAI Block Data Size
359 #define SAI_DATASIZE_8 ((uint32_t)SAI_xCR1_DS_1)
360 #define SAI_DATASIZE_10 ((uint32_t)(SAI_xCR1_DS_1 | SAI_xCR1_DS_0))
361 #define SAI_DATASIZE_16 ((uint32_t)SAI_xCR1_DS_2)
362 #define SAI_DATASIZE_20 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_0))
363 #define SAI_DATASIZE_24 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_1))
364 #define SAI_DATASIZE_32 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_1 | SAI_xCR1_DS_0))
369 /** @defgroup SAI_Block_MSB_LSB_transmission SAI Block MSB LSB transmission
372 #define SAI_FIRSTBIT_MSB ((uint32_t)0x00000000U)
373 #define SAI_FIRSTBIT_LSB ((uint32_t)SAI_xCR1_LSBFIRST)
378 /** @defgroup SAI_Block_Clock_Strobing SAI Block Clock Strobing
381 #define SAI_CLOCKSTROBING_FALLINGEDGE 0
382 #define SAI_CLOCKSTROBING_RISINGEDGE 1
387 /** @defgroup SAI_Block_Synchronization SAI Block Synchronization
390 #define SAI_ASYNCHRONOUS 0 /*!< Asynchronous */
391 #define SAI_SYNCHRONOUS 1 /*!< Synchronous with other block of same SAI */
392 #define SAI_SYNCHRONOUS_EXT_SAI1 2 /*!< Synchronous with other SAI, SAI1 */
393 #define SAI_SYNCHRONOUS_EXT_SAI2 3 /*!< Synchronous with other SAI, SAI2 */
398 /** @defgroup SAI_Block_Output_Drive SAI Block Output Drive
401 #define SAI_OUTPUTDRIVE_DISABLE ((uint32_t)0x00000000U)
402 #define SAI_OUTPUTDRIVE_ENABLE ((uint32_t)SAI_xCR1_OUTDRIV)
407 /** @defgroup SAI_Block_NoDivider SAI Block NoDivider
410 #define SAI_MASTERDIVIDER_ENABLE ((uint32_t)0x00000000U)
411 #define SAI_MASTERDIVIDER_DISABLE ((uint32_t)SAI_xCR1_NODIV)
416 /** @defgroup SAI_Block_FS_Definition SAI Block FS Definition
419 #define SAI_FS_STARTFRAME ((uint32_t)0x00000000U)
420 #define SAI_FS_CHANNEL_IDENTIFICATION ((uint32_t)SAI_xFRCR_FSDEF)
425 /** @defgroup SAI_Block_FS_Polarity SAI Block FS Polarity
428 #define SAI_FS_ACTIVE_LOW ((uint32_t)0x00000000U)
429 #define SAI_FS_ACTIVE_HIGH ((uint32_t)SAI_xFRCR_FSPOL)
434 /** @defgroup SAI_Block_FS_Offset SAI Block FS Offset
437 #define SAI_FS_FIRSTBIT ((uint32_t)0x00000000U)
438 #define SAI_FS_BEFOREFIRSTBIT ((uint32_t)SAI_xFRCR_FSOFF)
443 /** @defgroup SAI_Block_Slot_Size SAI Block Slot Size
446 #define SAI_SLOTSIZE_DATASIZE ((uint32_t)0x00000000U)
447 #define SAI_SLOTSIZE_16B ((uint32_t)SAI_xSLOTR_SLOTSZ_0)
448 #define SAI_SLOTSIZE_32B ((uint32_t)SAI_xSLOTR_SLOTSZ_1)
453 /** @defgroup SAI_Block_Slot_Active SAI Block Slot Active
456 #define SAI_SLOT_NOTACTIVE ((uint32_t)0x00000000U)
457 #define SAI_SLOTACTIVE_0 ((uint32_t)0x00000001U)
458 #define SAI_SLOTACTIVE_1 ((uint32_t)0x00000002U)
459 #define SAI_SLOTACTIVE_2 ((uint32_t)0x00000004U)
460 #define SAI_SLOTACTIVE_3 ((uint32_t)0x00000008U)
461 #define SAI_SLOTACTIVE_4 ((uint32_t)0x00000010U)
462 #define SAI_SLOTACTIVE_5 ((uint32_t)0x00000020U)
463 #define SAI_SLOTACTIVE_6 ((uint32_t)0x00000040U)
464 #define SAI_SLOTACTIVE_7 ((uint32_t)0x00000080U)
465 #define SAI_SLOTACTIVE_8 ((uint32_t)0x00000100U)
466 #define SAI_SLOTACTIVE_9 ((uint32_t)0x00000200U)
467 #define SAI_SLOTACTIVE_10 ((uint32_t)0x00000400U)
468 #define SAI_SLOTACTIVE_11 ((uint32_t)0x00000800U)
469 #define SAI_SLOTACTIVE_12 ((uint32_t)0x00001000U)
470 #define SAI_SLOTACTIVE_13 ((uint32_t)0x00002000U)
471 #define SAI_SLOTACTIVE_14 ((uint32_t)0x00004000U)
472 #define SAI_SLOTACTIVE_15 ((uint32_t)0x00008000U)
473 #define SAI_SLOTACTIVE_ALL ((uint32_t)0x0000FFFFU)
478 /** @defgroup SAI_Mono_Stereo_Mode SAI Mono Stereo Mode
481 #define SAI_STEREOMODE ((uint32_t)0x00000000U)
482 #define SAI_MONOMODE ((uint32_t)SAI_xCR1_MONO)
487 /** @defgroup SAI_TRIState_Management SAI TRIState Management
490 #define SAI_OUTPUT_NOTRELEASED ((uint32_t)0x00000000U)
491 #define SAI_OUTPUT_RELEASED ((uint32_t)SAI_xCR2_TRIS)
496 /** @defgroup SAI_Block_Fifo_Threshold SAI Block Fifo Threshold
499 #define SAI_FIFOTHRESHOLD_EMPTY ((uint32_t)0x00000000U)
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))
508 /** @defgroup SAI_Block_Companding_Mode SAI Block Companding Mode
511 #define SAI_NOCOMPANDING ((uint32_t)0x00000000U)
512 #define SAI_ULAW_1CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1))
513 #define SAI_ALAW_1CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0))
514 #define SAI_ULAW_2CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_CPL))
515 #define SAI_ALAW_2CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0 | SAI_xCR2_CPL))
520 /** @defgroup SAI_Block_Mute_Value SAI Block Mute Value
523 #define SAI_ZERO_VALUE ((uint32_t)0x00000000U)
524 #define SAI_LAST_SENT_VALUE ((uint32_t)SAI_xCR2_MUTEVAL)
529 /** @defgroup SAI_Block_Interrupts_Definition SAI Block Interrupts Definition
532 #define SAI_IT_OVRUDR ((uint32_t)SAI_xIMR_OVRUDRIE)
533 #define SAI_IT_MUTEDET ((uint32_t)SAI_xIMR_MUTEDETIE)
534 #define SAI_IT_WCKCFG ((uint32_t)SAI_xIMR_WCKCFGIE)
535 #define SAI_IT_FREQ ((uint32_t)SAI_xIMR_FREQIE)
536 #define SAI_IT_CNRDY ((uint32_t)SAI_xIMR_CNRDYIE)
537 #define SAI_IT_AFSDET ((uint32_t)SAI_xIMR_AFSDETIE)
538 #define SAI_IT_LFSDET ((uint32_t)SAI_xIMR_LFSDETIE)
543 /** @defgroup SAI_Block_Flags_Definition SAI Block Flags Definition
546 #define SAI_FLAG_OVRUDR ((uint32_t)SAI_xSR_OVRUDR)
547 #define SAI_FLAG_MUTEDET ((uint32_t)SAI_xSR_MUTEDET)
548 #define SAI_FLAG_WCKCFG ((uint32_t)SAI_xSR_WCKCFG)
549 #define SAI_FLAG_FREQ ((uint32_t)SAI_xSR_FREQ)
550 #define SAI_FLAG_CNRDY ((uint32_t)SAI_xSR_CNRDY)
551 #define SAI_FLAG_AFSDET ((uint32_t)SAI_xSR_AFSDET)
552 #define SAI_FLAG_LFSDET ((uint32_t)SAI_xSR_LFSDET)
557 /** @defgroup SAI_Block_Fifo_Status_Level SAI Block Fifo Status Level
560 #define SAI_FIFOSTATUS_EMPTY ((uint32_t)0x00000000U)
561 #define SAI_FIFOSTATUS_LESS1QUARTERFULL ((uint32_t)0x00010000U)
562 #define SAI_FIFOSTATUS_1QUARTERFULL ((uint32_t)0x00020000U)
563 #define SAI_FIFOSTATUS_HALFFULL ((uint32_t)0x00030000U)
564 #define SAI_FIFOSTATUS_3QUARTERFULL ((uint32_t)0x00040000U)
565 #define SAI_FIFOSTATUS_FULL ((uint32_t)0x00050000U)
574 /* Exported macro ------------------------------------------------------------*/
575 /** @defgroup SAI_Exported_Macros SAI Exported Macros
576 * @brief macros to handle interrupts and specific configurations
580 /** @brief Reset SAI handle state.
581 * @param __HANDLE__ specifies the SAI Handle.
584 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
585 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) do{ \
586 (__HANDLE__)->State = HAL_SAI_STATE_RESET; \
587 (__HANDLE__)->MspInitCallback = NULL; \
588 (__HANDLE__)->MspDeInitCallback = NULL; \
591 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SAI_STATE_RESET)
592 #endif /* USE_HAL_SAI_REGISTER_CALLBACKS */
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 enable
607 #define __HAL_SAI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR |= (__INTERRUPT__))
608 #define __HAL_SAI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR &= (~(__INTERRUPT__)))
610 /** @brief Check whether the specified SAI interrupt source is enabled or not.
611 * @param __HANDLE__ specifies the SAI Handle.
612 * @param __INTERRUPT__ specifies the SAI interrupt source to check.
613 * This parameter can be one of the following values:
614 * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
615 * @arg SAI_IT_MUTEDET: Mute detection interrupt enable
616 * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
617 * @arg SAI_IT_FREQ: FIFO request interrupt enable
618 * @arg SAI_IT_CNRDY: Codec not ready interrupt enable
619 * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
620 * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
621 * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
623 #define __HAL_SAI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IMR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
625 /** @brief Check whether the specified SAI flag is set or not.
626 * @param __HANDLE__ specifies the SAI Handle.
627 * @param __FLAG__ specifies the flag to check.
628 * This parameter can be one of the following values:
629 * @arg SAI_FLAG_OVRUDR: Overrun underrun flag.
630 * @arg SAI_FLAG_MUTEDET: Mute detection flag.
631 * @arg SAI_FLAG_WCKCFG: Wrong Clock Configuration flag.
632 * @arg SAI_FLAG_FREQ: FIFO request flag.
633 * @arg SAI_FLAG_CNRDY: Codec not ready flag.
634 * @arg SAI_FLAG_AFSDET: Anticipated frame synchronization detection flag.
635 * @arg SAI_FLAG_LFSDET: Late frame synchronization detection flag.
636 * @retval The new state of __FLAG__ (TRUE or FALSE).
638 #define __HAL_SAI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
640 /** @brief Clear the specified SAI pending flag.
641 * @param __HANDLE__ specifies the SAI Handle.
642 * @param __FLAG__ specifies the flag to check.
643 * This parameter can be any combination of the following values:
644 * @arg SAI_FLAG_OVRUDR: Clear Overrun underrun
645 * @arg SAI_FLAG_MUTEDET: Clear Mute detection
646 * @arg SAI_FLAG_WCKCFG: Clear Wrong Clock Configuration
647 * @arg SAI_FLAG_FREQ: Clear FIFO request
648 * @arg SAI_FLAG_CNRDY: Clear Codec not ready
649 * @arg SAI_FLAG_AFSDET: Clear Anticipated frame synchronization detection
650 * @arg SAI_FLAG_LFSDET: Clear Late frame synchronization detection
654 #define __HAL_SAI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__))
656 #define __HAL_SAI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SAI_xCR1_SAIEN)
657 #define __HAL_SAI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~SAI_xCR1_SAIEN)
663 /* Exported functions --------------------------------------------------------*/
664 /** @addtogroup SAI_Exported_Functions
668 /* Initialization/de-initialization functions ********************************/
669 /** @addtogroup SAI_Exported_Functions_Group1
672 HAL_StatusTypeDef
HAL_SAI_InitProtocol(SAI_HandleTypeDef
*hsai
, uint32_t protocol
, uint32_t datasize
, uint32_t nbslot
);
673 HAL_StatusTypeDef
HAL_SAI_Init(SAI_HandleTypeDef
*hsai
);
674 HAL_StatusTypeDef
HAL_SAI_DeInit (SAI_HandleTypeDef
*hsai
);
675 void HAL_SAI_MspInit(SAI_HandleTypeDef
*hsai
);
676 void HAL_SAI_MspDeInit(SAI_HandleTypeDef
*hsai
);
678 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
679 /* SAI callbacks register/unregister functions ********************************/
680 HAL_StatusTypeDef
HAL_SAI_RegisterCallback(SAI_HandleTypeDef
*hsai
,
681 HAL_SAI_CallbackIDTypeDef CallbackID
,
682 pSAI_CallbackTypeDef pCallback
);
683 HAL_StatusTypeDef
HAL_SAI_UnRegisterCallback(SAI_HandleTypeDef
*hsai
,
684 HAL_SAI_CallbackIDTypeDef CallbackID
);
690 /* I/O operation functions ***************************************************/
692 /** @addtogroup SAI_Exported_Functions_Group2
695 /* Blocking mode: Polling */
696 HAL_StatusTypeDef
HAL_SAI_Transmit(SAI_HandleTypeDef
*hsai
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
);
697 HAL_StatusTypeDef
HAL_SAI_Receive(SAI_HandleTypeDef
*hsai
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
);
699 /* Non-Blocking mode: Interrupt */
700 HAL_StatusTypeDef
HAL_SAI_Transmit_IT(SAI_HandleTypeDef
*hsai
, uint8_t *pData
, uint16_t Size
);
701 HAL_StatusTypeDef
HAL_SAI_Receive_IT(SAI_HandleTypeDef
*hsai
, uint8_t *pData
, uint16_t Size
);
703 /* Non-Blocking mode: DMA */
704 HAL_StatusTypeDef
HAL_SAI_Transmit_DMA(SAI_HandleTypeDef
*hsai
, uint8_t *pData
, uint16_t Size
);
705 HAL_StatusTypeDef
HAL_SAI_Receive_DMA(SAI_HandleTypeDef
*hsai
, uint8_t *pData
, uint16_t Size
);
706 HAL_StatusTypeDef
HAL_SAI_DMAPause(SAI_HandleTypeDef
*hsai
);
707 HAL_StatusTypeDef
HAL_SAI_DMAResume(SAI_HandleTypeDef
*hsai
);
708 HAL_StatusTypeDef
HAL_SAI_DMAStop(SAI_HandleTypeDef
*hsai
);
711 HAL_StatusTypeDef
HAL_SAI_Abort(SAI_HandleTypeDef
*hsai
);
713 /* Mute management */
714 HAL_StatusTypeDef
HAL_SAI_EnableTxMuteMode(SAI_HandleTypeDef
*hsai
, uint16_t val
);
715 HAL_StatusTypeDef
HAL_SAI_DisableTxMuteMode(SAI_HandleTypeDef
*hsai
);
716 HAL_StatusTypeDef
HAL_SAI_EnableRxMuteMode(SAI_HandleTypeDef
*hsai
, SAIcallback callback
, uint16_t counter
);
717 HAL_StatusTypeDef
HAL_SAI_DisableRxMuteMode(SAI_HandleTypeDef
*hsai
);
719 /* SAI IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
720 void HAL_SAI_IRQHandler(SAI_HandleTypeDef
*hsai
);
721 void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef
*hsai
);
722 void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef
*hsai
);
723 void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef
*hsai
);
724 void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef
*hsai
);
725 void HAL_SAI_ErrorCallback(SAI_HandleTypeDef
*hsai
);
730 /** @addtogroup SAI_Exported_Functions_Group3
733 /* Peripheral State functions ************************************************/
734 HAL_SAI_StateTypeDef
HAL_SAI_GetState(SAI_HandleTypeDef
*hsai
);
735 uint32_t HAL_SAI_GetError(SAI_HandleTypeDef
*hsai
);
744 /* Private macros ------------------------------------------------------------*/
745 /** @addtogroup SAI_Private_Macros
748 #define IS_SAI_BLOCK_SYNCEXT(STATE) (((STATE) == SAI_SYNCEXT_DISABLE) ||\
749 ((STATE) == SAI_SYNCEXT_OUTBLOCKA_ENABLE) ||\
750 ((STATE) == SAI_SYNCEXT_OUTBLOCKB_ENABLE))
752 #define IS_SAI_SUPPORTED_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_I2S_STANDARD) ||\
753 ((PROTOCOL) == SAI_I2S_MSBJUSTIFIED) ||\
754 ((PROTOCOL) == SAI_I2S_LSBJUSTIFIED) ||\
755 ((PROTOCOL) == SAI_PCM_LONG) ||\
756 ((PROTOCOL) == SAI_PCM_SHORT))
758 #define IS_SAI_PROTOCOL_DATASIZE(DATASIZE) (((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BIT) ||\
759 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BITEXTENDED) ||\
760 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_24BIT) ||\
761 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_32BIT))
763 #define IS_SAI_AUDIO_FREQUENCY(AUDIO) (((AUDIO) == SAI_AUDIO_FREQUENCY_192K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_96K) || \
764 ((AUDIO) == SAI_AUDIO_FREQUENCY_48K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_44K) || \
765 ((AUDIO) == SAI_AUDIO_FREQUENCY_32K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_22K) || \
766 ((AUDIO) == SAI_AUDIO_FREQUENCY_16K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_11K) || \
767 ((AUDIO) == SAI_AUDIO_FREQUENCY_8K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_MCKDIV))
769 #define IS_SAI_BLOCK_MODE(MODE) (((MODE) == SAI_MODEMASTER_TX) || \
770 ((MODE) == SAI_MODEMASTER_RX) || \
771 ((MODE) == SAI_MODESLAVE_TX) || \
772 ((MODE) == SAI_MODESLAVE_RX))
774 #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_FREE_PROTOCOL) || \
775 ((PROTOCOL) == SAI_AC97_PROTOCOL) || \
776 ((PROTOCOL) == SAI_SPDIF_PROTOCOL))
778 #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DATASIZE_8) || \
779 ((DATASIZE) == SAI_DATASIZE_10) || \
780 ((DATASIZE) == SAI_DATASIZE_16) || \
781 ((DATASIZE) == SAI_DATASIZE_20) || \
782 ((DATASIZE) == SAI_DATASIZE_24) || \
783 ((DATASIZE) == SAI_DATASIZE_32))
785 #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FIRSTBIT_MSB) || \
786 ((BIT) == SAI_FIRSTBIT_LSB))
788 #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_CLOCKSTROBING_FALLINGEDGE) || \
789 ((CLOCK) == SAI_CLOCKSTROBING_RISINGEDGE))
791 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS) || \
792 ((SYNCHRO) == SAI_SYNCHRONOUS) || \
793 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI1) || \
794 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI2))
796 #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OUTPUTDRIVE_DISABLE) || \
797 ((DRIVE) == SAI_OUTPUTDRIVE_ENABLE))
799 #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MASTERDIVIDER_ENABLE) || \
800 ((NODIVIDER) == SAI_MASTERDIVIDER_DISABLE))
802 #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63)
804 #define IS_SAI_BLOCK_MUTE_VALUE(VALUE) (((VALUE) == SAI_ZERO_VALUE) || \
805 ((VALUE) == SAI_LAST_SENT_VALUE))
807 #define IS_SAI_BLOCK_COMPANDING_MODE(MODE) (((MODE) == SAI_NOCOMPANDING) || \
808 ((MODE) == SAI_ULAW_1CPL_COMPANDING) || \
809 ((MODE) == SAI_ALAW_1CPL_COMPANDING) || \
810 ((MODE) == SAI_ULAW_2CPL_COMPANDING) || \
811 ((MODE) == SAI_ALAW_2CPL_COMPANDING))
813 #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_FIFOTHRESHOLD_EMPTY) || \
814 ((THRESHOLD) == SAI_FIFOTHRESHOLD_1QF) || \
815 ((THRESHOLD) == SAI_FIFOTHRESHOLD_HF) || \
816 ((THRESHOLD) == SAI_FIFOTHRESHOLD_3QF) || \
817 ((THRESHOLD) == SAI_FIFOTHRESHOLD_FULL))
819 #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_OUTPUT_NOTRELEASED) ||\
820 ((STATE) == SAI_OUTPUT_RELEASED))
822 #define IS_SAI_MONO_STEREO_MODE(MODE) (((MODE) == SAI_MONOMODE) ||\
823 ((MODE) == SAI_STEREOMODE))
825 #define IS_SAI_SLOT_ACTIVE(ACTIVE) ((ACTIVE) <= SAI_SLOTACTIVE_ALL)
827 #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1 <= (NUMBER)) && ((NUMBER) <= 16))
829 #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SLOTSIZE_DATASIZE) || \
830 ((SIZE) == SAI_SLOTSIZE_16B) || \
831 ((SIZE) == SAI_SLOTSIZE_32B))
833 #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24)
835 #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FIRSTBIT) || \
836 ((OFFSET) == SAI_FS_BEFOREFIRSTBIT))
838 #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ACTIVE_LOW) || \
839 ((POLARITY) == SAI_FS_ACTIVE_HIGH))
841 #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_STARTFRAME) || \
842 ((DEFINITION) == SAI_FS_CHANNEL_IDENTIFICATION))
844 #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 15)
846 #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8 <= (LENGTH)) && ((LENGTH) <= 256))
848 #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1 <= (LENGTH)) && ((LENGTH) <= 128))
854 /* Private functions ---------------------------------------------------------*/
855 /** @defgroup SAI_Private_Functions SAI Private Functions
875 #endif /* __STM32F7xx_HAL_SAI_H */
877 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/