stm32g4xx_hal_sai.h 38 KB

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