stm32f4xx_sai.h 27 KB

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