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.
 
 
 

632 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. #define HAL_I2S_ERROR_NO_OGT (0x00000040UL) /*!< No On Going Transfer error */
  149. #define HAL_I2S_ERROR_NOT_SUPPORTED (0x00000080UL) /*!< Requested operation not supported */
  150. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
  151. #define HAL_I2S_ERROR_INVALID_CALLBACK (0x00000100UL) /*!< Invalid Callback error */
  152. #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
  153. /**
  154. * @}
  155. */
  156. /** @defgroup I2S_Mode I2S Mode
  157. * @{
  158. */
  159. #define I2S_MODE_SLAVE_TX (0x00000000UL)
  160. #define I2S_MODE_SLAVE_RX (SPI_I2SCFGR_I2SCFG_0)
  161. #define I2S_MODE_MASTER_TX (SPI_I2SCFGR_I2SCFG_1)
  162. #define I2S_MODE_MASTER_RX (SPI_I2SCFGR_I2SCFG_0 | SPI_I2SCFGR_I2SCFG_1)
  163. #define I2S_MODE_SLAVE_FULLDUPLEX (SPI_I2SCFGR_I2SCFG_2)
  164. #define I2S_MODE_MASTER_FULLDUPLEX (SPI_I2SCFGR_I2SCFG_2 | SPI_I2SCFGR_I2SCFG_0)
  165. /**
  166. * @}
  167. */
  168. /** @defgroup I2S_Standard I2S Standard
  169. * @{
  170. */
  171. #define I2S_STANDARD_PHILIPS (0x00000000UL)
  172. #define I2S_STANDARD_MSB (SPI_I2SCFGR_I2SSTD_0)
  173. #define I2S_STANDARD_LSB (SPI_I2SCFGR_I2SSTD_1)
  174. #define I2S_STANDARD_PCM_SHORT (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1)
  175. #define I2S_STANDARD_PCM_LONG (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1 | SPI_I2SCFGR_PCMSYNC)
  176. /**
  177. * @}
  178. */
  179. /** @defgroup I2S_Data_Format I2S Data Format
  180. * @{
  181. */
  182. #define I2S_DATAFORMAT_16B (0x00000000UL)
  183. #define I2S_DATAFORMAT_16B_EXTENDED (SPI_I2SCFGR_CHLEN)
  184. #define I2S_DATAFORMAT_24B (SPI_I2SCFGR_DATLEN_0)
  185. #define I2S_DATAFORMAT_32B (SPI_I2SCFGR_DATLEN_1)
  186. /**
  187. * @}
  188. */
  189. /** @defgroup I2S_MCLK_Output I2S MCLK Output
  190. * @{
  191. */
  192. #define I2S_MCLKOUTPUT_ENABLE (SPI_I2SCFGR_MCKOE)
  193. #define I2S_MCLKOUTPUT_DISABLE (0x00000000UL)
  194. /**
  195. * @}
  196. */
  197. /** @defgroup I2S_Audio_Frequency I2S Audio Frequency
  198. * @{
  199. */
  200. #define I2S_AUDIOFREQ_192K (192000UL)
  201. #define I2S_AUDIOFREQ_96K (96000UL)
  202. #define I2S_AUDIOFREQ_48K (48000UL)
  203. #define I2S_AUDIOFREQ_44K (44100UL)
  204. #define I2S_AUDIOFREQ_32K (32000UL)
  205. #define I2S_AUDIOFREQ_22K (22050UL)
  206. #define I2S_AUDIOFREQ_16K (16000UL)
  207. #define I2S_AUDIOFREQ_11K (11025UL)
  208. #define I2S_AUDIOFREQ_8K (8000UL)
  209. #define I2S_AUDIOFREQ_DEFAULT (2UL)
  210. /**
  211. * @}
  212. */
  213. /** @defgroup I2S_FullDuplex_Mode I2S FullDuplex Mode
  214. * @{
  215. */
  216. #define I2S_CPOL_LOW (0x00000000UL)
  217. #define I2S_CPOL_HIGH (SPI_I2SCFGR_CKPOL)
  218. /**
  219. * @}
  220. */
  221. /** @defgroup I2S_MSB_LSB_Transmission I2S MSB LSB Transmission
  222. * @{
  223. */
  224. #define I2S_FIRSTBIT_MSB (0x00000000UL)
  225. #define I2S_FIRSTBIT_LSB SPI_CFG2_LSBFRST
  226. /**
  227. * @}
  228. */
  229. /** @defgroup I2S_WSInversion I2S Word Select Inversion
  230. * @{
  231. */
  232. #define I2S_WS_INVERSION_DISABLE (0x00000000UL)
  233. #define I2S_WS_INVERSION_ENABLE SPI_I2SCFGR_WSINV
  234. /**
  235. * @}
  236. */
  237. /** @defgroup I2S_Data_24Bit_Alignment Data Padding 24Bit
  238. * @{
  239. */
  240. #define I2S_DATA_24BIT_ALIGNMENT_RIGHT (0x00000000UL)
  241. #define I2S_DATA_24BIT_ALIGNMENT_LEFT SPI_I2SCFGR_DATFMT
  242. /**
  243. * @}
  244. */
  245. /** @defgroup I2S_Master_Keep_IO_State Keep IO State
  246. * @{
  247. */
  248. #define I2S_MASTER_KEEP_IO_STATE_DISABLE (0x00000000U)
  249. #define I2S_MASTER_KEEP_IO_STATE_ENABLE SPI_CFG2_AFCNTR
  250. /**
  251. * @}
  252. */
  253. /** @defgroup I2S_Interrupts_Definition I2S Interrupts Definition
  254. * @{
  255. */
  256. #define I2S_IT_RXP SPI_IER_RXPIE
  257. #define I2S_IT_TXP SPI_IER_TXPIE
  258. #define I2S_IT_UDR SPI_IER_UDRIE
  259. #define I2S_IT_OVR SPI_IER_OVRIE
  260. #define I2S_IT_FRE SPI_IER_TIFREIE
  261. #define I2S_IT_ERR (SPI_IER_UDRIE | SPI_IER_OVRIE | SPI_IER_TIFREIE)
  262. /**
  263. * @}
  264. */
  265. /** @defgroup I2S_Flags_Definition I2S Flags Definition
  266. * @{
  267. */
  268. #define I2S_FLAG_RXP SPI_SR_RXP /* I2S status flag : Rx-Packet available flag */
  269. #define I2S_FLAG_TXP SPI_SR_TXP /* I2S status flag : Tx-Packet space available flag */
  270. #define I2S_FLAG_UDR SPI_SR_UDR /* I2S Error flag : Underrun flag */
  271. #define I2S_FLAG_OVR SPI_SR_OVR /* I2S Error flag : Overrun flag */
  272. #define I2S_FLAG_FRE SPI_SR_TIFRE /* I2S Error flag : TI mode frame format error flag */
  273. #define I2S_FLAG_MASK (SPI_SR_RXP | SPI_SR_TXP | SPI_SR_UDR | SPI_SR_OVR | SPI_SR_TIFRE)
  274. /**
  275. * @}
  276. */
  277. /**
  278. * @}
  279. */
  280. /* Exported macros -----------------------------------------------------------*/
  281. /** @defgroup I2S_Exported_macros I2S Exported Macros
  282. * @{
  283. */
  284. /** @brief Reset I2S handle state
  285. * @param __HANDLE__ specifies the I2S Handle.
  286. * @retval None
  287. */
  288. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
  289. #define __HAL_I2S_RESET_HANDLE_STATE(__HANDLE__) do{ \
  290. (__HANDLE__)->State = HAL_I2S_STATE_RESET; \
  291. (__HANDLE__)->MspInitCallback = NULL; \
  292. (__HANDLE__)->MspDeInitCallback = NULL; \
  293. } while(0)
  294. #else
  295. #define __HAL_I2S_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2S_STATE_RESET)
  296. #endif
  297. /** @brief Enable the specified SPI peripheral (in I2S mode).
  298. * @param __HANDLE__ specifies the I2S Handle.
  299. * @retval None
  300. */
  301. #define __HAL_I2S_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE))
  302. /** @brief Disable the specified SPI peripheral (in I2S mode).
  303. * @param __HANDLE__ specifies the I2S Handle.
  304. * @retval None
  305. */
  306. #define __HAL_I2S_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE))
  307. /** @brief Enable the specified I2S interrupts.
  308. * @param __HANDLE__ specifies the I2S Handle.
  309. * This parameter can be I2S where x: 1, 2 or 3 to select the I2S peripheral.
  310. * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
  311. * This parameter can be one of the following values:
  312. * @arg I2S_IT_RXP : Rx-Packet available interrupt
  313. * @arg I2S_IT_TXP : Tx-Packet space available interrupt
  314. * @arg I2S_IT_UDR : Underrun interrupt
  315. * @arg I2S_IT_OVR : Overrun interrupt
  316. * @arg I2S_IT_FRE : TI mode frame format error interrupt
  317. * @arg I2S_IT_ERR : Error interrupt enable
  318. * @retval None
  319. */
  320. #define __HAL_I2S_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER |= (__INTERRUPT__))
  321. /** @brief Disable the specified I2S interrupts.
  322. * @param __HANDLE__ specifies the I2S Handle.
  323. * This parameter can be I2S where x: 1, 2 or 3 to select the I2S peripheral.
  324. * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
  325. * This parameter can be one of the following values:
  326. * @arg I2S_IT_RXP : Rx-Packet available interrupt
  327. * @arg I2S_IT_TXP : Tx-Packet space available interrupt
  328. * @arg I2S_IT_UDR : Underrun interrupt
  329. * @arg I2S_IT_OVR : Overrun interrupt
  330. * @arg I2S_IT_FRE : TI mode frame format error interrupt
  331. * @arg I2S_IT_ERR : Error interrupt enable
  332. * @retval None
  333. */
  334. #define __HAL_I2S_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER &= (~(__INTERRUPT__)))
  335. /** @brief Check if the specified I2S interrupt source is enabled or disabled.
  336. * @param __HANDLE__ specifies the I2S Handle.
  337. * This parameter can be I2S where x: 1, 2 or 3 to select the I2S peripheral.
  338. * @param __INTERRUPT__ specifies the I2S interrupt source to check.
  339. * This parameter can be one of the following values:
  340. * @arg I2S_IT_RXP : Rx-Packet available interrupt
  341. * @arg I2S_IT_TXP : Tx-Packet space available interrupt
  342. * @arg I2S_IT_UDR : Underrun interrupt
  343. * @arg I2S_IT_OVR : Overrun interrupt
  344. * @arg I2S_IT_FRE : TI mode frame format error interrupt
  345. * @arg I2S_IT_ERR : Error interrupt enable
  346. * @retval The new state of __IT__ (TRUE or FALSE).
  347. */
  348. #define __HAL_I2S_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  349. /** @brief Check whether the specified I2S flag is set or not.
  350. * @param __HANDLE__ specifies the I2S Handle.
  351. * This parameter can be I2S where x: 1, 2 or 3 to select the I2S peripheral.
  352. * @param __FLAG__ specifies the flag to check.
  353. * This parameter can be one of the following values:
  354. * @arg I2S_FLAG_RXP : Rx-Packet available flag
  355. * @arg I2S_FLAG_TXP : Tx-Packet space available flag
  356. * @arg I2S_FLAG_UDR : Underrun flag
  357. * @arg I2S_FLAG_OVR : Overrun flag
  358. * @arg I2S_FLAG_FRE : TI mode frame format error flag
  359. * @retval The new state of __FLAG__ (TRUE or FALSE).
  360. */
  361. #define __HAL_I2S_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
  362. /** @brief Clear the I2S OVR pending flag.
  363. * @param __HANDLE__ specifies the I2S Handle.
  364. * @retval None
  365. */
  366. #define __HAL_I2S_CLEAR_OVRFLAG(__HANDLE__) SET_BIT((__HANDLE__)->Instance->IFCR , SPI_IFCR_OVRC)
  367. /** @brief Clear the I2S UDR pending flag.
  368. * @param __HANDLE__ specifies the I2S Handle.
  369. * @retval None
  370. */
  371. #define __HAL_I2S_CLEAR_UDRFLAG(__HANDLE__) SET_BIT((__HANDLE__)->Instance->IFCR , SPI_IFCR_UDRC)
  372. /** @brief Clear the I2S FRE pending flag.
  373. * @param __HANDLE__: specifies the I2S Handle.
  374. * @retval None
  375. */
  376. #define __HAL_I2S_CLEAR_TIFREFLAG(__HANDLE__) SET_BIT((__HANDLE__)->Instance->IFCR , SPI_IFCR_TIFREC)
  377. /**
  378. * @}
  379. */
  380. /* Exported functions --------------------------------------------------------*/
  381. /** @addtogroup I2S_Exported_Functions
  382. * @{
  383. */
  384. /** @addtogroup I2S_Exported_Functions_Group1
  385. * @{
  386. */
  387. /* Initialization/de-initialization functions ********************************/
  388. HAL_StatusTypeDef HAL_I2S_Init(I2S_HandleTypeDef *hi2s);
  389. HAL_StatusTypeDef HAL_I2S_DeInit(I2S_HandleTypeDef *hi2s);
  390. void HAL_I2S_MspInit(I2S_HandleTypeDef *hi2s);
  391. void HAL_I2S_MspDeInit(I2S_HandleTypeDef *hi2s);
  392. /* Callbacks Register/UnRegister functions ***********************************/
  393. #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
  394. HAL_StatusTypeDef HAL_I2S_RegisterCallback(I2S_HandleTypeDef *hi2s, HAL_I2S_CallbackIDTypeDef CallbackID, 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. /** @defgroup I2S_Private_Constants I2S Private Constants
  442. * @{
  443. */
  444. /**
  445. * @}
  446. */
  447. /* Private macros ------------------------------------------------------------*/
  448. /** @defgroup I2S_Private_Macros I2S Private Macros
  449. * @{
  450. */
  451. /** @brief Check whether the specified SPI flag is set or not.
  452. * @param __SR__ copy of I2S SR register.
  453. * @param __FLAG__ specifies the flag to check.
  454. * This parameter can be one of the following values:
  455. * @arg I2S_FLAG_RXP : Rx-Packet available flag
  456. * @arg I2S_FLAG_TXP : Tx-Packet space available flag
  457. * @arg I2S_FLAG_UDR : Underrun flag
  458. * @arg I2S_FLAG_OVR : Overrun flag
  459. * @arg I2S_FLAG_FRE : TI mode frame format error flag
  460. * @retval SET or RESET.
  461. */
  462. #define I2S_CHECK_FLAG(__SR__, __FLAG__) ((((__SR__) & ((__FLAG__) & I2S_FLAG_MASK)) == ((__FLAG__) & I2S_FLAG_MASK)) ? SET : RESET)
  463. /** @brief Check whether the specified SPI Interrupt is set or not.
  464. * @param __IER__ copy of I2S IER register.
  465. * @param __INTERRUPT__ specifies the SPI interrupt source to check.
  466. * This parameter can be one of the following values:
  467. * @arg I2S_IT_RXP : Rx-Packet available interrupt
  468. * @arg I2S_IT_TXP : Tx-Packet space available interrupt
  469. * @arg I2S_IT_UDR : Underrun interrupt
  470. * @arg I2S_IT_OVR : Overrun interrupt
  471. * @arg I2S_IT_FRE : TI mode frame format error interrupt
  472. * @arg I2S_IT_ERR : Error interrupt enable
  473. * @retval SET or RESET.
  474. */
  475. #define I2S_CHECK_IT_SOURCE(__IER__, __INTERRUPT__) ((((__IER__) & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  476. /** @brief Checks if I2S Mode parameter is in allowed range.
  477. * @param __MODE__ specifies the I2S Mode.
  478. * This parameter can be a value of @ref I2S_Mode
  479. * @retval None
  480. */
  481. #define IS_I2S_MODE(__MODE__) (((__MODE__) == I2S_MODE_SLAVE_TX) || \
  482. ((__MODE__) == I2S_MODE_SLAVE_RX) || \
  483. ((__MODE__) == I2S_MODE_MASTER_TX) || \
  484. ((__MODE__) == I2S_MODE_MASTER_RX) || \
  485. ((__MODE__) == I2S_MODE_SLAVE_FULLDUPLEX) || \
  486. ((__MODE__) == I2S_MODE_MASTER_FULLDUPLEX))
  487. #define IS_I2S_MASTER(__MODE__) (((__MODE__) == I2S_MODE_MASTER_TX) || \
  488. ((__MODE__) == I2S_MODE_MASTER_RX) || \
  489. ((__MODE__) == I2S_MODE_MASTER_FULLDUPLEX))
  490. #define IS_I2S_SLAVE(__MODE__) (((__MODE__) == I2S_MODE_SLAVE_TX) || \
  491. ((__MODE__) == I2S_MODE_SLAVE_RX) || \
  492. ((__MODE__) == I2S_MODE_SLAVE_FULLDUPLEX))
  493. #define IS_I2S_STANDARD(__STANDARD__) (((__STANDARD__) == I2S_STANDARD_PHILIPS) || \
  494. ((__STANDARD__) == I2S_STANDARD_MSB) || \
  495. ((__STANDARD__) == I2S_STANDARD_LSB) || \
  496. ((__STANDARD__) == I2S_STANDARD_PCM_SHORT) || \
  497. ((__STANDARD__) == I2S_STANDARD_PCM_LONG))
  498. #define IS_I2S_DATA_FORMAT(__FORMAT__) (((__FORMAT__) == I2S_DATAFORMAT_16B) || \
  499. ((__FORMAT__) == I2S_DATAFORMAT_16B_EXTENDED) || \
  500. ((__FORMAT__) == I2S_DATAFORMAT_24B) || \
  501. ((__FORMAT__) == I2S_DATAFORMAT_32B))
  502. #define IS_I2S_MCLK_OUTPUT(__OUTPUT__) (((__OUTPUT__) == I2S_MCLKOUTPUT_ENABLE) || \
  503. ((__OUTPUT__) == I2S_MCLKOUTPUT_DISABLE))
  504. #define IS_I2S_AUDIO_FREQ(__FREQ__) ((((__FREQ__) >= I2S_AUDIOFREQ_8K) && \
  505. ((__FREQ__) <= I2S_AUDIOFREQ_192K)) || \
  506. ((__FREQ__) == I2S_AUDIOFREQ_DEFAULT))
  507. #define IS_I2S_CPOL(__CPOL__) (((__CPOL__) == I2S_CPOL_LOW) || \
  508. ((__CPOL__) == I2S_CPOL_HIGH))
  509. #define IS_I2S_FIRST_BIT(__BIT__) (((__BIT__) == I2S_FIRSTBIT_MSB) || \
  510. ((__BIT__) == I2S_FIRSTBIT_LSB))
  511. #define IS_I2S_WS_INVERSION(__WSINV__) (((__WSINV__) == I2S_WS_INVERSION_DISABLE) || \
  512. ((__WSINV__) == I2S_WS_INVERSION_ENABLE))
  513. #define IS_I2S_DATA_24BIT_ALIGNMENT(__ALIGNMENT__) (((__ALIGNMENT__) == I2S_DATA_24BIT_ALIGNMENT_RIGHT) || \
  514. ((__ALIGNMENT__) == I2S_DATA_24BIT_ALIGNMENT_LEFT))
  515. #define IS_I2S_MASTER_KEEP_IO_STATE(__AFCNTR__) (((__AFCNTR__) == I2S_MASTER_KEEP_IO_STATE_DISABLE) || \
  516. ((__AFCNTR__) == I2S_MASTER_KEEP_IO_STATE_ENABLE))
  517. /**
  518. * @}
  519. */
  520. /**
  521. * @}
  522. */
  523. /**
  524. * @}
  525. */
  526. #ifdef __cplusplus
  527. }
  528. #endif
  529. #endif /* STM32H7xx_HAL_I2S_H */
  530. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/