Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: BSP OneHopeOnePrayer FINAL_AUDIO_RECORD AudioDemo
Fork of STM32L4xx_HAL_Driver by
stm32l4xx_hal_sai.h
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_sai.h 00004 * @author MCD Application Team 00005 * @version V1.1.0 00006 * @date 16-September-2015 00007 * @brief Header file of SAI HAL module. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2015 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 = 0x00, /*!< SAI not yet initialized or disabled */ 00068 HAL_SAI_STATE_READY = 0x01, /*!< SAI initialized and ready for use */ 00069 HAL_SAI_STATE_BUSY = 0x02, /*!< SAI internal process is ongoing */ 00070 HAL_SAI_STATE_BUSY_TX = 0x12, /*!< Data transmission process is ongoing */ 00071 HAL_SAI_STATE_BUSY_RX = 0x22 /*!< 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_Block_SyncExt SAI External synchronisation 00080 * @{ 00081 */ 00082 #define SAI_SYNCEXT_DISABLE 0 00083 #define SAI_SYNCEXT_IN_ENABLE 1 00084 #define SAI_SYNCEXT_OUTBLOCKA_ENABLE 2 00085 #define SAI_SYNCEXT_OUTBLOCKB_ENABLE 3 00086 00087 /** 00088 * @} 00089 */ 00090 00091 /** @defgroup SAI_Protocol SAI Supported protocol 00092 * @{ 00093 */ 00094 #define SAI_I2S_STANDARD 0 00095 #define SAI_I2S_MSBJUSTIFIED 1 00096 #define SAI_I2S_LSBJUSTIFIED 2 00097 #define SAI_PCM_LONG 3 00098 #define SAI_PCM_SHORT 4 00099 00100 /** 00101 * @} 00102 */ 00103 00104 /** @defgroup SAI_Protocol_DataSize SAI protocol data size 00105 * @{ 00106 */ 00107 #define SAI_PROTOCOL_DATASIZE_16BIT 0 00108 #define SAI_PROTOCOL_DATASIZE_16BITEXTENDED 1 00109 #define SAI_PROTOCOL_DATASIZE_24BIT 2 00110 #define SAI_PROTOCOL_DATASIZE_32BIT 3 00111 00112 /** 00113 * @} 00114 */ 00115 00116 /** @defgroup SAI_Init_Structure_definition SAI Init Structure definition 00117 * @brief SAI Init Structure definition 00118 * @{ 00119 */ 00120 typedef struct 00121 { 00122 uint32_t AudioMode; /*!< Specifies the SAI Block audio Mode. 00123 This parameter can be a value of @ref SAI_Block_Mode */ 00124 00125 uint32_t Synchro; /*!< Specifies SAI Block synchronization 00126 This parameter can be a value of @ref SAI_Block_Synchronization */ 00127 00128 uint32_t SynchroExt; /*!< Specifies SAI Block synchronization, this setup is common 00129 for BLOCKA and BLOB 00130 This parameter can be a value of @ref SAI_Block_SyncExt */ 00131 00132 uint32_t OutputDrive; /*!< Specifies when SAI Block outputs are driven. 00133 This parameter can be a value of @ref SAI_Block_Output_Drive 00134 @note this value has to be set before enabling the audio block 00135 but after the audio block configuration. */ 00136 00137 uint32_t NoDivider; /*!< Specifies whether master clock will be divided or not. 00138 This parameter can be a value of @ref SAI_Block_NoDivider 00139 @note: If bit NODIV in the SAI_xCR1 register is cleared, the frame length 00140 should be aligned to a number equal to a power of 2, from 8 to 256. 00141 If bit NODIV in the SAI_xCR1 register is set, the frame length can 00142 take any of the values without constraint since the input clock of 00143 the audio block should be equal to the bit clock. 00144 There is no MCLK_x clock which can be output. */ 00145 00146 uint32_t FIFOThreshold; /*!< Specifies SAI Block FIFO threshold. 00147 This parameter can be a value of @ref SAI_Block_Fifo_Threshold */ 00148 00149 uint32_t AudioFrequency; /*!< Specifies the audio frequency sampling. 00150 This parameter can be a value of @ref SAI_Audio_Frequency */ 00151 00152 uint32_t Mckdiv; /*!< Specifies the master clock divider, the parameter will be used if for 00153 AudioFrequency the user choice 00154 This parameter must be a number between Min_Data = 0 and Max_Data = 15 */ 00155 00156 uint32_t MonoStereoMode; /*!< Specifies if the mono or stereo mode is selected. 00157 This parameter can be a value of @ref SAI_Mono_Stereo_Mode */ 00158 00159 uint32_t CompandingMode; /*!< Specifies the companding mode type. 00160 This parameter can be a value of @ref SAI_Block_Companding_Mode */ 00161 00162 uint32_t TriState; /*!< Specifies the companding mode type. 00163 This parameter can be a value of @ref SAI_TRIState_Management */ 00164 00165 /* This part of the structure is automatically filled if your are using the high level initialisation 00166 function HAL_SAI_InitProtocol */ 00167 00168 uint32_t Protocol; /*!< Specifies the SAI Block protocol. 00169 This parameter can be a value of @ref SAI_Block_Protocol */ 00170 00171 uint32_t DataSize; /*!< Specifies the SAI Block data size. 00172 This parameter can be a value of @ref SAI_Block_Data_Size */ 00173 00174 uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit. 00175 This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission */ 00176 00177 uint32_t ClockStrobing; /*!< Specifies the SAI Block clock strobing edge sensitivity. 00178 This parameter can be a value of @ref SAI_Block_Clock_Strobing */ 00179 }SAI_InitTypeDef; 00180 /** 00181 * @} 00182 */ 00183 00184 /** @defgroup SAI_Frame_Structure_definition SAI Frame Structure definition 00185 * @brief SAI Frame Init structure definition 00186 * @{ 00187 */ 00188 typedef struct 00189 { 00190 00191 uint32_t FrameLength; /*!< Specifies the Frame length, the number of SCK clocks for each audio frame. 00192 This parameter must be a number between Min_Data = 8 and Max_Data = 256. 00193 @note: If master clock MCLK_x pin is declared as an output, the frame length 00194 should be aligned to a number equal to power of 2 in order to keep 00195 in an audio frame, an integer number of MCLK pulses by bit Clock. */ 00196 00197 uint32_t ActiveFrameLength; /*!< Specifies the Frame synchronization active level length. 00198 This Parameter specifies the length in number of bit clock (SCK + 1) 00199 of the active level of FS signal in audio frame. 00200 This parameter must be a number between Min_Data = 1 and Max_Data = 128 */ 00201 00202 uint32_t FSDefinition; /*!< Specifies the Frame synchronization definition. 00203 This parameter can be a value of @ref SAI_Block_FS_Definition */ 00204 00205 uint32_t FSPolarity; /*!< Specifies the Frame synchronization Polarity. 00206 This parameter can be a value of @ref SAI_Block_FS_Polarity */ 00207 00208 uint32_t FSOffset; /*!< Specifies the Frame synchronization Offset. 00209 This parameter can be a value of @ref SAI_Block_FS_Offset */ 00210 00211 }SAI_FrameInitTypeDef; 00212 /** 00213 * @} 00214 */ 00215 00216 /** @defgroup SAI_Slot_Structure_definition SAI Slot Structure definition 00217 * @brief SAI Block Slot Init Structure definition 00218 * @{ 00219 */ 00220 00221 typedef struct 00222 { 00223 uint32_t FirstBitOffset; /*!< Specifies the position of first data transfer bit in the slot. 00224 This parameter must be a number between Min_Data = 0 and Max_Data = 24 */ 00225 00226 uint32_t SlotSize; /*!< Specifies the Slot Size. 00227 This parameter can be a value of @ref SAI_Block_Slot_Size */ 00228 00229 uint32_t SlotNumber; /*!< Specifies the number of slot in the audio frame. 00230 This parameter must be a number between Min_Data = 1 and Max_Data = 16 */ 00231 00232 uint32_t SlotActive; /*!< Specifies the slots in audio frame that will be activated. 00233 This parameter can be a value of @ref SAI_Block_Slot_Active */ 00234 }SAI_SlotInitTypeDef; 00235 /** 00236 * @} 00237 */ 00238 00239 /** @defgroup SAI_Handle_Structure_definition SAI Handle Structure definition 00240 * @brief SAI handle Structure definition 00241 * @{ 00242 */ 00243 typedef struct __SAI_HandleTypeDef 00244 { 00245 SAI_Block_TypeDef *Instance; /*!< SAI Blockx registers base address */ 00246 00247 SAI_InitTypeDef Init; /*!< SAI communication parameters */ 00248 00249 SAI_FrameInitTypeDef FrameInit; /*!< SAI Frame configuration parameters*/ 00250 00251 SAI_SlotInitTypeDef SlotInit; /*!< SAI Slot configuration parameters */ 00252 00253 uint8_t *pBuffPtr; /*!< Pointer to SAI transfer Buffer */ 00254 00255 uint16_t XferSize; /*!< SAI transfer size */ 00256 00257 uint16_t XferCount; /*!< SAI transfer counter */ 00258 00259 DMA_HandleTypeDef *hdmatx; /*!< SAI DMA tx handle parameters */ 00260 00261 DMA_HandleTypeDef *hdmarx; /*!< SAI DMA rx handle parameters */ 00262 00263 SAIcallback mutecallback;/*!< SAI mute callback */ 00264 00265 void (*InterruptServiceRoutine)(struct __SAI_HandleTypeDef *hsai); /* function pointer for IRQ handler */ 00266 00267 HAL_LockTypeDef Lock; /*!< SAI locking object */ 00268 00269 HAL_SAI_StateTypeDef State; /*!< SAI communication state */ 00270 00271 uint32_t ErrorCode; /*!< SAI Error code */ 00272 }SAI_HandleTypeDef; 00273 /** 00274 * @} 00275 */ 00276 00277 /** 00278 * @} 00279 */ 00280 00281 /* Exported constants --------------------------------------------------------*/ 00282 00283 /** @defgroup SAI_Exported_Constants SAI Exported Constants 00284 * @{ 00285 */ 00286 00287 /** @defgroup SAI_Error_Code SAI Error Code 00288 * @{ 00289 */ 00290 #define HAL_SAI_ERROR_NONE (uint32_t)0x00000000 /*!< No error */ 00291 #define HAL_SAI_ERROR_OVR (uint32_t)0x00000001 /*!< Overrun Error */ 00292 #define HAL_SAI_ERROR_UDR (uint32_t)0x00000002 /*!< Underrun error */ 00293 #define HAL_SAI_ERROR_AFSDET (uint32_t)0x00000004 /*!< Anticipated Frame synchronisation detection */ 00294 #define HAL_SAI_ERROR_LFSDET (uint32_t)0x00000008 /*!< Late Frame synchronisation detection */ 00295 #define HAL_SAI_ERROR_CNREADY (uint32_t)0x00000010 /*!< codec not ready */ 00296 #define HAL_SAI_ERROR_WCKCFG (uint32_t)0x00000020 /*!< Wrong clock configuration */ 00297 /** 00298 * @} 00299 */ 00300 00301 /** @defgroup SAI_Audio_Frequency SAI Audio Frequency 00302 * @{ 00303 */ 00304 #define SAI_AUDIO_FREQUENCY_192K ((uint32_t)192000) 00305 #define SAI_AUDIO_FREQUENCY_96K ((uint32_t)96000) 00306 #define SAI_AUDIO_FREQUENCY_48K ((uint32_t)48000) 00307 #define SAI_AUDIO_FREQUENCY_44K ((uint32_t)44100) 00308 #define SAI_AUDIO_FREQUENCY_32K ((uint32_t)32000) 00309 #define SAI_AUDIO_FREQUENCY_22K ((uint32_t)22050) 00310 #define SAI_AUDIO_FREQUENCY_16K ((uint32_t)16000) 00311 #define SAI_AUDIO_FREQUENCY_11K ((uint32_t)11025) 00312 #define SAI_AUDIO_FREQUENCY_8K ((uint32_t)8000) 00313 #define SAI_AUDIO_FREQUENCY_MCKDIV ((uint32_t)0) 00314 00315 /** 00316 * @} 00317 */ 00318 00319 /** @defgroup SAI_Block_Mode SAI Block Mode 00320 * @{ 00321 */ 00322 #define SAI_MODEMASTER_TX ((uint32_t)0x00000000) 00323 #define SAI_MODEMASTER_RX (SAI_xCR1_MODE_0) 00324 #define SAI_MODESLAVE_TX (SAI_xCR1_MODE_1) 00325 #define SAI_MODESLAVE_RX (SAI_xCR1_MODE_1 | SAI_xCR1_MODE_0) 00326 00327 /** 00328 * @} 00329 */ 00330 00331 /** @defgroup SAI_Block_Protocol SAI Block Protocol 00332 * @{ 00333 */ 00334 #define SAI_FREE_PROTOCOL ((uint32_t)0x00000000) 00335 #define SAI_SPDIF_PROTOCOL (SAI_xCR1_PRTCFG_0) 00336 #define SAI_AC97_PROTOCOL (SAI_xCR1_PRTCFG_1) 00337 00338 /** 00339 * @} 00340 */ 00341 00342 /** @defgroup SAI_Block_Data_Size SAI Block Data Size 00343 * @{ 00344 */ 00345 #define SAI_DATASIZE_8 (SAI_xCR1_DS_1) 00346 #define SAI_DATASIZE_10 (SAI_xCR1_DS_1 | SAI_xCR1_DS_0) 00347 #define SAI_DATASIZE_16 (SAI_xCR1_DS_2) 00348 #define SAI_DATASIZE_20 (SAI_xCR1_DS_2 | SAI_xCR1_DS_0) 00349 #define SAI_DATASIZE_24 (SAI_xCR1_DS_2 | SAI_xCR1_DS_1) 00350 #define SAI_DATASIZE_32 (SAI_xCR1_DS_2 | SAI_xCR1_DS_1 | SAI_xCR1_DS_0) 00351 00352 /** 00353 * @} 00354 */ 00355 00356 /** @defgroup SAI_Block_MSB_LSB_transmission SAI Block MSB LSB transmission 00357 * @{ 00358 */ 00359 #define SAI_FIRSTBIT_MSB ((uint32_t)0x00000000) 00360 #define SAI_FIRSTBIT_LSB ((uint32_t)SAI_xCR1_LSBFIRST) 00361 00362 /** 00363 * @} 00364 */ 00365 00366 /** @defgroup SAI_Block_Clock_Strobing SAI Block Clock Strobing 00367 * @{ 00368 */ 00369 #define SAI_CLOCKSTROBING_FALLINGEDGE ((uint32_t)0x00000000) 00370 #define SAI_CLOCKSTROBING_RISINGEDGE ((uint32_t)SAI_xCR1_CKSTR) 00371 00372 /** 00373 * @} 00374 */ 00375 00376 /** @defgroup SAI_Block_Synchronization SAI Block Synchronization 00377 * @{ 00378 */ 00379 #define SAI_ASYNCHRONOUS ((uint32_t)0x00000000) 00380 #define SAI_SYNCHRONOUS ((uint32_t)SAI_xCR1_SYNCEN_0) 00381 #define SAI_SYNCHRONOUS_EXT ((uint32_t)SAI_xCR1_SYNCEN_1) 00382 00383 /** 00384 * @} 00385 */ 00386 00387 /** @defgroup SAI_Block_Output_Drive SAI Block Output Drive 00388 * @{ 00389 */ 00390 #define SAI_OUTPUTDRIVE_DISABLE ((uint32_t)0x00000000) 00391 #define SAI_OUTPUTDRIVE_ENABLE ((uint32_t)SAI_xCR1_OUTDRIV) 00392 00393 /** 00394 * @} 00395 */ 00396 00397 /** @defgroup SAI_Block_NoDivider SAI Block NoDivider 00398 * @{ 00399 */ 00400 #define SAI_MASTERDIVIDER_ENABLE ((uint32_t)0x00000000) 00401 #define SAI_MASTERDIVIDER_DISABLE ((uint32_t)SAI_xCR1_NODIV) 00402 00403 /** 00404 * @} 00405 */ 00406 00407 00408 /** @defgroup SAI_Block_FS_Definition SAI Block FS Definition 00409 * @{ 00410 */ 00411 #define SAI_FS_STARTFRAME ((uint32_t)0x00000000) 00412 #define SAI_FS_CHANNEL_IDENTIFICATION ((uint32_t)SAI_xFRCR_FSDEF) 00413 00414 /** 00415 * @} 00416 */ 00417 00418 /** @defgroup SAI_Block_FS_Polarity SAI Block FS Polarity 00419 * @{ 00420 */ 00421 #define SAI_FS_ACTIVE_LOW ((uint32_t)0x00000000) 00422 #define SAI_FS_ACTIVE_HIGH ((uint32_t)SAI_xFRCR_FSPO) 00423 00424 /** 00425 * @} 00426 */ 00427 00428 /** @defgroup SAI_Block_FS_Offset SAI Block FS Offset 00429 * @{ 00430 */ 00431 #define SAI_FS_FIRSTBIT ((uint32_t)0x00000000) 00432 #define SAI_FS_BEFOREFIRSTBIT ((uint32_t)SAI_xFRCR_FSOFF) 00433 00434 /** 00435 * @} 00436 */ 00437 00438 00439 /** @defgroup SAI_Block_Slot_Size SAI Block Slot Size 00440 * @{ 00441 */ 00442 #define SAI_SLOTSIZE_DATASIZE ((uint32_t)0x00000000) 00443 #define SAI_SLOTSIZE_16B ((uint32_t)SAI_xSLOTR_SLOTSZ_0) 00444 #define SAI_SLOTSIZE_32B ((uint32_t)SAI_xSLOTR_SLOTSZ_1) 00445 /** 00446 * @} 00447 */ 00448 00449 /** @defgroup SAI_Block_Slot_Active SAI Block Slot Active 00450 * @{ 00451 */ 00452 #define SAI_SLOT_NOTACTIVE ((uint32_t)0x00000000) 00453 #define SAI_SLOTACTIVE_0 ((uint32_t)0x00010000) 00454 #define SAI_SLOTACTIVE_1 ((uint32_t)0x00020000) 00455 #define SAI_SLOTACTIVE_2 ((uint32_t)0x00040000) 00456 #define SAI_SLOTACTIVE_3 ((uint32_t)0x00080000) 00457 #define SAI_SLOTACTIVE_4 ((uint32_t)0x00100000) 00458 #define SAI_SLOTACTIVE_5 ((uint32_t)0x00200000) 00459 #define SAI_SLOTACTIVE_6 ((uint32_t)0x00400000) 00460 #define SAI_SLOTACTIVE_7 ((uint32_t)0x00800000) 00461 #define SAI_SLOTACTIVE_8 ((uint32_t)0x01000000) 00462 #define SAI_SLOTACTIVE_9 ((uint32_t)0x02000000) 00463 #define SAI_SLOTACTIVE_10 ((uint32_t)0x04000000) 00464 #define SAI_SLOTACTIVE_11 ((uint32_t)0x08000000) 00465 #define SAI_SLOTACTIVE_12 ((uint32_t)0x10000000) 00466 #define SAI_SLOTACTIVE_13 ((uint32_t)0x20000000) 00467 #define SAI_SLOTACTIVE_14 ((uint32_t)0x40000000) 00468 #define SAI_SLOTACTIVE_15 ((uint32_t)0x80000000) 00469 #define SAI_SLOTACTIVE_ALL ((uint32_t)0xFFFF0000) 00470 00471 /** 00472 * @} 00473 */ 00474 00475 /** @defgroup SAI_Mono_Stereo_Mode SAI Mono Stereo Mode 00476 * @{ 00477 */ 00478 #define SAI_STEREOMODE ((uint32_t)0x00000000) 00479 #define SAI_MONOMODE ((uint32_t)SAI_xCR1_MONO) 00480 00481 /** 00482 * @} 00483 */ 00484 00485 /** @defgroup SAI_TRIState_Management SAI TRIState Management 00486 * @{ 00487 */ 00488 #define SAI_OUTPUT_NOTRELEASED ((uint32_t)0x00000000) 00489 #define SAI_OUTPUT_RELEASED ((uint32_t)SAI_xCR2_TRIS) 00490 00491 /** 00492 * @} 00493 */ 00494 00495 /** @defgroup SAI_Block_Fifo_Threshold SAI Block Fifo Threshold 00496 * @{ 00497 */ 00498 #define SAI_FIFOTHRESHOLD_EMPTY ((uint32_t)0x00000000) 00499 #define SAI_FIFOTHRESHOLD_1QF ((uint32_t)( SAI_xCR2_FTH_0)) 00500 #define SAI_FIFOTHRESHOLD_HF ((uint32_t)( SAI_xCR2_FTH_1)) 00501 #define SAI_FIFOTHRESHOLD_3QF ((uint32_t)( SAI_xCR2_FTH_1 | SAI_xCR2_FTH_0)) 00502 #define SAI_FIFOTHRESHOLD_FULL ((uint32_t) SAI_xCR2_FTH_2) 00503 00504 /** 00505 * @} 00506 */ 00507 00508 /** @defgroup SAI_Block_Companding_Mode SAI Block Companding Mode 00509 * @{ 00510 */ 00511 #define SAI_NOCOMPANDING ((uint32_t)0x00000000) 00512 #define SAI_ULAW_1CPL_COMPANDING ((uint32_t)SAI_xCR2_COMP_1) 00513 #define SAI_ALAW_1CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0)) 00514 #define SAI_ULAW_2CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_CPL)) 00515 #define SAI_ALAW_2CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0 | SAI_xCR2_CPL)) 00516 00517 /** 00518 * @} 00519 */ 00520 00521 /** @defgroup SAI_Block_Mute_Value SAI Block Mute Value 00522 * @{ 00523 */ 00524 #define SAI_ZERO_VALUE ((uint32_t)0x00000000) 00525 #define SAI_LAST_SENT_VALUE ((uint32_t)SAI_xCR2_MUTEVAL) 00526 00527 /** 00528 * @} 00529 */ 00530 00531 00532 /** @defgroup SAI_Block_Interrupts_Definition SAI Block Interrupts Definition 00533 * @{ 00534 */ 00535 #define SAI_IT_OVRUDR ((uint32_t)SAI_xIMR_OVRUDRIE) 00536 #define SAI_IT_MUTEDET ((uint32_t)SAI_xIMR_MUTEDETIE) 00537 #define SAI_IT_WCKCFG ((uint32_t)SAI_xIMR_WCKCFGIE) 00538 #define SAI_IT_FREQ ((uint32_t)SAI_xIMR_FREQIE) 00539 #define SAI_IT_CNRDY ((uint32_t)SAI_xIMR_CNRDYIE) 00540 #define SAI_IT_AFSDET ((uint32_t)SAI_xIMR_AFSDETIE) 00541 #define SAI_IT_LFSDET ((uint32_t)SAI_xIMR_LFSDETIE) 00542 00543 /** 00544 * @} 00545 */ 00546 00547 /** @defgroup SAI_Block_Flags_Definition SAI Block Flags Definition 00548 * @{ 00549 */ 00550 #define SAI_FLAG_OVRUDR ((uint32_t)SAI_xSR_OVRUDR) 00551 #define SAI_FLAG_MUTEDET ((uint32_t)SAI_xSR_MUTEDET) 00552 #define SAI_FLAG_WCKCFG ((uint32_t)SAI_xSR_WCKCFG) 00553 #define SAI_FLAG_FREQ ((uint32_t)SAI_xSR_FREQ) 00554 #define SAI_FLAG_CNRDY ((uint32_t)SAI_xSR_CNRDY) 00555 #define SAI_FLAG_AFSDET ((uint32_t)SAI_xSR_AFSDET) 00556 #define SAI_FLAG_LFSDET ((uint32_t)SAI_xSR_LFSDET) 00557 00558 /** 00559 * @} 00560 */ 00561 00562 /** @defgroup SAI_Block_Fifo_Status_Level SAI Block Fifo Status Level 00563 * @{ 00564 */ 00565 #define SAI_FIFOSTATUS_EMPTY ((uint32_t)0x00000000) 00566 #define SAI_FIFOSTATUS_LESS1QUARTERFULL ((uint32_t)0x00010000) 00567 #define SAI_FIFOSTATUS_1QUARTERFULL ((uint32_t)0x00020000) 00568 #define SAI_FIFOSTATUS_HALFFULL ((uint32_t)0x00030000) 00569 #define SAI_FIFOSTATUS_3QUARTERFULL ((uint32_t)0x00040000) 00570 #define SAI_FIFOSTATUS_FULL ((uint32_t)0x00050000) 00571 /** 00572 * @} 00573 */ 00574 00575 /** 00576 * @} 00577 */ 00578 00579 /* Exported macro ------------------------------------------------------------*/ 00580 00581 /** @defgroup SAI_Exported_Macros SAI Exported Macros 00582 * @brief macros to handle interrupts and specific configurations 00583 * @{ 00584 */ 00585 00586 /** @brief Reset SAI handle state. 00587 * @param __HANDLE__: specifies the SAI Handle. 00588 * @retval None 00589 */ 00590 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SAI_STATE_RESET) 00591 00592 /** @brief Enable or disable the specified SAI interrupts. 00593 * @param __HANDLE__: specifies the SAI Handle. 00594 * @param __INTERRUPT__: specifies the interrupt source to enable or disable. 00595 * This parameter can be one of the following values: 00596 * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable 00597 * @arg SAI_IT_MUTEDET: Mute detection interrupt enable 00598 * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable 00599 * @arg SAI_IT_FREQ: FIFO request interrupt enable 00600 * @arg SAI_IT_CNRDY: Codec not ready interrupt enable 00601 * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable 00602 * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable 00603 * @retval None 00604 */ 00605 00606 #define __HAL_SAI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR |= (__INTERRUPT__)) 00607 #define __HAL_SAI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR &= (~(__INTERRUPT__))) 00608 00609 /** @brief Check whether the specified SAI interrupt source is enabled or not. 00610 * @param __HANDLE__: specifies the SAI Handle. 00611 * @param __INTERRUPT__: specifies the SAI interrupt source to check. 00612 * This parameter can be one of the following values: 00613 * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable 00614 * @arg SAI_IT_MUTEDET: Mute detection interrupt enable 00615 * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable 00616 * @arg SAI_IT_FREQ: FIFO request interrupt enable 00617 * @arg SAI_IT_CNRDY: Codec not ready interrupt enable 00618 * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable 00619 * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable 00620 * @retval The new state of __INTERRUPT__ (TRUE or FALSE). 00621 */ 00622 #define __HAL_SAI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IMR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) 00623 00624 /** @brief Check whether the specified SAI flag is set or not. 00625 * @param __HANDLE__: specifies the SAI Handle. 00626 * @param __FLAG__: specifies the flag to check. 00627 * This parameter can be one of the following values: 00628 * @arg SAI_FLAG_OVRUDR: Overrun underrun flag. 00629 * @arg SAI_FLAG_MUTEDET: Mute detection flag. 00630 * @arg SAI_FLAG_WCKCFG: Wrong Clock Configuration flag. 00631 * @arg SAI_FLAG_FREQ: FIFO request flag. 00632 * @arg SAI_FLAG_CNRDY: Codec not ready flag. 00633 * @arg SAI_FLAG_AFSDET: Anticipated frame synchronization detection flag. 00634 * @arg SAI_FLAG_LFSDET: Late frame synchronization detection flag. 00635 * @retval The new state of __FLAG__ (TRUE or FALSE). 00636 */ 00637 #define __HAL_SAI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__)) 00638 00639 /** @brief Clear the specified SAI pending flag. 00640 * @param __HANDLE__: specifies the SAI Handle. 00641 * @param __FLAG__: specifies the flag to check. 00642 * This parameter can be any combination of the following values: 00643 * @arg SAI_FLAG_OVRUDR: Clear Overrun underrun 00644 * @arg SAI_FLAG_MUTEDET: Clear Mute detection 00645 * @arg SAI_FLAG_WCKCFG: Clear Wrong Clock Configuration 00646 * @arg SAI_FLAG_FREQ: Clear FIFO request 00647 * @arg SAI_FLAG_CNRDY: Clear Codec not ready 00648 * @arg SAI_FLAG_AFSDET: Clear Anticipated frame synchronization detection 00649 * @arg SAI_FLAG_LFSDET: Clear Late frame synchronization detection 00650 * 00651 * @retval None 00652 */ 00653 #define __HAL_SAI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__)) 00654 00655 #define __HAL_SAI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SAI_xCR1_SAIEN) 00656 #define __HAL_SAI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~SAI_xCR1_SAIEN) 00657 00658 /** 00659 * @} 00660 */ 00661 00662 /* Exported functions --------------------------------------------------------*/ 00663 00664 /** @addtogroup SAI_Exported_Functions 00665 * @{ 00666 */ 00667 00668 /* Initialization/de-initialization functions **********************************/ 00669 /** @addtogroup SAI_Exported_Functions_Group1 00670 * @{ 00671 */ 00672 HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai); 00673 HAL_StatusTypeDef HAL_SAI_InitProtocol(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot); 00674 HAL_StatusTypeDef HAL_SAI_DeInit (SAI_HandleTypeDef *hsai); 00675 void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai); 00676 void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai); 00677 00678 /** 00679 * @} 00680 */ 00681 00682 /* I/O operation functions *****************************************************/ 00683 /** @addtogroup SAI_Exported_Functions_Group2 00684 * @{ 00685 */ 00686 /* Blocking mode: Polling */ 00687 HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout); 00688 HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout); 00689 00690 /* Non-Blocking mode: Interrupt */ 00691 HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size); 00692 HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size); 00693 00694 /* Non-Blocking mode: DMA */ 00695 HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size); 00696 HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size); 00697 HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai); 00698 HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai); 00699 HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai); 00700 00701 /* Abort function */ 00702 HAL_StatusTypeDef HAL_SAI_Abort(SAI_HandleTypeDef *hsai); 00703 00704 /* Mute management */ 00705 HAL_StatusTypeDef HAL_SAI_EnableTxMuteMode(SAI_HandleTypeDef *hsai, uint16_t val); 00706 HAL_StatusTypeDef HAL_SAI_DisableTxMuteMode(SAI_HandleTypeDef *hsai); 00707 HAL_StatusTypeDef HAL_SAI_EnableRxMuteMode(SAI_HandleTypeDef *hsai, SAIcallback callback, uint16_t counter); 00708 HAL_StatusTypeDef HAL_SAI_DisableRxMuteMode(SAI_HandleTypeDef *hsai); 00709 00710 /* SAI IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */ 00711 void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai); 00712 void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai); 00713 void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai); 00714 void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai); 00715 void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai); 00716 void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai); 00717 /** 00718 * @} 00719 */ 00720 00721 /** @addtogroup SAI_Exported_Functions_Group3 00722 * @{ 00723 */ 00724 /* Peripheral State functions **************************************************/ 00725 HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai); 00726 uint32_t HAL_SAI_GetError(SAI_HandleTypeDef *hsai); 00727 /** 00728 * @} 00729 */ 00730 00731 /** 00732 * @} 00733 */ 00734 00735 /* Private types -------------------------------------------------------------*/ 00736 /* Private variables ---------------------------------------------------------*/ 00737 00738 /* Private constants ---------------------------------------------------------*/ 00739 /** @defgroup SAI_Private_Constants SAI Private Constants 00740 * @{ 00741 */ 00742 00743 /** 00744 * @} 00745 */ 00746 00747 /* Private macros ------------------------------------------------------------*/ 00748 /** @addtogroup SAI_Private_Macros 00749 * @{ 00750 */ 00751 #define IS_SAI_AUDIO_FREQUENCY(AUDIO) (((AUDIO) == SAI_AUDIO_FREQUENCY_192K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_96K) || \ 00752 ((AUDIO) == SAI_AUDIO_FREQUENCY_48K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_44K) || \ 00753 ((AUDIO) == SAI_AUDIO_FREQUENCY_32K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_22K) || \ 00754 ((AUDIO) == SAI_AUDIO_FREQUENCY_16K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_11K) || \ 00755 ((AUDIO) == SAI_AUDIO_FREQUENCY_8K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_MCKDIV)) 00756 00757 #define IS_SAI_BLOCK_MODE(MODE) (((MODE) == SAI_MODEMASTER_TX) || \ 00758 ((MODE) == SAI_MODEMASTER_RX) || \ 00759 ((MODE) == SAI_MODESLAVE_TX) || \ 00760 ((MODE) == SAI_MODESLAVE_RX)) 00761 00762 #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_FREE_PROTOCOL) || \ 00763 ((PROTOCOL) == SAI_AC97_PROTOCOL) || \ 00764 ((PROTOCOL) == SAI_SPDIF_PROTOCOL)) 00765 00766 #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DATASIZE_8) || \ 00767 ((DATASIZE) == SAI_DATASIZE_10) || \ 00768 ((DATASIZE) == SAI_DATASIZE_16) || \ 00769 ((DATASIZE) == SAI_DATASIZE_20) || \ 00770 ((DATASIZE) == SAI_DATASIZE_24) || \ 00771 ((DATASIZE) == SAI_DATASIZE_32)) 00772 00773 #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FIRSTBIT_MSB) || \ 00774 ((BIT) == SAI_FIRSTBIT_LSB)) 00775 00776 #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_CLOCKSTROBING_FALLINGEDGE) || \ 00777 ((CLOCK) == SAI_CLOCKSTROBING_RISINGEDGE)) 00778 00779 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS) || \ 00780 ((SYNCHRO) == SAI_SYNCHRONOUS) || \ 00781 ((SYNCHRO) == SAI_SYNCHRONOUS_EXT)) 00782 00783 #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OUTPUTDRIVE_DISABLE) || \ 00784 ((DRIVE) == SAI_OUTPUTDRIVE_ENABLE)) 00785 00786 #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MASTERDIVIDER_ENABLE) || \ 00787 ((NODIVIDER) == SAI_MASTERDIVIDER_DISABLE)) 00788 00789 #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63) 00790 00791 #define IS_SAI_BLOCK_MUTE_VALUE(VALUE) (((VALUE) == SAI_ZERO_VALUE) || \ 00792 ((VALUE) == SAI_LAST_SENT_VALUE)) 00793 00794 #define IS_SAI_BLOCK_COMPANDING_MODE(MODE) (((MODE) == SAI_NOCOMPANDING) || \ 00795 ((MODE) == SAI_ULAW_1CPL_COMPANDING) || \ 00796 ((MODE) == SAI_ALAW_1CPL_COMPANDING) || \ 00797 ((MODE) == SAI_ULAW_2CPL_COMPANDING) || \ 00798 ((MODE) == SAI_ALAW_2CPL_COMPANDING)) 00799 00800 #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_FIFOTHRESHOLD_EMPTY) || \ 00801 ((THRESHOLD) == SAI_FIFOTHRESHOLD_1QF) || \ 00802 ((THRESHOLD) == SAI_FIFOTHRESHOLD_HF) || \ 00803 ((THRESHOLD) == SAI_FIFOTHRESHOLD_3QF) || \ 00804 ((THRESHOLD) == SAI_FIFOTHRESHOLD_FULL)) 00805 00806 #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_OUTPUT_NOTRELEASED) ||\ 00807 ((STATE) == SAI_OUTPUT_RELEASED)) 00808 00809 #define IS_SAI_BLOCK_SYNCEXT(STATE) (((STATE) == SAI_SYNCEXT_DISABLE) ||\ 00810 ((STATE) == SAI_SYNCEXT_IN_ENABLE) ||\ 00811 ((STATE) == SAI_SYNCEXT_OUTBLOCKA_ENABLE) ||\ 00812 ((STATE) == SAI_SYNCEXT_OUTBLOCKB_ENABLE)) 00813 00814 #define IS_SAI_MONOSTEREO_MODE(CHANNEL) (((CHANNEL) == SAI_STEREOMODE) ||\ 00815 ((CHANNEL) == SAI_MONOMODE)) 00816 00817 #define IS_SAI_SLOT_ACTIVE(ACTIVE) ((((ACTIVE) >> 16 ) > 0) && (((ACTIVE) >> 16 ) <= (SAI_SLOTACTIVE_ALL >> 16))) 00818 00819 #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1 <= (NUMBER)) && ((NUMBER) <= 16)) 00820 00821 #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SLOTSIZE_DATASIZE) || \ 00822 ((SIZE) == SAI_SLOTSIZE_16B) || \ 00823 ((SIZE) == SAI_SLOTSIZE_32B)) 00824 00825 #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24) 00826 00827 #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FIRSTBIT) || \ 00828 ((OFFSET) == SAI_FS_BEFOREFIRSTBIT)) 00829 00830 #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ACTIVE_LOW) || \ 00831 ((POLARITY) == SAI_FS_ACTIVE_HIGH)) 00832 00833 #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_STARTFRAME) || \ 00834 ((DEFINITION) == SAI_FS_CHANNEL_IDENTIFICATION)) 00835 00836 #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 15) 00837 00838 #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8 <= (LENGTH)) && ((LENGTH) <= 256)) 00839 00840 #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1 <= (LENGTH)) && ((LENGTH) <= 128)) 00841 00842 /** 00843 * @} 00844 */ 00845 00846 /* Private functions ---------------------------------------------------------*/ 00847 /** @defgroup SAI_Private_Functions SAI Private Functions 00848 * @{ 00849 */ 00850 00851 /** 00852 * @} 00853 */ 00854 00855 /** 00856 * @} 00857 */ 00858 00859 /** 00860 * @} 00861 */ 00862 #ifdef __cplusplus 00863 } 00864 #endif 00865 00866 #endif /* __STM32L4xx_HAL_SAI_H */ 00867 00868 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 00869
Generated on Tue Jul 12 2022 11:35:15 by
