stm32f4xx_sai.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_sai.h
  4. * @author MCD Application Team
  5. * @version V1.8.1
  6. * @date 27-January-2022
  7. * @brief This file contains all the functions prototypes for the SAI
  8. * firmware library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * Copyright (c) 2016 STMicroelectronics.
  13. * All rights reserved.
  14. *
  15. * This software is licensed under terms that can be found in the LICENSE file
  16. * in the root directory of this software component.
  17. * If no LICENSE file comes with this software, it is provided AS-IS.
  18. *
  19. ******************************************************************************
  20. */
  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __STM32F4xx_SAI_H
  23. #define __STM32F4xx_SAI_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "stm32f4xx.h"
  29. /** @addtogroup STM32F4xx_StdPeriph_Driver
  30. * @{
  31. */
  32. /** @addtogroup SAI
  33. * @{
  34. */
  35. #if defined (STM32F40_41xxx) || defined (STM32F427_437xx) || defined (STM32F429_439xx) || \
  36. defined (STM32F401xx) || defined (STM32F411xE) || defined (STM32F446xx) || defined (STM32F469_479xx) || \
  37. defined (STM32F413_423xx)
  38. /* Exported types ------------------------------------------------------------*/
  39. /**
  40. * @brief SAI Block Init structure definition
  41. */
  42. typedef struct
  43. {
  44. uint32_t SAI_AudioMode; /*!< Specifies the SAI Block Audio Mode.
  45. This parameter can be a value of @ref SAI_Block_Mode */
  46. uint32_t SAI_Protocol; /*!< Specifies the SAI Block Protocol.
  47. This parameter can be a value of @ref SAI_Block_Protocol */
  48. uint32_t SAI_DataSize; /*!< Specifies the SAI Block data size.
  49. This parameter can be a value of @ref SAI_Block_Data_Size
  50. @note this value is ignored when AC'97 or SPDIF protocols are selected.*/
  51. uint32_t SAI_FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
  52. This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission
  53. @note this value has no meaning when AC'97 or SPDIF protocols are selected.*/
  54. uint32_t SAI_ClockStrobing; /*!< Specifies the SAI Block clock strobing edge sensitivity.
  55. This parameter can be a value of @ref SAI_Block_Clock_Strobing */
  56. uint32_t SAI_Synchro; /*!< Specifies SAI Block synchronization
  57. This parameter can be a value of @ref SAI_Block_Synchronization */
  58. uint32_t SAI_SynchroExt; /*!< Specifies SAI external output synchronization, this setup is common
  59. for BlockA and BlockB
  60. This parameter can be a value of @ref SAI_Block_SyncExt
  61. @note: If both audio blocks of same SAI are used, this parameter has
  62. to be set to the same value for each audio block */
  63. uint32_t SAI_OUTDRIV; /*!< Specifies when SAI Block outputs are driven.
  64. This parameter can be a value of @ref SAI_Block_Output_Drive
  65. @note this value has to be set before enabling the audio block
  66. but after the audio block configuration. */
  67. uint32_t SAI_NoDivider; /*!< Specifies whether Master Clock will be divided or not.
  68. This parameter can be a value of @ref SAI_Block_NoDivider */
  69. uint32_t SAI_MasterDivider; /*!< Specifies SAI Block Master Clock Divider.
  70. @note the Master Clock Frequency is calculated accordingly to the
  71. following formula : MCLK_x = SAI_CK_x/(MCKDIV[3:0]*2)*/
  72. uint32_t SAI_FIFOThreshold; /*!< Specifies SAI Block FIFO Threshold.
  73. This parameter can be a value of @ref SAI_Block_Fifo_Threshold */
  74. }SAI_InitTypeDef;
  75. /**
  76. * @brief SAI Block Frame Init structure definition
  77. */
  78. typedef struct
  79. {
  80. uint32_t SAI_FrameLength; /*!< Specifies the Frame Length, the number of SCK clocks
  81. for each audio frame.
  82. This parameter must be a number between 8 and 256.
  83. @note If master Clock MCLK_x pin is declared as an output, the frame length
  84. should be Aligned to a number equal to power of 2 in order to keep
  85. in an audio frame, an integer number of MCLK pulses by bit Clock.
  86. @note this value is ignored when AC'97 or SPDIF protocols are selected.*/
  87. uint32_t SAI_ActiveFrameLength; /*!< Specifies the Frame synchronization active level length.
  88. This Parameter specifies the length in number of bit clock (SCK + 1)
  89. of the active level of FS signal in audio frame.
  90. This parameter must be a number between 1 and 128.
  91. @note this value is ignored when AC'97 or SPDIF protocols are selected.*/
  92. uint32_t SAI_FSDefinition; /*!< Specifies the Frame Synchronization definition.
  93. This parameter can be a value of @ref SAI_Block_FS_Definition
  94. @note this value is ignored when AC'97 or SPDIF protocols are selected.*/
  95. uint32_t SAI_FSPolarity; /*!< Specifies the Frame Synchronization Polarity.
  96. This parameter can be a value of @ref SAI_Block_FS_Polarity
  97. @note this value is ignored when AC'97 or SPDIF protocols are selected.*/
  98. uint32_t SAI_FSOffset; /*!< Specifies the Frame Synchronization Offset.
  99. This parameter can be a value of @ref SAI_Block_FS_Offset
  100. @note this value is ignored when AC'97 or SPDIF protocols are selected.*/
  101. }SAI_FrameInitTypeDef;
  102. /**
  103. * @brief SAI Block Slot Init Structure definition
  104. */
  105. typedef struct
  106. {
  107. uint32_t SAI_FirstBitOffset; /*!< Specifies the position of first data transfer bit in the slot.
  108. This parameter must be a number between 0 and 24.
  109. @note this value is ignored when AC'97 or SPDIF protocols are selected.*/
  110. uint32_t SAI_SlotSize; /*!< Specifies the Slot Size.
  111. This parameter can be a value of @ref SAI_Block_Slot_Size
  112. @note this value is ignored when AC'97 or SPDIF protocols are selected.*/
  113. uint32_t SAI_SlotNumber; /*!< Specifies the number of slot in the audio frame.
  114. This parameter must be a number between 1 and 16.
  115. @note this value is ignored when AC'97 or SPDIF protocols are selected.*/
  116. uint32_t SAI_SlotActive; /*!< Specifies the slots in audio frame that will be activated.
  117. This parameter can be a value of @ ref SAI_Block_Slot_Active
  118. @note this value is ignored when AC'97 or SPDIF protocols are selected.*/
  119. }SAI_SlotInitTypeDef;
  120. /* Exported constants --------------------------------------------------------*/
  121. /** @defgroup SAI_Exported_Constants
  122. * @{
  123. */
  124. #if defined(STM32F446xx)
  125. #define IS_SAI_PERIPH(PERIPH) (((PERIPH) == SAI1) || ((PERIPH) == SAI2))
  126. #define IS_SAI_BLOCK_PERIPH(PERIPH) (((PERIPH) == SAI1_Block_A) || \
  127. ((PERIPH) == SAI1_Block_B) || \
  128. ((PERIPH) == SAI2_Block_A) || \
  129. ((PERIPH) == SAI2_Block_B))
  130. #endif /* STM32F446xx */
  131. #if defined (STM32F40_41xxx) || defined (STM32F427_437xx) || defined (STM32F429_439xx) || defined (STM32F401xx) || defined (STM32F411xE) || defined(STM32F413_423xx) || defined (STM32F469_479xx)
  132. #define IS_SAI_PERIPH(PERIPH) ((PERIPH) == SAI1)
  133. #define IS_SAI_BLOCK_PERIPH(PERIPH) (((PERIPH) == SAI1_Block_A) || \
  134. ((PERIPH) == SAI1_Block_B))
  135. #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx || STM32F411xE || STM32F413_423xx || STM32F469_479xx */
  136. /** @defgroup SAI_Block_Mode
  137. * @{
  138. */
  139. #define SAI_Mode_MasterTx ((uint32_t)0x00000000)
  140. #define SAI_Mode_MasterRx ((uint32_t)0x00000001)
  141. #define SAI_Mode_SlaveTx ((uint32_t)0x00000002)
  142. #define SAI_Mode_SlaveRx ((uint32_t)0x00000003)
  143. #define IS_SAI_BLOCK_MODE(MODE) (((MODE) == SAI_Mode_MasterTx) || \
  144. ((MODE) == SAI_Mode_MasterRx) || \
  145. ((MODE) == SAI_Mode_SlaveTx) || \
  146. ((MODE) == SAI_Mode_SlaveRx))
  147. /**
  148. * @}
  149. */
  150. /** @defgroup SAI_Block_Protocol
  151. * @{
  152. */
  153. #define SAI_Free_Protocol ((uint32_t)0x00000000)
  154. #define SAI_SPDIF_Protocol ((uint32_t)SAI_xCR1_PRTCFG_0)
  155. #define SAI_AC97_Protocol ((uint32_t)SAI_xCR1_PRTCFG_1)
  156. #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_Free_Protocol) || \
  157. ((PROTOCOL) == SAI_SPDIF_Protocol) || \
  158. ((PROTOCOL) == SAI_AC97_Protocol))
  159. /**
  160. * @}
  161. */
  162. /** @defgroup SAI_Block_Data_Size
  163. * @{
  164. */
  165. #define SAI_DataSize_8b ((uint32_t)0x00000040)
  166. #define SAI_DataSize_10b ((uint32_t)0x00000060)
  167. #define SAI_DataSize_16b ((uint32_t)0x00000080)
  168. #define SAI_DataSize_20b ((uint32_t)0x000000A0)
  169. #define SAI_DataSize_24b ((uint32_t)0x000000C0)
  170. #define SAI_DataSize_32b ((uint32_t)0x000000E0)
  171. #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DataSize_8b) || \
  172. ((DATASIZE) == SAI_DataSize_10b) || \
  173. ((DATASIZE) == SAI_DataSize_16b) || \
  174. ((DATASIZE) == SAI_DataSize_20b) || \
  175. ((DATASIZE) == SAI_DataSize_24b) || \
  176. ((DATASIZE) == SAI_DataSize_32b))
  177. /**
  178. * @}
  179. */
  180. /** @defgroup SAI_Block_MSB_LSB_transmission
  181. * @{
  182. */
  183. #define SAI_FirstBit_MSB ((uint32_t)0x00000000)
  184. #define SAI_FirstBit_LSB ((uint32_t)SAI_xCR1_LSBFIRST)
  185. #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FirstBit_MSB) || \
  186. ((BIT) == SAI_FirstBit_LSB))
  187. /**
  188. * @}
  189. */
  190. /** @defgroup SAI_Block_Clock_Strobing
  191. * @{
  192. */
  193. #define SAI_ClockStrobing_FallingEdge ((uint32_t)0x00000000)
  194. #define SAI_ClockStrobing_RisingEdge ((uint32_t)SAI_xCR1_CKSTR)
  195. #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_ClockStrobing_FallingEdge) || \
  196. ((CLOCK) == SAI_ClockStrobing_RisingEdge))
  197. /**
  198. * @}
  199. */
  200. /** @defgroup SAI_Block_Synchronization
  201. * @{
  202. */
  203. #define SAI_Asynchronous ((uint32_t)0x00000000)
  204. #define SAI_Synchronous ((uint32_t)SAI_xCR1_SYNCEN_0)
  205. #define SAI_Synchronous_Ext ((uint32_t)SAI_xCR1_SYNCEN_1)
  206. #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_Synchronous) || \
  207. ((SYNCHRO) == SAI_Asynchronous) || \
  208. ((SYNCHRO) == SAI_Synchronous_Ext))
  209. /**
  210. * @}
  211. */
  212. /** @defgroup SAI_Block_SyncExt SAI External synchronisation
  213. * @{
  214. */
  215. #define SAI_SyncExt_Disable ((uint32_t)0x00000000)
  216. #define SAI_SyncExt_OutBlockA_Enable ((uint32_t)SAI_GCR_SYNCOUT_0)
  217. #define SAI_SyncExt_OutBlockB_Enable ((uint32_t)SAI_GCR_SYNCOUT_1)
  218. #define IS_SAI_BLOCK_SYNCEXT(SYNCHRO) (((SYNCHRO) == SAI_SyncExt_Disable) || \
  219. ((SYNCHRO) == SAI_SyncExt_OutBlockA_Enable)|| \
  220. ((SYNCHRO) == SAI_SyncExt_OutBlockB_Enable))
  221. /**
  222. * @}
  223. */
  224. /** @defgroup SAI_Block_Output_Drive
  225. * @{
  226. */
  227. #define SAI_OutputDrive_Disabled ((uint32_t)0x00000000)
  228. #define SAI_OutputDrive_Enabled ((uint32_t)SAI_xCR1_OUTDRIV)
  229. #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OutputDrive_Disabled) || \
  230. ((DRIVE) == SAI_OutputDrive_Enabled))
  231. /**
  232. * @}
  233. */
  234. /** @defgroup SAI_Block_NoDivider
  235. * @{
  236. */
  237. #define SAI_MasterDivider_Enabled ((uint32_t)0x00000000)
  238. #define SAI_MasterDivider_Disabled ((uint32_t)SAI_xCR1_NODIV)
  239. #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MasterDivider_Enabled) || \
  240. ((NODIVIDER) == SAI_MasterDivider_Disabled))
  241. /**
  242. * @}
  243. */
  244. /** @defgroup SAI_Block_Master_Divider
  245. * @{
  246. */
  247. #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 15)
  248. /**
  249. * @}
  250. */
  251. /** @defgroup SAI_Block_Frame_Length
  252. * @{
  253. */
  254. #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8 <= (LENGTH)) && ((LENGTH) <= 256))
  255. /**
  256. * @}
  257. */
  258. /** @defgroup SAI_Block_Active_FrameLength
  259. * @{
  260. */
  261. #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1 <= (LENGTH)) && ((LENGTH) <= 128))
  262. /**
  263. * @}
  264. */
  265. /** @defgroup SAI_Block_FS_Definition
  266. * @{
  267. */
  268. #define SAI_FS_StartFrame ((uint32_t)0x00000000)
  269. #define I2S_FS_ChannelIdentification ((uint32_t)SAI_xFRCR_FSDEF)
  270. #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_StartFrame) || \
  271. ((DEFINITION) == I2S_FS_ChannelIdentification))
  272. /**
  273. * @}
  274. */
  275. /** @defgroup SAI_Block_FS_Polarity
  276. * @{
  277. */
  278. #define SAI_FS_ActiveLow ((uint32_t)0x00000000)
  279. #define SAI_FS_ActiveHigh ((uint32_t)SAI_xFRCR_FSPO)
  280. #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ActiveLow) || \
  281. ((POLARITY) == SAI_FS_ActiveHigh))
  282. /**
  283. * @}
  284. */
  285. /** @defgroup SAI_Block_FS_Offset
  286. * @{
  287. */
  288. #define SAI_FS_FirstBit ((uint32_t)0x00000000)
  289. #define SAI_FS_BeforeFirstBit ((uint32_t)SAI_xFRCR_FSOFF)
  290. #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FirstBit) || \
  291. ((OFFSET) == SAI_FS_BeforeFirstBit))
  292. /**
  293. * @}
  294. */
  295. /** @defgroup SAI_Block_Slot_FirstBit_Offset
  296. * @{
  297. */
  298. #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24)
  299. /**
  300. * @}
  301. */
  302. /** @defgroup SAI_Block_Slot_Size
  303. * @{
  304. */
  305. #define SAI_SlotSize_DataSize ((uint32_t)0x00000000)
  306. #define SAI_SlotSize_16b ((uint32_t)SAI_xSLOTR_SLOTSZ_0)
  307. #define SAI_SlotSize_32b ((uint32_t)SAI_xSLOTR_SLOTSZ_1)
  308. #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SlotSize_DataSize) || \
  309. ((SIZE) == SAI_SlotSize_16b) || \
  310. ((SIZE) == SAI_SlotSize_32b))
  311. /**
  312. * @}
  313. */
  314. /** @defgroup SAI_Block_Slot_Number
  315. * @{
  316. */
  317. #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1 <= (NUMBER)) && ((NUMBER) <= 16))
  318. /**
  319. * @}
  320. */
  321. /** @defgroup SAI_Block_Slot_Active
  322. * @{
  323. */
  324. #define SAI_Slot_NotActive ((uint32_t)0x00000000)
  325. #define SAI_SlotActive_0 ((uint32_t)0x00010000)
  326. #define SAI_SlotActive_1 ((uint32_t)0x00020000)
  327. #define SAI_SlotActive_2 ((uint32_t)0x00040000)
  328. #define SAI_SlotActive_3 ((uint32_t)0x00080000)
  329. #define SAI_SlotActive_4 ((uint32_t)0x00100000)
  330. #define SAI_SlotActive_5 ((uint32_t)0x00200000)
  331. #define SAI_SlotActive_6 ((uint32_t)0x00400000)
  332. #define SAI_SlotActive_7 ((uint32_t)0x00800000)
  333. #define SAI_SlotActive_8 ((uint32_t)0x01000000)
  334. #define SAI_SlotActive_9 ((uint32_t)0x02000000)
  335. #define SAI_SlotActive_10 ((uint32_t)0x04000000)
  336. #define SAI_SlotActive_11 ((uint32_t)0x08000000)
  337. #define SAI_SlotActive_12 ((uint32_t)0x10000000)
  338. #define SAI_SlotActive_13 ((uint32_t)0x20000000)
  339. #define SAI_SlotActive_14 ((uint32_t)0x40000000)
  340. #define SAI_SlotActive_15 ((uint32_t)0x80000000)
  341. #define SAI_SlotActive_ALL ((uint32_t)0xFFFF0000)
  342. #define IS_SAI_SLOT_ACTIVE(ACTIVE) ((ACTIVE) != 0)
  343. /**
  344. * @}
  345. */
  346. /** @defgroup SAI_Mono_Streo_Mode
  347. * @{
  348. */
  349. #define SAI_MonoMode ((uint32_t)SAI_xCR1_MONO)
  350. #define SAI_StreoMode ((uint32_t)0x00000000)
  351. #define IS_SAI_BLOCK_MONO_STREO_MODE(MODE) (((MODE) == SAI_MonoMode) ||\
  352. ((MODE) == SAI_StreoMode))
  353. /**
  354. * @}
  355. */
  356. /** @defgroup SAI_TRIState_Management
  357. * @{
  358. */
  359. #define SAI_Output_NotReleased ((uint32_t)0x00000000)
  360. #define SAI_Output_Released ((uint32_t)SAI_xCR2_TRIS)
  361. #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_Output_NotReleased) ||\
  362. ((STATE) == SAI_Output_Released))
  363. /**
  364. * @}
  365. */
  366. /** @defgroup SAI_Block_Fifo_Threshold
  367. * @{
  368. */
  369. #define SAI_Threshold_FIFOEmpty ((uint32_t)0x00000000)
  370. #define SAI_FIFOThreshold_1QuarterFull ((uint32_t)0x00000001)
  371. #define SAI_FIFOThreshold_HalfFull ((uint32_t)0x00000002)
  372. #define SAI_FIFOThreshold_3QuartersFull ((uint32_t)0x00000003)
  373. #define SAI_FIFOThreshold_Full ((uint32_t)0x00000004)
  374. #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_Threshold_FIFOEmpty) || \
  375. ((THRESHOLD) == SAI_FIFOThreshold_1QuarterFull) || \
  376. ((THRESHOLD) == SAI_FIFOThreshold_HalfFull) || \
  377. ((THRESHOLD) == SAI_FIFOThreshold_3QuartersFull) || \
  378. ((THRESHOLD) == SAI_FIFOThreshold_Full))
  379. /**
  380. * @}
  381. */
  382. /** @defgroup SAI_Block_Companding_Mode
  383. * @{
  384. */
  385. #define SAI_NoCompanding ((uint32_t)0x00000000)
  386. #define SAI_ULaw_1CPL_Companding ((uint32_t)0x00008000)
  387. #define SAI_ALaw_1CPL_Companding ((uint32_t)0x0000C000)
  388. #define SAI_ULaw_2CPL_Companding ((uint32_t)0x0000A000)
  389. #define SAI_ALaw_2CPL_Companding ((uint32_t)0x0000E000)
  390. #define IS_SAI_BLOCK_COMPANDING_MODE(MODE) (((MODE) == SAI_NoCompanding) || \
  391. ((MODE) == SAI_ULaw_1CPL_Companding) || \
  392. ((MODE) == SAI_ALaw_1CPL_Companding) || \
  393. ((MODE) == SAI_ULaw_2CPL_Companding) || \
  394. ((MODE) == SAI_ALaw_2CPL_Companding))
  395. /**
  396. * @}
  397. */
  398. /** @defgroup SAI_Block_Mute_Value
  399. * @{
  400. */
  401. #define SAI_ZeroValue ((uint32_t)0x00000000)
  402. #define SAI_LastSentValue ((uint32_t)SAI_xCR2_MUTEVAL)
  403. #define IS_SAI_BLOCK_MUTE_VALUE(VALUE) (((VALUE) == SAI_ZeroValue) || \
  404. ((VALUE) == SAI_LastSentValue))
  405. /**
  406. * @}
  407. */
  408. /** @defgroup SAI_Block_Mute_Frame_Counter
  409. * @{
  410. */
  411. #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63)
  412. /**
  413. * @}
  414. */
  415. /** @defgroup SAI_Block_Interrupts_Definition
  416. * @{
  417. */
  418. #define SAI_IT_OVRUDR ((uint32_t)SAI_xIMR_OVRUDRIE)
  419. #define SAI_IT_MUTEDET ((uint32_t)SAI_xIMR_MUTEDETIE)
  420. #define SAI_IT_WCKCFG ((uint32_t)SAI_xIMR_WCKCFGIE)
  421. #define SAI_IT_FREQ ((uint32_t)SAI_xIMR_FREQIE)
  422. #define SAI_IT_CNRDY ((uint32_t)SAI_xIMR_CNRDYIE)
  423. #define SAI_IT_AFSDET ((uint32_t)SAI_xIMR_AFSDETIE)
  424. #define SAI_IT_LFSDET ((uint32_t)SAI_xIMR_LFSDETIE)
  425. #define IS_SAI_BLOCK_CONFIG_IT(IT) (((IT) == SAI_IT_OVRUDR) || \
  426. ((IT) == SAI_IT_MUTEDET) || \
  427. ((IT) == SAI_IT_WCKCFG) || \
  428. ((IT) == SAI_IT_FREQ) || \
  429. ((IT) == SAI_IT_CNRDY) || \
  430. ((IT) == SAI_IT_AFSDET) || \
  431. ((IT) == SAI_IT_LFSDET))
  432. /**
  433. * @}
  434. */
  435. /** @defgroup SAI_Block_Flags_Definition
  436. * @{
  437. */
  438. #define SAI_FLAG_OVRUDR ((uint32_t)SAI_xSR_OVRUDR)
  439. #define SAI_FLAG_MUTEDET ((uint32_t)SAI_xSR_MUTEDET)
  440. #define SAI_FLAG_WCKCFG ((uint32_t)SAI_xSR_WCKCFG)
  441. #define SAI_FLAG_FREQ ((uint32_t)SAI_xSR_FREQ)
  442. #define SAI_FLAG_CNRDY ((uint32_t)SAI_xSR_CNRDY)
  443. #define SAI_FLAG_AFSDET ((uint32_t)SAI_xSR_AFSDET)
  444. #define SAI_FLAG_LFSDET ((uint32_t)SAI_xSR_LFSDET)
  445. #define IS_SAI_BLOCK_GET_FLAG(FLAG) (((FLAG) == SAI_FLAG_OVRUDR) || \
  446. ((FLAG) == SAI_FLAG_MUTEDET) || \
  447. ((FLAG) == SAI_FLAG_WCKCFG) || \
  448. ((FLAG) == SAI_FLAG_FREQ) || \
  449. ((FLAG) == SAI_FLAG_CNRDY) || \
  450. ((FLAG) == SAI_FLAG_AFSDET) || \
  451. ((FLAG) == SAI_FLAG_LFSDET))
  452. #define IS_SAI_BLOCK_CLEAR_FLAG(FLAG) (((FLAG) == SAI_FLAG_OVRUDR) || \
  453. ((FLAG) == SAI_FLAG_MUTEDET) || \
  454. ((FLAG) == SAI_FLAG_WCKCFG) || \
  455. ((FLAG) == SAI_FLAG_FREQ) || \
  456. ((FLAG) == SAI_FLAG_CNRDY) || \
  457. ((FLAG) == SAI_FLAG_AFSDET) || \
  458. ((FLAG) == SAI_FLAG_LFSDET))
  459. /**
  460. * @}
  461. */
  462. /** @defgroup SAI_Block_Fifo_Status_Level
  463. * @{
  464. */
  465. #define SAI_FIFOStatus_Empty ((uint32_t)0x00000000)
  466. #define SAI_FIFOStatus_Less1QuarterFull ((uint32_t)0x00010000)
  467. #define SAI_FIFOStatus_1QuarterFull ((uint32_t)0x00020000)
  468. #define SAI_FIFOStatus_HalfFull ((uint32_t)0x00030000)
  469. #define SAI_FIFOStatus_3QuartersFull ((uint32_t)0x00040000)
  470. #define SAI_FIFOStatus_Full ((uint32_t)0x00050000)
  471. #define IS_SAI_BLOCK_FIFO_STATUS(STATUS) (((STATUS) == SAI_FIFOStatus_Less1QuarterFull ) || \
  472. ((STATUS) == SAI_FIFOStatus_HalfFull) || \
  473. ((STATUS) == SAI_FIFOStatus_1QuarterFull) || \
  474. ((STATUS) == SAI_FIFOStatus_3QuartersFull) || \
  475. ((STATUS) == SAI_FIFOStatus_Full) || \
  476. ((STATUS) == SAI_FIFOStatus_Empty))
  477. /**
  478. * @}
  479. */
  480. /**
  481. * @}
  482. */
  483. /* Exported macro ------------------------------------------------------------*/
  484. /* Exported functions --------------------------------------------------------*/
  485. /* Function used to set the SAI configuration to the default reset state *****/
  486. void SAI_DeInit(SAI_TypeDef* SAIx);
  487. /* Initialization and Configuration functions *********************************/
  488. void SAI_Init(SAI_Block_TypeDef* SAI_Block_x, SAI_InitTypeDef* SAI_InitStruct);
  489. void SAI_FrameInit(SAI_Block_TypeDef* SAI_Block_x, SAI_FrameInitTypeDef* SAI_FrameInitStruct);
  490. void SAI_SlotInit(SAI_Block_TypeDef* SAI_Block_x, SAI_SlotInitTypeDef* SAI_SlotInitStruct);
  491. void SAI_StructInit(SAI_InitTypeDef* SAI_InitStruct);
  492. void SAI_FrameStructInit(SAI_FrameInitTypeDef* SAI_FrameInitStruct);
  493. void SAI_SlotStructInit(SAI_SlotInitTypeDef* SAI_SlotInitStruct);
  494. void SAI_Cmd(SAI_Block_TypeDef* SAI_Block_x, FunctionalState NewState);
  495. void SAI_MonoModeConfig(SAI_Block_TypeDef* SAI_Block_x, uint32_t SAI_Mono_StreoMode);
  496. void SAI_TRIStateConfig(SAI_Block_TypeDef* SAI_Block_x, uint32_t SAI_TRIState);
  497. void SAI_CompandingModeConfig(SAI_Block_TypeDef* SAI_Block_x, uint32_t SAI_CompandingMode);
  498. void SAI_MuteModeCmd(SAI_Block_TypeDef* SAI_Block_x, FunctionalState NewState);
  499. void SAI_MuteValueConfig(SAI_Block_TypeDef* SAI_Block_x, uint32_t SAI_MuteValue);
  500. void SAI_MuteFrameCounterConfig(SAI_Block_TypeDef* SAI_Block_x, uint32_t SAI_MuteCounter);
  501. void SAI_FlushFIFO(SAI_Block_TypeDef* SAI_Block_x);
  502. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
  503. defined(STM32F469_479xx) || defined(STM32F413_423xx) || defined(STM32F446xx)
  504. void SAI_BlockSynchroConfig(SAI_InitTypeDef* SAI_InitStruct, SAI_TypeDef* SAIx);
  505. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469_479xx || STM32F413_423xx || STM32F446xx */
  506. /* Data transfers functions ***************************************************/
  507. void SAI_SendData(SAI_Block_TypeDef* SAI_Block_x, uint32_t Data);
  508. uint32_t SAI_ReceiveData(SAI_Block_TypeDef* SAI_Block_x);
  509. /* DMA transfers management functions *****************************************/
  510. void SAI_DMACmd(SAI_Block_TypeDef* SAI_Block_x, FunctionalState NewState);
  511. /* Interrupts and flags management functions **********************************/
  512. void SAI_ITConfig(SAI_Block_TypeDef* SAI_Block_x, uint32_t SAI_IT, FunctionalState NewState);
  513. FlagStatus SAI_GetFlagStatus(SAI_Block_TypeDef* SAI_Block_x, uint32_t SAI_FLAG);
  514. void SAI_ClearFlag(SAI_Block_TypeDef* SAI_Block_x, uint32_t SAI_FLAG);
  515. ITStatus SAI_GetITStatus(SAI_Block_TypeDef* SAI_Block_x, uint32_t SAI_IT);
  516. void SAI_ClearITPendingBit(SAI_Block_TypeDef* SAI_Block_x, uint32_t SAI_IT);
  517. FunctionalState SAI_GetCmdStatus(SAI_Block_TypeDef* SAI_Block_x);
  518. uint32_t SAI_GetFIFOStatus(SAI_Block_TypeDef* SAI_Block_x);
  519. #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx || STM32F411xE || STM32F446xx || STM32F469_479xx */
  520. /**
  521. * @}
  522. */
  523. /**
  524. * @}
  525. */
  526. #ifdef __cplusplus
  527. }
  528. #endif
  529. #endif /*__STM32F4xx_SAI_H */