stm32l4xx_hal_sai.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_sai.h
  4. * @author MCD Application Team
  5. * @brief Header file of SAI HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32L4xx_HAL_SAI_H
  37. #define __STM32L4xx_HAL_SAI_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx_hal_def.h"
  43. /** @addtogroup STM32L4xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup SAI
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup SAI_Exported_Types SAI Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief HAL State structures definition
  55. */
  56. typedef enum
  57. {
  58. HAL_SAI_STATE_RESET = 0x00U, /*!< SAI not yet initialized or disabled */
  59. HAL_SAI_STATE_READY = 0x01U, /*!< SAI initialized and ready for use */
  60. HAL_SAI_STATE_BUSY = 0x02U, /*!< SAI internal process is ongoing */
  61. HAL_SAI_STATE_BUSY_TX = 0x12U, /*!< Data transmission process is ongoing */
  62. HAL_SAI_STATE_BUSY_RX = 0x22U, /*!< Data reception process is ongoing */
  63. }HAL_SAI_StateTypeDef;
  64. /**
  65. * @brief SAI Callback prototype
  66. */
  67. typedef void (*SAIcallback)(void);
  68. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  69. /**
  70. * @brief SAI PDM Init structure definition
  71. */
  72. typedef struct
  73. {
  74. FunctionalState Activation; /*!< Enable/disable PDM interface */
  75. uint32_t MicPairsNbr; /*!< Specifies the number of microphone pairs used.
  76. This parameter must be a number between Min_Data = 1 and Max_Data = 3. */
  77. uint32_t ClockEnable; /*!< Specifies which clock must be enabled.
  78. This parameter can be a values combination of @ref SAI_PDM_ClockEnable */
  79. }SAI_PdmInitTypeDef;
  80. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  81. /** @defgroup SAI_Init_Structure_definition SAI Init Structure definition
  82. * @brief SAI Init Structure definition
  83. * @{
  84. */
  85. typedef struct
  86. {
  87. uint32_t AudioMode; /*!< Specifies the SAI Block audio Mode.
  88. This parameter can be a value of @ref SAI_Block_Mode */
  89. uint32_t Synchro; /*!< Specifies SAI Block synchronization
  90. This parameter can be a value of @ref SAI_Block_Synchronization */
  91. uint32_t SynchroExt; /*!< Specifies SAI external output synchronization, this setup is common
  92. for BlockA and BlockB
  93. This parameter can be a value of @ref SAI_Block_SyncExt
  94. @note: If both audio blocks of same SAI are used, this parameter has
  95. to be set to the same value for each audio block */
  96. uint32_t OutputDrive; /*!< Specifies when SAI Block outputs are driven.
  97. This parameter can be a value of @ref SAI_Block_Output_Drive
  98. @note this value has to be set before enabling the audio block
  99. but after the audio block configuration. */
  100. uint32_t NoDivider; /*!< Specifies whether master clock will be divided or not.
  101. This parameter can be a value of @ref SAI_Block_NoDivider
  102. @note: For STM32L4Rx/STM32L4Sx devices :
  103. If bit NOMCK in the SAI_xCR1 register is cleared, the frame length
  104. should be aligned to a number equal to a power of 2, from 8 to 256.
  105. If bit NOMCK in the SAI_xCR1 register is set, the frame length can
  106. take any of the values without constraint. There is no MCLK_x clock
  107. which can be output.
  108. For other devices :
  109. If bit NODIV in the SAI_xCR1 register is cleared, the frame length
  110. should be aligned to a number equal to a power of 2, from 8 to 256.
  111. If bit NODIV in the SAI_xCR1 register is set, the frame length can
  112. take any of the values without constraint since the input clock of
  113. the audio block should be equal to the bit clock.
  114. There is no MCLK_x clock which can be output. */
  115. uint32_t FIFOThreshold; /*!< Specifies SAI Block FIFO threshold.
  116. This parameter can be a value of @ref SAI_Block_Fifo_Threshold */
  117. uint32_t AudioFrequency; /*!< Specifies the audio frequency sampling.
  118. This parameter can be a value of @ref SAI_Audio_Frequency */
  119. uint32_t Mckdiv; /*!< Specifies the master clock divider, the parameter will be used if for
  120. AudioFrequency the user choice
  121. This parameter must be a number between Min_Data = 0 and Max_Data = 63 on STM32L4Rx/STM32L4Sx devices.
  122. This parameter must be a number between Min_Data = 0 and Max_Data = 15 on other devices. */
  123. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  124. uint32_t MckOverSampling; /*!< Specifies the master clock oversampling.
  125. This parameter can be a value of @ref SAI_Block_Mck_OverSampling */
  126. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  127. uint32_t MonoStereoMode; /*!< Specifies if the mono or stereo mode is selected.
  128. This parameter can be a value of @ref SAI_Mono_Stereo_Mode */
  129. uint32_t CompandingMode; /*!< Specifies the companding mode type.
  130. This parameter can be a value of @ref SAI_Block_Companding_Mode */
  131. uint32_t TriState; /*!< Specifies the companding mode type.
  132. This parameter can be a value of @ref SAI_TRIState_Management */
  133. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  134. SAI_PdmInitTypeDef PdmInit; /*!< Specifies the PDM configuration. */
  135. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  136. /* This part of the structure is automatically filled if your are using the high level initialisation
  137. function HAL_SAI_InitProtocol */
  138. uint32_t Protocol; /*!< Specifies the SAI Block protocol.
  139. This parameter can be a value of @ref SAI_Block_Protocol */
  140. uint32_t DataSize; /*!< Specifies the SAI Block data size.
  141. This parameter can be a value of @ref SAI_Block_Data_Size */
  142. uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
  143. This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission */
  144. uint32_t ClockStrobing; /*!< Specifies the SAI Block clock strobing edge sensitivity.
  145. This parameter can be a value of @ref SAI_Block_Clock_Strobing */
  146. }SAI_InitTypeDef;
  147. /**
  148. * @}
  149. */
  150. /** @defgroup SAI_Frame_Structure_definition SAI Frame Structure definition
  151. * @brief SAI Frame Init structure definition
  152. * @{
  153. */
  154. typedef struct
  155. {
  156. uint32_t FrameLength; /*!< Specifies the Frame length, the number of SCK clocks for each audio frame.
  157. This parameter must be a number between Min_Data = 8 and Max_Data = 256.
  158. @note: If master clock MCLK_x pin is declared as an output, the frame length
  159. should be aligned to a number equal to power of 2 in order to keep
  160. in an audio frame, an integer number of MCLK pulses by bit Clock. */
  161. uint32_t ActiveFrameLength; /*!< Specifies the Frame synchronization active level length.
  162. This Parameter specifies the length in number of bit clock (SCK + 1)
  163. of the active level of FS signal in audio frame.
  164. This parameter must be a number between Min_Data = 1 and Max_Data = 128 */
  165. uint32_t FSDefinition; /*!< Specifies the Frame synchronization definition.
  166. This parameter can be a value of @ref SAI_Block_FS_Definition */
  167. uint32_t FSPolarity; /*!< Specifies the Frame synchronization Polarity.
  168. This parameter can be a value of @ref SAI_Block_FS_Polarity */
  169. uint32_t FSOffset; /*!< Specifies the Frame synchronization Offset.
  170. This parameter can be a value of @ref SAI_Block_FS_Offset */
  171. }SAI_FrameInitTypeDef;
  172. /**
  173. * @}
  174. */
  175. /** @defgroup SAI_Slot_Structure_definition SAI Slot Structure definition
  176. * @brief SAI Block Slot Init Structure definition
  177. * @{
  178. */
  179. typedef struct
  180. {
  181. uint32_t FirstBitOffset; /*!< Specifies the position of first data transfer bit in the slot.
  182. This parameter must be a number between Min_Data = 0 and Max_Data = 24 */
  183. uint32_t SlotSize; /*!< Specifies the Slot Size.
  184. This parameter can be a value of @ref SAI_Block_Slot_Size */
  185. uint32_t SlotNumber; /*!< Specifies the number of slot in the audio frame.
  186. This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
  187. uint32_t SlotActive; /*!< Specifies the slots in audio frame that will be activated.
  188. This parameter can be a value of @ref SAI_Block_Slot_Active */
  189. }SAI_SlotInitTypeDef;
  190. /**
  191. * @}
  192. */
  193. /** @defgroup SAI_Handle_Structure_definition SAI Handle Structure definition
  194. * @brief SAI handle Structure definition
  195. * @{
  196. */
  197. typedef struct __SAI_HandleTypeDef
  198. {
  199. SAI_Block_TypeDef *Instance; /*!< SAI Blockx registers base address */
  200. SAI_InitTypeDef Init; /*!< SAI communication parameters */
  201. SAI_FrameInitTypeDef FrameInit; /*!< SAI Frame configuration parameters */
  202. SAI_SlotInitTypeDef SlotInit; /*!< SAI Slot configuration parameters */
  203. uint8_t *pBuffPtr; /*!< Pointer to SAI transfer Buffer */
  204. uint16_t XferSize; /*!< SAI transfer size */
  205. uint16_t XferCount; /*!< SAI transfer counter */
  206. DMA_HandleTypeDef *hdmatx; /*!< SAI Tx DMA handle parameters */
  207. DMA_HandleTypeDef *hdmarx; /*!< SAI Rx DMA handle parameters */
  208. SAIcallback mutecallback; /*!< SAI mute callback */
  209. void (*InterruptServiceRoutine)(struct __SAI_HandleTypeDef *hsai); /* function pointer for IRQ handler */
  210. HAL_LockTypeDef Lock; /*!< SAI locking object */
  211. __IO HAL_SAI_StateTypeDef State; /*!< SAI communication state */
  212. __IO uint32_t ErrorCode; /*!< SAI Error code */
  213. }SAI_HandleTypeDef;
  214. /**
  215. * @}
  216. */
  217. /**
  218. * @}
  219. */
  220. /* Exported constants --------------------------------------------------------*/
  221. /** @defgroup SAI_Exported_Constants SAI Exported Constants
  222. * @{
  223. */
  224. /** @defgroup SAI_Error_Code SAI Error Code
  225. * @{
  226. */
  227. #define HAL_SAI_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
  228. #define HAL_SAI_ERROR_OVR ((uint32_t)0x00000001U) /*!< Overrun Error */
  229. #define HAL_SAI_ERROR_UDR ((uint32_t)0x00000002U) /*!< Underrun error */
  230. #define HAL_SAI_ERROR_AFSDET ((uint32_t)0x00000004U) /*!< Anticipated Frame synchronisation detection */
  231. #define HAL_SAI_ERROR_LFSDET ((uint32_t)0x00000008U) /*!< Late Frame synchronisation detection */
  232. #define HAL_SAI_ERROR_CNREADY ((uint32_t)0x00000010U) /*!< codec not ready */
  233. #define HAL_SAI_ERROR_WCKCFG ((uint32_t)0x00000020U) /*!< Wrong clock configuration */
  234. #define HAL_SAI_ERROR_TIMEOUT ((uint32_t)0x00000040U) /*!< Timeout error */
  235. #define HAL_SAI_ERROR_DMA ((uint32_t)0x00000080U) /*!< DMA error */
  236. /**
  237. * @}
  238. */
  239. /** @defgroup SAI_Block_SyncExt SAI External synchronisation
  240. * @{
  241. */
  242. #define SAI_SYNCEXT_DISABLE 0
  243. #define SAI_SYNCEXT_OUTBLOCKA_ENABLE 1
  244. #define SAI_SYNCEXT_OUTBLOCKB_ENABLE 2
  245. /**
  246. * @}
  247. */
  248. /** @defgroup SAI_Protocol SAI Supported protocol
  249. * @{
  250. */
  251. #define SAI_I2S_STANDARD 0
  252. #define SAI_I2S_MSBJUSTIFIED 1
  253. #define SAI_I2S_LSBJUSTIFIED 2
  254. #define SAI_PCM_LONG 3
  255. #define SAI_PCM_SHORT 4
  256. /**
  257. * @}
  258. */
  259. /** @defgroup SAI_Protocol_DataSize SAI protocol data size
  260. * @{
  261. */
  262. #define SAI_PROTOCOL_DATASIZE_16BIT 0
  263. #define SAI_PROTOCOL_DATASIZE_16BITEXTENDED 1
  264. #define SAI_PROTOCOL_DATASIZE_24BIT 2
  265. #define SAI_PROTOCOL_DATASIZE_32BIT 3
  266. /**
  267. * @}
  268. */
  269. /** @defgroup SAI_Audio_Frequency SAI Audio Frequency
  270. * @{
  271. */
  272. #define SAI_AUDIO_FREQUENCY_192K ((uint32_t)192000U)
  273. #define SAI_AUDIO_FREQUENCY_96K ((uint32_t)96000U)
  274. #define SAI_AUDIO_FREQUENCY_48K ((uint32_t)48000U)
  275. #define SAI_AUDIO_FREQUENCY_44K ((uint32_t)44100U)
  276. #define SAI_AUDIO_FREQUENCY_32K ((uint32_t)32000U)
  277. #define SAI_AUDIO_FREQUENCY_22K ((uint32_t)22050U)
  278. #define SAI_AUDIO_FREQUENCY_16K ((uint32_t)16000U)
  279. #define SAI_AUDIO_FREQUENCY_11K ((uint32_t)11025U)
  280. #define SAI_AUDIO_FREQUENCY_8K ((uint32_t)8000U)
  281. #define SAI_AUDIO_FREQUENCY_MCKDIV ((uint32_t)0U)
  282. /**
  283. * @}
  284. */
  285. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  286. /** @defgroup SAI_Block_Mck_OverSampling SAI Block Master Clock OverSampling
  287. * @{
  288. */
  289. #define SAI_MCK_OVERSAMPLING_DISABLE ((uint32_t)0x00000000U)
  290. #define SAI_MCK_OVERSAMPLING_ENABLE ((uint32_t)SAI_xCR1_OSR)
  291. /**
  292. * @}
  293. */
  294. /** @defgroup SAI_PDM_ClockEnable SAI PDM Clock Enable
  295. * @{
  296. */
  297. #define SAI_PDM_CLOCK1_ENABLE ((uint32_t)SAI_PDMCR_CKEN1)
  298. #define SAI_PDM_CLOCK2_ENABLE ((uint32_t)SAI_PDMCR_CKEN2)
  299. /**
  300. * @}
  301. */
  302. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  303. /** @defgroup SAI_Block_Mode SAI Block Mode
  304. * @{
  305. */
  306. #define SAI_MODEMASTER_TX ((uint32_t)0x00000000U)
  307. #define SAI_MODEMASTER_RX ((uint32_t)SAI_xCR1_MODE_0)
  308. #define SAI_MODESLAVE_TX ((uint32_t)SAI_xCR1_MODE_1)
  309. #define SAI_MODESLAVE_RX ((uint32_t)(SAI_xCR1_MODE_1 | SAI_xCR1_MODE_0))
  310. /**
  311. * @}
  312. */
  313. /** @defgroup SAI_Block_Protocol SAI Block Protocol
  314. * @{
  315. */
  316. #define SAI_FREE_PROTOCOL ((uint32_t)0x00000000U)
  317. #define SAI_SPDIF_PROTOCOL ((uint32_t)SAI_xCR1_PRTCFG_0)
  318. #define SAI_AC97_PROTOCOL ((uint32_t)SAI_xCR1_PRTCFG_1)
  319. /**
  320. * @}
  321. */
  322. /** @defgroup SAI_Block_Data_Size SAI Block Data Size
  323. * @{
  324. */
  325. #define SAI_DATASIZE_8 ((uint32_t)SAI_xCR1_DS_1)
  326. #define SAI_DATASIZE_10 ((uint32_t)(SAI_xCR1_DS_1 | SAI_xCR1_DS_0))
  327. #define SAI_DATASIZE_16 ((uint32_t)SAI_xCR1_DS_2)
  328. #define SAI_DATASIZE_20 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_0))
  329. #define SAI_DATASIZE_24 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_1))
  330. #define SAI_DATASIZE_32 ((uint32_t)(SAI_xCR1_DS_2 | SAI_xCR1_DS_1 | SAI_xCR1_DS_0))
  331. /**
  332. * @}
  333. */
  334. /** @defgroup SAI_Block_MSB_LSB_transmission SAI Block MSB LSB transmission
  335. * @{
  336. */
  337. #define SAI_FIRSTBIT_MSB ((uint32_t)0x00000000U)
  338. #define SAI_FIRSTBIT_LSB ((uint32_t)SAI_xCR1_LSBFIRST)
  339. /**
  340. * @}
  341. */
  342. /** @defgroup SAI_Block_Clock_Strobing SAI Block Clock Strobing
  343. * @{
  344. */
  345. #define SAI_CLOCKSTROBING_FALLINGEDGE 0
  346. #define SAI_CLOCKSTROBING_RISINGEDGE 1
  347. /**
  348. * @}
  349. */
  350. /** @defgroup SAI_Block_Synchronization SAI Block Synchronization
  351. * @{
  352. */
  353. #define SAI_ASYNCHRONOUS 0 /*!< Asynchronous */
  354. #define SAI_SYNCHRONOUS 1 /*!< Synchronous with other block of same SAI */
  355. #define SAI_SYNCHRONOUS_EXT_SAI1 2 /*!< Synchronous with other SAI, SAI1 */
  356. #define SAI_SYNCHRONOUS_EXT_SAI2 3 /*!< Synchronous with other SAI, SAI2 */
  357. /**
  358. * @}
  359. */
  360. /** @defgroup SAI_Block_Output_Drive SAI Block Output Drive
  361. * @{
  362. */
  363. #define SAI_OUTPUTDRIVE_DISABLE ((uint32_t)0x00000000U)
  364. #define SAI_OUTPUTDRIVE_ENABLE ((uint32_t)SAI_xCR1_OUTDRIV)
  365. /**
  366. * @}
  367. */
  368. /** @defgroup SAI_Block_NoDivider SAI Block NoDivider
  369. * @{
  370. */
  371. #define SAI_MASTERDIVIDER_ENABLE ((uint32_t)0x00000000U)
  372. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  373. #define SAI_MASTERDIVIDER_DISABLE ((uint32_t)SAI_xCR1_NOMCK)
  374. #else
  375. #define SAI_MASTERDIVIDER_DISABLE ((uint32_t)SAI_xCR1_NODIV)
  376. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  377. /**
  378. * @}
  379. */
  380. /** @defgroup SAI_Block_FS_Definition SAI Block FS Definition
  381. * @{
  382. */
  383. #define SAI_FS_STARTFRAME ((uint32_t)0x00000000U)
  384. #define SAI_FS_CHANNEL_IDENTIFICATION ((uint32_t)SAI_xFRCR_FSDEF)
  385. /**
  386. * @}
  387. */
  388. /** @defgroup SAI_Block_FS_Polarity SAI Block FS Polarity
  389. * @{
  390. */
  391. #define SAI_FS_ACTIVE_LOW ((uint32_t)0x00000000U)
  392. #define SAI_FS_ACTIVE_HIGH ((uint32_t)SAI_xFRCR_FSPOL)
  393. /**
  394. * @}
  395. */
  396. /** @defgroup SAI_Block_FS_Offset SAI Block FS Offset
  397. * @{
  398. */
  399. #define SAI_FS_FIRSTBIT ((uint32_t)0x00000000U)
  400. #define SAI_FS_BEFOREFIRSTBIT ((uint32_t)SAI_xFRCR_FSOFF)
  401. /**
  402. * @}
  403. */
  404. /** @defgroup SAI_Block_Slot_Size SAI Block Slot Size
  405. * @{
  406. */
  407. #define SAI_SLOTSIZE_DATASIZE ((uint32_t)0x00000000U)
  408. #define SAI_SLOTSIZE_16B ((uint32_t)SAI_xSLOTR_SLOTSZ_0)
  409. #define SAI_SLOTSIZE_32B ((uint32_t)SAI_xSLOTR_SLOTSZ_1)
  410. /**
  411. * @}
  412. */
  413. /** @defgroup SAI_Block_Slot_Active SAI Block Slot Active
  414. * @{
  415. */
  416. #define SAI_SLOT_NOTACTIVE ((uint32_t)0x00000000U)
  417. #define SAI_SLOTACTIVE_0 ((uint32_t)0x00000001U)
  418. #define SAI_SLOTACTIVE_1 ((uint32_t)0x00000002U)
  419. #define SAI_SLOTACTIVE_2 ((uint32_t)0x00000004U)
  420. #define SAI_SLOTACTIVE_3 ((uint32_t)0x00000008U)
  421. #define SAI_SLOTACTIVE_4 ((uint32_t)0x00000010U)
  422. #define SAI_SLOTACTIVE_5 ((uint32_t)0x00000020U)
  423. #define SAI_SLOTACTIVE_6 ((uint32_t)0x00000040U)
  424. #define SAI_SLOTACTIVE_7 ((uint32_t)0x00000080U)
  425. #define SAI_SLOTACTIVE_8 ((uint32_t)0x00000100U)
  426. #define SAI_SLOTACTIVE_9 ((uint32_t)0x00000200U)
  427. #define SAI_SLOTACTIVE_10 ((uint32_t)0x00000400U)
  428. #define SAI_SLOTACTIVE_11 ((uint32_t)0x00000800U)
  429. #define SAI_SLOTACTIVE_12 ((uint32_t)0x00001000U)
  430. #define SAI_SLOTACTIVE_13 ((uint32_t)0x00002000U)
  431. #define SAI_SLOTACTIVE_14 ((uint32_t)0x00004000U)
  432. #define SAI_SLOTACTIVE_15 ((uint32_t)0x00008000U)
  433. #define SAI_SLOTACTIVE_ALL ((uint32_t)0x0000FFFFU)
  434. /**
  435. * @}
  436. */
  437. /** @defgroup SAI_Mono_Stereo_Mode SAI Mono Stereo Mode
  438. * @{
  439. */
  440. #define SAI_STEREOMODE ((uint32_t)0x00000000U)
  441. #define SAI_MONOMODE ((uint32_t)SAI_xCR1_MONO)
  442. /**
  443. * @}
  444. */
  445. /** @defgroup SAI_TRIState_Management SAI TRIState Management
  446. * @{
  447. */
  448. #define SAI_OUTPUT_NOTRELEASED ((uint32_t)0x00000000U)
  449. #define SAI_OUTPUT_RELEASED ((uint32_t)SAI_xCR2_TRIS)
  450. /**
  451. * @}
  452. */
  453. /** @defgroup SAI_Block_Fifo_Threshold SAI Block Fifo Threshold
  454. * @{
  455. */
  456. #define SAI_FIFOTHRESHOLD_EMPTY ((uint32_t)0x00000000U)
  457. #define SAI_FIFOTHRESHOLD_1QF ((uint32_t)(SAI_xCR2_FTH_0))
  458. #define SAI_FIFOTHRESHOLD_HF ((uint32_t)(SAI_xCR2_FTH_1))
  459. #define SAI_FIFOTHRESHOLD_3QF ((uint32_t)(SAI_xCR2_FTH_1 | SAI_xCR2_FTH_0))
  460. #define SAI_FIFOTHRESHOLD_FULL ((uint32_t)(SAI_xCR2_FTH_2))
  461. /**
  462. * @}
  463. */
  464. /** @defgroup SAI_Block_Companding_Mode SAI Block Companding Mode
  465. * @{
  466. */
  467. #define SAI_NOCOMPANDING ((uint32_t)0x00000000U)
  468. #define SAI_ULAW_1CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1))
  469. #define SAI_ALAW_1CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0))
  470. #define SAI_ULAW_2CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_CPL))
  471. #define SAI_ALAW_2CPL_COMPANDING ((uint32_t)(SAI_xCR2_COMP_1 | SAI_xCR2_COMP_0 | SAI_xCR2_CPL))
  472. /**
  473. * @}
  474. */
  475. /** @defgroup SAI_Block_Mute_Value SAI Block Mute Value
  476. * @{
  477. */
  478. #define SAI_ZERO_VALUE ((uint32_t)0x00000000U)
  479. #define SAI_LAST_SENT_VALUE ((uint32_t)SAI_xCR2_MUTEVAL)
  480. /**
  481. * @}
  482. */
  483. /** @defgroup SAI_Block_Interrupts_Definition SAI Block Interrupts Definition
  484. * @{
  485. */
  486. #define SAI_IT_OVRUDR ((uint32_t)SAI_xIMR_OVRUDRIE)
  487. #define SAI_IT_MUTEDET ((uint32_t)SAI_xIMR_MUTEDETIE)
  488. #define SAI_IT_WCKCFG ((uint32_t)SAI_xIMR_WCKCFGIE)
  489. #define SAI_IT_FREQ ((uint32_t)SAI_xIMR_FREQIE)
  490. #define SAI_IT_CNRDY ((uint32_t)SAI_xIMR_CNRDYIE)
  491. #define SAI_IT_AFSDET ((uint32_t)SAI_xIMR_AFSDETIE)
  492. #define SAI_IT_LFSDET ((uint32_t)SAI_xIMR_LFSDETIE)
  493. /**
  494. * @}
  495. */
  496. /** @defgroup SAI_Block_Flags_Definition SAI Block Flags Definition
  497. * @{
  498. */
  499. #define SAI_FLAG_OVRUDR ((uint32_t)SAI_xSR_OVRUDR)
  500. #define SAI_FLAG_MUTEDET ((uint32_t)SAI_xSR_MUTEDET)
  501. #define SAI_FLAG_WCKCFG ((uint32_t)SAI_xSR_WCKCFG)
  502. #define SAI_FLAG_FREQ ((uint32_t)SAI_xSR_FREQ)
  503. #define SAI_FLAG_CNRDY ((uint32_t)SAI_xSR_CNRDY)
  504. #define SAI_FLAG_AFSDET ((uint32_t)SAI_xSR_AFSDET)
  505. #define SAI_FLAG_LFSDET ((uint32_t)SAI_xSR_LFSDET)
  506. /**
  507. * @}
  508. */
  509. /** @defgroup SAI_Block_Fifo_Status_Level SAI Block Fifo Status Level
  510. * @{
  511. */
  512. #define SAI_FIFOSTATUS_EMPTY ((uint32_t)0x00000000U)
  513. #define SAI_FIFOSTATUS_LESS1QUARTERFULL ((uint32_t)0x00010000U)
  514. #define SAI_FIFOSTATUS_1QUARTERFULL ((uint32_t)0x00020000U)
  515. #define SAI_FIFOSTATUS_HALFFULL ((uint32_t)0x00030000U)
  516. #define SAI_FIFOSTATUS_3QUARTERFULL ((uint32_t)0x00040000U)
  517. #define SAI_FIFOSTATUS_FULL ((uint32_t)0x00050000U)
  518. /**
  519. * @}
  520. */
  521. /**
  522. * @}
  523. */
  524. /* Exported macro ------------------------------------------------------------*/
  525. /** @defgroup SAI_Exported_Macros SAI Exported Macros
  526. * @brief macros to handle interrupts and specific configurations
  527. * @{
  528. */
  529. /** @brief Reset SAI handle state.
  530. * @param __HANDLE__ specifies the SAI Handle.
  531. * @retval None
  532. */
  533. #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SAI_STATE_RESET)
  534. /** @brief Enable or disable the specified SAI interrupts.
  535. * @param __HANDLE__ specifies the SAI Handle.
  536. * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
  537. * This parameter can be one of the following values:
  538. * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
  539. * @arg SAI_IT_MUTEDET: Mute detection interrupt enable
  540. * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
  541. * @arg SAI_IT_FREQ: FIFO request interrupt enable
  542. * @arg SAI_IT_CNRDY: Codec not ready interrupt enable
  543. * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
  544. * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
  545. * @retval None
  546. */
  547. #define __HAL_SAI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR |= (__INTERRUPT__))
  548. #define __HAL_SAI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR &= (~(__INTERRUPT__)))
  549. /** @brief Check whether the specified SAI interrupt source is enabled or not.
  550. * @param __HANDLE__ specifies the SAI Handle.
  551. * @param __INTERRUPT__ specifies the SAI interrupt source to check.
  552. * This parameter can be one of the following values:
  553. * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
  554. * @arg SAI_IT_MUTEDET: Mute detection interrupt enable
  555. * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
  556. * @arg SAI_IT_FREQ: FIFO request interrupt enable
  557. * @arg SAI_IT_CNRDY: Codec not ready interrupt enable
  558. * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
  559. * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
  560. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  561. */
  562. #define __HAL_SAI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IMR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  563. /** @brief Check whether the specified SAI flag is set or not.
  564. * @param __HANDLE__ specifies the SAI Handle.
  565. * @param __FLAG__ specifies the flag to check.
  566. * This parameter can be one of the following values:
  567. * @arg SAI_FLAG_OVRUDR: Overrun underrun flag.
  568. * @arg SAI_FLAG_MUTEDET: Mute detection flag.
  569. * @arg SAI_FLAG_WCKCFG: Wrong Clock Configuration flag.
  570. * @arg SAI_FLAG_FREQ: FIFO request flag.
  571. * @arg SAI_FLAG_CNRDY: Codec not ready flag.
  572. * @arg SAI_FLAG_AFSDET: Anticipated frame synchronization detection flag.
  573. * @arg SAI_FLAG_LFSDET: Late frame synchronization detection flag.
  574. * @retval The new state of __FLAG__ (TRUE or FALSE).
  575. */
  576. #define __HAL_SAI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
  577. /** @brief Clear the specified SAI pending flag.
  578. * @param __HANDLE__ specifies the SAI Handle.
  579. * @param __FLAG__ specifies the flag to check.
  580. * This parameter can be any combination of the following values:
  581. * @arg SAI_FLAG_OVRUDR: Clear Overrun underrun
  582. * @arg SAI_FLAG_MUTEDET: Clear Mute detection
  583. * @arg SAI_FLAG_WCKCFG: Clear Wrong Clock Configuration
  584. * @arg SAI_FLAG_FREQ: Clear FIFO request
  585. * @arg SAI_FLAG_CNRDY: Clear Codec not ready
  586. * @arg SAI_FLAG_AFSDET: Clear Anticipated frame synchronization detection
  587. * @arg SAI_FLAG_LFSDET: Clear Late frame synchronization detection
  588. *
  589. * @retval None
  590. */
  591. #define __HAL_SAI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__))
  592. #define __HAL_SAI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SAI_xCR1_SAIEN)
  593. #define __HAL_SAI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~SAI_xCR1_SAIEN)
  594. /**
  595. * @}
  596. */
  597. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  598. /* Include SAI HAL Extension module */
  599. #include "stm32l4xx_hal_sai_ex.h"
  600. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  601. /* Exported functions --------------------------------------------------------*/
  602. /** @addtogroup SAI_Exported_Functions
  603. * @{
  604. */
  605. /* Initialization/de-initialization functions ********************************/
  606. /** @addtogroup SAI_Exported_Functions_Group1
  607. * @{
  608. */
  609. HAL_StatusTypeDef HAL_SAI_InitProtocol(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot);
  610. HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai);
  611. HAL_StatusTypeDef HAL_SAI_DeInit (SAI_HandleTypeDef *hsai);
  612. void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai);
  613. void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai);
  614. /**
  615. * @}
  616. */
  617. /* I/O operation functions ***************************************************/
  618. /** @addtogroup SAI_Exported_Functions_Group2
  619. * @{
  620. */
  621. /* Blocking mode: Polling */
  622. HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  623. HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  624. /* Non-Blocking mode: Interrupt */
  625. HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
  626. HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
  627. /* Non-Blocking mode: DMA */
  628. HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
  629. HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size);
  630. HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai);
  631. HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai);
  632. HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai);
  633. /* Abort function */
  634. HAL_StatusTypeDef HAL_SAI_Abort(SAI_HandleTypeDef *hsai);
  635. /* Mute management */
  636. HAL_StatusTypeDef HAL_SAI_EnableTxMuteMode(SAI_HandleTypeDef *hsai, uint16_t val);
  637. HAL_StatusTypeDef HAL_SAI_DisableTxMuteMode(SAI_HandleTypeDef *hsai);
  638. HAL_StatusTypeDef HAL_SAI_EnableRxMuteMode(SAI_HandleTypeDef *hsai, SAIcallback callback, uint16_t counter);
  639. HAL_StatusTypeDef HAL_SAI_DisableRxMuteMode(SAI_HandleTypeDef *hsai);
  640. /* SAI IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
  641. void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai);
  642. void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai);
  643. void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai);
  644. void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai);
  645. void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai);
  646. void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai);
  647. /**
  648. * @}
  649. */
  650. /** @addtogroup SAI_Exported_Functions_Group3
  651. * @{
  652. */
  653. /* Peripheral State functions ************************************************/
  654. HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai);
  655. uint32_t HAL_SAI_GetError(SAI_HandleTypeDef *hsai);
  656. /**
  657. * @}
  658. */
  659. /**
  660. * @}
  661. */
  662. /* Private macros ------------------------------------------------------------*/
  663. /** @addtogroup SAI_Private_Macros
  664. * @{
  665. */
  666. #define IS_SAI_BLOCK_SYNCEXT(STATE) (((STATE) == SAI_SYNCEXT_DISABLE) ||\
  667. ((STATE) == SAI_SYNCEXT_OUTBLOCKA_ENABLE) ||\
  668. ((STATE) == SAI_SYNCEXT_OUTBLOCKB_ENABLE))
  669. #define IS_SAI_SUPPORTED_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_I2S_STANDARD) ||\
  670. ((PROTOCOL) == SAI_I2S_MSBJUSTIFIED) ||\
  671. ((PROTOCOL) == SAI_I2S_LSBJUSTIFIED) ||\
  672. ((PROTOCOL) == SAI_PCM_LONG) ||\
  673. ((PROTOCOL) == SAI_PCM_SHORT))
  674. #define IS_SAI_PROTOCOL_DATASIZE(DATASIZE) (((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BIT) ||\
  675. ((DATASIZE) == SAI_PROTOCOL_DATASIZE_16BITEXTENDED) ||\
  676. ((DATASIZE) == SAI_PROTOCOL_DATASIZE_24BIT) ||\
  677. ((DATASIZE) == SAI_PROTOCOL_DATASIZE_32BIT))
  678. #define IS_SAI_AUDIO_FREQUENCY(AUDIO) (((AUDIO) == SAI_AUDIO_FREQUENCY_192K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_96K) || \
  679. ((AUDIO) == SAI_AUDIO_FREQUENCY_48K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_44K) || \
  680. ((AUDIO) == SAI_AUDIO_FREQUENCY_32K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_22K) || \
  681. ((AUDIO) == SAI_AUDIO_FREQUENCY_16K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_11K) || \
  682. ((AUDIO) == SAI_AUDIO_FREQUENCY_8K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_MCKDIV))
  683. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  684. #define IS_SAI_BLOCK_MCK_OVERSAMPLING(VALUE) (((VALUE) == SAI_MCK_OVERSAMPLING_DISABLE) || \
  685. ((VALUE) == SAI_MCK_OVERSAMPLING_ENABLE))
  686. #define IS_SAI_PDM_MIC_PAIRS_NUMBER(VALUE) ((1U <= (VALUE)) && ((VALUE) <= 3U))
  687. #define IS_SAI_PDM_CLOCK_ENABLE(CLOCK) (((CLOCK) != 0U) && \
  688. (((CLOCK) & ~(SAI_PDM_CLOCK1_ENABLE | SAI_PDM_CLOCK2_ENABLE)) == 0U))
  689. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  690. #define IS_SAI_BLOCK_MODE(MODE) (((MODE) == SAI_MODEMASTER_TX) || \
  691. ((MODE) == SAI_MODEMASTER_RX) || \
  692. ((MODE) == SAI_MODESLAVE_TX) || \
  693. ((MODE) == SAI_MODESLAVE_RX))
  694. #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_FREE_PROTOCOL) || \
  695. ((PROTOCOL) == SAI_AC97_PROTOCOL) || \
  696. ((PROTOCOL) == SAI_SPDIF_PROTOCOL))
  697. #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DATASIZE_8) || \
  698. ((DATASIZE) == SAI_DATASIZE_10) || \
  699. ((DATASIZE) == SAI_DATASIZE_16) || \
  700. ((DATASIZE) == SAI_DATASIZE_20) || \
  701. ((DATASIZE) == SAI_DATASIZE_24) || \
  702. ((DATASIZE) == SAI_DATASIZE_32))
  703. #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FIRSTBIT_MSB) || \
  704. ((BIT) == SAI_FIRSTBIT_LSB))
  705. #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_CLOCKSTROBING_FALLINGEDGE) || \
  706. ((CLOCK) == SAI_CLOCKSTROBING_RISINGEDGE))
  707. #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS) || \
  708. ((SYNCHRO) == SAI_SYNCHRONOUS) || \
  709. ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI1) || \
  710. ((SYNCHRO) == SAI_SYNCHRONOUS_EXT_SAI2))
  711. #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OUTPUTDRIVE_DISABLE) || \
  712. ((DRIVE) == SAI_OUTPUTDRIVE_ENABLE))
  713. #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MASTERDIVIDER_ENABLE) || \
  714. ((NODIVIDER) == SAI_MASTERDIVIDER_DISABLE))
  715. #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63)
  716. #define IS_SAI_BLOCK_MUTE_VALUE(VALUE) (((VALUE) == SAI_ZERO_VALUE) || \
  717. ((VALUE) == SAI_LAST_SENT_VALUE))
  718. #define IS_SAI_BLOCK_COMPANDING_MODE(MODE) (((MODE) == SAI_NOCOMPANDING) || \
  719. ((MODE) == SAI_ULAW_1CPL_COMPANDING) || \
  720. ((MODE) == SAI_ALAW_1CPL_COMPANDING) || \
  721. ((MODE) == SAI_ULAW_2CPL_COMPANDING) || \
  722. ((MODE) == SAI_ALAW_2CPL_COMPANDING))
  723. #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_FIFOTHRESHOLD_EMPTY) || \
  724. ((THRESHOLD) == SAI_FIFOTHRESHOLD_1QF) || \
  725. ((THRESHOLD) == SAI_FIFOTHRESHOLD_HF) || \
  726. ((THRESHOLD) == SAI_FIFOTHRESHOLD_3QF) || \
  727. ((THRESHOLD) == SAI_FIFOTHRESHOLD_FULL))
  728. #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_OUTPUT_NOTRELEASED) ||\
  729. ((STATE) == SAI_OUTPUT_RELEASED))
  730. #define IS_SAI_MONO_STEREO_MODE(MODE) (((MODE) == SAI_MONOMODE) ||\
  731. ((MODE) == SAI_STEREOMODE))
  732. #define IS_SAI_SLOT_ACTIVE(ACTIVE) ((ACTIVE) <= SAI_SLOTACTIVE_ALL)
  733. #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1 <= (NUMBER)) && ((NUMBER) <= 16))
  734. #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SLOTSIZE_DATASIZE) || \
  735. ((SIZE) == SAI_SLOTSIZE_16B) || \
  736. ((SIZE) == SAI_SLOTSIZE_32B))
  737. #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24)
  738. #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FIRSTBIT) || \
  739. ((OFFSET) == SAI_FS_BEFOREFIRSTBIT))
  740. #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ACTIVE_LOW) || \
  741. ((POLARITY) == SAI_FS_ACTIVE_HIGH))
  742. #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_STARTFRAME) || \
  743. ((DEFINITION) == SAI_FS_CHANNEL_IDENTIFICATION))
  744. #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 15)
  745. #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8 <= (LENGTH)) && ((LENGTH) <= 256))
  746. #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1 <= (LENGTH)) && ((LENGTH) <= 128))
  747. /**
  748. * @}
  749. */
  750. /* Private functions ---------------------------------------------------------*/
  751. /** @defgroup SAI_Private_Functions SAI Private Functions
  752. * @{
  753. */
  754. /**
  755. * @}
  756. */
  757. /**
  758. * @}
  759. */
  760. /**
  761. * @}
  762. */
  763. #ifdef __cplusplus
  764. }
  765. #endif
  766. #endif /* __STM32L4xx_HAL_SAI_H */
  767. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/