stm32f1xx_hal_i2s.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_hal_i2s.h
  4. * @author MCD Application Team
  5. * @brief Header file of I2S HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 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 STM32F1xx_HAL_I2S_H
  20. #define STM32F1xx_HAL_I2S_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32f1xx_hal_def.h"
  26. #if defined(SPI_I2S_SUPPORT)
  27. /** @addtogroup STM32F1xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup I2S
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup I2S_Exported_Types I2S Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief I2S Init structure definition
  39. */
  40. typedef struct
  41. {
  42. uint32_t Mode; /*!< Specifies the I2S operating mode.
  43. This parameter can be a value of @ref I2S_Mode */
  44. uint32_t Standard; /*!< Specifies the standard used for the I2S communication.
  45. This parameter can be a value of @ref I2S_Standard */
  46. uint32_t DataFormat; /*!< Specifies the data format for the I2S communication.
  47. This parameter can be a value of @ref I2S_Data_Format */
  48. uint32_t MCLKOutput; /*!< Specifies whether the I2S MCLK output is enabled or not.
  49. This parameter can be a value of @ref I2S_MCLK_Output */
  50. uint32_t AudioFreq; /*!< Specifies the frequency selected for the I2S communication.
  51. This parameter can be a value of @ref I2S_Audio_Frequency */
  52. uint32_t CPOL; /*!< Specifies the idle state of the I2S clock.
  53. This parameter can be a value of @ref I2S_Clock_Polarity */
  54. } I2S_InitTypeDef;
  55. /**
  56. * @brief HAL State structures definition
  57. */
  58. typedef enum
  59. {
  60. HAL_I2S_STATE_RESET = 0x00U, /*!< I2S not yet initialized or disabled */
  61. HAL_I2S_STATE_READY = 0x01U, /*!< I2S initialized and ready for use */
  62. HAL_I2S_STATE_BUSY = 0x02U, /*!< I2S internal process is ongoing */
  63. HAL_I2S_STATE_BUSY_TX = 0x03U, /*!< Data Transmission process is ongoing */
  64. HAL_I2S_STATE_BUSY_RX = 0x04U, /*!< Data Reception process is ongoing */
  65. HAL_I2S_STATE_TIMEOUT = 0x06U, /*!< I2S timeout state */
  66. HAL_I2S_STATE_ERROR = 0x07U /*!< I2S error state */
  67. } HAL_I2S_StateTypeDef;
  68. /**
  69. * @brief I2S handle Structure definition
  70. */
  71. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1)
  72. typedef struct __I2S_HandleTypeDef
  73. #else
  74. typedef struct
  75. #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
  76. {
  77. SPI_TypeDef *Instance; /*!< I2S registers base address */
  78. I2S_InitTypeDef Init; /*!< I2S communication parameters */
  79. uint16_t *pTxBuffPtr; /*!< Pointer to I2S Tx transfer buffer */
  80. __IO uint16_t TxXferSize; /*!< I2S Tx transfer size */
  81. __IO uint16_t TxXferCount; /*!< I2S Tx transfer Counter */
  82. uint16_t *pRxBuffPtr; /*!< Pointer to I2S Rx transfer buffer */
  83. __IO uint16_t RxXferSize; /*!< I2S Rx transfer size */
  84. __IO uint16_t RxXferCount; /*!< I2S Rx transfer counter
  85. (This field is initialized at the
  86. same value as transfer size at the
  87. beginning of the transfer and
  88. decremented when a sample is received
  89. NbSamplesReceived = RxBufferSize-RxBufferCount) */
  90. DMA_HandleTypeDef *hdmatx; /*!< I2S Tx DMA handle parameters */
  91. DMA_HandleTypeDef *hdmarx; /*!< I2S Rx DMA handle parameters */
  92. __IO HAL_LockTypeDef Lock; /*!< I2S locking object */
  93. __IO HAL_I2S_StateTypeDef State; /*!< I2S communication state */
  94. __IO uint32_t ErrorCode; /*!< I2S Error code
  95. This parameter can be a value of @ref I2S_Error */
  96. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1U)
  97. void (* TxCpltCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Tx Completed callback */
  98. void (* RxCpltCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Rx Completed callback */
  99. void (* TxHalfCpltCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Tx Half Completed callback */
  100. void (* RxHalfCpltCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Rx Half Completed callback */
  101. void (* ErrorCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Error callback */
  102. void (* MspInitCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Msp Init callback */
  103. void (* MspDeInitCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Msp DeInit callback */
  104. #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
  105. } I2S_HandleTypeDef;
  106. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1U)
  107. /**
  108. * @brief HAL I2S Callback ID enumeration definition
  109. */
  110. typedef enum
  111. {
  112. HAL_I2S_TX_COMPLETE_CB_ID = 0x00U, /*!< I2S Tx Completed callback ID */
  113. HAL_I2S_RX_COMPLETE_CB_ID = 0x01U, /*!< I2S Rx Completed callback ID */
  114. HAL_I2S_TX_HALF_COMPLETE_CB_ID = 0x03U, /*!< I2S Tx Half Completed callback ID */
  115. HAL_I2S_RX_HALF_COMPLETE_CB_ID = 0x04U, /*!< I2S Rx Half Completed callback ID */
  116. HAL_I2S_ERROR_CB_ID = 0x06U, /*!< I2S Error callback ID */
  117. HAL_I2S_MSPINIT_CB_ID = 0x07U, /*!< I2S Msp Init callback ID */
  118. HAL_I2S_MSPDEINIT_CB_ID = 0x08U /*!< I2S Msp DeInit callback ID */
  119. } HAL_I2S_CallbackIDTypeDef;
  120. /**
  121. * @brief HAL I2S Callback pointer definition
  122. */
  123. typedef void (*pI2S_CallbackTypeDef)(I2S_HandleTypeDef *hi2s); /*!< pointer to an I2S callback function */
  124. #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
  125. /**
  126. * @}
  127. */
  128. /* Exported constants --------------------------------------------------------*/
  129. /** @defgroup I2S_Exported_Constants I2S Exported Constants
  130. * @{
  131. */
  132. /** @defgroup I2S_Error I2S Error
  133. * @{
  134. */
  135. #define HAL_I2S_ERROR_NONE (0x00000000U) /*!< No error */
  136. #define HAL_I2S_ERROR_TIMEOUT (0x00000001U) /*!< Timeout error */
  137. #define HAL_I2S_ERROR_OVR (0x00000002U) /*!< OVR error */
  138. #define HAL_I2S_ERROR_UDR (0x00000004U) /*!< UDR error */
  139. #define HAL_I2S_ERROR_DMA (0x00000008U) /*!< DMA transfer error */
  140. #define HAL_I2S_ERROR_PRESCALER (0x00000010U) /*!< Prescaler Calculation error */
  141. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1U)
  142. #define HAL_I2S_ERROR_INVALID_CALLBACK (0x00000020U) /*!< Invalid Callback error */
  143. #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
  144. #define HAL_I2S_ERROR_BUSY_LINE_RX (0x00000040U) /*!< Busy Rx Line error */
  145. /**
  146. * @}
  147. */
  148. /** @defgroup I2S_Mode I2S Mode
  149. * @{
  150. */
  151. #define I2S_MODE_SLAVE_TX (0x00000000U)
  152. #define I2S_MODE_SLAVE_RX (SPI_I2SCFGR_I2SCFG_0)
  153. #define I2S_MODE_MASTER_TX (SPI_I2SCFGR_I2SCFG_1)
  154. #define I2S_MODE_MASTER_RX ((SPI_I2SCFGR_I2SCFG_0 | SPI_I2SCFGR_I2SCFG_1))
  155. /**
  156. * @}
  157. */
  158. /** @defgroup I2S_Standard I2S Standard
  159. * @{
  160. */
  161. #define I2S_STANDARD_PHILIPS (0x00000000U)
  162. #define I2S_STANDARD_MSB (SPI_I2SCFGR_I2SSTD_0)
  163. #define I2S_STANDARD_LSB (SPI_I2SCFGR_I2SSTD_1)
  164. #define I2S_STANDARD_PCM_SHORT ((SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1))
  165. #define I2S_STANDARD_PCM_LONG ((SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1 | SPI_I2SCFGR_PCMSYNC))
  166. /**
  167. * @}
  168. */
  169. /** @defgroup I2S_Data_Format I2S Data Format
  170. * @{
  171. */
  172. #define I2S_DATAFORMAT_16B (0x00000000U)
  173. #define I2S_DATAFORMAT_16B_EXTENDED (SPI_I2SCFGR_CHLEN)
  174. #define I2S_DATAFORMAT_24B ((SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_0))
  175. #define I2S_DATAFORMAT_32B ((SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_1))
  176. /**
  177. * @}
  178. */
  179. /** @defgroup I2S_MCLK_Output I2S MCLK Output
  180. * @{
  181. */
  182. #define I2S_MCLKOUTPUT_ENABLE (SPI_I2SPR_MCKOE)
  183. #define I2S_MCLKOUTPUT_DISABLE (0x00000000U)
  184. /**
  185. * @}
  186. */
  187. /** @defgroup I2S_Audio_Frequency I2S Audio Frequency
  188. * @{
  189. */
  190. #define I2S_AUDIOFREQ_192K (192000U)
  191. #define I2S_AUDIOFREQ_96K (96000U)
  192. #define I2S_AUDIOFREQ_48K (48000U)
  193. #define I2S_AUDIOFREQ_44K (44100U)
  194. #define I2S_AUDIOFREQ_32K (32000U)
  195. #define I2S_AUDIOFREQ_22K (22050U)
  196. #define I2S_AUDIOFREQ_16K (16000U)
  197. #define I2S_AUDIOFREQ_11K (11025U)
  198. #define I2S_AUDIOFREQ_8K (8000U)
  199. #define I2S_AUDIOFREQ_DEFAULT (2U)
  200. /**
  201. * @}
  202. */
  203. /** @defgroup I2S_Clock_Polarity I2S Clock Polarity
  204. * @{
  205. */
  206. #define I2S_CPOL_LOW (0x00000000U)
  207. #define I2S_CPOL_HIGH (SPI_I2SCFGR_CKPOL)
  208. /**
  209. * @}
  210. */
  211. /** @defgroup I2S_Interrupts_Definition I2S Interrupts Definition
  212. * @{
  213. */
  214. #define I2S_IT_TXE SPI_CR2_TXEIE
  215. #define I2S_IT_RXNE SPI_CR2_RXNEIE
  216. #define I2S_IT_ERR SPI_CR2_ERRIE
  217. /**
  218. * @}
  219. */
  220. /** @defgroup I2S_Flags_Definition I2S Flags Definition
  221. * @{
  222. */
  223. #define I2S_FLAG_TXE SPI_SR_TXE
  224. #define I2S_FLAG_RXNE SPI_SR_RXNE
  225. #define I2S_FLAG_UDR SPI_SR_UDR
  226. #define I2S_FLAG_OVR SPI_SR_OVR
  227. #define I2S_FLAG_FRE SPI_SR_FRE
  228. #define I2S_FLAG_CHSIDE SPI_SR_CHSIDE
  229. #define I2S_FLAG_BSY SPI_SR_BSY
  230. #define I2S_FLAG_MASK (SPI_SR_RXNE\
  231. | SPI_SR_TXE | SPI_SR_UDR | SPI_SR_OVR | SPI_SR_CHSIDE | SPI_SR_BSY)
  232. /**
  233. * @}
  234. */
  235. /**
  236. * @}
  237. */
  238. /* Exported macros -----------------------------------------------------------*/
  239. /** @defgroup I2S_Exported_macros I2S Exported Macros
  240. * @{
  241. */
  242. /** @brief Reset I2S handle state
  243. * @param __HANDLE__ specifies the I2S Handle.
  244. * @retval None
  245. */
  246. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1U)
  247. #define __HAL_I2S_RESET_HANDLE_STATE(__HANDLE__) do{ \
  248. (__HANDLE__)->State = HAL_I2S_STATE_RESET; \
  249. (__HANDLE__)->MspInitCallback = NULL; \
  250. (__HANDLE__)->MspDeInitCallback = NULL; \
  251. } while(0)
  252. #else
  253. #define __HAL_I2S_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2S_STATE_RESET)
  254. #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
  255. /** @brief Enable the specified SPI peripheral (in I2S mode).
  256. * @param __HANDLE__ specifies the I2S Handle.
  257. * @retval None
  258. */
  259. #define __HAL_I2S_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->I2SCFGR, SPI_I2SCFGR_I2SE))
  260. /** @brief Disable the specified SPI peripheral (in I2S mode).
  261. * @param __HANDLE__ specifies the I2S Handle.
  262. * @retval None
  263. */
  264. #define __HAL_I2S_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->I2SCFGR, SPI_I2SCFGR_I2SE))
  265. /** @brief Enable the specified I2S interrupts.
  266. * @param __HANDLE__ specifies the I2S Handle.
  267. * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
  268. * This parameter can be one of the following values:
  269. * @arg I2S_IT_TXE: Tx buffer empty interrupt enable
  270. * @arg I2S_IT_RXNE: RX buffer not empty interrupt enable
  271. * @arg I2S_IT_ERR: Error interrupt enable
  272. * @retval None
  273. */
  274. #define __HAL_I2S_ENABLE_IT(__HANDLE__, __INTERRUPT__) (SET_BIT((__HANDLE__)->Instance->CR2,(__INTERRUPT__)))
  275. /** @brief Disable the specified I2S interrupts.
  276. * @param __HANDLE__ specifies the I2S Handle.
  277. * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
  278. * This parameter can be one of the following values:
  279. * @arg I2S_IT_TXE: Tx buffer empty interrupt enable
  280. * @arg I2S_IT_RXNE: RX buffer not empty interrupt enable
  281. * @arg I2S_IT_ERR: Error interrupt enable
  282. * @retval None
  283. */
  284. #define __HAL_I2S_DISABLE_IT(__HANDLE__, __INTERRUPT__) (CLEAR_BIT((__HANDLE__)->Instance->CR2,(__INTERRUPT__)))
  285. /** @brief Checks if the specified I2S interrupt source is enabled or disabled.
  286. * @param __HANDLE__ specifies the I2S Handle.
  287. * This parameter can be I2S where x: 1, 2, or 3 to select the I2S peripheral.
  288. * @param __INTERRUPT__ specifies the I2S interrupt source to check.
  289. * This parameter can be one of the following values:
  290. * @arg I2S_IT_TXE: Tx buffer empty interrupt enable
  291. * @arg I2S_IT_RXNE: RX buffer not empty interrupt enable
  292. * @arg I2S_IT_ERR: Error interrupt enable
  293. * @retval The new state of __IT__ (TRUE or FALSE).
  294. */
  295. #define __HAL_I2S_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2\
  296. & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  297. /** @brief Checks whether the specified I2S flag is set or not.
  298. * @param __HANDLE__ specifies the I2S Handle.
  299. * @param __FLAG__ specifies the flag to check.
  300. * This parameter can be one of the following values:
  301. * @arg I2S_FLAG_RXNE: Receive buffer not empty flag
  302. * @arg I2S_FLAG_TXE: Transmit buffer empty flag
  303. * @arg I2S_FLAG_UDR: Underrun flag
  304. * @arg I2S_FLAG_OVR: Overrun flag
  305. * @arg I2S_FLAG_FRE: Frame error flag
  306. * @arg I2S_FLAG_CHSIDE: Channel Side flag
  307. * @arg I2S_FLAG_BSY: Busy flag
  308. * @retval The new state of __FLAG__ (TRUE or FALSE).
  309. */
  310. #define __HAL_I2S_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
  311. /** @brief Clears the I2S OVR pending flag.
  312. * @param __HANDLE__ specifies the I2S Handle.
  313. * @retval None
  314. */
  315. #define __HAL_I2S_CLEAR_OVRFLAG(__HANDLE__) do{ \
  316. __IO uint32_t tmpreg_ovr = 0x00U; \
  317. tmpreg_ovr = (__HANDLE__)->Instance->DR; \
  318. tmpreg_ovr = (__HANDLE__)->Instance->SR; \
  319. UNUSED(tmpreg_ovr); \
  320. }while(0U)
  321. /** @brief Clears the I2S UDR pending flag.
  322. * @param __HANDLE__ specifies the I2S Handle.
  323. * @retval None
  324. */
  325. #define __HAL_I2S_CLEAR_UDRFLAG(__HANDLE__) do{\
  326. __IO uint32_t tmpreg_udr = 0x00U;\
  327. tmpreg_udr = ((__HANDLE__)->Instance->SR);\
  328. UNUSED(tmpreg_udr); \
  329. }while(0U)
  330. /** @brief Flush the I2S DR Register.
  331. * @param __HANDLE__ specifies the I2S Handle.
  332. * @retval None
  333. */
  334. #define __HAL_I2S_FLUSH_RX_DR(__HANDLE__) do{\
  335. __IO uint32_t tmpreg_dr = 0x00U;\
  336. tmpreg_dr = ((__HANDLE__)->Instance->DR);\
  337. UNUSED(tmpreg_dr); \
  338. }while(0U)
  339. /**
  340. * @}
  341. */
  342. /* Exported functions --------------------------------------------------------*/
  343. /** @addtogroup I2S_Exported_Functions
  344. * @{
  345. */
  346. /** @addtogroup I2S_Exported_Functions_Group1
  347. * @{
  348. */
  349. /* Initialization/de-initialization functions ********************************/
  350. HAL_StatusTypeDef HAL_I2S_Init(I2S_HandleTypeDef *hi2s);
  351. HAL_StatusTypeDef HAL_I2S_DeInit(I2S_HandleTypeDef *hi2s);
  352. void HAL_I2S_MspInit(I2S_HandleTypeDef *hi2s);
  353. void HAL_I2S_MspDeInit(I2S_HandleTypeDef *hi2s);
  354. /* Callbacks Register/UnRegister functions ***********************************/
  355. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1U)
  356. HAL_StatusTypeDef HAL_I2S_RegisterCallback(I2S_HandleTypeDef *hi2s, HAL_I2S_CallbackIDTypeDef CallbackID,
  357. pI2S_CallbackTypeDef pCallback);
  358. HAL_StatusTypeDef HAL_I2S_UnRegisterCallback(I2S_HandleTypeDef *hi2s, HAL_I2S_CallbackIDTypeDef CallbackID);
  359. #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
  360. /**
  361. * @}
  362. */
  363. /** @addtogroup I2S_Exported_Functions_Group2
  364. * @{
  365. */
  366. /* I/O operation functions ***************************************************/
  367. /* Blocking mode: Polling */
  368. HAL_StatusTypeDef HAL_I2S_Transmit(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size, uint32_t Timeout);
  369. HAL_StatusTypeDef HAL_I2S_Receive(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size, uint32_t Timeout);
  370. /* Non-Blocking mode: Interrupt */
  371. HAL_StatusTypeDef HAL_I2S_Transmit_IT(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size);
  372. HAL_StatusTypeDef HAL_I2S_Receive_IT(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size);
  373. void HAL_I2S_IRQHandler(I2S_HandleTypeDef *hi2s);
  374. /* Non-Blocking mode: DMA */
  375. HAL_StatusTypeDef HAL_I2S_Transmit_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size);
  376. HAL_StatusTypeDef HAL_I2S_Receive_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size);
  377. HAL_StatusTypeDef HAL_I2S_DMAPause(I2S_HandleTypeDef *hi2s);
  378. HAL_StatusTypeDef HAL_I2S_DMAResume(I2S_HandleTypeDef *hi2s);
  379. HAL_StatusTypeDef HAL_I2S_DMAStop(I2S_HandleTypeDef *hi2s);
  380. /* Callbacks used in non blocking modes (Interrupt and DMA) *******************/
  381. void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s);
  382. void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s);
  383. void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s);
  384. void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s);
  385. void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s);
  386. /**
  387. * @}
  388. */
  389. /** @addtogroup I2S_Exported_Functions_Group3
  390. * @{
  391. */
  392. /* Peripheral Control and State functions ************************************/
  393. HAL_I2S_StateTypeDef HAL_I2S_GetState(I2S_HandleTypeDef *hi2s);
  394. uint32_t HAL_I2S_GetError(I2S_HandleTypeDef *hi2s);
  395. /**
  396. * @}
  397. */
  398. /**
  399. * @}
  400. */
  401. /* Private types -------------------------------------------------------------*/
  402. /* Private variables ---------------------------------------------------------*/
  403. /* Private constants ---------------------------------------------------------*/
  404. /* Private macros ------------------------------------------------------------*/
  405. /** @defgroup I2S_Private_Macros I2S Private Macros
  406. * @{
  407. */
  408. /** @brief Check whether the specified SPI flag is set or not.
  409. * @param __SR__ copy of I2S SR register.
  410. * @param __FLAG__ specifies the flag to check.
  411. * This parameter can be one of the following values:
  412. * @arg I2S_FLAG_RXNE: Receive buffer not empty flag
  413. * @arg I2S_FLAG_TXE: Transmit buffer empty flag
  414. * @arg I2S_FLAG_UDR: Underrun error flag
  415. * @arg I2S_FLAG_OVR: Overrun flag
  416. * @arg I2S_FLAG_CHSIDE: Channel side flag
  417. * @arg I2S_FLAG_BSY: Busy flag
  418. * @retval SET or RESET.
  419. */
  420. #define I2S_CHECK_FLAG(__SR__, __FLAG__) ((((__SR__)\
  421. & ((__FLAG__) & I2S_FLAG_MASK)) == ((__FLAG__) & I2S_FLAG_MASK)) ? SET : RESET)
  422. /** @brief Check whether the specified SPI Interrupt is set or not.
  423. * @param __CR2__ copy of I2S CR2 register.
  424. * @param __INTERRUPT__ specifies the SPI interrupt source to check.
  425. * This parameter can be one of the following values:
  426. * @arg I2S_IT_TXE: Tx buffer empty interrupt enable
  427. * @arg I2S_IT_RXNE: RX buffer not empty interrupt enable
  428. * @arg I2S_IT_ERR: Error interrupt enable
  429. * @retval SET or RESET.
  430. */
  431. #define I2S_CHECK_IT_SOURCE(__CR2__, __INTERRUPT__) ((((__CR2__)\
  432. & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  433. /** @brief Checks if I2S Mode parameter is in allowed range.
  434. * @param __MODE__ specifies the I2S Mode.
  435. * This parameter can be a value of @ref I2S_Mode
  436. * @retval None
  437. */
  438. #define IS_I2S_MODE(__MODE__) (((__MODE__) == I2S_MODE_SLAVE_TX) || \
  439. ((__MODE__) == I2S_MODE_SLAVE_RX) || \
  440. ((__MODE__) == I2S_MODE_MASTER_TX) || \
  441. ((__MODE__) == I2S_MODE_MASTER_RX))
  442. #define IS_I2S_STANDARD(__STANDARD__) (((__STANDARD__) == I2S_STANDARD_PHILIPS) || \
  443. ((__STANDARD__) == I2S_STANDARD_MSB) || \
  444. ((__STANDARD__) == I2S_STANDARD_LSB) || \
  445. ((__STANDARD__) == I2S_STANDARD_PCM_SHORT) || \
  446. ((__STANDARD__) == I2S_STANDARD_PCM_LONG))
  447. #define IS_I2S_DATA_FORMAT(__FORMAT__) (((__FORMAT__) == I2S_DATAFORMAT_16B) || \
  448. ((__FORMAT__) == I2S_DATAFORMAT_16B_EXTENDED) || \
  449. ((__FORMAT__) == I2S_DATAFORMAT_24B) || \
  450. ((__FORMAT__) == I2S_DATAFORMAT_32B))
  451. #define IS_I2S_MCLK_OUTPUT(__OUTPUT__) (((__OUTPUT__) == I2S_MCLKOUTPUT_ENABLE) || \
  452. ((__OUTPUT__) == I2S_MCLKOUTPUT_DISABLE))
  453. #define IS_I2S_AUDIO_FREQ(__FREQ__) ((((__FREQ__) >= I2S_AUDIOFREQ_8K) && \
  454. ((__FREQ__) <= I2S_AUDIOFREQ_192K)) || \
  455. ((__FREQ__) == I2S_AUDIOFREQ_DEFAULT))
  456. /** @brief Checks if I2S Serial clock steady state parameter is in allowed range.
  457. * @param __CPOL__ specifies the I2S serial clock steady state.
  458. * This parameter can be a value of @ref I2S_Clock_Polarity
  459. * @retval None
  460. */
  461. #define IS_I2S_CPOL(__CPOL__) (((__CPOL__) == I2S_CPOL_LOW) || \
  462. ((__CPOL__) == I2S_CPOL_HIGH))
  463. /**
  464. * @}
  465. */
  466. /**
  467. * @}
  468. */
  469. /**
  470. * @}
  471. */
  472. #endif /* SPI_I2S_SUPPORT */
  473. #ifdef __cplusplus
  474. }
  475. #endif
  476. #endif /* STM32F1xx_HAL_I2S_H */