STM32L443xx HAL User Manual
stm32l4xx_hal_sai.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_sai.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of SAI HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * Copyright (c) 2017 STMicroelectronics.
00010   * All rights reserved.
00011   *
00012   * This software is licensed under terms that can be found in the LICENSE file
00013   * in the root directory of this software component.
00014   * If no LICENSE file comes with this software, it is provided AS-IS.
00015   *
00016   ******************************************************************************
00017   */
00018 
00019 /* Define to prevent recursive inclusion -------------------------------------*/
00020 #ifndef STM32L4xx_HAL_SAI_H
00021 #define STM32L4xx_HAL_SAI_H
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00027 #if !defined(STM32L412xx) && !defined(STM32L422xx)
00028 
00029 /* Includes ------------------------------------------------------------------*/
00030 #include "stm32l4xx_hal_def.h"
00031 
00032 /** @addtogroup STM32L4xx_HAL_Driver
00033   * @{
00034   */
00035 
00036 /** @addtogroup SAI
00037   * @{
00038   */
00039 
00040 /* Exported types ------------------------------------------------------------*/
00041 /** @defgroup SAI_Exported_Types SAI Exported Types
00042   * @{
00043   */
00044 
00045 /**
00046   * @brief  HAL State structures definition
00047   */
00048 typedef enum
00049 {
00050   HAL_SAI_STATE_RESET   = 0x00U, /*!< SAI not yet initialized or disabled  */
00051   HAL_SAI_STATE_READY   = 0x01U, /*!< SAI initialized and ready for use    */
00052   HAL_SAI_STATE_BUSY    = 0x02U, /*!< SAI internal process is ongoing      */
00053   HAL_SAI_STATE_BUSY_TX = 0x12U, /*!< Data transmission process is ongoing */
00054   HAL_SAI_STATE_BUSY_RX = 0x22U, /*!< Data reception process is ongoing    */
00055 } HAL_SAI_StateTypeDef;
00056 
00057 /**
00058   * @brief  SAI Callback prototype
00059   */
00060 typedef void (*SAIcallback)(void);
00061 
00062 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) || \
00063     defined(STM32L4P5xx) || defined(STM32L4Q5xx)
00064 /** @defgroup SAI_PDM_Structure_definition SAI PDM Structure definition
00065   * @brief  SAI PDM Init structure definition
00066   * @{
00067   */
00068 typedef struct
00069 {
00070   FunctionalState  Activation;  /*!< Enable/disable PDM interface */
00071   uint32_t         MicPairsNbr; /*!< Specifies the number of microphone pairs used.
00072                                      This parameter must be a number between Min_Data = 1 and Max_Data = 3. */
00073   uint32_t         ClockEnable; /*!< Specifies which clock must be enabled.
00074                                      This parameter can be a values combination of @ref SAI_PDM_ClockEnable */
00075 } SAI_PdmInitTypeDef;
00076 /**
00077   * @}
00078   */
00079 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx || */
00080 /* STM32L4P5xx || STM32L4Q5xx */
00081 
00082 /** @defgroup SAI_Init_Structure_definition SAI Init Structure definition
00083   * @brief  SAI Init Structure definition
00084   * @{
00085   */
00086 typedef struct
00087 {
00088   uint32_t AudioMode;           /*!< Specifies the SAI Block audio Mode.
00089                                      This parameter can be a value of @ref SAI_Block_Mode */
00090 
00091   uint32_t Synchro;             /*!< Specifies SAI Block synchronization
00092                                      This parameter can be a value of @ref SAI_Block_Synchronization */
00093 
00094   uint32_t SynchroExt;          /*!< Specifies SAI external output synchronization, this setup is common
00095                                      for BlockA and BlockB
00096                                      This parameter can be a value of @ref SAI_Block_SyncExt
00097                                      @note If both audio blocks of same SAI are used, this parameter has
00098                                            to be set to the same value for each audio block */
00099 
00100   uint32_t OutputDrive;         /*!< Specifies when SAI Block outputs are driven.
00101                                      This parameter can be a value of @ref SAI_Block_Output_Drive
00102                                      @note This value has to be set before enabling the audio block
00103                                            but after the audio block configuration. */
00104 
00105   uint32_t NoDivider;           /*!< Specifies whether master clock will be divided or not.
00106                                      This parameter can be a value of @ref SAI_Block_NoDivider
00107                                      @note For STM32L4Rx/STM32L4Sx devices :
00108                                              If bit NOMCK in the SAI_xCR1 register is cleared, the frame length
00109                                              should be aligned to a number equal to a power of 2, from 8 to 256.
00110                                              If bit NOMCK in the SAI_xCR1 register is set, the frame length can
00111                                              take any of the values without constraint. There is no MCLK_x clock
00112                                              which can be output.
00113                                            For other devices :
00114                                              If bit NODIV in the SAI_xCR1 register is cleared, the frame length
00115                                              should be aligned to a number equal to a power of 2, from 8 to 256.
00116                                              If bit NODIV in the SAI_xCR1 register is set, the frame length can
00117                                              take any of the values without constraint since the input clock of
00118                                              the audio block should be equal to the bit clock.
00119                                              There is no MCLK_x clock which can be output. */
00120 
00121   uint32_t FIFOThreshold;       /*!< Specifies SAI Block FIFO threshold.
00122                                      This parameter can be a value of @ref SAI_Block_Fifo_Threshold */
00123 
00124   uint32_t AudioFrequency;      /*!< Specifies the audio frequency sampling.
00125                                      This parameter can be a value of @ref SAI_Audio_Frequency */
00126 
00127   uint32_t Mckdiv;              /*!< Specifies the master clock divider.
00128                                      This parameter must be a number between Min_Data = 0 and Max_Data = 63 on STM32L4Rx/STM32L4Sx devices.
00129                                      This parameter must be a number between Min_Data = 0 and Max_Data = 15 on other devices.
00130                                      @note This parameter is used only if AudioFrequency is set to
00131                                            SAI_AUDIO_FREQUENCY_MCKDIV otherwise it is internally computed. */
00132 
00133 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) || \
00134     defined(STM32L4P5xx) || defined(STM32L4Q5xx)
00135   uint32_t MckOverSampling;     /*!< Specifies the master clock oversampling.
00136                                      This parameter can be a value of @ref SAI_Block_Mck_OverSampling */
00137 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx || */
00138 /* STM32L4P5xx || STM32L4Q5xx */
00139 
00140   uint32_t MonoStereoMode;      /*!< Specifies if the mono or stereo mode is selected.
00141                                      This parameter can be a value of @ref SAI_Mono_Stereo_Mode */
00142 
00143   uint32_t CompandingMode;      /*!< Specifies the companding mode type.
00144                                      This parameter can be a value of @ref SAI_Block_Companding_Mode */
00145 
00146   uint32_t TriState;            /*!< Specifies the companding mode type.
00147                                      This parameter can be a value of @ref SAI_TRIState_Management */
00148 
00149 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) || \
00150     defined(STM32L4P5xx) || defined(STM32L4Q5xx)
00151   SAI_PdmInitTypeDef PdmInit;   /*!< Specifies the PDM configuration. */
00152 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx || */
00153 /* STM32L4P5xx || STM32L4Q5xx */
00154 
00155   /* This part of the structure is automatically filled if your are using the high level initialisation
00156      function HAL_SAI_InitProtocol */
00157 
00158   uint32_t Protocol;        /*!< Specifies the SAI Block protocol.
00159                                  This parameter can be a value of @ref SAI_Block_Protocol */
00160 
00161   uint32_t DataSize;        /*!< Specifies the SAI Block data size.
00162                                  This parameter can be a value of @ref SAI_Block_Data_Size */
00163 
00164   uint32_t FirstBit;        /*!< Specifies whether data transfers start from MSB or LSB bit.
00165                                  This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission */
00166 
00167   uint32_t ClockStrobing;   /*!< Specifies the SAI Block clock strobing edge sensitivity.
00168                                  This parameter can be a value of @ref SAI_Block_Clock_Strobing */
00169 } SAI_InitTypeDef;
00170 /**
00171   * @}
00172   */
00173 
00174 /** @defgroup SAI_Frame_Structure_definition SAI Frame Structure definition
00175   * @brief  SAI Frame Init structure definition
00176   * @note   For SPDIF and AC97 protocol, these parameters are not used (set by hardware).
00177   * @{
00178   */
00179 typedef struct
00180 {
00181 
00182   uint32_t FrameLength;        /*!< Specifies the Frame length, the number of SCK clocks for each audio frame.
00183                                     This parameter must be a number between Min_Data = 8 and Max_Data = 256.
00184                                     @note If master clock MCLK_x pin is declared as an output, the frame length
00185                                           should be aligned to a number equal to power of 2 in order to keep
00186                                           in an audio frame, an integer number of MCLK pulses by bit Clock. */
00187 
00188   uint32_t ActiveFrameLength;  /*!< Specifies the Frame synchronization active level length.
00189                                     This Parameter specifies the length in number of bit clock (SCK + 1)
00190                                     of the active level of FS signal in audio frame.
00191                                     This parameter must be a number between Min_Data = 1 and Max_Data = 128 */
00192 
00193   uint32_t FSDefinition;       /*!< Specifies the Frame synchronization definition.
00194                                     This parameter can be a value of @ref SAI_Block_FS_Definition */
00195 
00196   uint32_t FSPolarity;         /*!< Specifies the Frame synchronization Polarity.
00197                                     This parameter can be a value of @ref SAI_Block_FS_Polarity */
00198 
00199   uint32_t FSOffset;           /*!< Specifies the Frame synchronization Offset.
00200                                     This parameter can be a value of @ref SAI_Block_FS_Offset */
00201 
00202 } SAI_FrameInitTypeDef;
00203 /**
00204   * @}
00205   */
00206 
00207 /** @defgroup SAI_Slot_Structure_definition SAI Slot Structure definition
00208   * @brief   SAI Block Slot Init Structure definition
00209   * @note    For SPDIF protocol, these parameters are not used (set by hardware).
00210   * @note    For AC97 protocol, only SlotActive parameter is used (the others are set by hardware).
00211   * @{
00212   */
00213 typedef struct
00214 {
00215   uint32_t FirstBitOffset;  /*!< Specifies the position of first data transfer bit in the slot.
00216                                  This parameter must be a number between Min_Data = 0 and Max_Data = 24 */
00217 
00218   uint32_t SlotSize;        /*!< Specifies the Slot Size.
00219                                  This parameter can be a value of @ref SAI_Block_Slot_Size */
00220 
00221   uint32_t SlotNumber;      /*!< Specifies the number of slot in the audio frame.
00222                                  This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
00223 
00224   uint32_t SlotActive;      /*!< Specifies the slots in audio frame that will be activated.
00225                                  This parameter can be a value of @ref SAI_Block_Slot_Active */
00226 } SAI_SlotInitTypeDef;
00227 /**
00228   * @}
00229   */
00230 
00231 /** @defgroup SAI_Handle_Structure_definition SAI Handle Structure definition
00232   * @brief  SAI handle Structure definition
00233   * @{
00234   */
00235 typedef struct __SAI_HandleTypeDef
00236 {
00237   SAI_Block_TypeDef         *Instance;    /*!< SAI Blockx registers base address */
00238 
00239   SAI_InitTypeDef           Init;         /*!< SAI communication parameters */
00240 
00241   SAI_FrameInitTypeDef      FrameInit;    /*!< SAI Frame configuration parameters */
00242 
00243   SAI_SlotInitTypeDef       SlotInit;     /*!< SAI Slot configuration parameters */
00244 
00245   uint8_t                  *pBuffPtr;     /*!< Pointer to SAI transfer Buffer */
00246 
00247   uint16_t                  XferSize;     /*!< SAI transfer size */
00248 
00249   uint16_t                  XferCount;    /*!< SAI transfer counter */
00250 
00251   DMA_HandleTypeDef         *hdmatx;      /*!< SAI Tx DMA handle parameters */
00252 
00253   DMA_HandleTypeDef         *hdmarx;      /*!< SAI Rx DMA handle parameters */
00254 
00255   SAIcallback               mutecallback; /*!< SAI mute callback */
00256 
00257   void (*InterruptServiceRoutine)(struct __SAI_HandleTypeDef *hsai); /* function pointer for IRQ handler */
00258 
00259   HAL_LockTypeDef           Lock;         /*!< SAI locking object */
00260 
00261   __IO HAL_SAI_StateTypeDef State;        /*!< SAI communication state */
00262 
00263   __IO uint32_t             ErrorCode;    /*!< SAI Error code */
00264 
00265 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
00266   void (*RxCpltCallback)(struct __SAI_HandleTypeDef *hsai);      /*!< SAI receive complete callback */
00267   void (*RxHalfCpltCallback)(struct __SAI_HandleTypeDef *hsai);  /*!< SAI receive half complete callback */
00268   void (*TxCpltCallback)(struct __SAI_HandleTypeDef *hsai);      /*!< SAI transmit complete callback */
00269   void (*TxHalfCpltCallback)(struct __SAI_HandleTypeDef *hsai);  /*!< SAI transmit half complete callback */
00270   void (*ErrorCallback)(struct __SAI_HandleTypeDef *hsai);       /*!< SAI error callback */
00271   void (*MspInitCallback)(struct __SAI_HandleTypeDef *hsai);     /*!< SAI MSP init callback */
00272   void (*MspDeInitCallback)(struct __SAI_HandleTypeDef *hsai);   /*!< SAI MSP de-init callback */
00273 #endif
00274 } SAI_HandleTypeDef;
00275 /**
00276   * @}
00277   */
00278 
00279 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
00280 /**
00281   * @brief  SAI callback ID enumeration definition
00282   */
00283 typedef enum
00284 {
00285   HAL_SAI_RX_COMPLETE_CB_ID     = 0x00U, /*!< SAI receive complete callback ID */
00286   HAL_SAI_RX_HALFCOMPLETE_CB_ID = 0x01U, /*!< SAI receive half complete callback ID */
00287   HAL_SAI_TX_COMPLETE_CB_ID     = 0x02U, /*!< SAI transmit complete callback ID */
00288   HAL_SAI_TX_HALFCOMPLETE_CB_ID = 0x03U, /*!< SAI transmit half complete callback ID */
00289   HAL_SAI_ERROR_CB_ID           = 0x04U, /*!< SAI error callback ID */
00290   HAL_SAI_MSPINIT_CB_ID         = 0x05U, /*!< SAI MSP init callback ID */
00291   HAL_SAI_MSPDEINIT_CB_ID       = 0x06U  /*!< SAI MSP de-init callback ID */
00292 } HAL_SAI_CallbackIDTypeDef;
00293 
00294 /**
00295   * @brief  SAI callback pointer definition
00296   */
00297 typedef void (*pSAI_CallbackTypeDef)(SAI_HandleTypeDef *hsai);
00298 #endif
00299 
00300 /**
00301   * @}
00302   */
00303 
00304 /* Exported constants --------------------------------------------------------*/
00305 /** @defgroup SAI_Exported_Constants SAI Exported Constants
00306   * @{
00307   */
00308 
00309 /** @defgroup SAI_Error_Code SAI Error Code
00310   * @{
00311   */
00312 #define HAL_SAI_ERROR_NONE             0x00000000U  /*!< No error */
00313 #define HAL_SAI_ERROR_OVR              0x00000001U  /*!< Overrun Error */
00314 #define HAL_SAI_ERROR_UDR              0x00000002U  /*!< Underrun error */
00315 #define HAL_SAI_ERROR_AFSDET           0x00000004U  /*!< Anticipated Frame synchronisation detection */
00316 #define HAL_SAI_ERROR_LFSDET           0x00000008U  /*!< Late Frame synchronisation detection */
00317 #define HAL_SAI_ERROR_CNREADY          0x00000010U  /*!< codec not ready */
00318 #define HAL_SAI_ERROR_WCKCFG           0x00000020U  /*!< Wrong clock configuration */
00319 #define HAL_SAI_ERROR_TIMEOUT          0x00000040U  /*!< Timeout error */
00320 #define HAL_SAI_ERROR_DMA              0x00000080U  /*!< DMA error */
00321 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
00322 #define HAL_SAI_ERROR_INVALID_CALLBACK 0x00000100U  /*!< Invalid callback error */
00323 #endif
00324 /**
00325   * @}
00326   */
00327 
00328 /** @defgroup SAI_Block_SyncExt SAI External synchronisation
00329   * @{
00330   */
00331 #define SAI_SYNCEXT_DISABLE          0U
00332 #define SAI_SYNCEXT_OUTBLOCKA_ENABLE 1U
00333 #define SAI_SYNCEXT_OUTBLOCKB_ENABLE 2U
00334 /**
00335   * @}
00336   */
00337 
00338 /** @defgroup SAI_Protocol SAI Supported protocol
00339   * @{
00340   */
00341 #define SAI_I2S_STANDARD      0U
00342 #define SAI_I2S_MSBJUSTIFIED  1U
00343 #define SAI_I2S_LSBJUSTIFIED  2U
00344 #define SAI_PCM_LONG          3U
00345 #define SAI_PCM_SHORT         4U
00346 /**
00347   * @}
00348   */
00349 
00350 /** @defgroup SAI_Protocol_DataSize SAI protocol data size
00351   * @{
00352   */
00353 #define SAI_PROTOCOL_DATASIZE_16BIT         0U
00354 #define SAI_PROTOCOL_DATASIZE_16BITEXTENDED 1U
00355 #define SAI_PROTOCOL_DATASIZE_24BIT         2U
00356 #define SAI_PROTOCOL_DATASIZE_32BIT         3U
00357 /**
00358   * @}
00359   */
00360 
00361 /** @defgroup SAI_Audio_Frequency SAI Audio Frequency
00362   * @{
00363   */
00364 #define SAI_AUDIO_FREQUENCY_192K          192000U
00365 #define SAI_AUDIO_FREQUENCY_96K           96000U
00366 #define SAI_AUDIO_FREQUENCY_48K           48000U
00367 #define SAI_AUDIO_FREQUENCY_44K           44100U
00368 #define SAI_AUDIO_FREQUENCY_32K           32000U
00369 #define SAI_AUDIO_FREQUENCY_22K           22050U
00370 #define SAI_AUDIO_FREQUENCY_16K           16000U
00371 #define SAI_AUDIO_FREQUENCY_11K           11025U
00372 #define SAI_AUDIO_FREQUENCY_8K            8000U
00373 #define SAI_AUDIO_FREQUENCY_MCKDIV        0U
00374 /**
00375   * @}
00376   */
00377 
00378 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) || \
00379     defined(STM32L4P5xx) || defined(STM32L4Q5xx)
00380 /** @defgroup SAI_Block_Mck_OverSampling SAI Block Master Clock OverSampling
00381   * @{
00382   */
00383 #define SAI_MCK_OVERSAMPLING_DISABLE      0x00000000U
00384 #define SAI_MCK_OVERSAMPLING_ENABLE       SAI_xCR1_OSR
00385 /**
00386   * @}
00387   */
00388 
00389 /** @defgroup SAI_PDM_ClockEnable SAI PDM Clock Enable
00390   * @{
00391   */
00392 #define SAI_PDM_CLOCK1_ENABLE     SAI_PDMCR_CKEN1
00393 #define SAI_PDM_CLOCK2_ENABLE     SAI_PDMCR_CKEN2
00394 /**
00395   * @}
00396   */
00397 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx || */
00398 /* STM32L4P5xx || STM32L4Q5xx */
00399 
00400 /** @defgroup SAI_Block_Mode SAI Block Mode
00401   * @{
00402   */
00403 #define SAI_MODEMASTER_TX         0x00000000U
00404 #define SAI_MODEMASTER_RX         SAI_xCR1_MODE_0
00405 #define SAI_MODESLAVE_TX          SAI_xCR1_MODE_1
00406 #define SAI_MODESLAVE_RX          (SAI_xCR1_MODE_1 | SAI_xCR1_MODE_0)
00407 
00408 /**
00409   * @}
00410   */
00411 
00412 /** @defgroup SAI_Block_Protocol SAI Block Protocol
00413   * @{
00414   */
00415 #define SAI_FREE_PROTOCOL                 0x00000000U
00416 #define SAI_SPDIF_PROTOCOL                SAI_xCR1_PRTCFG_0
00417 #define SAI_AC97_PROTOCOL                 SAI_xCR1_PRTCFG_1
00418 /**
00419   * @}
00420   */
00421 
00422 /** @defgroup SAI_Block_Data_Size SAI Block Data Size
00423   * @{
00424   */
00425 #define SAI_DATASIZE_8     SAI_xCR1_DS_1
00426 #define SAI_DATASIZE_10    (SAI_xCR1_DS_1 | SAI_xCR1_DS_0)
00427 #define SAI_DATASIZE_16    SAI_xCR1_DS_2
00428 #define SAI_DATASIZE_20    (SAI_xCR1_DS_2 | SAI_xCR1_DS_0)
00429 #define SAI_DATASIZE_24    (SAI_xCR1_DS_2 | SAI_xCR1_DS_1)
00430 #define SAI_DATASIZE_32    (SAI_xCR1_DS_2 | SAI_xCR1_DS_1 | SAI_xCR1_DS_0)
00431 /**
00432   * @}
00433   */
00434 
00435 /** @defgroup SAI_Block_MSB_LSB_transmission SAI Block MSB LSB transmission
00436   * @{
00437   */
00438 #define SAI_FIRSTBIT_MSB                  0x00000000U
00439 #define SAI_FIRSTBIT_LSB                  SAI_xCR1_LSBFIRST
00440 /**
00441   * @}
00442   */
00443 
00444 /** @defgroup SAI_Block_Clock_Strobing SAI Block Clock Strobing
00445   * @{
00446   */
00447 #define SAI_CLOCKSTROBING_FALLINGEDGE     0U
00448 #define SAI_CLOCKSTROBING_RISINGEDGE      1U
00449 /**
00450   * @}
00451   */
00452 
00453 /** @defgroup SAI_Block_Synchronization SAI Block Synchronization
00454   * @{
00455   */
00456 #define SAI_ASYNCHRONOUS                  0U /*!< Asynchronous */
00457 #define SAI_SYNCHRONOUS                   1U /*!< Synchronous with other block of same SAI */
00458 #define SAI_SYNCHRONOUS_EXT_SAI1          2U /*!< Synchronous with other SAI, SAI1 */
00459 #define SAI_SYNCHRONOUS_EXT_SAI2          3U /*!< Synchronous with other SAI, SAI2 */
00460 /**
00461   * @}
00462   */
00463 
00464 /** @defgroup SAI_Block_Output_Drive SAI Block Output Drive
00465   * @{
00466   */
00467 #define SAI_OUTPUTDRIVE_DISABLE          0x00000000U
00468 #define SAI_OUTPUTDRIVE_ENABLE           SAI_xCR1_OUTDRIV
00469 /**
00470   * @}
00471   */
00472 
00473 /** @defgroup SAI_Block_NoDivider SAI Block NoDivider
00474   * @{
00475   */
00476 #define SAI_MASTERDIVIDER_ENABLE         0x00000000U
00477 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) || \
00478     defined(STM32L4P5xx) || defined(STM32L4Q5xx)
00479 #define SAI_MASTERDIVIDER_DISABLE        SAI_xCR1_NOMCK
00480 #else
00481 #define SAI_MASTERDIVIDER_DISABLE        SAI_xCR1_NODIV
00482 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx || */
00483 /* STM32L4P5xx || STM32L4Q5xx */
00484 /**
00485   * @}
00486   */
00487 
00488 /** @defgroup SAI_Block_FS_Definition SAI Block FS Definition
00489   * @{
00490   */
00491 #define SAI_FS_STARTFRAME                 0x00000000U
00492 #define SAI_FS_CHANNEL_IDENTIFICATION     SAI_xFRCR_FSDEF
00493 /**
00494   * @}
00495   */
00496 
00497 /** @defgroup SAI_Block_FS_Polarity SAI Block FS Polarity
00498   * @{
00499   */
00500 #define SAI_FS_ACTIVE_LOW                  0x00000000U
00501 #define SAI_FS_ACTIVE_HIGH                 SAI_xFRCR_FSPOL
00502 /**
00503   * @}
00504   */
00505 
00506 /** @defgroup SAI_Block_FS_Offset SAI Block FS Offset
00507   * @{
00508   */
00509 #define SAI_FS_FIRSTBIT                   0x00000000U
00510 #define SAI_FS_BEFOREFIRSTBIT             SAI_xFRCR_FSOFF
00511 /**
00512   * @}
00513   */
00514 
00515 /** @defgroup SAI_Block_Slot_Size SAI Block Slot Size
00516   * @{
00517   */
00518 #define SAI_SLOTSIZE_DATASIZE             0x00000000U
00519 #define SAI_SLOTSIZE_16B                  SAI_xSLOTR_SLOTSZ_0
00520 #define SAI_SLOTSIZE_32B                  SAI_xSLOTR_SLOTSZ_1
00521 /**
00522   * @}
00523   */
00524 
00525 /** @defgroup SAI_Block_Slot_Active SAI Block Slot Active
00526   * @{
00527   */
00528 #define SAI_SLOT_NOTACTIVE           0x00000000U
00529 #define SAI_SLOTACTIVE_0             0x00000001U
00530 #define SAI_SLOTACTIVE_1             0x00000002U
00531 #define SAI_SLOTACTIVE_2             0x00000004U
00532 #define SAI_SLOTACTIVE_3             0x00000008U
00533 #define SAI_SLOTACTIVE_4             0x00000010U
00534 #define SAI_SLOTACTIVE_5             0x00000020U
00535 #define SAI_SLOTACTIVE_6             0x00000040U
00536 #define SAI_SLOTACTIVE_7             0x00000080U
00537 #define SAI_SLOTACTIVE_8             0x00000100U
00538 #define SAI_SLOTACTIVE_9             0x00000200U
00539 #define SAI_SLOTACTIVE_10            0x00000400U
00540 #define SAI_SLOTACTIVE_11            0x00000800U
00541 #define SAI_SLOTACTIVE_12            0x00001000U
00542 #define SAI_SLOTACTIVE_13            0x00002000U
00543 #define SAI_SLOTACTIVE_14            0x00004000U
00544 #define SAI_SLOTACTIVE_15            0x00008000U
00545 #define SAI_SLOTACTIVE_ALL           0x0000FFFFU
00546 /**
00547   * @}
00548   */
00549 
00550 /** @defgroup SAI_Mono_Stereo_Mode SAI Mono Stereo Mode
00551   * @{
00552   */
00553 #define SAI_STEREOMODE               0x00000000U
00554 #define SAI_MONOMODE                 SAI_xCR1_MONO
00555 /**
00556   * @}
00557   */
00558 
00559 /** @defgroup SAI_TRIState_Management SAI TRIState Management
00560   * @{
00561   */
00562 #define SAI_OUTPUT_NOTRELEASED    0x00000000U
00563 #define SAI_OUTPUT_RELEASED       SAI_xCR2_TRIS
00564 /**
00565   * @}
00566   */
00567 
00568 /** @defgroup SAI_Block_Fifo_Threshold SAI Block Fifo Threshold
00569   * @{
00570   */
00571 #define SAI_FIFOTHRESHOLD_EMPTY  0x00000000U
00572 #define SAI_FIFOTHRESHOLD_1QF    SAI_xCR2_FTH_0
00573 #define SAI_FIFOTHRESHOLD_HF     SAI_xCR2_FTH_1
00574 #define SAI_FIFOTHRESHOLD_3QF    (SAI_xCR2_FTH_1 | SAI_xCR2_FTH_0)
00575 #define SAI_FIFOTHRESHOLD_FULL   SAI_xCR2_FTH_2
00576 /**
00577   * @}
00578   */
00579 
00580 /** @defgroup SAI_Block_Companding_Mode SAI Block Companding Mode
00581   * @{
00582   */
00583 #define SAI_NOCOMPANDING                 0x00000000U
00584 #define SAI_ULAW_1CPL_COMPANDING         SAI_xCR2_COMP_1
00585 #define SAI_ALAW_1CPL_COMPANDING         (SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0)
00586 #define SAI_ULAW_2CPL_COMPANDING         (SAI_xCR2_COMP_1 | SAI_xCR2_CPL)
00587 #define SAI_ALAW_2CPL_COMPANDING         (SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0 | SAI_xCR2_CPL)
00588 /**
00589   * @}
00590   */
00591 
00592 /** @defgroup SAI_Block_Mute_Value SAI Block Mute Value
00593   * @{
00594   */
00595 #define SAI_ZERO_VALUE                     0x00000000U
00596 #define SAI_LAST_SENT_VALUE                SAI_xCR2_MUTEVAL
00597 /**
00598   * @}
00599   */
00600 
00601 /** @defgroup SAI_Block_Interrupts_Definition SAI Block Interrupts Definition
00602   * @{
00603   */
00604 #define SAI_IT_OVRUDR                     SAI_xIMR_OVRUDRIE
00605 #define SAI_IT_MUTEDET                    SAI_xIMR_MUTEDETIE
00606 #define SAI_IT_WCKCFG                     SAI_xIMR_WCKCFGIE
00607 #define SAI_IT_FREQ                       SAI_xIMR_FREQIE
00608 #define SAI_IT_CNRDY                      SAI_xIMR_CNRDYIE
00609 #define SAI_IT_AFSDET                     SAI_xIMR_AFSDETIE
00610 #define SAI_IT_LFSDET                     SAI_xIMR_LFSDETIE
00611 /**
00612   * @}
00613   */
00614 
00615 /** @defgroup SAI_Block_Flags_Definition  SAI Block Flags Definition
00616   * @{
00617   */
00618 #define SAI_FLAG_OVRUDR                   SAI_xSR_OVRUDR
00619 #define SAI_FLAG_MUTEDET                  SAI_xSR_MUTEDET
00620 #define SAI_FLAG_WCKCFG                   SAI_xSR_WCKCFG
00621 #define SAI_FLAG_FREQ                     SAI_xSR_FREQ
00622 #define SAI_FLAG_CNRDY                    SAI_xSR_CNRDY
00623 #define SAI_FLAG_AFSDET                   SAI_xSR_AFSDET
00624 #define SAI_FLAG_LFSDET                   SAI_xSR_LFSDET
00625 /**
00626   * @}
00627   */
00628 
00629 /** @defgroup SAI_Block_Fifo_Status_Level   SAI Block Fifo Status Level
00630   * @{
00631   */
00632 #define SAI_FIFOSTATUS_EMPTY              0x00000000U
00633 #define SAI_FIFOSTATUS_LESS1QUARTERFULL   0x00010000U
00634 #define SAI_FIFOSTATUS_1QUARTERFULL       0x00020000U
00635 #define SAI_FIFOSTATUS_HALFFULL           0x00030000U
00636 #define SAI_FIFOSTATUS_3QUARTERFULL       0x00040000U
00637 #define SAI_FIFOSTATUS_FULL               0x00050000U
00638 /**
00639   * @}
00640   */
00641 
00642 /**
00643   * @}
00644   */
00645 
00646 /* Exported macro ------------------------------------------------------------*/
00647 /** @defgroup SAI_Exported_Macros SAI Exported Macros
00648   * @brief macros to handle interrupts and specific configurations
00649   * @{
00650   */
00651 
00652 /** @brief Reset SAI handle state.
00653   * @param  __HANDLE__ specifies the SAI Handle.
00654   * @retval None
00655   */
00656 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
00657 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) do{                                            \
00658                                                      (__HANDLE__)->State = HAL_SAI_STATE_RESET; \
00659                                                      (__HANDLE__)->MspInitCallback = NULL;      \
00660                                                      (__HANDLE__)->MspDeInitCallback = NULL;    \
00661                                                    } while(0)
00662 #else
00663 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SAI_STATE_RESET)
00664 #endif
00665 
00666 /** @brief  Enable the specified SAI interrupts.
00667   * @param  __HANDLE__ specifies the SAI Handle.
00668   * @param  __INTERRUPT__ specifies the interrupt source to enable or disable.
00669   *         This parameter can be one of the following values:
00670   *            @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
00671   *            @arg SAI_IT_MUTEDET: Mute detection interrupt enable
00672   *            @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
00673   *            @arg SAI_IT_FREQ: FIFO request interrupt enable
00674   *            @arg SAI_IT_CNRDY: Codec not ready interrupt enable
00675   *            @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
00676   *            @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
00677   * @retval None
00678   */
00679 #define __HAL_SAI_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->IMR |= (__INTERRUPT__))
00680 
00681 /** @brief  Disable the specified SAI interrupts.
00682   * @param  __HANDLE__ specifies the SAI Handle.
00683   * @param  __INTERRUPT__ specifies the interrupt source to enable or disable.
00684   *         This parameter can be one of the following values:
00685   *            @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
00686   *            @arg SAI_IT_MUTEDET: Mute detection interrupt enable
00687   *            @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
00688   *            @arg SAI_IT_FREQ: FIFO request interrupt enable
00689   *            @arg SAI_IT_CNRDY: Codec not ready interrupt enable
00690   *            @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
00691   *            @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
00692   * @retval None
00693   */
00694 #define __HAL_SAI_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((__HANDLE__)->Instance->IMR &= (~(__INTERRUPT__)))
00695 
00696 /** @brief  Check whether the specified SAI interrupt source is enabled or not.
00697   * @param  __HANDLE__ specifies the SAI Handle.
00698   * @param  __INTERRUPT__ specifies the SAI interrupt source to check.
00699   *         This parameter can be one of the following values:
00700   *            @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
00701   *            @arg SAI_IT_MUTEDET: Mute detection interrupt enable
00702   *            @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
00703   *            @arg SAI_IT_FREQ: FIFO request interrupt enable
00704   *            @arg SAI_IT_CNRDY: Codec not ready interrupt enable
00705   *            @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
00706   *            @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
00707   * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
00708   */
00709 #define __HAL_SAI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IMR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
00710 
00711 /** @brief  Check whether the specified SAI flag is set or not.
00712   * @param  __HANDLE__ specifies the SAI Handle.
00713   * @param  __FLAG__ specifies the flag to check.
00714   *         This parameter can be one of the following values:
00715   *            @arg SAI_FLAG_OVRUDR: Overrun underrun flag.
00716   *            @arg SAI_FLAG_MUTEDET: Mute detection flag.
00717   *            @arg SAI_FLAG_WCKCFG: Wrong Clock Configuration flag.
00718   *            @arg SAI_FLAG_FREQ: FIFO request flag.
00719   *            @arg SAI_FLAG_CNRDY: Codec not ready flag.
00720   *            @arg SAI_FLAG_AFSDET: Anticipated frame synchronization detection flag.
00721   *            @arg SAI_FLAG_LFSDET: Late frame synchronization detection flag.
00722   * @retval The new state of __FLAG__ (TRUE or FALSE).
00723   */
00724 #define __HAL_SAI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
00725 
00726 /** @brief  Clear the specified SAI pending flag.
00727   * @param  __HANDLE__ specifies the SAI Handle.
00728   * @param  __FLAG__ specifies the flag to check.
00729   *          This parameter can be any combination of the following values:
00730   *            @arg SAI_FLAG_OVRUDR: Clear Overrun underrun
00731   *            @arg SAI_FLAG_MUTEDET: Clear Mute detection
00732   *            @arg SAI_FLAG_WCKCFG: Clear Wrong Clock Configuration
00733   *            @arg SAI_FLAG_FREQ: Clear FIFO request
00734   *            @arg SAI_FLAG_CNRDY: Clear Codec not ready
00735   *            @arg SAI_FLAG_AFSDET: Clear Anticipated frame synchronization detection
00736   *            @arg SAI_FLAG_LFSDET: Clear Late frame synchronization detection
00737   *
00738   * @retval None
00739   */
00740 #define __HAL_SAI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__))
00741 
00742 /** @brief  Enable SAI.
00743   * @param  __HANDLE__ specifies the SAI Handle.
00744   * @retval None
00745   */
00746 #define __HAL_SAI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |=  SAI_xCR1_SAIEN)
00747 
00748 /** @brief  Disable SAI.
00749   * @param  __HANDLE__ specifies the SAI Handle.
00750   * @retval None
00751   */
00752 #define __HAL_SAI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &=  ~SAI_xCR1_SAIEN)
00753 
00754 /**
00755   * @}
00756   */
00757 
00758 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) || \
00759     defined(STM32L4P5xx) || defined(STM32L4Q5xx)
00760 /* Include SAI HAL Extension module */
00761 #include "stm32l4xx_hal_sai_ex.h"
00762 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx || */
00763 /* STM32L4P5xx || STM32L4Q5xx */
00764 
00765 /* Exported functions --------------------------------------------------------*/
00766 /** @addtogroup SAI_Exported_Functions
00767   * @{
00768   */
00769 
00770 /* Initialization/de-initialization functions  ********************************/
00771 /** @addtogroup SAI_Exported_Functions_Group1
00772   * @{
00773   */
00774 HAL_StatusTypeDef HAL_SAI_InitProtocol(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot);
00775 HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai);
00776 HAL_StatusTypeDef HAL_SAI_DeInit(SAI_HandleTypeDef *hsai);
00777 void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai);
00778 void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai);
00779 
00780 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
00781 /* SAI callbacks register/unregister functions ********************************/
00782 HAL_StatusTypeDef HAL_SAI_RegisterCallback(SAI_HandleTypeDef        *hsai,
00783                                            HAL_SAI_CallbackIDTypeDef CallbackID,
00784                                            pSAI_CallbackTypeDef      pCallback);
00785 HAL_StatusTypeDef HAL_SAI_UnRegisterCallback(SAI_HandleTypeDef        *hsai,
00786                                              HAL_SAI_CallbackIDTypeDef CallbackID);
00787 #endif
00788 /**
00789   * @}
00790   */
00791 
00792 /* I/O operation functions  ***************************************************/
00793 /** @addtogroup SAI_Exported_Functions_Group2
00794   * @{
00795   */
00796 /* Blocking mode: Polling */
00797 HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
00798 HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
00799 
00800 /* Non-Blocking mode: Interrupt */
00801 HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
00802 HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
00803 
00804 /* Non-Blocking mode: DMA */
00805 HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
00806 HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
00807 HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai);
00808 HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai);
00809 HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai);
00810 
00811 /* Abort function */
00812 HAL_StatusTypeDef HAL_SAI_Abort(SAI_HandleTypeDef *hsai);
00813 
00814 /* Mute management */
00815 HAL_StatusTypeDef HAL_SAI_EnableTxMuteMode(SAI_HandleTypeDef *hsai, uint16_t val);
00816 HAL_StatusTypeDef HAL_SAI_DisableTxMuteMode(SAI_HandleTypeDef *hsai);
00817 HAL_StatusTypeDef HAL_SAI_EnableRxMuteMode(SAI_HandleTypeDef *hsai, SAIcallback callback, uint16_t counter);
00818 HAL_StatusTypeDef HAL_SAI_DisableRxMuteMode(SAI_HandleTypeDef *hsai);
00819 
00820 /* SAI IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
00821 void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai);
00822 void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai);
00823 void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai);
00824 void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai);
00825 void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai);
00826 void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai);
00827 /**
00828   * @}
00829   */
00830 
00831 /** @addtogroup SAI_Exported_Functions_Group3
00832   * @{
00833   */
00834 /* Peripheral State functions  ************************************************/
00835 HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai);
00836 uint32_t HAL_SAI_GetError(SAI_HandleTypeDef *hsai);
00837 /**
00838   * @}
00839   */
00840 
00841 /**
00842   * @}
00843   */
00844 
00845 /* Private macros ------------------------------------------------------------*/
00846 /** @defgroup SAI_Private_Macros SAI Private Macros
00847   * @{
00848   */
00849 #define IS_SAI_BLOCK_SYNCEXT(STATE) (((STATE) == SAI_SYNCEXT_DISABLE) ||\
00850                                      ((STATE) == SAI_SYNCEXT_OUTBLOCKA_ENABLE) ||\
00851                                      ((STATE) == SAI_SYNCEXT_OUTBLOCKB_ENABLE))
00852 
00853 #define IS_SAI_SUPPORTED_PROTOCOL(PROTOCOL)   (((PROTOCOL) == SAI_I2S_STANDARD)     ||\
00854                                                ((PROTOCOL) == SAI_I2S_MSBJUSTIFIED) ||\
00855                                                ((PROTOCOL) == SAI_I2S_LSBJUSTIFIED) ||\
00856                                                ((PROTOCOL) == SAI_PCM_LONG)         ||\
00857                                                ((PROTOCOL) == SAI_PCM_SHORT))
00858 
00859 #define IS_SAI_PROTOCOL_DATASIZE(DATASIZE)   (((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BIT)         ||\
00860                                               ((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BITEXTENDED) ||\
00861                                               ((DATASIZE) == SAI_PROTOCOL_DATASIZE_24BIT)         ||\
00862                                               ((DATASIZE) == SAI_PROTOCOL_DATASIZE_32BIT))
00863 
00864 #define IS_SAI_AUDIO_FREQUENCY(AUDIO) (((AUDIO) == SAI_AUDIO_FREQUENCY_192K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_96K) || \
00865                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_48K)  || ((AUDIO) == SAI_AUDIO_FREQUENCY_44K) || \
00866                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_32K)  || ((AUDIO) == SAI_AUDIO_FREQUENCY_22K) || \
00867                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_16K)  || ((AUDIO) == SAI_AUDIO_FREQUENCY_11K) || \
00868                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_8K)   || ((AUDIO) == SAI_AUDIO_FREQUENCY_MCKDIV))
00869 
00870 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) || \
00871     defined(STM32L4P5xx) || defined(STM32L4Q5xx)
00872 #define IS_SAI_BLOCK_MCK_OVERSAMPLING(VALUE) (((VALUE) == SAI_MCK_OVERSAMPLING_DISABLE) || \
00873                                               ((VALUE) == SAI_MCK_OVERSAMPLING_ENABLE))
00874 
00875 #define IS_SAI_PDM_MIC_PAIRS_NUMBER(VALUE)   ((1U <= (VALUE)) && ((VALUE) <= 3U))
00876 
00877 #define IS_SAI_PDM_CLOCK_ENABLE(CLOCK) (((CLOCK) != 0U) && \
00878                                        (((CLOCK) & ~(SAI_PDM_CLOCK1_ENABLE | SAI_PDM_CLOCK2_ENABLE)) == 0U))
00879 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx || */
00880 /* STM32L4P5xx || STM32L4Q5xx */
00881 
00882 #define IS_SAI_BLOCK_MODE(MODE)  (((MODE) == SAI_MODEMASTER_TX) || \
00883                                   ((MODE) == SAI_MODEMASTER_RX) || \
00884                                   ((MODE) == SAI_MODESLAVE_TX)  || \
00885                                   ((MODE) == SAI_MODESLAVE_RX))
00886 
00887 #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_FREE_PROTOCOL)  || \
00888                                          ((PROTOCOL) == SAI_AC97_PROTOCOL)  || \
00889                                          ((PROTOCOL) == SAI_SPDIF_PROTOCOL))
00890 
00891 #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DATASIZE_8)  || \
00892                                          ((DATASIZE) == SAI_DATASIZE_10) || \
00893                                          ((DATASIZE) == SAI_DATASIZE_16) || \
00894                                          ((DATASIZE) == SAI_DATASIZE_20) || \
00895                                          ((DATASIZE) == SAI_DATASIZE_24) || \
00896                                          ((DATASIZE) == SAI_DATASIZE_32))
00897 
00898 #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FIRSTBIT_MSB) || \
00899                                      ((BIT) == SAI_FIRSTBIT_LSB))
00900 
00901 #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_CLOCKSTROBING_FALLINGEDGE) || \
00902                                             ((CLOCK) == SAI_CLOCKSTROBING_RISINGEDGE))
00903 
00904 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS)         || \
00905                                        ((SYNCHRO) == SAI_SYNCHRONOUS)          || \
00906                                        ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI1) || \
00907                                        ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI2))
00908 
00909 #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OUTPUTDRIVE_DISABLE) || \
00910                                           ((DRIVE) == SAI_OUTPUTDRIVE_ENABLE))
00911 
00912 #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MASTERDIVIDER_ENABLE) || \
00913                                            ((NODIVIDER) == SAI_MASTERDIVIDER_DISABLE))
00914 
00915 #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63U)
00916 
00917 #define IS_SAI_BLOCK_MUTE_VALUE(VALUE)    (((VALUE) == SAI_ZERO_VALUE)     || \
00918                                            ((VALUE) == SAI_LAST_SENT_VALUE))
00919 
00920 #define IS_SAI_BLOCK_COMPANDING_MODE(MODE)    (((MODE) == SAI_NOCOMPANDING)         || \
00921                                                ((MODE) == SAI_ULAW_1CPL_COMPANDING) || \
00922                                                ((MODE) == SAI_ALAW_1CPL_COMPANDING) || \
00923                                                ((MODE) == SAI_ULAW_2CPL_COMPANDING) || \
00924                                                ((MODE) == SAI_ALAW_2CPL_COMPANDING))
00925 
00926 #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_FIFOTHRESHOLD_EMPTY)   || \
00927                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_1QF)     || \
00928                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_HF)      || \
00929                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_3QF)     || \
00930                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_FULL))
00931 
00932 #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_OUTPUT_NOTRELEASED) ||\
00933                                                  ((STATE) == SAI_OUTPUT_RELEASED))
00934 
00935 #define IS_SAI_MONO_STEREO_MODE(MODE) (((MODE) == SAI_MONOMODE) ||\
00936                                        ((MODE) == SAI_STEREOMODE))
00937 
00938 #define IS_SAI_SLOT_ACTIVE(ACTIVE)  ((ACTIVE) <= SAI_SLOTACTIVE_ALL)
00939 
00940 #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1U <= (NUMBER)) && ((NUMBER) <= 16U))
00941 
00942 #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SLOTSIZE_DATASIZE) || \
00943                                       ((SIZE) == SAI_SLOTSIZE_16B)      || \
00944                                       ((SIZE) == SAI_SLOTSIZE_32B))
00945 
00946 #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24U)
00947 
00948 #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FIRSTBIT) || \
00949                                         ((OFFSET) == SAI_FS_BEFOREFIRSTBIT))
00950 
00951 #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ACTIVE_LOW) || \
00952                                             ((POLARITY) == SAI_FS_ACTIVE_HIGH))
00953 
00954 #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_STARTFRAME) || \
00955                                                 ((DEFINITION) == SAI_FS_CHANNEL_IDENTIFICATION))
00956 
00957 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) || \
00958     defined(STM32L4P5xx) || defined(STM32L4Q5xx)
00959 #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 63U)
00960 #else
00961 #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 15U)
00962 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx || */
00963 /* STM32L4P5xx || STM32L4Q5xx */
00964 
00965 #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8U <= (LENGTH)) && ((LENGTH) <= 256U))
00966 
00967 #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1U <= (LENGTH)) && ((LENGTH) <= 128U))
00968 
00969 /**
00970   * @}
00971   */
00972 
00973 /* Private functions ---------------------------------------------------------*/
00974 /** @defgroup SAI_Private_Functions SAI Private Functions
00975   * @{
00976   */
00977 
00978 /**
00979   * @}
00980   */
00981 
00982 /**
00983   * @}
00984   */
00985 
00986 /**
00987   * @}
00988   */
00989 
00990 #endif /* !STM32L412xx && !STM32L422xx */
00991 
00992 #ifdef __cplusplus
00993 }
00994 #endif
00995 
00996 #endif /* STM32L4xx_HAL_SAI_H */
00997