You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

630 lines
27 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_i2s.h
  4. * @author MCD Application Team
  5. * @brief Header file of I2S HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32H7xx_HAL_I2S_H
  21. #define STM32H7xx_HAL_I2S_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32h7xx_hal_def.h"
  27. /** @addtogroup STM32H7xx_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. uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
  55. This parameter can be a value of @ref I2S_MSB_LSB_transmission */
  56. uint32_t WSInversion; /*!< Control the Word Select Inversion.
  57. This parameter can be a value of @ref I2S_WSInversion */
  58. uint32_t Data24BitAlignment; /*!< Specifies the Data Padding for 24 bits data length
  59. This parameter can be a value of @ref I2S_Data_24Bit_Alignment */
  60. uint32_t MasterKeepIOState; /*!< Control of Alternate function GPIOs state
  61. This parameter can be a value of @ref SPI_Master_Keep_IO_State */
  62. } I2S_InitTypeDef;
  63. /**
  64. * @brief HAL State structures definition
  65. */
  66. typedef enum
  67. {
  68. HAL_I2S_STATE_RESET = 0x00UL, /*!< I2S not yet initialized or disabled */
  69. HAL_I2S_STATE_READY = 0x01UL, /*!< I2S initialized and ready for use */
  70. HAL_I2S_STATE_BUSY = 0x02UL, /*!< I2S internal process is ongoing */
  71. HAL_I2S_STATE_BUSY_TX = 0x03UL, /*!< Data Transmission process is ongoing */
  72. HAL_I2S_STATE_BUSY_RX = 0x04UL, /*!< Data Reception process is ongoing */
  73. HAL_I2S_STATE_TIMEOUT = 0x06UL, /*!< I2S timeout state */
  74. HAL_I2S_STATE_ERROR = 0x07UL /*!< I2S error state */
  75. } HAL_I2S_StateTypeDef;
  76. /**
  77. * @brief I2S handle Structure definition
  78. */
  79. typedef struct __I2S_HandleTypeDef
  80. {
  81. SPI_TypeDef *Instance; /*!< I2S registers base address */
  82. I2S_InitTypeDef Init; /*!< I2S communication parameters */
  83. uint16_t *pTxBuffPtr; /*!< Pointer to I2S Tx transfer buffer */
  84. __IO uint16_t TxXferSize; /*!< I2S Tx transfer size */
  85. __IO uint16_t TxXferCount; /*!< I2S Tx transfer Counter */
  86. uint16_t *pRxBuffPtr; /*!< Pointer to I2S Rx transfer buffer */
  87. __IO uint16_t RxXferSize; /*!< I2S Rx transfer size */
  88. __IO uint16_t RxXferCount; /*!< I2S Rx transfer counter
  89. (This field is initialized at the
  90. same value as transfer size at the
  91. beginning of the transfer and
  92. decremented when a sample is received
  93. NbSamplesReceived = RxBufferSize-RxBufferCount) */
  94. void (*RxISR)(struct __I2S_HandleTypeDef *hi2s); /*!< function pointer on Rx ISR */
  95. void (*TxISR)(struct __I2S_HandleTypeDef *hi2s); /*!< function pointer on Tx ISR */
  96. DMA_HandleTypeDef *hdmatx; /*!< I2S Tx DMA handle parameters */
  97. DMA_HandleTypeDef *hdmarx; /*!< I2S Rx DMA handle parameters */
  98. __IO HAL_LockTypeDef Lock; /*!< I2S locking object */
  99. __IO HAL_I2S_StateTypeDef State; /*!< I2S communication state */
  100. __IO uint32_t ErrorCode; /*!< I2S Error code
  101. This parameter can be a value of @ref I2S_Error */
  102. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1U)
  103. void (* TxCpltCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Tx Completed callback */
  104. void (* RxCpltCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Rx Completed callback */
  105. void (* TxHalfCpltCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Tx Half Completed callback */
  106. void (* RxHalfCpltCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Rx Half Completed callback */
  107. void (* ErrorCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Error callback */
  108. void (* MspInitCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Msp Init callback */
  109. void (* MspDeInitCallback)(struct __I2S_HandleTypeDef *hi2s); /*!< I2S Msp DeInit callback */
  110. #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
  111. } I2S_HandleTypeDef;
  112. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
  113. /**
  114. * @brief HAL I2S Callback ID enumeration definition
  115. */
  116. typedef enum
  117. {
  118. HAL_I2S_TX_COMPLETE_CB_ID = 0x00UL, /*!< I2S Tx Completed callback ID */
  119. HAL_I2S_RX_COMPLETE_CB_ID = 0x01UL, /*!< I2S Rx Completed callback ID */
  120. HAL_I2S_TX_HALF_COMPLETE_CB_ID = 0x03UL, /*!< I2S Tx Half Completed callback ID */
  121. HAL_I2S_RX_HALF_COMPLETE_CB_ID = 0x04UL, /*!< I2S Rx Half Completed callback ID */
  122. HAL_I2S_ERROR_CB_ID = 0x06UL, /*!< I2S Error callback ID */
  123. HAL_I2S_MSPINIT_CB_ID = 0x07UL, /*!< I2S Msp Init callback ID */
  124. HAL_I2S_MSPDEINIT_CB_ID = 0x08UL /*!< I2S Msp DeInit callback ID */
  125. } HAL_I2S_CallbackIDTypeDef;
  126. /**
  127. * @brief HAL I2S Callback pointer definition
  128. */
  129. typedef void (*pI2S_CallbackTypeDef)(I2S_HandleTypeDef *hi2s); /*!< pointer to an I2S callback function */
  130. #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
  131. /**
  132. * @}
  133. */
  134. /* Exported constants --------------------------------------------------------*/
  135. /** @defgroup I2S_Exported_Constants I2S Exported Constants
  136. * @{
  137. */
  138. /** @defgroup I2S_Error I2S Error
  139. * @{
  140. */
  141. #define HAL_I2S_ERROR_NONE (0x00000000UL) /*!< No error */
  142. #define HAL_I2S_ERROR_TIMEOUT (0x00000001UL) /*!< Timeout error */
  143. #define HAL_I2S_ERROR_OVR (0x00000002UL) /*!< OVR error */
  144. #define HAL_I2S_ERROR_UDR (0x00000004UL) /*!< UDR error */
  145. #define HAL_I2S_ERROR_DMA (0x00000008UL) /*!< DMA transfer error */
  146. #define HAL_I2S_ERROR_PRESCALER (0x00000010UL) /*!< Prescaler Calculation error */
  147. #define HAL_I2S_ERROR_FRE (0x00000020UL) /*!< FRE error */
  148. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
  149. #define HAL_I2S_ERROR_INVALID_CALLBACK (0x00000040UL) /*!< Invalid Callback error */
  150. #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
  151. /**
  152. * @}
  153. */
  154. /** @defgroup I2S_Mode I2S Mode
  155. * @{
  156. */
  157. #define I2S_MODE_SLAVE_TX (0x00000000UL)
  158. #define I2S_MODE_SLAVE_RX (SPI_I2SCFGR_I2SCFG_0)
  159. #define I2S_MODE_MASTER_TX (SPI_I2SCFGR_I2SCFG_1)
  160. #define I2S_MODE_MASTER_RX (SPI_I2SCFGR_I2SCFG_0 | SPI_I2SCFGR_I2SCFG_1)
  161. #define I2S_MODE_SLAVE_FULLDUPLEX (SPI_I2SCFGR_I2SCFG_2)
  162. #define I2S_MODE_MASTER_FULLDUPLEX (SPI_I2SCFGR_I2SCFG_2 | SPI_I2SCFGR_I2SCFG_0)
  163. /**
  164. * @}
  165. */
  166. /** @defgroup I2S_Standard I2S Standard
  167. * @{
  168. */
  169. #define I2S_STANDARD_PHILIPS (0x00000000UL)
  170. #define I2S_STANDARD_MSB (SPI_I2SCFGR_I2SSTD_0)
  171. #define I2S_STANDARD_LSB (SPI_I2SCFGR_I2SSTD_1)
  172. #define I2S_STANDARD_PCM_SHORT (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1)
  173. #define I2S_STANDARD_PCM_LONG (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1 | SPI_I2SCFGR_PCMSYNC)
  174. /**
  175. * @}
  176. */
  177. /** @defgroup I2S_Data_Format I2S Data Format
  178. * @{
  179. */
  180. #define I2S_DATAFORMAT_16B (0x00000000UL)
  181. #define I2S_DATAFORMAT_16B_EXTENDED (SPI_I2SCFGR_CHLEN)
  182. #define I2S_DATAFORMAT_24B (SPI_I2SCFGR_DATLEN_0)
  183. #define I2S_DATAFORMAT_32B (SPI_I2SCFGR_DATLEN_1)
  184. /**
  185. * @}
  186. */
  187. /** @defgroup I2S_MCLK_Output I2S MCLK Output
  188. * @{
  189. */
  190. #define I2S_MCLKOUTPUT_ENABLE (SPI_I2SCFGR_MCKOE)
  191. #define I2S_MCLKOUTPUT_DISABLE (0x00000000UL)
  192. /**
  193. * @}
  194. */
  195. /** @defgroup I2S_Audio_Frequency I2S Audio Frequency
  196. * @{
  197. */
  198. #define I2S_AUDIOFREQ_192K (192000UL)
  199. #define I2S_AUDIOFREQ_96K (96000UL)
  200. #define I2S_AUDIOFREQ_48K (48000UL)
  201. #define I2S_AUDIOFREQ_44K (44100UL)
  202. #define I2S_AUDIOFREQ_32K (32000UL)
  203. #define I2S_AUDIOFREQ_22K (22050UL)
  204. #define I2S_AUDIOFREQ_16K (16000UL)
  205. #define I2S_AUDIOFREQ_11K (11025UL)
  206. #define I2S_AUDIOFREQ_8K (8000UL)
  207. #define I2S_AUDIOFREQ_DEFAULT (2UL)
  208. /**
  209. * @}
  210. */
  211. /** @defgroup I2S_FullDuplex_Mode I2S FullDuplex Mode
  212. * @{
  213. */
  214. #define I2S_CPOL_LOW (0x00000000UL)
  215. #define I2S_CPOL_HIGH (SPI_I2SCFGR_CKPOL)
  216. /**
  217. * @}
  218. */
  219. /** @defgroup I2S_MSB_LSB_Transmission I2S MSB LSB Transmission
  220. * @{
  221. */
  222. #define I2S_FIRSTBIT_MSB (0x00000000UL)
  223. #define I2S_FIRSTBIT_LSB SPI_CFG2_LSBFRST
  224. /**
  225. * @}
  226. */
  227. /** @defgroup I2S_WSInversion I2S Word Select Inversion
  228. * @{
  229. */
  230. #define I2S_WS_INVERSION_DISABLE (0x00000000UL)
  231. #define I2S_WS_INVERSION_ENABLE SPI_I2SCFGR_WSINV
  232. /**
  233. * @}
  234. */
  235. /** @defgroup I2S_Data_24Bit_Alignment Data Padding 24Bit
  236. * @{
  237. */
  238. #define I2S_DATA_24BIT_ALIGNMENT_RIGHT (0x00000000UL)
  239. #define I2S_DATA_24BIT_ALIGNMENT_LEFT SPI_I2SCFGR_DATFMT
  240. /**
  241. * @}
  242. */
  243. /** @defgroup I2S_Master_Keep_IO_State Keep IO State
  244. * @{
  245. */
  246. #define I2S_MASTER_KEEP_IO_STATE_DISABLE (0x00000000U)
  247. #define I2S_MASTER_KEEP_IO_STATE_ENABLE SPI_CFG2_AFCNTR
  248. /**
  249. * @}
  250. */
  251. /** @defgroup I2S_Interrupts_Definition I2S Interrupts Definition
  252. * @{
  253. */
  254. #define I2S_IT_RXP SPI_IER_RXPIE
  255. #define I2S_IT_TXP SPI_IER_TXPIE
  256. #define I2S_IT_UDR SPI_IER_UDRIE
  257. #define I2S_IT_OVR SPI_IER_OVRIE
  258. #define I2S_IT_FRE SPI_IER_TIFREIE
  259. #define I2S_IT_ERR (SPI_IER_UDRIE | SPI_IER_OVRIE | SPI_IER_TIFREIE)
  260. /**
  261. * @}
  262. */
  263. /** @defgroup I2S_Flags_Definition I2S Flags Definition
  264. * @{
  265. */
  266. #define I2S_FLAG_RXP SPI_SR_RXP /* I2S status flag : Rx-Packet available flag */
  267. #define I2S_FLAG_TXP SPI_SR_TXP /* I2S status flag : Tx-Packet space available flag */
  268. #define I2S_FLAG_UDR SPI_SR_UDR /* I2S Error flag : Underrun flag */
  269. #define I2S_FLAG_OVR SPI_SR_OVR /* I2S Error flag : Overrun flag */
  270. #define I2S_FLAG_FRE SPI_SR_TIFRE /* I2S Error flag : TI mode frame format error flag */
  271. #define I2S_FLAG_MASK (SPI_SR_RXP | SPI_SR_TXP | SPI_SR_UDR | SPI_SR_OVR | SPI_SR_TIFRE)
  272. /**
  273. * @}
  274. */
  275. /**
  276. * @}
  277. */
  278. /* Exported macros -----------------------------------------------------------*/
  279. /** @defgroup I2S_Exported_macros I2S Exported Macros
  280. * @{
  281. */
  282. /** @brief Reset I2S handle state
  283. * @param __HANDLE__ specifies the I2S Handle.
  284. * @retval None
  285. */
  286. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
  287. #define __HAL_I2S_RESET_HANDLE_STATE(__HANDLE__) do{ \
  288. (__HANDLE__)->State = HAL_I2S_STATE_RESET; \
  289. (__HANDLE__)->MspInitCallback = NULL; \
  290. (__HANDLE__)->MspDeInitCallback = NULL; \
  291. } while(0)
  292. #else
  293. #define __HAL_I2S_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2S_STATE_RESET)
  294. #endif
  295. /** @brief Enable the specified SPI peripheral (in I2S mode).
  296. * @param __HANDLE__ specifies the I2S Handle.
  297. * @retval None
  298. */
  299. #define __HAL_I2S_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE))
  300. /** @brief Disable the specified SPI peripheral (in I2S mode).
  301. * @param __HANDLE__ specifies the I2S Handle.
  302. * @retval None
  303. */
  304. #define __HAL_I2S_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE))
  305. /** @brief Enable the specified I2S interrupts.
  306. * @param __HANDLE__ specifies the I2S Handle.
  307. * This parameter can be I2S where x: 1, 2 or 3 to select the I2S peripheral.
  308. * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
  309. * This parameter can be one of the following values:
  310. * @arg I2S_IT_RXP : Rx-Packet available interrupt
  311. * @arg I2S_IT_TXP : Tx-Packet space available interrupt
  312. * @arg I2S_IT_UDR : Underrun interrupt
  313. * @arg I2S_IT_OVR : Overrun interrupt
  314. * @arg I2S_IT_FRE : TI mode frame format error interrupt
  315. * @arg I2S_IT_ERR : Error interrupt enable
  316. * @retval None
  317. */
  318. #define __HAL_I2S_ENABLE_IT(__HANDLE__, __INTERRUPT__) (SET_BIT((__HANDLE__)->Instance->IER,(__INTERRUPT__)))
  319. /** @brief Disable the specified I2S interrupts.
  320. * @param __HANDLE__ specifies the I2S Handle.
  321. * This parameter can be I2S where x: 1, 2 or 3 to select the I2S peripheral.
  322. * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
  323. * This parameter can be one of the following values:
  324. * @arg I2S_IT_RXP : Rx-Packet available interrupt
  325. * @arg I2S_IT_TXP : Tx-Packet space available interrupt
  326. * @arg I2S_IT_UDR : Underrun interrupt
  327. * @arg I2S_IT_OVR : Overrun interrupt
  328. * @arg I2S_IT_FRE : TI mode frame format error interrupt
  329. * @arg I2S_IT_ERR : Error interrupt enable
  330. * @retval None
  331. */
  332. #define __HAL_I2S_DISABLE_IT(__HANDLE__, __INTERRUPT__) (CLEAR_BIT((__HANDLE__)->Instance->IER,(__INTERRUPT__)))
  333. /** @brief Check if the specified I2S interrupt source is enabled or disabled.
  334. * @param __HANDLE__ specifies the I2S Handle.
  335. * This parameter can be I2S where x: 1, 2 or 3 to select the I2S peripheral.
  336. * @param __INTERRUPT__ specifies the I2S interrupt source to check.
  337. * This parameter can be one of the following values:
  338. * @arg I2S_IT_RXP : Rx-Packet available interrupt
  339. * @arg I2S_IT_TXP : Tx-Packet space available interrupt
  340. * @arg I2S_IT_UDR : Underrun interrupt
  341. * @arg I2S_IT_OVR : Overrun interrupt
  342. * @arg I2S_IT_FRE : TI mode frame format error interrupt
  343. * @arg I2S_IT_ERR : Error interrupt enable
  344. * @retval The new state of __IT__ (TRUE or FALSE).
  345. */
  346. #define __HAL_I2S_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  347. /** @brief Check whether the specified I2S flag is set or not.
  348. * @param __HANDLE__ specifies the I2S Handle.
  349. * This parameter can be I2S where x: 1, 2 or 3 to select the I2S peripheral.
  350. * @param __FLAG__ specifies the flag to check.
  351. * This parameter can be one of the following values:
  352. * @arg I2S_FLAG_RXP : Rx-Packet available flag
  353. * @arg I2S_FLAG_TXP : Tx-Packet space available flag
  354. * @arg I2S_FLAG_UDR : Underrun flag
  355. * @arg I2S_FLAG_OVR : Overrun flag
  356. * @arg I2S_FLAG_FRE : TI mode frame format error flag
  357. * @retval The new state of __FLAG__ (TRUE or FALSE).
  358. */
  359. #define __HAL_I2S_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
  360. /** @brief Clear the I2S OVR pending flag.
  361. * @param __HANDLE__ specifies the I2S Handle.
  362. * @retval None
  363. */
  364. #define __HAL_I2S_CLEAR_OVRFLAG(__HANDLE__) SET_BIT((__HANDLE__)->Instance->IFCR , SPI_IFCR_OVRC)
  365. /** @brief Clear the I2S UDR pending flag.
  366. * @param __HANDLE__ specifies the I2S Handle.
  367. * @retval None
  368. */
  369. #define __HAL_I2S_CLEAR_UDRFLAG(__HANDLE__) SET_BIT((__HANDLE__)->Instance->IFCR , SPI_IFCR_UDRC)
  370. /** @brief Clear the I2S FRE pending flag.
  371. * @param __HANDLE__: specifies the I2S Handle.
  372. * @retval None
  373. */
  374. #define __HAL_I2S_CLEAR_TIFREFLAG(__HANDLE__) SET_BIT((__HANDLE__)->Instance->IFCR , SPI_IFCR_TIFREC)
  375. /**
  376. * @}
  377. */
  378. /* Exported functions --------------------------------------------------------*/
  379. /** @addtogroup I2S_Exported_Functions
  380. * @{
  381. */
  382. /** @addtogroup I2S_Exported_Functions_Group1
  383. * @{
  384. */
  385. /* Initialization/de-initialization functions ********************************/
  386. HAL_StatusTypeDef HAL_I2S_Init(I2S_HandleTypeDef *hi2s);
  387. HAL_StatusTypeDef HAL_I2S_DeInit(I2S_HandleTypeDef *hi2s);
  388. void HAL_I2S_MspInit(I2S_HandleTypeDef *hi2s);
  389. void HAL_I2S_MspDeInit(I2S_HandleTypeDef *hi2s);
  390. /* Callbacks Register/UnRegister functions ***********************************/
  391. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
  392. HAL_StatusTypeDef HAL_I2S_RegisterCallback(I2S_HandleTypeDef *hi2s, HAL_I2S_CallbackIDTypeDef CallbackID, pI2S_CallbackTypeDef pCallback);
  393. HAL_StatusTypeDef HAL_I2S_UnRegisterCallback(I2S_HandleTypeDef *hi2s, HAL_I2S_CallbackIDTypeDef CallbackID);
  394. #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
  395. /**
  396. * @}
  397. */
  398. /** @addtogroup I2S_Exported_Functions_Group2
  399. * @{
  400. */
  401. /* I/O operation functions ***************************************************/
  402. /* Blocking mode: Polling */
  403. HAL_StatusTypeDef HAL_I2S_Transmit(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size, uint32_t Timeout);
  404. HAL_StatusTypeDef HAL_I2S_Receive(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size, uint32_t Timeout);
  405. /* Non-Blocking mode: Interrupt */
  406. HAL_StatusTypeDef HAL_I2S_Transmit_IT(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size);
  407. HAL_StatusTypeDef HAL_I2S_Receive_IT(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size);
  408. void HAL_I2S_IRQHandler(I2S_HandleTypeDef *hi2s);
  409. /* Non-Blocking mode: DMA */
  410. HAL_StatusTypeDef HAL_I2S_Transmit_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size);
  411. HAL_StatusTypeDef HAL_I2S_Receive_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size);
  412. HAL_StatusTypeDef HAL_I2S_DMAPause(I2S_HandleTypeDef *hi2s);
  413. HAL_StatusTypeDef HAL_I2S_DMAResume(I2S_HandleTypeDef *hi2s);
  414. HAL_StatusTypeDef HAL_I2S_DMAStop(I2S_HandleTypeDef *hi2s);
  415. /* Callbacks used in non blocking modes (Interrupt and DMA) *******************/
  416. void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s);
  417. void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s);
  418. void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s);
  419. void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s);
  420. void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s);
  421. /**
  422. * @}
  423. */
  424. /** @addtogroup I2S_Exported_Functions_Group3
  425. * @{
  426. */
  427. /* Peripheral Control and State functions ************************************/
  428. HAL_I2S_StateTypeDef HAL_I2S_GetState(I2S_HandleTypeDef *hi2s);
  429. uint32_t HAL_I2S_GetError(I2S_HandleTypeDef *hi2s);
  430. /**
  431. * @}
  432. */
  433. /**
  434. * @}
  435. */
  436. /* Private types -------------------------------------------------------------*/
  437. /* Private variables ---------------------------------------------------------*/
  438. /* Private constants ---------------------------------------------------------*/
  439. /** @defgroup I2S_Private_Constants I2S Private Constants
  440. * @{
  441. */
  442. /**
  443. * @}
  444. */
  445. /* Private macros ------------------------------------------------------------*/
  446. /** @defgroup I2S_Private_Macros I2S Private Macros
  447. * @{
  448. */
  449. /** @brief Check whether the specified SPI flag is set or not.
  450. * @param __SR__ copy of I2S SR register.
  451. * @param __FLAG__ specifies the flag to check.
  452. * This parameter can be one of the following values:
  453. * @arg I2S_FLAG_RXP : Rx-Packet available flag
  454. * @arg I2S_FLAG_TXP : Tx-Packet space available flag
  455. * @arg I2S_FLAG_UDR : Underrun flag
  456. * @arg I2S_FLAG_OVR : Overrun flag
  457. * @arg I2S_FLAG_FRE : TI mode frame format error flag
  458. * @retval SET or RESET.
  459. */
  460. #define I2S_CHECK_FLAG(__SR__, __FLAG__) ((((__SR__) & ((__FLAG__) & I2S_FLAG_MASK)) == ((__FLAG__) & I2S_FLAG_MASK)) ? SET : RESET)
  461. /** @brief Check whether the specified SPI Interrupt is set or not.
  462. * @param __IER__ copy of I2S IER register.
  463. * @param __INTERRUPT__ specifies the SPI interrupt source to check.
  464. * This parameter can be one of the following values:
  465. * @arg I2S_IT_RXP : Rx-Packet available interrupt
  466. * @arg I2S_IT_TXP : Tx-Packet space available interrupt
  467. * @arg I2S_IT_UDR : Underrun interrupt
  468. * @arg I2S_IT_OVR : Overrun interrupt
  469. * @arg I2S_IT_FRE : TI mode frame format error interrupt
  470. * @arg I2S_IT_ERR : Error interrupt enable
  471. * @retval SET or RESET.
  472. */
  473. #define I2S_CHECK_IT_SOURCE(__IER__, __INTERRUPT__) ((((__IER__) & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  474. /** @brief Checks if I2S Mode parameter is in allowed range.
  475. * @param __MODE__ specifies the I2S Mode.
  476. * This parameter can be a value of @ref I2S_Mode
  477. * @retval None
  478. */
  479. #define IS_I2S_MODE(__MODE__) (((__MODE__) == I2S_MODE_SLAVE_TX) || \
  480. ((__MODE__) == I2S_MODE_SLAVE_RX) || \
  481. ((__MODE__) == I2S_MODE_MASTER_TX) || \
  482. ((__MODE__) == I2S_MODE_MASTER_RX) || \
  483. ((__MODE__) == I2S_MODE_SLAVE_FULLDUPLEX) || \
  484. ((__MODE__) == I2S_MODE_MASTER_FULLDUPLEX))
  485. #define IS_I2S_MASTER(__MODE__) (((__MODE__) == I2S_MODE_MASTER_TX) || \
  486. ((__MODE__) == I2S_MODE_MASTER_RX) || \
  487. ((__MODE__) == I2S_MODE_MASTER_FULLDUPLEX))
  488. #define IS_I2S_SLAVE(__MODE__) (((__MODE__) == I2S_MODE_SLAVE_TX) || \
  489. ((__MODE__) == I2S_MODE_SLAVE_RX) || \
  490. ((__MODE__) == I2S_MODE_SLAVE_FULLDUPLEX))
  491. #define IS_I2S_STANDARD(__STANDARD__) (((__STANDARD__) == I2S_STANDARD_PHILIPS) || \
  492. ((__STANDARD__) == I2S_STANDARD_MSB) || \
  493. ((__STANDARD__) == I2S_STANDARD_LSB) || \
  494. ((__STANDARD__) == I2S_STANDARD_PCM_SHORT) || \
  495. ((__STANDARD__) == I2S_STANDARD_PCM_LONG))
  496. #define IS_I2S_DATA_FORMAT(__FORMAT__) (((__FORMAT__) == I2S_DATAFORMAT_16B) || \
  497. ((__FORMAT__) == I2S_DATAFORMAT_16B_EXTENDED) || \
  498. ((__FORMAT__) == I2S_DATAFORMAT_24B) || \
  499. ((__FORMAT__) == I2S_DATAFORMAT_32B))
  500. #define IS_I2S_MCLK_OUTPUT(__OUTPUT__) (((__OUTPUT__) == I2S_MCLKOUTPUT_ENABLE) || \
  501. ((__OUTPUT__) == I2S_MCLKOUTPUT_DISABLE))
  502. #define IS_I2S_AUDIO_FREQ(__FREQ__) ((((__FREQ__) >= I2S_AUDIOFREQ_8K) && \
  503. ((__FREQ__) <= I2S_AUDIOFREQ_192K)) || \
  504. ((__FREQ__) == I2S_AUDIOFREQ_DEFAULT))
  505. #define IS_I2S_CPOL(__CPOL__) (((__CPOL__) == I2S_CPOL_LOW) || \
  506. ((__CPOL__) == I2S_CPOL_HIGH))
  507. #define IS_I2S_FIRST_BIT(__BIT__) (((__BIT__) == I2S_FIRSTBIT_MSB) || \
  508. ((__BIT__) == I2S_FIRSTBIT_LSB))
  509. #define IS_I2S_WS_INVERSION(__WSINV__) (((__WSINV__) == I2S_WS_INVERSION_DISABLE) || \
  510. ((__WSINV__) == I2S_WS_INVERSION_ENABLE))
  511. #define IS_I2S_DATA_24BIT_ALIGNMENT(__ALIGNMENT__) (((__ALIGNMENT__) == I2S_DATA_24BIT_ALIGNMENT_RIGHT) || \
  512. ((__ALIGNMENT__) == I2S_DATA_24BIT_ALIGNMENT_LEFT))
  513. #define IS_I2S_MASTER_KEEP_IO_STATE(__AFCNTR__) (((__AFCNTR__) == I2S_MASTER_KEEP_IO_STATE_DISABLE) || \
  514. ((__AFCNTR__) == I2S_MASTER_KEEP_IO_STATE_ENABLE))
  515. /**
  516. * @}
  517. */
  518. /**
  519. * @}
  520. */
  521. /**
  522. * @}
  523. */
  524. #ifdef __cplusplus
  525. }
  526. #endif
  527. #endif /* STM32H7xx_HAL_I2S_H */
  528. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/