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.
 
 
 

562 lines
23 KiB

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