2 ******************************************************************************
3 * @file stm32h7xx_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 STM32H7xx_HAL_SAI_H
22 #define STM32H7xx_HAL_SAI_H
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h7xx_hal_def.h"
31 /** @addtogroup STM32H7xx_HAL_Driver
39 /* Exported types ------------------------------------------------------------*/
40 /** @defgroup SAI_Exported_Types SAI Exported Types
45 * @brief HAL State structures definition
49 HAL_SAI_STATE_RESET
= 0x00U
, /*!< SAI not yet initialized or disabled */
50 HAL_SAI_STATE_READY
= 0x01U
, /*!< SAI initialized and ready for use */
51 HAL_SAI_STATE_BUSY
= 0x02U
, /*!< SAI internal process is ongoing */
52 HAL_SAI_STATE_BUSY_TX
= 0x12U
, /*!< Data transmission process is ongoing */
53 HAL_SAI_STATE_BUSY_RX
= 0x22U
, /*!< Data reception process is ongoing */
54 } HAL_SAI_StateTypeDef
;
57 * @brief SAI Callback prototype
59 typedef void (*SAIcallback
)(void);
61 /** @defgroup SAI_PDM_Structure_definition SAI PDM Structure definition
62 * @brief SAI PDM Init structure definition
67 FunctionalState Activation
; /*!< Enable/disable PDM interface */
68 uint32_t MicPairsNbr
; /*!< Specifies the number of microphone pairs used.
69 This parameter must be a number between Min_Data = 1 and Max_Data = 3. */
70 uint32_t ClockEnable
; /*!< Specifies which clock must be enabled.
71 This parameter can be a values combination of @ref SAI_PDM_ClockEnable */
77 /** @defgroup SAI_Init_Structure_definition SAI Init Structure definition
78 * @brief SAI Init Structure definition
83 uint32_t AudioMode
; /*!< Specifies the SAI Block audio Mode.
84 This parameter can be a value of @ref SAI_Block_Mode */
86 uint32_t Synchro
; /*!< Specifies SAI Block synchronization
87 This parameter can be a value of @ref SAI_Block_Synchronization */
89 uint32_t SynchroExt
; /*!< Specifies SAI external output synchronization, this setup is common
91 This parameter can be a value of @ref SAI_Block_SyncExt
92 @note If both audio blocks of same SAI are used, this parameter has
93 to be set to the same value for each audio block */
95 uint32_t MckOutput
; /*!< Specifies whether master clock output will be generated or not.
96 This parameter can be a value of @ref SAI_Block_MckOutput
97 @note This feature is only available on STM32H7xx Rev.B and above */
99 uint32_t OutputDrive
; /*!< Specifies when SAI Block outputs are driven.
100 This parameter can be a value of @ref SAI_Block_Output_Drive
101 @note This value has to be set before enabling the audio block
102 but after the audio block configuration. */
104 uint32_t NoDivider
; /*!< Specifies whether master clock will be divided or not.
105 This parameter can be a value of @ref SAI_Block_NoDivider
106 @note If bit NODIV in the SAI_xCR1 register is cleared, the frame length
107 should be aligned to a number equal to a power of 2, from 8 to 256.
108 If bit NODIV in the SAI_xCR1 register is set, the frame length can
109 take any of the values from 8 to 256.
110 @note The NODIV bit is the same as NOMCK bit in STM32H7xx rev.Y */
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.
119 This parameter must be a number between Min_Data = 0 and Max_Data = 63.
120 @note This parameter is used only if AudioFrequency is set to
121 SAI_AUDIO_FREQUENCY_MCKDIV otherwise it is internally computed. */
123 uint32_t MckOverSampling
; /*!< Specifies the master clock oversampling.
124 This parameter can be a value of @ref SAI_Block_Mck_OverSampling */
126 uint32_t MonoStereoMode
; /*!< Specifies if the mono or stereo mode is selected.
127 This parameter can be a value of @ref SAI_Mono_Stereo_Mode */
129 uint32_t CompandingMode
; /*!< Specifies the companding mode type.
130 This parameter can be a value of @ref SAI_Block_Companding_Mode */
132 uint32_t TriState
; /*!< Specifies the companding mode type.
133 This parameter can be a value of @ref SAI_TRIState_Management */
135 SAI_PdmInitTypeDef PdmInit
; /*!< Specifies the PDM configuration. */
137 /* This part of the structure is automatically filled if your are using the high level initialisation
138 function HAL_SAI_InitProtocol */
140 uint32_t Protocol
; /*!< Specifies the SAI Block protocol.
141 This parameter can be a value of @ref SAI_Block_Protocol */
143 uint32_t DataSize
; /*!< Specifies the SAI Block data size.
144 This parameter can be a value of @ref SAI_Block_Data_Size */
146 uint32_t FirstBit
; /*!< Specifies whether data transfers start from MSB or LSB bit.
147 This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission */
149 uint32_t ClockStrobing
; /*!< Specifies the SAI Block clock strobing edge sensitivity.
150 This parameter can be a value of @ref SAI_Block_Clock_Strobing */
156 /** @defgroup SAI_Frame_Structure_definition SAI Frame Structure definition
157 * @brief SAI Frame Init structure definition
158 * @note For SPDIF and AC97 protocol, these parameters are not used (set by hardware).
164 uint32_t FrameLength
; /*!< Specifies the Frame length, the number of SCK clocks for each audio frame.
165 This parameter must be a number between Min_Data = 8 and Max_Data = 256.
166 @note If master clock MCLK_x pin is declared as an output, the frame length
167 should be aligned to a number equal to power of 2 in order to keep
168 in an audio frame, an integer number of MCLK pulses by bit Clock. */
170 uint32_t ActiveFrameLength
; /*!< Specifies the Frame synchronization active level length.
171 This Parameter specifies the length in number of bit clock (SCK + 1)
172 of the active level of FS signal in audio frame.
173 This parameter must be a number between Min_Data = 1 and Max_Data = 128 */
175 uint32_t FSDefinition
; /*!< Specifies the Frame synchronization definition.
176 This parameter can be a value of @ref SAI_Block_FS_Definition */
178 uint32_t FSPolarity
; /*!< Specifies the Frame synchronization Polarity.
179 This parameter can be a value of @ref SAI_Block_FS_Polarity */
181 uint32_t FSOffset
; /*!< Specifies the Frame synchronization Offset.
182 This parameter can be a value of @ref SAI_Block_FS_Offset */
184 } SAI_FrameInitTypeDef
;
189 /** @defgroup SAI_Slot_Structure_definition SAI Slot Structure definition
190 * @brief SAI Block Slot Init Structure definition
191 * @note For SPDIF protocol, these parameters are not used (set by hardware).
192 * @note For AC97 protocol, only SlotActive parameter is used (the others are set by hardware).
197 uint32_t FirstBitOffset
; /*!< Specifies the position of first data transfer bit in the slot.
198 This parameter must be a number between Min_Data = 0 and Max_Data = 24 */
200 uint32_t SlotSize
; /*!< Specifies the Slot Size.
201 This parameter can be a value of @ref SAI_Block_Slot_Size */
203 uint32_t SlotNumber
; /*!< Specifies the number of slot in the audio frame.
204 This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
206 uint32_t SlotActive
; /*!< Specifies the slots in audio frame that will be activated.
207 This parameter can be a value of @ref SAI_Block_Slot_Active */
208 } SAI_SlotInitTypeDef
;
213 /** @defgroup SAI_Handle_Structure_definition SAI Handle Structure definition
214 * @brief SAI handle Structure definition
217 typedef struct __SAI_HandleTypeDef
219 SAI_Block_TypeDef
*Instance
; /*!< SAI Blockx registers base address */
221 SAI_InitTypeDef Init
; /*!< SAI communication parameters */
223 SAI_FrameInitTypeDef FrameInit
; /*!< SAI Frame configuration parameters */
225 SAI_SlotInitTypeDef SlotInit
; /*!< SAI Slot configuration parameters */
227 uint8_t *pBuffPtr
; /*!< Pointer to SAI transfer Buffer */
229 uint16_t XferSize
; /*!< SAI transfer size */
231 uint16_t XferCount
; /*!< SAI transfer counter */
233 DMA_HandleTypeDef
*hdmatx
; /*!< SAI Tx DMA handle parameters */
235 DMA_HandleTypeDef
*hdmarx
; /*!< SAI Rx DMA handle parameters */
237 SAIcallback mutecallback
; /*!< SAI mute callback */
239 void (*InterruptServiceRoutine
)(struct __SAI_HandleTypeDef
*hsai
); /* function pointer for IRQ handler */
241 HAL_LockTypeDef Lock
; /*!< SAI locking object */
243 __IO HAL_SAI_StateTypeDef State
; /*!< SAI communication state */
245 __IO
uint32_t ErrorCode
; /*!< SAI Error code */
247 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
248 void (*RxCpltCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI receive complete callback */
249 void (*RxHalfCpltCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI receive half complete callback */
250 void (*TxCpltCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI transmit complete callback */
251 void (*TxHalfCpltCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI transmit half complete callback */
252 void (*ErrorCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI error callback */
253 void (*MspInitCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI MSP init callback */
254 void (*MspDeInitCallback
)(struct __SAI_HandleTypeDef
*hsai
); /*!< SAI MSP de-init callback */
261 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
263 * @brief SAI callback ID enumeration definition
267 HAL_SAI_RX_COMPLETE_CB_ID
= 0x00U
, /*!< SAI receive complete callback ID */
268 HAL_SAI_RX_HALFCOMPLETE_CB_ID
= 0x01U
, /*!< SAI receive half complete callback ID */
269 HAL_SAI_TX_COMPLETE_CB_ID
= 0x02U
, /*!< SAI transmit complete callback ID */
270 HAL_SAI_TX_HALFCOMPLETE_CB_ID
= 0x03U
, /*!< SAI transmit half complete callback ID */
271 HAL_SAI_ERROR_CB_ID
= 0x04U
, /*!< SAI error callback ID */
272 HAL_SAI_MSPINIT_CB_ID
= 0x05U
, /*!< SAI MSP init callback ID */
273 HAL_SAI_MSPDEINIT_CB_ID
= 0x06U
/*!< SAI MSP de-init callback ID */
274 } HAL_SAI_CallbackIDTypeDef
;
277 * @brief SAI callback pointer definition
279 typedef void (*pSAI_CallbackTypeDef
)(SAI_HandleTypeDef
*hsai
);
286 /* Exported constants --------------------------------------------------------*/
287 /** @defgroup SAI_Exported_Constants SAI Exported Constants
291 /** @defgroup SAI_Error_Code SAI Error Code
294 #define HAL_SAI_ERROR_NONE 0x00000000U /*!< No error */
295 #define HAL_SAI_ERROR_OVR 0x00000001U /*!< Overrun Error */
296 #define HAL_SAI_ERROR_UDR 0x00000002U /*!< Underrun error */
297 #define HAL_SAI_ERROR_AFSDET 0x00000004U /*!< Anticipated Frame synchronisation detection */
298 #define HAL_SAI_ERROR_LFSDET 0x00000008U /*!< Late Frame synchronisation detection */
299 #define HAL_SAI_ERROR_CNREADY 0x00000010U /*!< codec not ready */
300 #define HAL_SAI_ERROR_WCKCFG 0x00000020U /*!< Wrong clock configuration */
301 #define HAL_SAI_ERROR_TIMEOUT 0x00000040U /*!< Timeout error */
302 #define HAL_SAI_ERROR_DMA 0x00000080U /*!< DMA error */
303 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
304 #define HAL_SAI_ERROR_INVALID_CALLBACK 0x00000100U /*!< Invalid callback error */
310 /** @defgroup SAI_Block_SyncExt SAI External synchronisation
313 #define SAI_SYNCEXT_DISABLE 0U
314 #define SAI_SYNCEXT_OUTBLOCKA_ENABLE 1U
315 #define SAI_SYNCEXT_OUTBLOCKB_ENABLE 2U
320 /** @defgroup SAI_Block_MckOutput SAI Block Master Clock Output
323 #define SAI_MCK_OUTPUT_DISABLE 0x00000000U
324 #define SAI_MCK_OUTPUT_ENABLE SAI_xCR1_MCKEN
329 /** @defgroup SAI_Protocol SAI Supported protocol
332 #define SAI_I2S_STANDARD 0U
333 #define SAI_I2S_MSBJUSTIFIED 1U
334 #define SAI_I2S_LSBJUSTIFIED 2U
335 #define SAI_PCM_LONG 3U
336 #define SAI_PCM_SHORT 4U
341 /** @defgroup SAI_Protocol_DataSize SAI protocol data size
344 #define SAI_PROTOCOL_DATASIZE_16BIT 0U
345 #define SAI_PROTOCOL_DATASIZE_16BITEXTENDED 1U
346 #define SAI_PROTOCOL_DATASIZE_24BIT 2U
347 #define SAI_PROTOCOL_DATASIZE_32BIT 3U
352 /** @defgroup SAI_Audio_Frequency SAI Audio Frequency
355 #define SAI_AUDIO_FREQUENCY_192K 192000U
356 #define SAI_AUDIO_FREQUENCY_96K 96000U
357 #define SAI_AUDIO_FREQUENCY_48K 48000U
358 #define SAI_AUDIO_FREQUENCY_44K 44100U
359 #define SAI_AUDIO_FREQUENCY_32K 32000U
360 #define SAI_AUDIO_FREQUENCY_22K 22050U
361 #define SAI_AUDIO_FREQUENCY_16K 16000U
362 #define SAI_AUDIO_FREQUENCY_11K 11025U
363 #define SAI_AUDIO_FREQUENCY_8K 8000U
364 #define SAI_AUDIO_FREQUENCY_MCKDIV 0U
369 /** @defgroup SAI_Block_Mck_OverSampling SAI Block Master Clock OverSampling
372 #define SAI_MCK_OVERSAMPLING_DISABLE 0x00000000U
373 #define SAI_MCK_OVERSAMPLING_ENABLE SAI_xCR1_OSR
378 /** @defgroup SAI_PDM_ClockEnable SAI PDM Clock Enable
381 #define SAI_PDM_CLOCK1_ENABLE SAI_PDMCR_CKEN1
382 #define SAI_PDM_CLOCK2_ENABLE SAI_PDMCR_CKEN2
387 /** @defgroup SAI_Block_Mode SAI Block Mode
390 #define SAI_MODEMASTER_TX 0x00000000U
391 #define SAI_MODEMASTER_RX SAI_xCR1_MODE_0
392 #define SAI_MODESLAVE_TX SAI_xCR1_MODE_1
393 #define SAI_MODESLAVE_RX (SAI_xCR1_MODE_1 | SAI_xCR1_MODE_0)
399 /** @defgroup SAI_Block_Protocol SAI Block Protocol
402 #define SAI_FREE_PROTOCOL 0x00000000U
403 #define SAI_SPDIF_PROTOCOL SAI_xCR1_PRTCFG_0
404 #define SAI_AC97_PROTOCOL SAI_xCR1_PRTCFG_1
409 /** @defgroup SAI_Block_Data_Size SAI Block Data Size
412 #define SAI_DATASIZE_8 SAI_xCR1_DS_1
413 #define SAI_DATASIZE_10 (SAI_xCR1_DS_1 | SAI_xCR1_DS_0)
414 #define SAI_DATASIZE_16 SAI_xCR1_DS_2
415 #define SAI_DATASIZE_20 (SAI_xCR1_DS_2 | SAI_xCR1_DS_0)
416 #define SAI_DATASIZE_24 (SAI_xCR1_DS_2 | SAI_xCR1_DS_1)
417 #define SAI_DATASIZE_32 (SAI_xCR1_DS_2 | SAI_xCR1_DS_1 | SAI_xCR1_DS_0)
422 /** @defgroup SAI_Block_MSB_LSB_transmission SAI Block MSB LSB transmission
425 #define SAI_FIRSTBIT_MSB 0x00000000U
426 #define SAI_FIRSTBIT_LSB SAI_xCR1_LSBFIRST
431 /** @defgroup SAI_Block_Clock_Strobing SAI Block Clock Strobing
434 #define SAI_CLOCKSTROBING_FALLINGEDGE 0U
435 #define SAI_CLOCKSTROBING_RISINGEDGE 1U
440 /** @defgroup SAI_Block_Synchronization SAI Block Synchronization
443 #define SAI_ASYNCHRONOUS 0U /*!< Asynchronous */
444 #define SAI_SYNCHRONOUS 1U /*!< Synchronous with other block of same SAI */
445 #define SAI_SYNCHRONOUS_EXT_SAI1 2U /*!< Synchronous with other SAI, SAI1 */
447 #define SAI_SYNCHRONOUS_EXT_SAI2 3U /*!< Synchronous with other SAI, SAI2 */
450 #define SAI_SYNCHRONOUS_EXT_SAI3 4U /*!< Synchronous with other SAI, SAI3 */
453 #define SAI_SYNCHRONOUS_EXT_SAI4 5U /*!< Synchronous with other SAI, SAI4 */
459 /** @defgroup SAI_Block_Output_Drive SAI Block Output Drive
462 #define SAI_OUTPUTDRIVE_DISABLE 0x00000000U
463 #define SAI_OUTPUTDRIVE_ENABLE SAI_xCR1_OUTDRIV
468 /** @defgroup SAI_Block_NoDivider SAI Block NoDivider
471 #define SAI_MASTERDIVIDER_ENABLE 0x00000000U
472 #define SAI_MASTERDIVIDER_DISABLE SAI_xCR1_NODIV
477 /** @defgroup SAI_Block_FS_Definition SAI Block FS Definition
480 #define SAI_FS_STARTFRAME 0x00000000U
481 #define SAI_FS_CHANNEL_IDENTIFICATION SAI_xFRCR_FSDEF
486 /** @defgroup SAI_Block_FS_Polarity SAI Block FS Polarity
489 #define SAI_FS_ACTIVE_LOW 0x00000000U
490 #define SAI_FS_ACTIVE_HIGH SAI_xFRCR_FSPOL
495 /** @defgroup SAI_Block_FS_Offset SAI Block FS Offset
498 #define SAI_FS_FIRSTBIT 0x00000000U
499 #define SAI_FS_BEFOREFIRSTBIT SAI_xFRCR_FSOFF
504 /** @defgroup SAI_Block_Slot_Size SAI Block Slot Size
507 #define SAI_SLOTSIZE_DATASIZE 0x00000000U
508 #define SAI_SLOTSIZE_16B SAI_xSLOTR_SLOTSZ_0
509 #define SAI_SLOTSIZE_32B SAI_xSLOTR_SLOTSZ_1
514 /** @defgroup SAI_Block_Slot_Active SAI Block Slot Active
517 #define SAI_SLOT_NOTACTIVE 0x00000000U
518 #define SAI_SLOTACTIVE_0 0x00000001U
519 #define SAI_SLOTACTIVE_1 0x00000002U
520 #define SAI_SLOTACTIVE_2 0x00000004U
521 #define SAI_SLOTACTIVE_3 0x00000008U
522 #define SAI_SLOTACTIVE_4 0x00000010U
523 #define SAI_SLOTACTIVE_5 0x00000020U
524 #define SAI_SLOTACTIVE_6 0x00000040U
525 #define SAI_SLOTACTIVE_7 0x00000080U
526 #define SAI_SLOTACTIVE_8 0x00000100U
527 #define SAI_SLOTACTIVE_9 0x00000200U
528 #define SAI_SLOTACTIVE_10 0x00000400U
529 #define SAI_SLOTACTIVE_11 0x00000800U
530 #define SAI_SLOTACTIVE_12 0x00001000U
531 #define SAI_SLOTACTIVE_13 0x00002000U
532 #define SAI_SLOTACTIVE_14 0x00004000U
533 #define SAI_SLOTACTIVE_15 0x00008000U
534 #define SAI_SLOTACTIVE_ALL 0x0000FFFFU
539 /** @defgroup SAI_Mono_Stereo_Mode SAI Mono Stereo Mode
542 #define SAI_STEREOMODE 0x00000000U
543 #define SAI_MONOMODE SAI_xCR1_MONO
548 /** @defgroup SAI_TRIState_Management SAI TRIState Management
551 #define SAI_OUTPUT_NOTRELEASED 0x00000000U
552 #define SAI_OUTPUT_RELEASED SAI_xCR2_TRIS
557 /** @defgroup SAI_Block_Fifo_Threshold SAI Block Fifo Threshold
560 #define SAI_FIFOTHRESHOLD_EMPTY 0x00000000U
561 #define SAI_FIFOTHRESHOLD_1QF SAI_xCR2_FTH_0
562 #define SAI_FIFOTHRESHOLD_HF SAI_xCR2_FTH_1
563 #define SAI_FIFOTHRESHOLD_3QF (SAI_xCR2_FTH_1 | SAI_xCR2_FTH_0)
564 #define SAI_FIFOTHRESHOLD_FULL SAI_xCR2_FTH_2
569 /** @defgroup SAI_Block_Companding_Mode SAI Block Companding Mode
572 #define SAI_NOCOMPANDING 0x00000000U
573 #define SAI_ULAW_1CPL_COMPANDING SAI_xCR2_COMP_1
574 #define SAI_ALAW_1CPL_COMPANDING (SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0)
575 #define SAI_ULAW_2CPL_COMPANDING (SAI_xCR2_COMP_1 | SAI_xCR2_CPL)
576 #define SAI_ALAW_2CPL_COMPANDING (SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0 | SAI_xCR2_CPL)
581 /** @defgroup SAI_Block_Mute_Value SAI Block Mute Value
584 #define SAI_ZERO_VALUE 0x00000000U
585 #define SAI_LAST_SENT_VALUE SAI_xCR2_MUTEVAL
590 /** @defgroup SAI_Block_Interrupts_Definition SAI Block Interrupts Definition
593 #define SAI_IT_OVRUDR SAI_xIMR_OVRUDRIE
594 #define SAI_IT_MUTEDET SAI_xIMR_MUTEDETIE
595 #define SAI_IT_WCKCFG SAI_xIMR_WCKCFGIE
596 #define SAI_IT_FREQ SAI_xIMR_FREQIE
597 #define SAI_IT_CNRDY SAI_xIMR_CNRDYIE
598 #define SAI_IT_AFSDET SAI_xIMR_AFSDETIE
599 #define SAI_IT_LFSDET SAI_xIMR_LFSDETIE
604 /** @defgroup SAI_Block_Flags_Definition SAI Block Flags Definition
607 #define SAI_FLAG_OVRUDR SAI_xSR_OVRUDR
608 #define SAI_FLAG_MUTEDET SAI_xSR_MUTEDET
609 #define SAI_FLAG_WCKCFG SAI_xSR_WCKCFG
610 #define SAI_FLAG_FREQ SAI_xSR_FREQ
611 #define SAI_FLAG_CNRDY SAI_xSR_CNRDY
612 #define SAI_FLAG_AFSDET SAI_xSR_AFSDET
613 #define SAI_FLAG_LFSDET SAI_xSR_LFSDET
618 /** @defgroup SAI_Block_Fifo_Status_Level SAI Block Fifo Status Level
621 #define SAI_FIFOSTATUS_EMPTY 0x00000000U
622 #define SAI_FIFOSTATUS_LESS1QUARTERFULL 0x00010000U
623 #define SAI_FIFOSTATUS_1QUARTERFULL 0x00020000U
624 #define SAI_FIFOSTATUS_HALFFULL 0x00030000U
625 #define SAI_FIFOSTATUS_3QUARTERFULL 0x00040000U
626 #define SAI_FIFOSTATUS_FULL 0x00050000U
635 /* Exported macro ------------------------------------------------------------*/
636 /** @defgroup SAI_Exported_Macros SAI Exported Macros
637 * @brief macros to handle interrupts and specific configurations
641 /** @brief Reset SAI handle state.
642 * @param __HANDLE__ specifies the SAI Handle.
645 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
646 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) do{ \
647 (__HANDLE__)->State = HAL_SAI_STATE_RESET; \
648 (__HANDLE__)->MspInitCallback = NULL; \
649 (__HANDLE__)->MspDeInitCallback = NULL; \
652 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SAI_STATE_RESET)
655 /** @brief Enable the specified SAI interrupts.
656 * @param __HANDLE__ specifies the SAI Handle.
657 * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
658 * This parameter can be one of the following values:
659 * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
660 * @arg SAI_IT_MUTEDET: Mute detection interrupt enable
661 * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
662 * @arg SAI_IT_FREQ: FIFO request interrupt enable
663 * @arg SAI_IT_CNRDY: Codec not ready interrupt enable
664 * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
665 * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
668 #define __HAL_SAI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR |= (__INTERRUPT__))
670 /** @brief Disable the specified SAI interrupts.
671 * @param __HANDLE__ specifies the SAI Handle.
672 * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
673 * This parameter can be one of the following values:
674 * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
675 * @arg SAI_IT_MUTEDET: Mute detection interrupt enable
676 * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
677 * @arg SAI_IT_FREQ: FIFO request interrupt enable
678 * @arg SAI_IT_CNRDY: Codec not ready interrupt enable
679 * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
680 * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
683 #define __HAL_SAI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR &= (~(__INTERRUPT__)))
685 /** @brief Check whether the specified SAI interrupt source is enabled or not.
686 * @param __HANDLE__ specifies the SAI Handle.
687 * @param __INTERRUPT__ specifies the SAI interrupt source to check.
688 * This parameter can be one of the following values:
689 * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
690 * @arg SAI_IT_MUTEDET: Mute detection interrupt enable
691 * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
692 * @arg SAI_IT_FREQ: FIFO request interrupt enable
693 * @arg SAI_IT_CNRDY: Codec not ready interrupt enable
694 * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
695 * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
696 * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
698 #define __HAL_SAI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IMR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
700 /** @brief Check whether the specified SAI flag is set or not.
701 * @param __HANDLE__ specifies the SAI Handle.
702 * @param __FLAG__ specifies the flag to check.
703 * This parameter can be one of the following values:
704 * @arg SAI_FLAG_OVRUDR: Overrun underrun flag.
705 * @arg SAI_FLAG_MUTEDET: Mute detection flag.
706 * @arg SAI_FLAG_WCKCFG: Wrong Clock Configuration flag.
707 * @arg SAI_FLAG_FREQ: FIFO request flag.
708 * @arg SAI_FLAG_CNRDY: Codec not ready flag.
709 * @arg SAI_FLAG_AFSDET: Anticipated frame synchronization detection flag.
710 * @arg SAI_FLAG_LFSDET: Late frame synchronization detection flag.
711 * @retval The new state of __FLAG__ (TRUE or FALSE).
713 #define __HAL_SAI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
715 /** @brief Clear the specified SAI pending flag.
716 * @param __HANDLE__ specifies the SAI Handle.
717 * @param __FLAG__ specifies the flag to check.
718 * This parameter can be any combination of the following values:
719 * @arg SAI_FLAG_OVRUDR: Clear Overrun underrun
720 * @arg SAI_FLAG_MUTEDET: Clear Mute detection
721 * @arg SAI_FLAG_WCKCFG: Clear Wrong Clock Configuration
722 * @arg SAI_FLAG_FREQ: Clear FIFO request
723 * @arg SAI_FLAG_CNRDY: Clear Codec not ready
724 * @arg SAI_FLAG_AFSDET: Clear Anticipated frame synchronization detection
725 * @arg SAI_FLAG_LFSDET: Clear Late frame synchronization detection
729 #define __HAL_SAI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__))
731 /** @brief Enable SAI.
732 * @param __HANDLE__ specifies the SAI Handle.
735 #define __HAL_SAI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SAI_xCR1_SAIEN)
737 /** @brief Disable SAI.
738 * @param __HANDLE__ specifies the SAI Handle.
741 #define __HAL_SAI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~SAI_xCR1_SAIEN)
747 /* Include SAI HAL Extension module */
748 #include "stm32h7xx_hal_sai_ex.h"
750 /* Exported functions --------------------------------------------------------*/
751 /** @addtogroup SAI_Exported_Functions
755 /* Initialization/de-initialization functions ********************************/
756 /** @addtogroup SAI_Exported_Functions_Group1
759 HAL_StatusTypeDef
HAL_SAI_InitProtocol(SAI_HandleTypeDef
*hsai
, uint32_t protocol
, uint32_t datasize
, uint32_t nbslot
);
760 HAL_StatusTypeDef
HAL_SAI_Init(SAI_HandleTypeDef
*hsai
);
761 HAL_StatusTypeDef
HAL_SAI_DeInit(SAI_HandleTypeDef
*hsai
);
762 void HAL_SAI_MspInit(SAI_HandleTypeDef
*hsai
);
763 void HAL_SAI_MspDeInit(SAI_HandleTypeDef
*hsai
);
765 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
766 /* SAI callbacks register/unregister functions ********************************/
767 HAL_StatusTypeDef
HAL_SAI_RegisterCallback(SAI_HandleTypeDef
*hsai
,
768 HAL_SAI_CallbackIDTypeDef CallbackID
,
769 pSAI_CallbackTypeDef pCallback
);
770 HAL_StatusTypeDef
HAL_SAI_UnRegisterCallback(SAI_HandleTypeDef
*hsai
,
771 HAL_SAI_CallbackIDTypeDef CallbackID
);
777 /* I/O operation functions ***************************************************/
778 /** @addtogroup SAI_Exported_Functions_Group2
781 /* Blocking mode: Polling */
782 HAL_StatusTypeDef
HAL_SAI_Transmit(SAI_HandleTypeDef
*hsai
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
);
783 HAL_StatusTypeDef
HAL_SAI_Receive(SAI_HandleTypeDef
*hsai
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
);
785 /* Non-Blocking mode: Interrupt */
786 HAL_StatusTypeDef
HAL_SAI_Transmit_IT(SAI_HandleTypeDef
*hsai
, uint8_t *pData
, uint16_t Size
);
787 HAL_StatusTypeDef
HAL_SAI_Receive_IT(SAI_HandleTypeDef
*hsai
, uint8_t *pData
, uint16_t Size
);
789 /* Non-Blocking mode: DMA */
790 HAL_StatusTypeDef
HAL_SAI_Transmit_DMA(SAI_HandleTypeDef
*hsai
, uint8_t *pData
, uint16_t Size
);
791 HAL_StatusTypeDef
HAL_SAI_Receive_DMA(SAI_HandleTypeDef
*hsai
, uint8_t *pData
, uint16_t Size
);
792 HAL_StatusTypeDef
HAL_SAI_DMAPause(SAI_HandleTypeDef
*hsai
);
793 HAL_StatusTypeDef
HAL_SAI_DMAResume(SAI_HandleTypeDef
*hsai
);
794 HAL_StatusTypeDef
HAL_SAI_DMAStop(SAI_HandleTypeDef
*hsai
);
797 HAL_StatusTypeDef
HAL_SAI_Abort(SAI_HandleTypeDef
*hsai
);
799 /* Mute management */
800 HAL_StatusTypeDef
HAL_SAI_EnableTxMuteMode(SAI_HandleTypeDef
*hsai
, uint16_t val
);
801 HAL_StatusTypeDef
HAL_SAI_DisableTxMuteMode(SAI_HandleTypeDef
*hsai
);
802 HAL_StatusTypeDef
HAL_SAI_EnableRxMuteMode(SAI_HandleTypeDef
*hsai
, SAIcallback callback
, uint16_t counter
);
803 HAL_StatusTypeDef
HAL_SAI_DisableRxMuteMode(SAI_HandleTypeDef
*hsai
);
805 /* SAI IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
806 void HAL_SAI_IRQHandler(SAI_HandleTypeDef
*hsai
);
807 void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef
*hsai
);
808 void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef
*hsai
);
809 void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef
*hsai
);
810 void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef
*hsai
);
811 void HAL_SAI_ErrorCallback(SAI_HandleTypeDef
*hsai
);
816 /** @addtogroup SAI_Exported_Functions_Group3
819 /* Peripheral State functions ************************************************/
820 HAL_SAI_StateTypeDef
HAL_SAI_GetState(SAI_HandleTypeDef
*hsai
);
821 uint32_t HAL_SAI_GetError(SAI_HandleTypeDef
*hsai
);
830 /* Private macros ------------------------------------------------------------*/
831 /** @defgroup SAI_Private_Macros SAI Private Macros
834 #define IS_SAI_BLOCK_SYNCEXT(STATE) (((STATE) == SAI_SYNCEXT_DISABLE) ||\
835 ((STATE) == SAI_SYNCEXT_OUTBLOCKA_ENABLE) ||\
836 ((STATE) == SAI_SYNCEXT_OUTBLOCKB_ENABLE))
838 #define IS_SAI_SUPPORTED_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_I2S_STANDARD) ||\
839 ((PROTOCOL) == SAI_I2S_MSBJUSTIFIED) ||\
840 ((PROTOCOL) == SAI_I2S_LSBJUSTIFIED) ||\
841 ((PROTOCOL) == SAI_PCM_LONG) ||\
842 ((PROTOCOL) == SAI_PCM_SHORT))
844 #define IS_SAI_PROTOCOL_DATASIZE(DATASIZE) (((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BIT) ||\
845 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BITEXTENDED) ||\
846 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_24BIT) ||\
847 ((DATASIZE) == SAI_PROTOCOL_DATASIZE_32BIT))
849 #define IS_SAI_AUDIO_FREQUENCY(AUDIO) (((AUDIO) == SAI_AUDIO_FREQUENCY_192K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_96K) || \
850 ((AUDIO) == SAI_AUDIO_FREQUENCY_48K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_44K) || \
851 ((AUDIO) == SAI_AUDIO_FREQUENCY_32K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_22K) || \
852 ((AUDIO) == SAI_AUDIO_FREQUENCY_16K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_11K) || \
853 ((AUDIO) == SAI_AUDIO_FREQUENCY_8K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_MCKDIV))
855 #define IS_SAI_BLOCK_MCK_OVERSAMPLING(VALUE) (((VALUE) == SAI_MCK_OVERSAMPLING_DISABLE) || \
856 ((VALUE) == SAI_MCK_OVERSAMPLING_ENABLE))
858 #define IS_SAI_PDM_MIC_PAIRS_NUMBER(VALUE) ((1U <= (VALUE)) && ((VALUE) <= 3U))
860 #define IS_SAI_PDM_CLOCK_ENABLE(CLOCK) (((CLOCK) != 0U) && \
861 (((CLOCK) & ~(SAI_PDM_CLOCK1_ENABLE | SAI_PDM_CLOCK2_ENABLE)) == 0U))
863 #define IS_SAI_BLOCK_MODE(MODE) (((MODE) == SAI_MODEMASTER_TX) || \
864 ((MODE) == SAI_MODEMASTER_RX) || \
865 ((MODE) == SAI_MODESLAVE_TX) || \
866 ((MODE) == SAI_MODESLAVE_RX))
868 #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_FREE_PROTOCOL) || \
869 ((PROTOCOL) == SAI_AC97_PROTOCOL) || \
870 ((PROTOCOL) == SAI_SPDIF_PROTOCOL))
872 #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DATASIZE_8) || \
873 ((DATASIZE) == SAI_DATASIZE_10) || \
874 ((DATASIZE) == SAI_DATASIZE_16) || \
875 ((DATASIZE) == SAI_DATASIZE_20) || \
876 ((DATASIZE) == SAI_DATASIZE_24) || \
877 ((DATASIZE) == SAI_DATASIZE_32))
879 #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FIRSTBIT_MSB) || \
880 ((BIT) == SAI_FIRSTBIT_LSB))
882 #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_CLOCKSTROBING_FALLINGEDGE) || \
883 ((CLOCK) == SAI_CLOCKSTROBING_RISINGEDGE))
884 #if defined(SAI2) && defined(SAI3) && defined(SAI4)
885 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS) || \
886 ((SYNCHRO) == SAI_SYNCHRONOUS) || \
887 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI1) || \
888 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI2) || \
889 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI3) || \
890 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI4))
892 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS) || \
893 ((SYNCHRO) == SAI_SYNCHRONOUS) || \
894 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI1) || \
895 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI2))
897 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS) || \
898 ((SYNCHRO) == SAI_SYNCHRONOUS) || \
899 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI1) || \
900 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI4))
903 #define IS_SAI_BLOCK_MCK_OUTPUT(VALUE) (((VALUE) == SAI_MCK_OUTPUT_ENABLE) || \
904 ((VALUE) == SAI_MCK_OUTPUT_DISABLE))
906 #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OUTPUTDRIVE_DISABLE) || \
907 ((DRIVE) == SAI_OUTPUTDRIVE_ENABLE))
909 #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MASTERDIVIDER_ENABLE) || \
910 ((NODIVIDER) == SAI_MASTERDIVIDER_DISABLE))
912 #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63U)
914 #define IS_SAI_BLOCK_MUTE_VALUE(VALUE) (((VALUE) == SAI_ZERO_VALUE) || \
915 ((VALUE) == SAI_LAST_SENT_VALUE))
917 #define IS_SAI_BLOCK_COMPANDING_MODE(MODE) (((MODE) == SAI_NOCOMPANDING) || \
918 ((MODE) == SAI_ULAW_1CPL_COMPANDING) || \
919 ((MODE) == SAI_ALAW_1CPL_COMPANDING) || \
920 ((MODE) == SAI_ULAW_2CPL_COMPANDING) || \
921 ((MODE) == SAI_ALAW_2CPL_COMPANDING))
923 #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_FIFOTHRESHOLD_EMPTY) || \
924 ((THRESHOLD) == SAI_FIFOTHRESHOLD_1QF) || \
925 ((THRESHOLD) == SAI_FIFOTHRESHOLD_HF) || \
926 ((THRESHOLD) == SAI_FIFOTHRESHOLD_3QF) || \
927 ((THRESHOLD) == SAI_FIFOTHRESHOLD_FULL))
929 #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_OUTPUT_NOTRELEASED) ||\
930 ((STATE) == SAI_OUTPUT_RELEASED))
932 #define IS_SAI_MONO_STEREO_MODE(MODE) (((MODE) == SAI_MONOMODE) ||\
933 ((MODE) == SAI_STEREOMODE))
935 #define IS_SAI_SLOT_ACTIVE(ACTIVE) ((ACTIVE) <= SAI_SLOTACTIVE_ALL)
937 #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1U <= (NUMBER)) && ((NUMBER) <= 16U))
939 #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SLOTSIZE_DATASIZE) || \
940 ((SIZE) == SAI_SLOTSIZE_16B) || \
941 ((SIZE) == SAI_SLOTSIZE_32B))
943 #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24U)
945 #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FIRSTBIT) || \
946 ((OFFSET) == SAI_FS_BEFOREFIRSTBIT))
948 #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ACTIVE_LOW) || \
949 ((POLARITY) == SAI_FS_ACTIVE_HIGH))
951 #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_STARTFRAME) || \
952 ((DEFINITION) == SAI_FS_CHANNEL_IDENTIFICATION))
954 #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 63U)
956 #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8U <= (LENGTH)) && ((LENGTH) <= 256U))
958 #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1U <= (LENGTH)) && ((LENGTH) <= 128U))
964 /* Private functions ---------------------------------------------------------*/
965 /** @defgroup SAI_Private_Functions SAI Private Functions
985 #endif /* STM32H7xx_HAL_SAI_H */
987 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/