Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:36

0001 /**
0002   ******************************************************************************
0003   * @file    stm32h7xx_hal_sai.h
0004   * @author  MCD Application Team
0005   * @brief   Header file of SAI HAL module.
0006   ******************************************************************************
0007   * @attention
0008   *
0009   * Copyright (c) 2017 STMicroelectronics.
0010   * All rights reserved.
0011   *
0012   * This software is licensed under terms that can be found in the LICENSE file
0013   * in the root directory of this software component.
0014   * If no LICENSE file comes with this software, it is provided AS-IS.
0015   *
0016   ******************************************************************************
0017   */
0018 
0019 /* Define to prevent recursive inclusion -------------------------------------*/
0020 #ifndef STM32H7xx_HAL_SAI_H
0021 #define STM32H7xx_HAL_SAI_H
0022 
0023 #ifdef __cplusplus
0024 extern "C" {
0025 #endif
0026 
0027 /* Includes ------------------------------------------------------------------*/
0028 #include "stm32h7xx_hal_def.h"
0029 
0030 /** @addtogroup STM32H7xx_HAL_Driver
0031   * @{
0032   */
0033 
0034 /** @addtogroup SAI
0035   * @{
0036   */
0037 
0038 /* Exported types ------------------------------------------------------------*/
0039 /** @defgroup SAI_Exported_Types SAI Exported Types
0040   * @ingroup RTEMSBSPsARMSTM32H7
0041   * @{
0042   */
0043 
0044 /**
0045   * @brief  HAL State structures definition
0046   */
0047 typedef enum
0048 {
0049   HAL_SAI_STATE_RESET   = 0x00U, /*!< SAI not yet initialized or disabled  */
0050   HAL_SAI_STATE_READY   = 0x01U, /*!< SAI initialized and ready for use    */
0051   HAL_SAI_STATE_BUSY    = 0x02U, /*!< SAI internal process is ongoing      */
0052   HAL_SAI_STATE_BUSY_TX = 0x12U, /*!< Data transmission process is ongoing */
0053   HAL_SAI_STATE_BUSY_RX = 0x22U, /*!< Data reception process is ongoing    */
0054 } HAL_SAI_StateTypeDef;
0055 
0056 /**
0057   * @brief  SAI Callback prototype
0058   */
0059 typedef void (*SAIcallback)(void);
0060 
0061 /** @defgroup SAI_PDM_Structure_definition SAI PDM Structure definition
0062   * @ingroup RTEMSBSPsARMSTM32H7
0063   * @brief  SAI PDM Init structure definition
0064   * @{
0065   */
0066 typedef struct
0067 {
0068   FunctionalState  Activation;  /*!< Enable/disable PDM interface */
0069   uint32_t         MicPairsNbr; /*!< Specifies the number of microphone pairs used.
0070                                      This parameter must be a number between Min_Data = 1 and Max_Data = 3. */
0071   uint32_t         ClockEnable; /*!< Specifies which clock must be enabled.
0072                                      This parameter can be a values combination of @ref SAI_PDM_ClockEnable */
0073 } SAI_PdmInitTypeDef;
0074 /**
0075   * @}
0076   */
0077 
0078 /** @defgroup SAI_Init_Structure_definition SAI Init Structure definition
0079   * @ingroup RTEMSBSPsARMSTM32H7
0080   * @brief  SAI Init Structure definition
0081   * @{
0082   */
0083 typedef struct
0084 {
0085   uint32_t AudioMode;           /*!< Specifies the SAI Block audio Mode.
0086                                      This parameter can be a value of @ref SAI_Block_Mode */
0087 
0088   uint32_t Synchro;             /*!< Specifies SAI Block synchronization
0089                                      This parameter can be a value of @ref SAI_Block_Synchronization */
0090 
0091   uint32_t SynchroExt;          /*!< Specifies SAI external output synchronization, this setup is common
0092                                      for BlockA and BlockB
0093                                      This parameter can be a value of @ref SAI_Block_SyncExt
0094                                      @note If both audio blocks of same SAI are used, this parameter has
0095                                            to be set to the same value for each audio block */
0096 
0097   uint32_t MckOutput;           /*!< Specifies whether master clock output will be generated or not.
0098                                      This parameter can be a value of @ref SAI_Block_MckOutput
0099                                      @note This feature is only available on STM32H7xx Rev.B and above */
0100 
0101   uint32_t OutputDrive;         /*!< Specifies when SAI Block outputs are driven.
0102                                      This parameter can be a value of @ref SAI_Block_Output_Drive
0103                                      @note This value has to be set before enabling the audio block
0104                                            but after the audio block configuration. */
0105 
0106   uint32_t NoDivider;           /*!< Specifies whether master clock will be divided or not.
0107                                      This parameter can be a value of @ref SAI_Block_NoDivider
0108                                      @note If bit NODIV in the SAI_xCR1 register is cleared, the frame length
0109                                            should be aligned to a number equal to a power of 2, from 8 to 256.
0110                                            If bit NODIV in the SAI_xCR1 register is set, the frame length can
0111                                            take any of the values from 8 to 256.
0112                                      @note The NODIV bit is the same as NOMCK bit in STM32H7xx rev.Y */
0113 
0114   uint32_t FIFOThreshold;       /*!< Specifies SAI Block FIFO threshold.
0115                                      This parameter can be a value of @ref SAI_Block_Fifo_Threshold */
0116 
0117   uint32_t AudioFrequency;      /*!< Specifies the audio frequency sampling.
0118                                      This parameter can be a value of @ref SAI_Audio_Frequency */
0119 
0120   uint32_t Mckdiv;              /*!< Specifies the master clock divider.
0121                                      This parameter must be a number between Min_Data = 0 and Max_Data = 63.
0122                                      @note This parameter is used only if AudioFrequency is set to
0123                                            SAI_AUDIO_FREQUENCY_MCKDIV otherwise it is internally computed. */
0124 
0125   uint32_t MckOverSampling;     /*!< Specifies the master clock oversampling.
0126                                      This parameter can be a value of @ref SAI_Block_Mck_OverSampling */
0127 
0128   uint32_t MonoStereoMode;      /*!< Specifies if the mono or stereo mode is selected.
0129                                      This parameter can be a value of @ref SAI_Mono_Stereo_Mode */
0130 
0131   uint32_t CompandingMode;      /*!< Specifies the companding mode type.
0132                                      This parameter can be a value of @ref SAI_Block_Companding_Mode */
0133 
0134   uint32_t TriState;            /*!< Specifies the companding mode type.
0135                                      This parameter can be a value of @ref SAI_TRIState_Management */
0136 
0137   SAI_PdmInitTypeDef PdmInit;   /*!< Specifies the PDM configuration. */
0138 
0139   /* This part of the structure is automatically filled if your are using the high level initialisation
0140      function HAL_SAI_InitProtocol */
0141 
0142   uint32_t Protocol;        /*!< Specifies the SAI Block protocol.
0143                                  This parameter can be a value of @ref SAI_Block_Protocol */
0144 
0145   uint32_t DataSize;        /*!< Specifies the SAI Block data size.
0146                                  This parameter can be a value of @ref SAI_Block_Data_Size */
0147 
0148   uint32_t FirstBit;        /*!< Specifies whether data transfers start from MSB or LSB bit.
0149                                  This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission */
0150 
0151   uint32_t ClockStrobing;   /*!< Specifies the SAI Block clock strobing edge sensitivity.
0152                                  This parameter can be a value of @ref SAI_Block_Clock_Strobing */
0153 } SAI_InitTypeDef;
0154 /**
0155   * @}
0156   */
0157 
0158 /** @defgroup SAI_Frame_Structure_definition SAI Frame Structure definition
0159   * @ingroup RTEMSBSPsARMSTM32H7
0160   * @brief  SAI Frame Init structure definition
0161   * @note   For SPDIF and AC97 protocol, these parameters are not used (set by hardware).
0162   * @{
0163   */
0164 typedef struct
0165 {
0166 
0167   uint32_t FrameLength;        /*!< Specifies the Frame length, the number of SCK clocks for each audio frame.
0168                                     This parameter must be a number between Min_Data = 8 and Max_Data = 256.
0169                                     @note If master clock MCLK_x pin is declared as an output, the frame length
0170                                           should be aligned to a number equal to power of 2 in order to keep
0171                                           in an audio frame, an integer number of MCLK pulses by bit Clock. */
0172 
0173   uint32_t ActiveFrameLength;  /*!< Specifies the Frame synchronization active level length.
0174                                     This Parameter specifies the length in number of bit clock (SCK + 1)
0175                                     of the active level of FS signal in audio frame.
0176                                     This parameter must be a number between Min_Data = 1 and Max_Data = 128 */
0177 
0178   uint32_t FSDefinition;       /*!< Specifies the Frame synchronization definition.
0179                                     This parameter can be a value of @ref SAI_Block_FS_Definition */
0180 
0181   uint32_t FSPolarity;         /*!< Specifies the Frame synchronization Polarity.
0182                                     This parameter can be a value of @ref SAI_Block_FS_Polarity */
0183 
0184   uint32_t FSOffset;           /*!< Specifies the Frame synchronization Offset.
0185                                     This parameter can be a value of @ref SAI_Block_FS_Offset */
0186 
0187 } SAI_FrameInitTypeDef;
0188 /**
0189   * @}
0190   */
0191 
0192 /** @defgroup SAI_Slot_Structure_definition SAI Slot Structure definition
0193   * @ingroup RTEMSBSPsARMSTM32H7
0194   * @brief   SAI Block Slot Init Structure definition
0195   * @note    For SPDIF protocol, these parameters are not used (set by hardware).
0196   * @note    For AC97 protocol, only SlotActive parameter is used (the others are set by hardware).
0197   * @{
0198   */
0199 typedef struct
0200 {
0201   uint32_t FirstBitOffset;  /*!< Specifies the position of first data transfer bit in the slot.
0202                                  This parameter must be a number between Min_Data = 0 and Max_Data = 24 */
0203 
0204   uint32_t SlotSize;        /*!< Specifies the Slot Size.
0205                                  This parameter can be a value of @ref SAI_Block_Slot_Size */
0206 
0207   uint32_t SlotNumber;      /*!< Specifies the number of slot in the audio frame.
0208                                  This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
0209 
0210   uint32_t SlotActive;      /*!< Specifies the slots in audio frame that will be activated.
0211                                  This parameter can be a value of @ref SAI_Block_Slot_Active */
0212 } SAI_SlotInitTypeDef;
0213 /**
0214   * @}
0215   */
0216 
0217 /** @defgroup SAI_Handle_Structure_definition SAI Handle Structure definition
0218   * @ingroup RTEMSBSPsARMSTM32H7
0219   * @brief  SAI handle Structure definition
0220   * @{
0221   */
0222 typedef struct __SAI_HandleTypeDef
0223 {
0224   SAI_Block_TypeDef         *Instance;    /*!< SAI Blockx registers base address */
0225 
0226   SAI_InitTypeDef           Init;         /*!< SAI communication parameters */
0227 
0228   SAI_FrameInitTypeDef      FrameInit;    /*!< SAI Frame configuration parameters */
0229 
0230   SAI_SlotInitTypeDef       SlotInit;     /*!< SAI Slot configuration parameters */
0231 
0232   uint8_t                  *pBuffPtr;     /*!< Pointer to SAI transfer Buffer */
0233 
0234   uint16_t                  XferSize;     /*!< SAI transfer size */
0235 
0236   uint16_t                  XferCount;    /*!< SAI transfer counter */
0237 
0238   DMA_HandleTypeDef         *hdmatx;      /*!< SAI Tx DMA handle parameters */
0239 
0240   DMA_HandleTypeDef         *hdmarx;      /*!< SAI Rx DMA handle parameters */
0241 
0242   SAIcallback               mutecallback; /*!< SAI mute callback */
0243 
0244   void (*InterruptServiceRoutine)(struct __SAI_HandleTypeDef *hsai); /* function pointer for IRQ handler */
0245 
0246   HAL_LockTypeDef           Lock;         /*!< SAI locking object */
0247 
0248   __IO HAL_SAI_StateTypeDef State;        /*!< SAI communication state */
0249 
0250   __IO uint32_t             ErrorCode;    /*!< SAI Error code */
0251 
0252 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
0253   void (*RxCpltCallback)(struct __SAI_HandleTypeDef *hsai);      /*!< SAI receive complete callback */
0254   void (*RxHalfCpltCallback)(struct __SAI_HandleTypeDef *hsai);  /*!< SAI receive half complete callback */
0255   void (*TxCpltCallback)(struct __SAI_HandleTypeDef *hsai);      /*!< SAI transmit complete callback */
0256   void (*TxHalfCpltCallback)(struct __SAI_HandleTypeDef *hsai);  /*!< SAI transmit half complete callback */
0257   void (*ErrorCallback)(struct __SAI_HandleTypeDef *hsai);       /*!< SAI error callback */
0258   void (*MspInitCallback)(struct __SAI_HandleTypeDef *hsai);     /*!< SAI MSP init callback */
0259   void (*MspDeInitCallback)(struct __SAI_HandleTypeDef *hsai);   /*!< SAI MSP de-init callback */
0260 #endif
0261 } SAI_HandleTypeDef;
0262 /**
0263   * @}
0264   */
0265 
0266 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
0267 /**
0268   * @brief  SAI callback ID enumeration definition
0269   */
0270 typedef enum
0271 {
0272   HAL_SAI_RX_COMPLETE_CB_ID       = 0x00U, /*!< SAI receive complete callback ID */
0273   HAL_SAI_RX_HALFCOMPLETE_CB_ID   = 0x01U, /*!< SAI receive half complete callback ID */
0274   HAL_SAI_TX_COMPLETE_CB_ID       = 0x02U, /*!< SAI transmit complete callback ID */
0275   HAL_SAI_TX_HALFCOMPLETE_CB_ID   = 0x03U, /*!< SAI transmit half complete callback ID */
0276   HAL_SAI_ERROR_CB_ID             = 0x04U, /*!< SAI error callback ID */
0277   HAL_SAI_MSPINIT_CB_ID           = 0x05U, /*!< SAI MSP init callback ID */
0278   HAL_SAI_MSPDEINIT_CB_ID         = 0x06U  /*!< SAI MSP de-init callback ID */
0279 } HAL_SAI_CallbackIDTypeDef;
0280 
0281 /**
0282   * @brief  SAI callback pointer definition
0283   */
0284 typedef void (*pSAI_CallbackTypeDef)(SAI_HandleTypeDef *hsai);
0285 #endif
0286 
0287 /**
0288   * @}
0289   */
0290 
0291 /* Exported constants --------------------------------------------------------*/
0292 /** @defgroup SAI_Exported_Constants SAI Exported Constants
0293   * @ingroup RTEMSBSPsARMSTM32H7
0294   * @{
0295   */
0296 
0297 /** @defgroup SAI_Error_Code SAI Error Code
0298   * @ingroup RTEMSBSPsARMSTM32H7
0299   * @{
0300   */
0301 #define HAL_SAI_ERROR_NONE          0x00000000U  /*!< No error */
0302 #define HAL_SAI_ERROR_OVR           0x00000001U  /*!< Overrun Error */
0303 #define HAL_SAI_ERROR_UDR           0x00000002U  /*!< Underrun error */
0304 #define HAL_SAI_ERROR_AFSDET        0x00000004U  /*!< Anticipated Frame synchronisation detection */
0305 #define HAL_SAI_ERROR_LFSDET        0x00000008U  /*!< Late Frame synchronisation detection */
0306 #define HAL_SAI_ERROR_CNREADY       0x00000010U  /*!< codec not ready */
0307 #define HAL_SAI_ERROR_WCKCFG        0x00000020U  /*!< Wrong clock configuration */
0308 #define HAL_SAI_ERROR_TIMEOUT       0x00000040U  /*!< Timeout error */
0309 #define HAL_SAI_ERROR_DMA           0x00000080U  /*!< DMA error */
0310 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
0311 #define HAL_SAI_ERROR_INVALID_CALLBACK   0x00000100U  /*!< Invalid callback error */
0312 #endif
0313 /**
0314   * @}
0315   */
0316 
0317 /** @defgroup SAI_Block_SyncExt SAI External synchronisation
0318   * @ingroup RTEMSBSPsARMSTM32H7
0319   * @{
0320   */
0321 #define SAI_SYNCEXT_DISABLE           0U
0322 #define SAI_SYNCEXT_OUTBLOCKA_ENABLE  1U
0323 #define SAI_SYNCEXT_OUTBLOCKB_ENABLE  2U
0324 /**
0325   * @}
0326   */
0327 
0328 /** @defgroup SAI_Block_MckOutput SAI Block Master Clock Output
0329   * @ingroup RTEMSBSPsARMSTM32H7
0330   * @{
0331   */
0332 #define SAI_MCK_OUTPUT_DISABLE      0x00000000U
0333 #define SAI_MCK_OUTPUT_ENABLE       SAI_xCR1_MCKEN
0334 /**
0335   * @}
0336   */
0337 
0338 /** @defgroup SAI_Protocol SAI Supported protocol
0339   * @ingroup RTEMSBSPsARMSTM32H7
0340   * @{
0341   */
0342 #define SAI_I2S_STANDARD         0U
0343 #define SAI_I2S_MSBJUSTIFIED     1U
0344 #define SAI_I2S_LSBJUSTIFIED     2U
0345 #define SAI_PCM_LONG             3U
0346 #define SAI_PCM_SHORT            4U
0347 /**
0348   * @}
0349   */
0350 
0351 /** @defgroup SAI_Protocol_DataSize SAI protocol data size
0352   * @ingroup RTEMSBSPsARMSTM32H7
0353   * @{
0354   */
0355 #define SAI_PROTOCOL_DATASIZE_16BIT         0U
0356 #define SAI_PROTOCOL_DATASIZE_16BITEXTENDED 1U
0357 #define SAI_PROTOCOL_DATASIZE_24BIT         2U
0358 #define SAI_PROTOCOL_DATASIZE_32BIT         3U
0359 /**
0360   * @}
0361   */
0362 
0363 /** @defgroup SAI_Audio_Frequency SAI Audio Frequency
0364   * @ingroup RTEMSBSPsARMSTM32H7
0365   * @{
0366   */
0367 #define SAI_AUDIO_FREQUENCY_192K      192000U
0368 #define SAI_AUDIO_FREQUENCY_96K        96000U
0369 #define SAI_AUDIO_FREQUENCY_48K        48000U
0370 #define SAI_AUDIO_FREQUENCY_44K        44100U
0371 #define SAI_AUDIO_FREQUENCY_32K        32000U
0372 #define SAI_AUDIO_FREQUENCY_22K        22050U
0373 #define SAI_AUDIO_FREQUENCY_16K        16000U
0374 #define SAI_AUDIO_FREQUENCY_11K        11025U
0375 #define SAI_AUDIO_FREQUENCY_8K          8000U
0376 #define SAI_AUDIO_FREQUENCY_MCKDIV         0U
0377 /**
0378   * @}
0379   */
0380 
0381 /** @defgroup SAI_Block_Mck_OverSampling SAI Block Master Clock OverSampling
0382   * @ingroup RTEMSBSPsARMSTM32H7
0383   * @{
0384   */
0385 #define SAI_MCK_OVERSAMPLING_DISABLE  0x00000000U
0386 #define SAI_MCK_OVERSAMPLING_ENABLE   SAI_xCR1_OSR
0387 /**
0388   * @}
0389   */
0390 
0391 /** @defgroup SAI_PDM_ClockEnable SAI PDM Clock Enable
0392   * @ingroup RTEMSBSPsARMSTM32H7
0393   * @{
0394   */
0395 #define SAI_PDM_CLOCK1_ENABLE         SAI_PDMCR_CKEN1
0396 #define SAI_PDM_CLOCK2_ENABLE         SAI_PDMCR_CKEN2
0397 /**
0398   * @}
0399   */
0400 
0401 /** @defgroup SAI_Block_Mode SAI Block Mode
0402   * @ingroup RTEMSBSPsARMSTM32H7
0403   * @{
0404   */
0405 #define SAI_MODEMASTER_TX             0x00000000U
0406 #define SAI_MODEMASTER_RX             SAI_xCR1_MODE_0
0407 #define SAI_MODESLAVE_TX              SAI_xCR1_MODE_1
0408 #define SAI_MODESLAVE_RX              (SAI_xCR1_MODE_1 | SAI_xCR1_MODE_0)
0409 
0410 /**
0411   * @}
0412   */
0413 
0414 /** @defgroup SAI_Block_Protocol SAI Block Protocol
0415   * @ingroup RTEMSBSPsARMSTM32H7
0416   * @{
0417   */
0418 #define SAI_FREE_PROTOCOL             0x00000000U
0419 #define SAI_SPDIF_PROTOCOL            SAI_xCR1_PRTCFG_0
0420 #define SAI_AC97_PROTOCOL             SAI_xCR1_PRTCFG_1
0421 /**
0422   * @}
0423   */
0424 
0425 /** @defgroup SAI_Block_Data_Size SAI Block Data Size
0426   * @ingroup RTEMSBSPsARMSTM32H7
0427   * @{
0428   */
0429 #define SAI_DATASIZE_8                SAI_xCR1_DS_1
0430 #define SAI_DATASIZE_10               (SAI_xCR1_DS_1 | SAI_xCR1_DS_0)
0431 #define SAI_DATASIZE_16               SAI_xCR1_DS_2
0432 #define SAI_DATASIZE_20               (SAI_xCR1_DS_2 | SAI_xCR1_DS_0)
0433 #define SAI_DATASIZE_24               (SAI_xCR1_DS_2 | SAI_xCR1_DS_1)
0434 #define SAI_DATASIZE_32               (SAI_xCR1_DS_2 | SAI_xCR1_DS_1 | SAI_xCR1_DS_0)
0435 /**
0436   * @}
0437   */
0438 
0439 /** @defgroup SAI_Block_MSB_LSB_transmission SAI Block MSB LSB transmission
0440   * @ingroup RTEMSBSPsARMSTM32H7
0441   * @{
0442   */
0443 #define SAI_FIRSTBIT_MSB              0x00000000U
0444 #define SAI_FIRSTBIT_LSB              SAI_xCR1_LSBFIRST
0445 /**
0446   * @}
0447   */
0448 
0449 /** @defgroup SAI_Block_Clock_Strobing SAI Block Clock Strobing
0450   * @ingroup RTEMSBSPsARMSTM32H7
0451   * @{
0452   */
0453 #define SAI_CLOCKSTROBING_FALLINGEDGE  0U
0454 #define SAI_CLOCKSTROBING_RISINGEDGE   1U
0455 /**
0456   * @}
0457   */
0458 
0459 /** @defgroup SAI_Block_Synchronization SAI Block Synchronization
0460   * @ingroup RTEMSBSPsARMSTM32H7
0461   * @{
0462   */
0463 #define SAI_ASYNCHRONOUS                  0U /*!< Asynchronous */
0464 #define SAI_SYNCHRONOUS                   1U /*!< Synchronous with other block of same SAI */
0465 #define SAI_SYNCHRONOUS_EXT_SAI1          2U /*!< Synchronous with other SAI, SAI1 */
0466 #if defined(SAI2)
0467 #define SAI_SYNCHRONOUS_EXT_SAI2          3U /*!< Synchronous with other SAI, SAI2 */
0468 #endif /* SAI2 */
0469 #if defined(SAI3)
0470 #define SAI_SYNCHRONOUS_EXT_SAI3          4U /*!< Synchronous with other SAI, SAI3 */
0471 #endif /* SAI3 */
0472 #if defined(SAI4)
0473 #define SAI_SYNCHRONOUS_EXT_SAI4          5U /*!< Synchronous with other SAI, SAI4 */
0474 #endif /* SAI4 */
0475 /**
0476   * @}
0477   */
0478 
0479 /** @defgroup SAI_Block_Output_Drive SAI Block Output Drive
0480   * @ingroup RTEMSBSPsARMSTM32H7
0481   * @{
0482   */
0483 #define SAI_OUTPUTDRIVE_DISABLE     0x00000000U
0484 #define SAI_OUTPUTDRIVE_ENABLE      SAI_xCR1_OUTDRIV
0485 /**
0486   * @}
0487   */
0488 
0489 /** @defgroup SAI_Block_NoDivider SAI Block NoDivider
0490   * @ingroup RTEMSBSPsARMSTM32H7
0491   * @{
0492   */
0493 #define SAI_MASTERDIVIDER_ENABLE    0x00000000U
0494 #define SAI_MASTERDIVIDER_DISABLE   SAI_xCR1_NODIV
0495 /**
0496   * @}
0497   */
0498 
0499 /** @defgroup SAI_Block_FS_Definition SAI Block FS Definition
0500   * @ingroup RTEMSBSPsARMSTM32H7
0501   * @{
0502   */
0503 #define SAI_FS_STARTFRAME               0x00000000U
0504 #define SAI_FS_CHANNEL_IDENTIFICATION   SAI_xFRCR_FSDEF
0505 /**
0506   * @}
0507   */
0508 
0509 /** @defgroup SAI_Block_FS_Polarity SAI Block FS Polarity
0510   * @ingroup RTEMSBSPsARMSTM32H7
0511   * @{
0512   */
0513 #define SAI_FS_ACTIVE_LOW           0x00000000U
0514 #define SAI_FS_ACTIVE_HIGH          SAI_xFRCR_FSPOL
0515 /**
0516   * @}
0517   */
0518 
0519 /** @defgroup SAI_Block_FS_Offset SAI Block FS Offset
0520   * @ingroup RTEMSBSPsARMSTM32H7
0521   * @{
0522   */
0523 #define SAI_FS_FIRSTBIT             0x00000000U
0524 #define SAI_FS_BEFOREFIRSTBIT       SAI_xFRCR_FSOFF
0525 /**
0526   * @}
0527   */
0528 
0529 /** @defgroup SAI_Block_Slot_Size SAI Block Slot Size
0530   * @ingroup RTEMSBSPsARMSTM32H7
0531   * @{
0532   */
0533 #define SAI_SLOTSIZE_DATASIZE       0x00000000U
0534 #define SAI_SLOTSIZE_16B            SAI_xSLOTR_SLOTSZ_0
0535 #define SAI_SLOTSIZE_32B            SAI_xSLOTR_SLOTSZ_1
0536 /**
0537   * @}
0538   */
0539 
0540 /** @defgroup SAI_Block_Slot_Active SAI Block Slot Active
0541   * @ingroup RTEMSBSPsARMSTM32H7
0542   * @{
0543   */
0544 #define SAI_SLOT_NOTACTIVE          0x00000000U
0545 #define SAI_SLOTACTIVE_0            0x00000001U
0546 #define SAI_SLOTACTIVE_1            0x00000002U
0547 #define SAI_SLOTACTIVE_2            0x00000004U
0548 #define SAI_SLOTACTIVE_3            0x00000008U
0549 #define SAI_SLOTACTIVE_4            0x00000010U
0550 #define SAI_SLOTACTIVE_5            0x00000020U
0551 #define SAI_SLOTACTIVE_6            0x00000040U
0552 #define SAI_SLOTACTIVE_7            0x00000080U
0553 #define SAI_SLOTACTIVE_8            0x00000100U
0554 #define SAI_SLOTACTIVE_9            0x00000200U
0555 #define SAI_SLOTACTIVE_10           0x00000400U
0556 #define SAI_SLOTACTIVE_11           0x00000800U
0557 #define SAI_SLOTACTIVE_12           0x00001000U
0558 #define SAI_SLOTACTIVE_13           0x00002000U
0559 #define SAI_SLOTACTIVE_14           0x00004000U
0560 #define SAI_SLOTACTIVE_15           0x00008000U
0561 #define SAI_SLOTACTIVE_ALL          0x0000FFFFU
0562 /**
0563   * @}
0564   */
0565 
0566 /** @defgroup SAI_Mono_Stereo_Mode SAI Mono Stereo Mode
0567   * @ingroup RTEMSBSPsARMSTM32H7
0568   * @{
0569   */
0570 #define SAI_STEREOMODE              0x00000000U
0571 #define SAI_MONOMODE                SAI_xCR1_MONO
0572 /**
0573   * @}
0574   */
0575 
0576 /** @defgroup SAI_TRIState_Management SAI TRIState Management
0577   * @ingroup RTEMSBSPsARMSTM32H7
0578   * @{
0579   */
0580 #define SAI_OUTPUT_NOTRELEASED      0x00000000U
0581 #define SAI_OUTPUT_RELEASED         SAI_xCR2_TRIS
0582 /**
0583   * @}
0584   */
0585 
0586 /** @defgroup SAI_Block_Fifo_Threshold SAI Block Fifo Threshold
0587   * @ingroup RTEMSBSPsARMSTM32H7
0588   * @{
0589   */
0590 #define SAI_FIFOTHRESHOLD_EMPTY     0x00000000U
0591 #define SAI_FIFOTHRESHOLD_1QF       SAI_xCR2_FTH_0
0592 #define SAI_FIFOTHRESHOLD_HF        SAI_xCR2_FTH_1
0593 #define SAI_FIFOTHRESHOLD_3QF       (SAI_xCR2_FTH_1 | SAI_xCR2_FTH_0)
0594 #define SAI_FIFOTHRESHOLD_FULL      SAI_xCR2_FTH_2
0595 /**
0596   * @}
0597   */
0598 
0599 /** @defgroup SAI_Block_Companding_Mode SAI Block Companding Mode
0600   * @ingroup RTEMSBSPsARMSTM32H7
0601   * @{
0602   */
0603 #define SAI_NOCOMPANDING            0x00000000U
0604 #define SAI_ULAW_1CPL_COMPANDING    SAI_xCR2_COMP_1
0605 #define SAI_ALAW_1CPL_COMPANDING    (SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0)
0606 #define SAI_ULAW_2CPL_COMPANDING    (SAI_xCR2_COMP_1 | SAI_xCR2_CPL)
0607 #define SAI_ALAW_2CPL_COMPANDING    (SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0 | SAI_xCR2_CPL)
0608 /**
0609   * @}
0610   */
0611 
0612 /** @defgroup SAI_Block_Mute_Value SAI Block Mute Value
0613   * @ingroup RTEMSBSPsARMSTM32H7
0614   * @{
0615   */
0616 #define SAI_ZERO_VALUE              0x00000000U
0617 #define SAI_LAST_SENT_VALUE         SAI_xCR2_MUTEVAL
0618 /**
0619   * @}
0620   */
0621 
0622 /** @defgroup SAI_Block_Interrupts_Definition SAI Block Interrupts Definition
0623   * @ingroup RTEMSBSPsARMSTM32H7
0624   * @{
0625   */
0626 #define SAI_IT_OVRUDR               SAI_xIMR_OVRUDRIE
0627 #define SAI_IT_MUTEDET              SAI_xIMR_MUTEDETIE
0628 #define SAI_IT_WCKCFG               SAI_xIMR_WCKCFGIE
0629 #define SAI_IT_FREQ                 SAI_xIMR_FREQIE
0630 #define SAI_IT_CNRDY                SAI_xIMR_CNRDYIE
0631 #define SAI_IT_AFSDET               SAI_xIMR_AFSDETIE
0632 #define SAI_IT_LFSDET               SAI_xIMR_LFSDETIE
0633 /**
0634   * @}
0635   */
0636 
0637 /** @defgroup SAI_Block_Flags_Definition  SAI Block Flags Definition
0638   * @ingroup RTEMSBSPsARMSTM32H7
0639   * @{
0640   */
0641 #define SAI_FLAG_OVRUDR             SAI_xSR_OVRUDR
0642 #define SAI_FLAG_MUTEDET            SAI_xSR_MUTEDET
0643 #define SAI_FLAG_WCKCFG             SAI_xSR_WCKCFG
0644 #define SAI_FLAG_FREQ               SAI_xSR_FREQ
0645 #define SAI_FLAG_CNRDY              SAI_xSR_CNRDY
0646 #define SAI_FLAG_AFSDET             SAI_xSR_AFSDET
0647 #define SAI_FLAG_LFSDET             SAI_xSR_LFSDET
0648 /**
0649   * @}
0650   */
0651 
0652 /** @defgroup SAI_Block_Fifo_Status_Level   SAI Block Fifo Status Level
0653   * @ingroup RTEMSBSPsARMSTM32H7
0654   * @{
0655   */
0656 #define SAI_FIFOSTATUS_EMPTY              0x00000000U
0657 #define SAI_FIFOSTATUS_LESS1QUARTERFULL   0x00010000U
0658 #define SAI_FIFOSTATUS_1QUARTERFULL       0x00020000U
0659 #define SAI_FIFOSTATUS_HALFFULL           0x00030000U
0660 #define SAI_FIFOSTATUS_3QUARTERFULL       0x00040000U
0661 #define SAI_FIFOSTATUS_FULL               0x00050000U
0662 /**
0663   * @}
0664   */
0665 
0666 /**
0667   * @}
0668   */
0669 
0670 /* Exported macro ------------------------------------------------------------*/
0671 /** @defgroup SAI_Exported_Macros SAI Exported Macros
0672   * @ingroup RTEMSBSPsARMSTM32H7
0673   * @brief macros to handle interrupts and specific configurations
0674   * @{
0675   */
0676 
0677 /** @brief Reset SAI handle state.
0678   * @param  __HANDLE__ specifies the SAI Handle.
0679   * @retval None
0680   */
0681 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
0682 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) do{                                            \
0683                                                      (__HANDLE__)->State = HAL_SAI_STATE_RESET; \
0684                                                      (__HANDLE__)->MspInitCallback = NULL;      \
0685                                                      (__HANDLE__)->MspDeInitCallback = NULL;    \
0686                                                    } while(0U)
0687 #else
0688 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SAI_STATE_RESET)
0689 #endif
0690 
0691 /** @brief  Enable the specified SAI interrupts.
0692   * @param  __HANDLE__ specifies the SAI Handle.
0693   * @param  __INTERRUPT__ specifies the interrupt source to enable or disable.
0694   *         This parameter can be one of the following values:
0695   *            @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
0696   *            @arg SAI_IT_MUTEDET: Mute detection interrupt enable
0697   *            @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
0698   *            @arg SAI_IT_FREQ: FIFO request interrupt enable
0699   *            @arg SAI_IT_CNRDY: Codec not ready interrupt enable
0700   *            @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
0701   *            @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
0702   * @retval None
0703   */
0704 #define __HAL_SAI_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->IMR |= (__INTERRUPT__))
0705 
0706 /** @brief  Disable the specified SAI interrupts.
0707   * @param  __HANDLE__ specifies the SAI Handle.
0708   * @param  __INTERRUPT__ specifies the interrupt source to enable or disable.
0709   *         This parameter can be one of the following values:
0710   *            @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
0711   *            @arg SAI_IT_MUTEDET: Mute detection interrupt enable
0712   *            @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
0713   *            @arg SAI_IT_FREQ: FIFO request interrupt enable
0714   *            @arg SAI_IT_CNRDY: Codec not ready interrupt enable
0715   *            @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
0716   *            @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
0717   * @retval None
0718   */
0719 #define __HAL_SAI_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((__HANDLE__)->Instance->IMR &= (~(__INTERRUPT__)))
0720 
0721 /** @brief  Check whether the specified SAI interrupt source is enabled or not.
0722   * @param  __HANDLE__ specifies the SAI Handle.
0723   * @param  __INTERRUPT__ specifies the SAI interrupt source to check.
0724   *         This parameter can be one of the following values:
0725   *            @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
0726   *            @arg SAI_IT_MUTEDET: Mute detection interrupt enable
0727   *            @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
0728   *            @arg SAI_IT_FREQ: FIFO request interrupt enable
0729   *            @arg SAI_IT_CNRDY: Codec not ready interrupt enable
0730   *            @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
0731   *            @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
0732   * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
0733   */
0734 #define __HAL_SAI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IMR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
0735 
0736 /** @brief  Check whether the specified SAI flag is set or not.
0737   * @param  __HANDLE__ specifies the SAI Handle.
0738   * @param  __FLAG__ specifies the flag to check.
0739   *         This parameter can be one of the following values:
0740   *            @arg SAI_FLAG_OVRUDR: Overrun underrun flag.
0741   *            @arg SAI_FLAG_MUTEDET: Mute detection flag.
0742   *            @arg SAI_FLAG_WCKCFG: Wrong Clock Configuration flag.
0743   *            @arg SAI_FLAG_FREQ: FIFO request flag.
0744   *            @arg SAI_FLAG_CNRDY: Codec not ready flag.
0745   *            @arg SAI_FLAG_AFSDET: Anticipated frame synchronization detection flag.
0746   *            @arg SAI_FLAG_LFSDET: Late frame synchronization detection flag.
0747   * @retval The new state of __FLAG__ (TRUE or FALSE).
0748   */
0749 #define __HAL_SAI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
0750 
0751 /** @brief  Clear the specified SAI pending flag.
0752   * @param  __HANDLE__ specifies the SAI Handle.
0753   * @param  __FLAG__ specifies the flag to check.
0754   *          This parameter can be any combination of the following values:
0755   *            @arg SAI_FLAG_OVRUDR: Clear Overrun underrun
0756   *            @arg SAI_FLAG_MUTEDET: Clear Mute detection
0757   *            @arg SAI_FLAG_WCKCFG: Clear Wrong Clock Configuration
0758   *            @arg SAI_FLAG_FREQ: Clear FIFO request
0759   *            @arg SAI_FLAG_CNRDY: Clear Codec not ready
0760   *            @arg SAI_FLAG_AFSDET: Clear Anticipated frame synchronization detection
0761   *            @arg SAI_FLAG_LFSDET: Clear Late frame synchronization detection
0762   *
0763   * @retval None
0764   */
0765 #define __HAL_SAI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__))
0766 
0767 /** @brief  Enable SAI.
0768   * @param  __HANDLE__ specifies the SAI Handle.
0769   * @retval None
0770   */
0771 #define __HAL_SAI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |=  SAI_xCR1_SAIEN)
0772 
0773 /** @brief  Disable SAI.
0774   * @param  __HANDLE__ specifies the SAI Handle.
0775   * @retval None
0776   */
0777 #define __HAL_SAI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &=  ~SAI_xCR1_SAIEN)
0778 
0779 /**
0780   * @}
0781   */
0782 
0783 /* Include SAI HAL Extension module */
0784 #include "stm32h7xx_hal_sai_ex.h"
0785 
0786 /* Exported functions --------------------------------------------------------*/
0787 /** @addtogroup SAI_Exported_Functions
0788   * @{
0789   */
0790 
0791 /* Initialization/de-initialization functions  ********************************/
0792 /** @addtogroup SAI_Exported_Functions_Group1
0793   * @{
0794   */
0795 HAL_StatusTypeDef HAL_SAI_InitProtocol(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot);
0796 HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai);
0797 HAL_StatusTypeDef HAL_SAI_DeInit(SAI_HandleTypeDef *hsai);
0798 void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai);
0799 void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai);
0800 
0801 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
0802 /* SAI callbacks register/unregister functions ********************************/
0803 HAL_StatusTypeDef HAL_SAI_RegisterCallback(SAI_HandleTypeDef        *hsai,
0804                                            HAL_SAI_CallbackIDTypeDef CallbackID,
0805                                            pSAI_CallbackTypeDef      pCallback);
0806 HAL_StatusTypeDef HAL_SAI_UnRegisterCallback(SAI_HandleTypeDef        *hsai,
0807                                              HAL_SAI_CallbackIDTypeDef CallbackID);
0808 #endif
0809 /**
0810   * @}
0811   */
0812 
0813 /* I/O operation functions  ***************************************************/
0814 /** @addtogroup SAI_Exported_Functions_Group2
0815   * @{
0816   */
0817 /* Blocking mode: Polling */
0818 HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
0819 HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
0820 
0821 /* Non-Blocking mode: Interrupt */
0822 HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
0823 HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
0824 
0825 /* Non-Blocking mode: DMA */
0826 HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
0827 HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
0828 HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai);
0829 HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai);
0830 HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai);
0831 
0832 /* Abort function */
0833 HAL_StatusTypeDef HAL_SAI_Abort(SAI_HandleTypeDef *hsai);
0834 
0835 /* Mute management */
0836 HAL_StatusTypeDef HAL_SAI_EnableTxMuteMode(SAI_HandleTypeDef *hsai, uint16_t val);
0837 HAL_StatusTypeDef HAL_SAI_DisableTxMuteMode(SAI_HandleTypeDef *hsai);
0838 HAL_StatusTypeDef HAL_SAI_EnableRxMuteMode(SAI_HandleTypeDef *hsai, SAIcallback callback, uint16_t counter);
0839 HAL_StatusTypeDef HAL_SAI_DisableRxMuteMode(SAI_HandleTypeDef *hsai);
0840 
0841 /* SAI IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
0842 void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai);
0843 void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai);
0844 void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai);
0845 void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai);
0846 void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai);
0847 void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai);
0848 /**
0849   * @}
0850   */
0851 
0852 /** @addtogroup SAI_Exported_Functions_Group3
0853   * @{
0854   */
0855 /* Peripheral State functions  ************************************************/
0856 HAL_SAI_StateTypeDef HAL_SAI_GetState(const SAI_HandleTypeDef *hsai);
0857 uint32_t HAL_SAI_GetError(const SAI_HandleTypeDef *hsai);
0858 /**
0859   * @}
0860   */
0861 
0862 /**
0863   * @}
0864   */
0865 
0866 /* Private macros ------------------------------------------------------------*/
0867 /** @defgroup SAI_Private_Macros SAI Private Macros
0868   * @ingroup RTEMSBSPsARMSTM32H7
0869   * @{
0870   */
0871 #define IS_SAI_BLOCK_SYNCEXT(STATE) (((STATE) == SAI_SYNCEXT_DISABLE) ||\
0872                                      ((STATE) == SAI_SYNCEXT_OUTBLOCKA_ENABLE) ||\
0873                                      ((STATE) == SAI_SYNCEXT_OUTBLOCKB_ENABLE))
0874 
0875 #define IS_SAI_SUPPORTED_PROTOCOL(PROTOCOL)   (((PROTOCOL) == SAI_I2S_STANDARD)     ||\
0876                                                ((PROTOCOL) == SAI_I2S_MSBJUSTIFIED) ||\
0877                                                ((PROTOCOL) == SAI_I2S_LSBJUSTIFIED) ||\
0878                                                ((PROTOCOL) == SAI_PCM_LONG)         ||\
0879                                                ((PROTOCOL) == SAI_PCM_SHORT))
0880 
0881 #define IS_SAI_PROTOCOL_DATASIZE(DATASIZE)   (((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BIT)         ||\
0882                                               ((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BITEXTENDED) ||\
0883                                               ((DATASIZE) == SAI_PROTOCOL_DATASIZE_24BIT)         ||\
0884                                               ((DATASIZE) == SAI_PROTOCOL_DATASIZE_32BIT))
0885 
0886 #define IS_SAI_AUDIO_FREQUENCY(AUDIO) (((AUDIO) == SAI_AUDIO_FREQUENCY_192K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_96K) || \
0887                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_48K)  || ((AUDIO) == SAI_AUDIO_FREQUENCY_44K) || \
0888                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_32K)  || ((AUDIO) == SAI_AUDIO_FREQUENCY_22K) || \
0889                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_16K)  || ((AUDIO) == SAI_AUDIO_FREQUENCY_11K) || \
0890                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_8K)   || ((AUDIO) == SAI_AUDIO_FREQUENCY_MCKDIV))
0891 
0892 #define IS_SAI_BLOCK_MCK_OVERSAMPLING(VALUE) (((VALUE) == SAI_MCK_OVERSAMPLING_DISABLE) || \
0893                                               ((VALUE) == SAI_MCK_OVERSAMPLING_ENABLE))
0894 
0895 #define IS_SAI_PDM_MIC_PAIRS_NUMBER(VALUE)   ((1U <= (VALUE)) && ((VALUE) <= 3U))
0896 
0897 #define IS_SAI_PDM_CLOCK_ENABLE(CLOCK) (((CLOCK) != 0U) && \
0898                                        (((CLOCK) & ~(SAI_PDM_CLOCK1_ENABLE | SAI_PDM_CLOCK2_ENABLE)) == 0U))
0899 
0900 #define IS_SAI_BLOCK_MODE(MODE)  (((MODE) == SAI_MODEMASTER_TX) || \
0901                                   ((MODE) == SAI_MODEMASTER_RX) || \
0902                                   ((MODE) == SAI_MODESLAVE_TX)  || \
0903                                   ((MODE) == SAI_MODESLAVE_RX))
0904 
0905 #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_FREE_PROTOCOL)  || \
0906                                          ((PROTOCOL) == SAI_AC97_PROTOCOL)  || \
0907                                          ((PROTOCOL) == SAI_SPDIF_PROTOCOL))
0908 
0909 #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DATASIZE_8)  || \
0910                                          ((DATASIZE) == SAI_DATASIZE_10) || \
0911                                          ((DATASIZE) == SAI_DATASIZE_16) || \
0912                                          ((DATASIZE) == SAI_DATASIZE_20) || \
0913                                          ((DATASIZE) == SAI_DATASIZE_24) || \
0914                                          ((DATASIZE) == SAI_DATASIZE_32))
0915 
0916 #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FIRSTBIT_MSB) || \
0917                                      ((BIT) == SAI_FIRSTBIT_LSB))
0918 
0919 #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_CLOCKSTROBING_FALLINGEDGE) || \
0920                                             ((CLOCK) == SAI_CLOCKSTROBING_RISINGEDGE))
0921 #if defined(SAI2) && defined(SAI3) && defined(SAI4)
0922 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS)          || \
0923                                        ((SYNCHRO) == SAI_SYNCHRONOUS)           || \
0924                                        ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI1)  || \
0925                                        ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI2)  || \
0926                                        ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI3)  || \
0927                                        ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI4))
0928 #elif defined(SAI2)
0929 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS)          || \
0930                                        ((SYNCHRO) == SAI_SYNCHRONOUS)           || \
0931                                        ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI1)  || \
0932                                        ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI2))
0933 #else
0934 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS)          || \
0935                                        ((SYNCHRO) == SAI_SYNCHRONOUS)           || \
0936                                        ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI1)  || \
0937                                        ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI4))
0938 #endif
0939 
0940 #define IS_SAI_BLOCK_MCK_OUTPUT(VALUE) (((VALUE) == SAI_MCK_OUTPUT_ENABLE) || \
0941                                         ((VALUE) == SAI_MCK_OUTPUT_DISABLE))
0942 
0943 #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OUTPUTDRIVE_DISABLE) || \
0944                                           ((DRIVE) == SAI_OUTPUTDRIVE_ENABLE))
0945 
0946 #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MASTERDIVIDER_ENABLE) || \
0947                                            ((NODIVIDER) == SAI_MASTERDIVIDER_DISABLE))
0948 
0949 #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63U)
0950 
0951 #define IS_SAI_BLOCK_MUTE_VALUE(VALUE)    (((VALUE) == SAI_ZERO_VALUE)     || \
0952                                            ((VALUE) == SAI_LAST_SENT_VALUE))
0953 
0954 #define IS_SAI_BLOCK_COMPANDING_MODE(MODE)    (((MODE) == SAI_NOCOMPANDING)         || \
0955                                                ((MODE) == SAI_ULAW_1CPL_COMPANDING) || \
0956                                                ((MODE) == SAI_ALAW_1CPL_COMPANDING) || \
0957                                                ((MODE) == SAI_ULAW_2CPL_COMPANDING) || \
0958                                                ((MODE) == SAI_ALAW_2CPL_COMPANDING))
0959 
0960 #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_FIFOTHRESHOLD_EMPTY)   || \
0961                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_1QF)     || \
0962                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_HF)      || \
0963                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_3QF)     || \
0964                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_FULL))
0965 
0966 #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_OUTPUT_NOTRELEASED) ||\
0967                                                  ((STATE) == SAI_OUTPUT_RELEASED))
0968 
0969 #define IS_SAI_MONO_STEREO_MODE(MODE) (((MODE) == SAI_MONOMODE) ||\
0970                                        ((MODE) == SAI_STEREOMODE))
0971 
0972 #define IS_SAI_SLOT_ACTIVE(ACTIVE)  ((ACTIVE) <= SAI_SLOTACTIVE_ALL)
0973 
0974 #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1U <= (NUMBER)) && ((NUMBER) <= 16U))
0975 
0976 #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SLOTSIZE_DATASIZE) || \
0977                                       ((SIZE) == SAI_SLOTSIZE_16B)      || \
0978                                       ((SIZE) == SAI_SLOTSIZE_32B))
0979 
0980 #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24U)
0981 
0982 #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FIRSTBIT) || \
0983                                         ((OFFSET) == SAI_FS_BEFOREFIRSTBIT))
0984 
0985 #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ACTIVE_LOW) || \
0986                                             ((POLARITY) == SAI_FS_ACTIVE_HIGH))
0987 
0988 #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_STARTFRAME) || \
0989                                                 ((DEFINITION) == SAI_FS_CHANNEL_IDENTIFICATION))
0990 
0991 #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 63U)
0992 
0993 #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8U <= (LENGTH)) && ((LENGTH) <= 256U))
0994 
0995 #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1U <= (LENGTH)) && ((LENGTH) <= 128U))
0996 
0997 /**
0998   * @}
0999   */
1000 
1001 /* Private functions ---------------------------------------------------------*/
1002 /** @defgroup SAI_Private_Functions SAI Private Functions
1003   * @ingroup RTEMSBSPsARMSTM32H7
1004   * @{
1005   */
1006 
1007 /**
1008   * @}
1009   */
1010 
1011 /**
1012   * @}
1013   */
1014 
1015 /**
1016   * @}
1017   */
1018 
1019 #ifdef __cplusplus
1020 }
1021 #endif
1022 
1023 #endif /* STM32H7xx_HAL_SAI_H */
1024