训练营PLSR题目
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

619 行
27 KiB

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