stm32l4xx_hal_sai.h 41 KB

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