TUKS MCU Introductory course / TUKS-COURSE-THERMOMETER

Fork of TUKS-COURSE-TIMER by TUKS MCU Introductory course

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_hal_sai.h Source File

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   * @version V1.5.1
00006   * @date    31-May-2016
00007   * @brief   Header file of SAI HAL module.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00012   *
00013   * Redistribution and use in source and binary forms, with or without modification,
00014   * are permitted provided that the following conditions are met:
00015   *   1. Redistributions of source code must retain the above copyright notice,
00016   *      this list of conditions and the following disclaimer.
00017   *   2. Redistributions in binary form must reproduce the above copyright notice,
00018   *      this list of conditions and the following disclaimer in the documentation
00019   *      and/or other materials provided with the distribution.
00020   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021   *      may be used to endorse or promote products derived from this software
00022   *      without specific prior written permission.
00023   *
00024   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034   *
00035   ******************************************************************************
00036   */
00037 
00038 /* Define to prevent recursive inclusion -------------------------------------*/
00039 #ifndef __STM32L4xx_HAL_SAI_H
00040 #define __STM32L4xx_HAL_SAI_H
00041 
00042 #ifdef __cplusplus
00043  extern "C" {
00044 #endif
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 #include "stm32l4xx_hal_def.h"
00048 
00049 /** @addtogroup STM32L4xx_HAL_Driver
00050   * @{
00051   */
00052 
00053 /** @addtogroup SAI
00054   * @{
00055   */
00056 
00057 /* Exported types ------------------------------------------------------------*/
00058 /** @defgroup SAI_Exported_Types SAI Exported Types
00059   * @{
00060   */
00061 
00062 /**
00063   * @brief  HAL State structures definition
00064   */
00065 typedef enum
00066 {
00067   HAL_SAI_STATE_RESET    = 0x00U, /*!< SAI not yet initialized or disabled  */
00068   HAL_SAI_STATE_READY    = 0x01U, /*!< SAI initialized and ready for use    */
00069   HAL_SAI_STATE_BUSY     = 0x02U, /*!< SAI internal process is ongoing      */
00070   HAL_SAI_STATE_BUSY_TX  = 0x12U, /*!< Data transmission process is ongoing */
00071   HAL_SAI_STATE_BUSY_RX  = 0x22U, /*!< Data reception process is ongoing    */
00072 }HAL_SAI_StateTypeDef;
00073 
00074 /**
00075   * @brief  SAI Callback prototype
00076   */
00077 typedef void (*SAIcallback)(void);
00078 
00079 /** @defgroup SAI_Init_Structure_definition SAI Init Structure definition
00080   * @brief  SAI Init Structure definition
00081   * @{
00082   */
00083 typedef struct
00084 {
00085   uint32_t AudioMode;           /*!< Specifies the SAI Block audio Mode.
00086                                      This parameter can be a value of @ref SAI_Block_Mode */
00087 
00088   uint32_t Synchro;             /*!< Specifies SAI Block synchronization
00089                                      This parameter can be a value of @ref SAI_Block_Synchronization */
00090 
00091   uint32_t SynchroExt;          /*!< Specifies SAI external output synchronization, this setup is common
00092                                      for BlockA and BlockB
00093                                      This parameter can be a value of @ref SAI_Block_SyncExt
00094                                      @note: If both audio blocks of same SAI are used, this parameter has
00095                                             to be set to the same value for each audio block */
00096 
00097   uint32_t OutputDrive;         /*!< Specifies when SAI Block outputs are driven.
00098                                      This parameter can be a value of @ref SAI_Block_Output_Drive
00099                                      @note this value has to be set before enabling the audio block
00100                                      but after the audio block configuration. */
00101 
00102   uint32_t NoDivider;           /*!< Specifies whether master clock will be divided or not.
00103                                      This parameter can be a value of @ref SAI_Block_NoDivider
00104                                      @note: If bit NODIV in the SAI_xCR1 register is cleared, the frame length
00105                                             should be aligned to a number equal to a power of 2, from 8 to 256.
00106                                             If bit NODIV in the SAI_xCR1 register is set, the frame length can
00107                                             take any of the values without constraint since the input clock of
00108                                             the audio block should be equal to the bit clock.
00109                                             There is no MCLK_x clock which can be output. */
00110 
00111   uint32_t FIFOThreshold;       /*!< Specifies SAI Block FIFO threshold.
00112                                      This parameter can be a value of @ref SAI_Block_Fifo_Threshold */
00113 
00114   uint32_t AudioFrequency;      /*!< Specifies the audio frequency sampling.
00115                                      This parameter can be a value of @ref SAI_Audio_Frequency */
00116 
00117   uint32_t Mckdiv;              /*!< Specifies the master clock divider, the parameter will be used if for
00118                                      AudioFrequency the user choice
00119                                      This parameter must be a number between Min_Data = 0 and Max_Data = 15 */
00120 
00121   uint32_t MonoStereoMode;      /*!< Specifies if the mono or stereo mode is selected.
00122                                      This parameter can be a value of @ref SAI_Mono_Stereo_Mode */
00123 
00124   uint32_t CompandingMode;      /*!< Specifies the companding mode type.
00125                                      This parameter can be a value of @ref SAI_Block_Companding_Mode */
00126 
00127   uint32_t TriState;            /*!< Specifies the companding mode type.
00128                                      This parameter can be a value of @ref SAI_TRIState_Management */
00129 
00130   /* This part of the structure is automatically filled if your are using the high level initialisation
00131      function HAL_SAI_InitProtocol */
00132 
00133   uint32_t Protocol;        /*!< Specifies the SAI Block protocol.
00134                                  This parameter can be a value of @ref SAI_Block_Protocol */
00135 
00136   uint32_t DataSize;        /*!< Specifies the SAI Block data size.
00137                                  This parameter can be a value of @ref SAI_Block_Data_Size */
00138 
00139   uint32_t FirstBit;        /*!< Specifies whether data transfers start from MSB or LSB bit.
00140                                  This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission */
00141 
00142   uint32_t ClockStrobing;   /*!< Specifies the SAI Block clock strobing edge sensitivity.
00143                                  This parameter can be a value of @ref SAI_Block_Clock_Strobing */
00144 }SAI_InitTypeDef;
00145 /**
00146   * @}
00147   */
00148 
00149 /** @defgroup SAI_Frame_Structure_definition SAI Frame Structure definition
00150   * @brief  SAI Frame Init structure definition
00151   * @{
00152   */
00153 typedef struct
00154 {
00155 
00156   uint32_t FrameLength;        /*!< Specifies the Frame length, the number of SCK clocks for each audio frame.
00157                                     This parameter must be a number between Min_Data = 8 and Max_Data = 256.
00158                                     @note: If master clock MCLK_x pin is declared as an output, the frame length
00159                                            should be aligned to a number equal to power of 2 in order to keep
00160                                            in an audio frame, an integer number of MCLK pulses by bit Clock. */
00161 
00162   uint32_t ActiveFrameLength;  /*!< Specifies the Frame synchronization active level length.
00163                                     This Parameter specifies the length in number of bit clock (SCK + 1)
00164                                     of the active level of FS signal in audio frame.
00165                                     This parameter must be a number between Min_Data = 1 and Max_Data = 128 */
00166 
00167   uint32_t FSDefinition;       /*!< Specifies the Frame synchronization definition.
00168                                     This parameter can be a value of @ref SAI_Block_FS_Definition */
00169 
00170   uint32_t FSPolarity;         /*!< Specifies the Frame synchronization Polarity.
00171                                     This parameter can be a value of @ref SAI_Block_FS_Polarity */
00172 
00173   uint32_t FSOffset;           /*!< Specifies the Frame synchronization Offset.
00174                                     This parameter can be a value of @ref SAI_Block_FS_Offset */
00175 
00176 }SAI_FrameInitTypeDef;
00177 /**
00178   * @}
00179   */
00180 
00181 /** @defgroup SAI_Slot_Structure_definition SAI Slot Structure definition
00182   * @brief   SAI Block Slot Init Structure definition
00183   * @{
00184   */
00185 typedef struct
00186 {
00187   uint32_t FirstBitOffset;  /*!< Specifies the position of first data transfer bit in the slot.
00188                                  This parameter must be a number between Min_Data = 0 and Max_Data = 24 */
00189 
00190   uint32_t SlotSize;        /*!< Specifies the Slot Size.
00191                                  This parameter can be a value of @ref SAI_Block_Slot_Size */
00192 
00193   uint32_t SlotNumber;      /*!< Specifies the number of slot in the audio frame.
00194                                  This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
00195 
00196   uint32_t SlotActive;      /*!< Specifies the slots in audio frame that will be activated.
00197                                  This parameter can be a value of @ref SAI_Block_Slot_Active */
00198 }SAI_SlotInitTypeDef;
00199 /**
00200   * @}
00201   */
00202 
00203 /** @defgroup SAI_Handle_Structure_definition SAI Handle Structure definition
00204   * @brief  SAI handle Structure definition
00205   * @{
00206   */
00207 typedef struct __SAI_HandleTypeDef
00208 {
00209   SAI_Block_TypeDef         *Instance;    /*!< SAI Blockx registers base address */
00210 
00211   SAI_InitTypeDef           Init;         /*!< SAI communication parameters */
00212 
00213   SAI_FrameInitTypeDef      FrameInit;    /*!< SAI Frame configuration parameters */
00214 
00215   SAI_SlotInitTypeDef       SlotInit;     /*!< SAI Slot configuration parameters */
00216 
00217   uint8_t                  *pBuffPtr;     /*!< Pointer to SAI transfer Buffer */
00218 
00219   uint16_t                  XferSize;     /*!< SAI transfer size */
00220 
00221   uint16_t                  XferCount;    /*!< SAI transfer counter */
00222 
00223   DMA_HandleTypeDef         *hdmatx;      /*!< SAI Tx DMA handle parameters */
00224 
00225   DMA_HandleTypeDef         *hdmarx;      /*!< SAI Rx DMA handle parameters */
00226 
00227   SAIcallback               mutecallback; /*!< SAI mute callback */
00228 
00229   void (*InterruptServiceRoutine)(struct __SAI_HandleTypeDef *hsai); /* function pointer for IRQ handler */
00230 
00231   HAL_LockTypeDef           Lock;         /*!< SAI locking object */
00232 
00233   __IO HAL_SAI_StateTypeDef State;        /*!< SAI communication state */
00234 
00235   __IO uint32_t             ErrorCode;    /*!< SAI Error code */
00236 }SAI_HandleTypeDef;
00237 /**
00238   * @}
00239   */
00240 
00241 /**
00242   * @}
00243   */
00244 
00245 /* Exported constants --------------------------------------------------------*/
00246 
00247 /** @defgroup SAI_Exported_Constants SAI Exported Constants
00248   * @{
00249   */
00250 
00251 /** @defgroup SAI_Error_Code SAI Error Code
00252   * @{
00253   */
00254 #define HAL_SAI_ERROR_NONE    ((uint32_t)0x00000000U)  /*!< No error */
00255 #define HAL_SAI_ERROR_OVR     ((uint32_t)0x00000001U)  /*!< Overrun Error */
00256 #define HAL_SAI_ERROR_UDR     ((uint32_t)0x00000002U)  /*!< Underrun error */
00257 #define HAL_SAI_ERROR_AFSDET  ((uint32_t)0x00000004U)  /*!< Anticipated Frame synchronisation detection */
00258 #define HAL_SAI_ERROR_LFSDET  ((uint32_t)0x00000008U)  /*!< Late Frame synchronisation detection */
00259 #define HAL_SAI_ERROR_CNREADY ((uint32_t)0x00000010U)  /*!< codec not ready */
00260 #define HAL_SAI_ERROR_WCKCFG  ((uint32_t)0x00000020U)  /*!< Wrong clock configuration */
00261 #define HAL_SAI_ERROR_TIMEOUT ((uint32_t)0x00000040U)  /*!< Timeout error */
00262 #define HAL_SAI_ERROR_DMA     ((uint32_t)0x00000080U)  /*!< DMA error */
00263 /**
00264   * @}
00265   */
00266 
00267 /** @defgroup SAI_Block_SyncExt SAI External synchronisation
00268   * @{
00269   */
00270 #define SAI_SYNCEXT_DISABLE          0
00271 #define SAI_SYNCEXT_OUTBLOCKA_ENABLE 1
00272 #define SAI_SYNCEXT_OUTBLOCKB_ENABLE 2
00273 /**
00274   * @}
00275   */
00276 
00277 /** @defgroup SAI_Protocol SAI Supported protocol
00278   * @{
00279   */
00280 #define SAI_I2S_STANDARD      0
00281 #define SAI_I2S_MSBJUSTIFIED  1
00282 #define SAI_I2S_LSBJUSTIFIED  2
00283 #define SAI_PCM_LONG          3
00284 #define SAI_PCM_SHORT         4
00285 /**
00286   * @}
00287   */
00288 
00289 /** @defgroup SAI_Protocol_DataSize SAI protocol data size
00290   * @{
00291   */
00292 #define SAI_PROTOCOL_DATASIZE_16BIT         0
00293 #define SAI_PROTOCOL_DATASIZE_16BITEXTENDED 1
00294 #define SAI_PROTOCOL_DATASIZE_24BIT         2
00295 #define SAI_PROTOCOL_DATASIZE_32BIT         3
00296 /**
00297   * @}
00298   */
00299 
00300 /** @defgroup SAI_Audio_Frequency SAI Audio Frequency
00301   * @{
00302   */
00303 #define SAI_AUDIO_FREQUENCY_192K          ((uint32_t)192000U)
00304 #define SAI_AUDIO_FREQUENCY_96K           ((uint32_t)96000U)
00305 #define SAI_AUDIO_FREQUENCY_48K           ((uint32_t)48000U)
00306 #define SAI_AUDIO_FREQUENCY_44K           ((uint32_t)44100U)
00307 #define SAI_AUDIO_FREQUENCY_32K           ((uint32_t)32000U)
00308 #define SAI_AUDIO_FREQUENCY_22K           ((uint32_t)22050U)
00309 #define SAI_AUDIO_FREQUENCY_16K           ((uint32_t)16000U)
00310 #define SAI_AUDIO_FREQUENCY_11K           ((uint32_t)11025U)
00311 #define SAI_AUDIO_FREQUENCY_8K            ((uint32_t)8000U)
00312 #define SAI_AUDIO_FREQUENCY_MCKDIV        ((uint32_t)0U)
00313 /**
00314   * @}
00315   */
00316 
00317 /** @defgroup SAI_Block_Mode SAI Block Mode
00318   * @{
00319   */
00320 #define SAI_MODEMASTER_TX         ((uint32_t)0x00000000U)
00321 #define SAI_MODEMASTER_RX         ((uint32_t)SAI_xCR1_MODE_0)
00322 #define SAI_MODESLAVE_TX          ((uint32_t)SAI_xCR1_MODE_1)
00323 #define SAI_MODESLAVE_RX          ((uint32_t)(SAI_xCR1_MODE_1 | SAI_xCR1_MODE_0))
00324 
00325 /**
00326   * @}
00327   */
00328 
00329 /** @defgroup SAI_Block_Protocol SAI Block Protocol
00330   * @{
00331   */
00332 #define SAI_FREE_PROTOCOL                 ((uint32_t)0x00000000U)
00333 #define SAI_SPDIF_PROTOCOL                ((uint32_t)SAI_xCR1_PRTCFG_0)
00334 #define SAI_AC97_PROTOCOL                 ((uint32_t)SAI_xCR1_PRTCFG_1)
00335 /**
00336   * @}
00337   */
00338 
00339 /** @defgroup SAI_Block_Data_Size SAI Block Data Size
00340   * @{
00341   */
00342 #define SAI_DATASIZE_8     ((uint32_t)SAI_xCR1_DS_1)
00343 #define SAI_DATASIZE_10    ((uint32_t)(SAI_xCR1_DS_1 | SAI_xCR1_DS_0))
00344 #define SAI_DATASIZE_16    ((uint32_t)SAI_xCR1_DS_2)
00345 #define SAI_DATASIZE_20    ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_0))
00346 #define SAI_DATASIZE_24    ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_1))
00347 #define SAI_DATASIZE_32    ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_1 | SAI_xCR1_DS_0))
00348 /**
00349   * @}
00350   */
00351 
00352 /** @defgroup SAI_Block_MSB_LSB_transmission SAI Block MSB LSB transmission
00353   * @{
00354   */
00355 #define SAI_FIRSTBIT_MSB                  ((uint32_t)0x00000000U)
00356 #define SAI_FIRSTBIT_LSB                  ((uint32_t)SAI_xCR1_LSBFIRST)
00357 /**
00358   * @}
00359   */
00360 
00361 /** @defgroup SAI_Block_Clock_Strobing SAI Block Clock Strobing
00362   * @{
00363   */
00364 #define SAI_CLOCKSTROBING_FALLINGEDGE     0
00365 #define SAI_CLOCKSTROBING_RISINGEDGE      1
00366 /**
00367   * @}
00368   */
00369 
00370 /** @defgroup SAI_Block_Synchronization SAI Block Synchronization
00371   * @{
00372   */
00373 #define SAI_ASYNCHRONOUS                  0 /*!< Asynchronous */
00374 #define SAI_SYNCHRONOUS                   1 /*!< Synchronous with other block of same SAI */
00375 #define SAI_SYNCHRONOUS_EXT_SAI1          2 /*!< Synchronous with other SAI, SAI1 */
00376 #define SAI_SYNCHRONOUS_EXT_SAI2          3 /*!< Synchronous with other SAI, SAI2 */
00377 /**
00378   * @}
00379   */ 
00380 
00381 /** @defgroup SAI_Block_Output_Drive SAI Block Output Drive
00382   * @{
00383   */
00384 #define SAI_OUTPUTDRIVE_DISABLE          ((uint32_t)0x00000000U)
00385 #define SAI_OUTPUTDRIVE_ENABLE           ((uint32_t)SAI_xCR1_OUTDRIV)
00386 /**
00387   * @}
00388   */
00389 
00390 /** @defgroup SAI_Block_NoDivider SAI Block NoDivider
00391   * @{
00392   */
00393 #define SAI_MASTERDIVIDER_ENABLE         ((uint32_t)0x00000000U)
00394 #define SAI_MASTERDIVIDER_DISABLE        ((uint32_t)SAI_xCR1_NODIV)
00395 /**
00396   * @}
00397   */
00398 
00399 
00400 /** @defgroup SAI_Block_FS_Definition SAI Block FS Definition
00401   * @{
00402   */
00403 #define SAI_FS_STARTFRAME                 ((uint32_t)0x00000000U)
00404 #define SAI_FS_CHANNEL_IDENTIFICATION     ((uint32_t)SAI_xFRCR_FSDEF)
00405 /**
00406   * @}
00407   */
00408 
00409 /** @defgroup SAI_Block_FS_Polarity SAI Block FS Polarity
00410   * @{
00411   */
00412 #define SAI_FS_ACTIVE_LOW                  ((uint32_t)0x00000000U)
00413 #define SAI_FS_ACTIVE_HIGH                 ((uint32_t)SAI_xFRCR_FSPOL)
00414 /**
00415   * @}
00416   */
00417 
00418 /** @defgroup SAI_Block_FS_Offset SAI Block FS Offset
00419   * @{
00420   */
00421 #define SAI_FS_FIRSTBIT                   ((uint32_t)0x00000000U)
00422 #define SAI_FS_BEFOREFIRSTBIT             ((uint32_t)SAI_xFRCR_FSOFF)
00423 /**
00424   * @}
00425   */
00426 
00427 
00428   /** @defgroup SAI_Block_Slot_Size SAI Block Slot Size
00429   * @{
00430   */
00431 #define SAI_SLOTSIZE_DATASIZE             ((uint32_t)0x00000000U)
00432 #define SAI_SLOTSIZE_16B                  ((uint32_t)SAI_xSLOTR_SLOTSZ_0)
00433 #define SAI_SLOTSIZE_32B                  ((uint32_t)SAI_xSLOTR_SLOTSZ_1)
00434 /**
00435   * @}
00436   */
00437 
00438 /** @defgroup SAI_Block_Slot_Active SAI Block Slot Active
00439   * @{
00440   */
00441 #define SAI_SLOT_NOTACTIVE           ((uint32_t)0x00000000U)
00442 #define SAI_SLOTACTIVE_0             ((uint32_t)0x00000001U)
00443 #define SAI_SLOTACTIVE_1             ((uint32_t)0x00000002U)
00444 #define SAI_SLOTACTIVE_2             ((uint32_t)0x00000004U)
00445 #define SAI_SLOTACTIVE_3             ((uint32_t)0x00000008U)
00446 #define SAI_SLOTACTIVE_4             ((uint32_t)0x00000010U)
00447 #define SAI_SLOTACTIVE_5             ((uint32_t)0x00000020U)
00448 #define SAI_SLOTACTIVE_6             ((uint32_t)0x00000040U)
00449 #define SAI_SLOTACTIVE_7             ((uint32_t)0x00000080U)
00450 #define SAI_SLOTACTIVE_8             ((uint32_t)0x00000100U)
00451 #define SAI_SLOTACTIVE_9             ((uint32_t)0x00000200U)
00452 #define SAI_SLOTACTIVE_10            ((uint32_t)0x00000400U)
00453 #define SAI_SLOTACTIVE_11            ((uint32_t)0x00000800U)
00454 #define SAI_SLOTACTIVE_12            ((uint32_t)0x00001000U)
00455 #define SAI_SLOTACTIVE_13            ((uint32_t)0x00002000U)
00456 #define SAI_SLOTACTIVE_14            ((uint32_t)0x00004000U)
00457 #define SAI_SLOTACTIVE_15            ((uint32_t)0x00008000U)
00458 #define SAI_SLOTACTIVE_ALL           ((uint32_t)0x0000FFFFU)
00459 /**
00460   * @}
00461   */
00462 
00463 /** @defgroup SAI_Mono_Stereo_Mode SAI Mono Stereo Mode
00464   * @{
00465   */
00466 #define SAI_STEREOMODE               ((uint32_t)0x00000000U)
00467 #define SAI_MONOMODE                 ((uint32_t)SAI_xCR1_MONO)
00468 /**
00469   * @}
00470   */
00471 
00472 /** @defgroup SAI_TRIState_Management SAI TRIState Management
00473   * @{
00474   */
00475 #define SAI_OUTPUT_NOTRELEASED    ((uint32_t)0x00000000U)
00476 #define SAI_OUTPUT_RELEASED       ((uint32_t)SAI_xCR2_TRIS)
00477 /**
00478   * @}
00479   */
00480 
00481 /** @defgroup SAI_Block_Fifo_Threshold SAI Block Fifo Threshold
00482   * @{
00483   */
00484 #define SAI_FIFOTHRESHOLD_EMPTY  ((uint32_t)0x00000000U)
00485 #define SAI_FIFOTHRESHOLD_1QF    ((uint32_t)(SAI_xCR2_FTH_0))
00486 #define SAI_FIFOTHRESHOLD_HF     ((uint32_t)(SAI_xCR2_FTH_1))
00487 #define SAI_FIFOTHRESHOLD_3QF    ((uint32_t)(SAI_xCR2_FTH_1 | SAI_xCR2_FTH_0))
00488 #define SAI_FIFOTHRESHOLD_FULL   ((uint32_t)(SAI_xCR2_FTH_2))
00489 /**
00490   * @}
00491   */
00492 
00493 /** @defgroup SAI_Block_Companding_Mode SAI Block Companding Mode
00494   * @{
00495   */
00496 #define SAI_NOCOMPANDING                 ((uint32_t)0x00000000U)
00497 #define SAI_ULAW_1CPL_COMPANDING         ((uint32_t)(SAI_xCR2_COMP_1))
00498 #define SAI_ALAW_1CPL_COMPANDING         ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0))
00499 #define SAI_ULAW_2CPL_COMPANDING         ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_CPL))
00500 #define SAI_ALAW_2CPL_COMPANDING         ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0 | SAI_xCR2_CPL))
00501 /**
00502   * @}
00503   */
00504 
00505 /** @defgroup SAI_Block_Mute_Value SAI Block Mute Value
00506   * @{
00507   */
00508 #define SAI_ZERO_VALUE                     ((uint32_t)0x00000000U)
00509 #define SAI_LAST_SENT_VALUE                ((uint32_t)SAI_xCR2_MUTEVAL)
00510 /**
00511   * @}
00512   */
00513 
00514 /** @defgroup SAI_Block_Interrupts_Definition SAI Block Interrupts Definition
00515   * @{
00516   */
00517 #define SAI_IT_OVRUDR                     ((uint32_t)SAI_xIMR_OVRUDRIE)
00518 #define SAI_IT_MUTEDET                    ((uint32_t)SAI_xIMR_MUTEDETIE)
00519 #define SAI_IT_WCKCFG                     ((uint32_t)SAI_xIMR_WCKCFGIE)
00520 #define SAI_IT_FREQ                       ((uint32_t)SAI_xIMR_FREQIE)
00521 #define SAI_IT_CNRDY                      ((uint32_t)SAI_xIMR_CNRDYIE)
00522 #define SAI_IT_AFSDET                     ((uint32_t)SAI_xIMR_AFSDETIE)
00523 #define SAI_IT_LFSDET                     ((uint32_t)SAI_xIMR_LFSDETIE)
00524 /**
00525   * @}
00526   */
00527 
00528 /** @defgroup SAI_Block_Flags_Definition  SAI Block Flags Definition
00529   * @{
00530   */
00531 #define SAI_FLAG_OVRUDR                   ((uint32_t)SAI_xSR_OVRUDR)
00532 #define SAI_FLAG_MUTEDET                  ((uint32_t)SAI_xSR_MUTEDET)
00533 #define SAI_FLAG_WCKCFG                   ((uint32_t)SAI_xSR_WCKCFG)
00534 #define SAI_FLAG_FREQ                     ((uint32_t)SAI_xSR_FREQ)
00535 #define SAI_FLAG_CNRDY                    ((uint32_t)SAI_xSR_CNRDY)
00536 #define SAI_FLAG_AFSDET                   ((uint32_t)SAI_xSR_AFSDET)
00537 #define SAI_FLAG_LFSDET                   ((uint32_t)SAI_xSR_LFSDET)
00538 /**
00539   * @}
00540   */
00541 
00542 /** @defgroup SAI_Block_Fifo_Status_Level   SAI Block Fifo Status Level
00543   * @{
00544   */
00545 #define SAI_FIFOSTATUS_EMPTY              ((uint32_t)0x00000000U)
00546 #define SAI_FIFOSTATUS_LESS1QUARTERFULL   ((uint32_t)0x00010000U)
00547 #define SAI_FIFOSTATUS_1QUARTERFULL       ((uint32_t)0x00020000U)
00548 #define SAI_FIFOSTATUS_HALFFULL           ((uint32_t)0x00030000U)
00549 #define SAI_FIFOSTATUS_3QUARTERFULL       ((uint32_t)0x00040000U)
00550 #define SAI_FIFOSTATUS_FULL               ((uint32_t)0x00050000U)
00551 /**
00552   * @}
00553   */
00554 
00555 /**
00556   * @}
00557   */
00558 
00559 /* Exported macro ------------------------------------------------------------*/
00560 
00561 /** @defgroup SAI_Exported_Macros SAI Exported Macros
00562  *  @brief macros to handle interrupts and specific configurations
00563  * @{
00564  */
00565 
00566 /** @brief Reset SAI handle state.
00567   * @param  __HANDLE__: specifies the SAI Handle.
00568   * @retval None
00569   */
00570 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SAI_STATE_RESET)
00571 
00572 /** @brief  Enable or disable the specified SAI interrupts.
00573   * @param  __HANDLE__: specifies the SAI Handle.
00574   * @param  __INTERRUPT__: specifies the interrupt source to enable or disable.
00575   *         This parameter can be one of the following values:
00576   *            @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
00577   *            @arg SAI_IT_MUTEDET: Mute detection interrupt enable
00578   *            @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
00579   *            @arg SAI_IT_FREQ: FIFO request interrupt enable
00580   *            @arg SAI_IT_CNRDY: Codec not ready interrupt enable
00581   *            @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
00582   *            @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
00583   * @retval None
00584   */
00585 #define __HAL_SAI_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->IMR |= (__INTERRUPT__))
00586 #define __HAL_SAI_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((__HANDLE__)->Instance->IMR &= (~(__INTERRUPT__)))
00587 
00588 /** @brief  Check whether the specified SAI interrupt source is enabled or not.
00589   * @param  __HANDLE__: specifies the SAI Handle.
00590   * @param  __INTERRUPT__: specifies the SAI interrupt source to check.
00591   *         This parameter can be one of the following values:
00592   *            @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
00593   *            @arg SAI_IT_MUTEDET: Mute detection interrupt enable
00594   *            @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
00595   *            @arg SAI_IT_FREQ: FIFO request interrupt enable
00596   *            @arg SAI_IT_CNRDY: Codec not ready interrupt enable
00597   *            @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
00598   *            @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
00599   * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
00600   */
00601 #define __HAL_SAI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IMR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
00602 
00603 /** @brief  Check whether the specified SAI flag is set or not.
00604   * @param  __HANDLE__: specifies the SAI Handle.
00605   * @param  __FLAG__: specifies the flag to check.
00606   *         This parameter can be one of the following values:
00607   *            @arg SAI_FLAG_OVRUDR: Overrun underrun flag.
00608   *            @arg SAI_FLAG_MUTEDET: Mute detection flag.
00609   *            @arg SAI_FLAG_WCKCFG: Wrong Clock Configuration flag.
00610   *            @arg SAI_FLAG_FREQ: FIFO request flag.
00611   *            @arg SAI_FLAG_CNRDY: Codec not ready flag.
00612   *            @arg SAI_FLAG_AFSDET: Anticipated frame synchronization detection flag.
00613   *            @arg SAI_FLAG_LFSDET: Late frame synchronization detection flag.
00614   * @retval The new state of __FLAG__ (TRUE or FALSE).
00615   */
00616 #define __HAL_SAI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
00617 
00618 /** @brief  Clear the specified SAI pending flag.
00619   * @param  __HANDLE__: specifies the SAI Handle.
00620   * @param  __FLAG__: specifies the flag to check.
00621   *          This parameter can be any combination of the following values:
00622   *            @arg SAI_FLAG_OVRUDR: Clear Overrun underrun
00623   *            @arg SAI_FLAG_MUTEDET: Clear Mute detection
00624   *            @arg SAI_FLAG_WCKCFG: Clear Wrong Clock Configuration
00625   *            @arg SAI_FLAG_FREQ: Clear FIFO request
00626   *            @arg SAI_FLAG_CNRDY: Clear Codec not ready
00627   *            @arg SAI_FLAG_AFSDET: Clear Anticipated frame synchronization detection
00628   *            @arg SAI_FLAG_LFSDET: Clear Late frame synchronization detection
00629   *
00630   * @retval None
00631   */
00632 #define __HAL_SAI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__))
00633 
00634 #define __HAL_SAI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |=  SAI_xCR1_SAIEN)
00635 #define __HAL_SAI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &=  ~SAI_xCR1_SAIEN)
00636 
00637  /**
00638   * @}
00639   */
00640 
00641 /* Exported functions --------------------------------------------------------*/
00642 
00643 /** @addtogroup SAI_Exported_Functions
00644   * @{
00645   */
00646 
00647 /* Initialization/de-initialization functions  ********************************/
00648 
00649 /** @addtogroup SAI_Exported_Functions_Group1
00650   * @{
00651   */
00652 HAL_StatusTypeDef HAL_SAI_InitProtocol(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot);
00653 HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai);
00654 HAL_StatusTypeDef HAL_SAI_DeInit (SAI_HandleTypeDef *hsai);
00655 void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai);
00656 void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai);
00657 
00658 /**
00659   * @}
00660   */
00661 
00662 /* I/O operation functions  ***************************************************/
00663 
00664 /** @addtogroup SAI_Exported_Functions_Group2
00665   * @{
00666   */
00667 /* Blocking mode: Polling */
00668 HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
00669 HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
00670 
00671 /* Non-Blocking mode: Interrupt */
00672 HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
00673 HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
00674 
00675 /* Non-Blocking mode: DMA */
00676 HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
00677 HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
00678 HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai);
00679 HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai);
00680 HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai);
00681 
00682 /* Abort function */
00683 HAL_StatusTypeDef HAL_SAI_Abort(SAI_HandleTypeDef *hsai);
00684 
00685 /* Mute management */
00686 HAL_StatusTypeDef HAL_SAI_EnableTxMuteMode(SAI_HandleTypeDef *hsai, uint16_t val);
00687 HAL_StatusTypeDef HAL_SAI_DisableTxMuteMode(SAI_HandleTypeDef *hsai);
00688 HAL_StatusTypeDef HAL_SAI_EnableRxMuteMode(SAI_HandleTypeDef *hsai, SAIcallback callback, uint16_t counter);
00689 HAL_StatusTypeDef HAL_SAI_DisableRxMuteMode(SAI_HandleTypeDef *hsai);
00690 
00691 /* SAI IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
00692 void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai);
00693 void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai);
00694 void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai);
00695 void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai);
00696 void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai);
00697 void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai);
00698 /**
00699   * @}
00700   */
00701 
00702 /** @addtogroup SAI_Exported_Functions_Group3
00703   * @{
00704   */
00705 /* Peripheral State functions  ************************************************/
00706 HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai);
00707 uint32_t HAL_SAI_GetError(SAI_HandleTypeDef *hsai);
00708 /**
00709   * @}
00710   */
00711 
00712 /**
00713   * @}
00714   */
00715 
00716 /* Private macros ------------------------------------------------------------*/
00717 /** @addtogroup SAI_Private_Macros
00718   * @{
00719   */
00720 #define IS_SAI_BLOCK_SYNCEXT(STATE) (((STATE) == SAI_SYNCEXT_DISABLE) ||\
00721                                      ((STATE) == SAI_SYNCEXT_OUTBLOCKA_ENABLE) ||\
00722                                      ((STATE) == SAI_SYNCEXT_OUTBLOCKB_ENABLE))
00723 
00724 #define IS_SAI_SUPPORTED_PROTOCOL(PROTOCOL)   (((PROTOCOL) == SAI_I2S_STANDARD)     ||\
00725                                                ((PROTOCOL) == SAI_I2S_MSBJUSTIFIED) ||\
00726                                                ((PROTOCOL) == SAI_I2S_LSBJUSTIFIED) ||\
00727                                                ((PROTOCOL) == SAI_PCM_LONG)         ||\
00728                                                ((PROTOCOL) == SAI_PCM_SHORT))
00729 
00730 #define IS_SAI_PROTOCOL_DATASIZE(DATASIZE)   (((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BIT)         ||\
00731                                               ((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BITEXTENDED) ||\
00732                                               ((DATASIZE) == SAI_PROTOCOL_DATASIZE_24BIT)         ||\
00733                                               ((DATASIZE) == SAI_PROTOCOL_DATASIZE_32BIT))
00734 
00735 #define IS_SAI_AUDIO_FREQUENCY(AUDIO) (((AUDIO) == SAI_AUDIO_FREQUENCY_192K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_96K) || \
00736                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_48K)  || ((AUDIO) == SAI_AUDIO_FREQUENCY_44K) || \
00737                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_32K)  || ((AUDIO) == SAI_AUDIO_FREQUENCY_22K) || \
00738                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_16K)  || ((AUDIO) == SAI_AUDIO_FREQUENCY_11K) || \
00739                                        ((AUDIO) == SAI_AUDIO_FREQUENCY_8K)   || ((AUDIO) == SAI_AUDIO_FREQUENCY_MCKDIV))
00740 
00741 #define IS_SAI_BLOCK_MODE(MODE)  (((MODE) == SAI_MODEMASTER_TX) || \
00742                                   ((MODE) == SAI_MODEMASTER_RX) || \
00743                                   ((MODE) == SAI_MODESLAVE_TX)  || \
00744                                   ((MODE) == SAI_MODESLAVE_RX))
00745 
00746 #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_FREE_PROTOCOL)  || \
00747                                          ((PROTOCOL) == SAI_AC97_PROTOCOL)  || \
00748                                          ((PROTOCOL) == SAI_SPDIF_PROTOCOL)) 
00749 
00750 #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DATASIZE_8)  || \
00751                                          ((DATASIZE) == SAI_DATASIZE_10) || \
00752                                          ((DATASIZE) == SAI_DATASIZE_16) || \
00753                                          ((DATASIZE) == SAI_DATASIZE_20) || \
00754                                          ((DATASIZE) == SAI_DATASIZE_24) || \
00755                                          ((DATASIZE) == SAI_DATASIZE_32))
00756 
00757 #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FIRSTBIT_MSB) || \
00758                                      ((BIT) == SAI_FIRSTBIT_LSB))
00759 
00760 #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_CLOCKSTROBING_FALLINGEDGE) || \
00761                                             ((CLOCK) == SAI_CLOCKSTROBING_RISINGEDGE))
00762 
00763 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS)         || \
00764                                        ((SYNCHRO) == SAI_SYNCHRONOUS)          || \
00765                                        ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI1) || \
00766                                        ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI2))
00767 
00768 #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OUTPUTDRIVE_DISABLE) || \
00769                                           ((DRIVE) == SAI_OUTPUTDRIVE_ENABLE))
00770 
00771 #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MASTERDIVIDER_ENABLE) || \
00772                                            ((NODIVIDER) == SAI_MASTERDIVIDER_DISABLE))
00773 
00774 #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63)
00775 
00776 #define IS_SAI_BLOCK_MUTE_VALUE(VALUE)    (((VALUE) == SAI_ZERO_VALUE)     || \
00777                                            ((VALUE) == SAI_LAST_SENT_VALUE)) 
00778 
00779 #define IS_SAI_BLOCK_COMPANDING_MODE(MODE)    (((MODE) == SAI_NOCOMPANDING)         || \
00780                                                ((MODE) == SAI_ULAW_1CPL_COMPANDING) || \
00781                                                ((MODE) == SAI_ALAW_1CPL_COMPANDING) || \
00782                                                ((MODE) == SAI_ULAW_2CPL_COMPANDING) || \
00783                                                ((MODE) == SAI_ALAW_2CPL_COMPANDING))
00784 
00785 #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_FIFOTHRESHOLD_EMPTY)   || \
00786                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_1QF)     || \
00787                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_HF)      || \
00788                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_3QF)     || \
00789                                                 ((THRESHOLD) == SAI_FIFOTHRESHOLD_FULL))  
00790 
00791 #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_OUTPUT_NOTRELEASED) ||\
00792                                                  ((STATE) == SAI_OUTPUT_RELEASED))
00793 
00794 #define IS_SAI_MONO_STEREO_MODE(MODE) (((MODE) == SAI_MONOMODE) ||\
00795                                        ((MODE) == SAI_STEREOMODE))
00796 
00797 #define IS_SAI_SLOT_ACTIVE(ACTIVE)  ((ACTIVE) <= SAI_SLOTACTIVE_ALL)
00798 
00799 #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1 <= (NUMBER)) && ((NUMBER) <= 16))
00800 
00801 #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SLOTSIZE_DATASIZE) || \
00802                                       ((SIZE) == SAI_SLOTSIZE_16B)      || \
00803                                       ((SIZE) == SAI_SLOTSIZE_32B))
00804 
00805 #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24)
00806 
00807 #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FIRSTBIT) || \
00808                                         ((OFFSET) == SAI_FS_BEFOREFIRSTBIT))
00809 
00810 #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ACTIVE_LOW) || \
00811                                             ((POLARITY) == SAI_FS_ACTIVE_HIGH))
00812 
00813 #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_STARTFRAME) || \
00814                                                 ((DEFINITION) == SAI_FS_CHANNEL_IDENTIFICATION))
00815 
00816 #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 15)
00817 
00818 #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8 <= (LENGTH)) && ((LENGTH) <= 256))
00819 
00820 #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1 <= (LENGTH)) && ((LENGTH) <= 128))
00821 
00822 /**
00823   * @}
00824   */
00825 
00826 /* Private functions ---------------------------------------------------------*/
00827 /** @defgroup SAI_Private_Functions SAI Private Functions
00828   * @{
00829   */
00830 
00831 /**
00832   * @}
00833   */
00834 
00835 /**
00836   * @}
00837   */
00838 
00839 /**
00840   * @}
00841   */
00842 
00843 #ifdef __cplusplus
00844 }
00845 #endif
00846 
00847 #endif /* __STM32L4xx_HAL_SAI_H */
00848 
00849 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/