2 ******************************************************************************
3 * @file stm32h7xx_hal_i2s.h
4 * @author MCD Application Team
5 * @brief Header file of I2S HAL module.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
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
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32H7xx_HAL_I2S_H
22 #define STM32H7xx_HAL_I2S_H
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h7xx_hal_def.h"
31 /** @addtogroup STM32H7xx_HAL_Driver
39 /* Exported types ------------------------------------------------------------*/
40 /** @defgroup I2S_Exported_Types I2S Exported Types
45 * @brief I2S Init structure definition
49 uint32_t Mode
; /*!< Specifies the I2S operating mode.
50 This parameter can be a value of @ref I2S_Mode */
52 uint32_t Standard
; /*!< Specifies the standard used for the I2S communication.
53 This parameter can be a value of @ref I2S_Standard */
55 uint32_t DataFormat
; /*!< Specifies the data format for the I2S communication.
56 This parameter can be a value of @ref I2S_Data_Format */
58 uint32_t MCLKOutput
; /*!< Specifies whether the I2S MCLK output is enabled or not.
59 This parameter can be a value of @ref I2S_MCLK_Output */
61 uint32_t AudioFreq
; /*!< Specifies the frequency selected for the I2S communication.
62 This parameter can be a value of @ref I2S_Audio_Frequency */
64 uint32_t CPOL
; /*!< Specifies the idle state of the I2S clock.
65 This parameter can be a value of @ref I2S_Clock_Polarity */
67 uint32_t FirstBit
; /*!< Specifies whether data transfers start from MSB or LSB bit.
68 This parameter can be a value of @ref I2S_MSB_LSB_transmission */
70 uint32_t WSInversion
; /*!< Control the Word Select Inversion.
71 This parameter can be a value of @ref I2S_WSInversion */
73 uint32_t Data24BitAlignment
; /*!< Specifies the Data Padding for 24 bits data length
74 This parameter can be a value of @ref I2S_Data_24Bit_Alignment */
76 uint32_t MasterKeepIOState
; /*!< Control of Alternate function GPIOs state
77 This parameter can be a value of @ref SPI_Master_Keep_IO_State */
82 * @brief HAL State structures definition
86 HAL_I2S_STATE_RESET
= 0x00UL
, /*!< I2S not yet initialized or disabled */
87 HAL_I2S_STATE_READY
= 0x01UL
, /*!< I2S initialized and ready for use */
88 HAL_I2S_STATE_BUSY
= 0x02UL
, /*!< I2S internal process is ongoing */
89 HAL_I2S_STATE_BUSY_TX
= 0x03UL
, /*!< Data Transmission process is ongoing */
90 HAL_I2S_STATE_BUSY_RX
= 0x04UL
, /*!< Data Reception process is ongoing */
91 HAL_I2S_STATE_TIMEOUT
= 0x06UL
, /*!< I2S timeout state */
92 HAL_I2S_STATE_ERROR
= 0x07UL
/*!< I2S error state */
93 } HAL_I2S_StateTypeDef
;
96 * @brief I2S handle Structure definition
98 typedef struct __I2S_HandleTypeDef
100 SPI_TypeDef
*Instance
; /*!< I2S registers base address */
102 I2S_InitTypeDef Init
; /*!< I2S communication parameters */
104 uint16_t *pTxBuffPtr
; /*!< Pointer to I2S Tx transfer buffer */
106 __IO
uint16_t TxXferSize
; /*!< I2S Tx transfer size */
108 __IO
uint16_t TxXferCount
; /*!< I2S Tx transfer Counter */
110 uint16_t *pRxBuffPtr
; /*!< Pointer to I2S Rx transfer buffer */
112 __IO
uint16_t RxXferSize
; /*!< I2S Rx transfer size */
114 __IO
uint16_t RxXferCount
; /*!< I2S Rx transfer counter
115 (This field is initialized at the
116 same value as transfer size at the
117 beginning of the transfer and
118 decremented when a sample is received
119 NbSamplesReceived = RxBufferSize-RxBufferCount) */
121 void (*RxISR
)(struct __I2S_HandleTypeDef
*hi2s
); /*!< function pointer on Rx ISR */
123 void (*TxISR
)(struct __I2S_HandleTypeDef
*hi2s
); /*!< function pointer on Tx ISR */
125 DMA_HandleTypeDef
*hdmatx
; /*!< I2S Tx DMA handle parameters */
127 DMA_HandleTypeDef
*hdmarx
; /*!< I2S Rx DMA handle parameters */
129 __IO HAL_LockTypeDef Lock
; /*!< I2S locking object */
131 __IO HAL_I2S_StateTypeDef State
; /*!< I2S communication state */
133 __IO
uint32_t ErrorCode
; /*!< I2S Error code
134 This parameter can be a value of @ref I2S_Error */
136 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1U)
137 void (* TxCpltCallback
)(struct __I2S_HandleTypeDef
*hi2s
); /*!< I2S Tx Completed callback */
138 void (* RxCpltCallback
)(struct __I2S_HandleTypeDef
*hi2s
); /*!< I2S Rx Completed callback */
139 void (* TxHalfCpltCallback
)(struct __I2S_HandleTypeDef
*hi2s
); /*!< I2S Tx Half Completed callback */
140 void (* RxHalfCpltCallback
)(struct __I2S_HandleTypeDef
*hi2s
); /*!< I2S Rx Half Completed callback */
141 void (* ErrorCallback
)(struct __I2S_HandleTypeDef
*hi2s
); /*!< I2S Error callback */
142 void (* MspInitCallback
)(struct __I2S_HandleTypeDef
*hi2s
); /*!< I2S Msp Init callback */
143 void (* MspDeInitCallback
)(struct __I2S_HandleTypeDef
*hi2s
); /*!< I2S Msp DeInit callback */
145 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
148 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
151 * @brief HAL I2S Callback ID enumeration definition
155 HAL_I2S_TX_COMPLETE_CB_ID
= 0x00UL
, /*!< I2S Tx Completed callback ID */
156 HAL_I2S_RX_COMPLETE_CB_ID
= 0x01UL
, /*!< I2S Rx Completed callback ID */
157 HAL_I2S_TX_HALF_COMPLETE_CB_ID
= 0x03UL
, /*!< I2S Tx Half Completed callback ID */
158 HAL_I2S_RX_HALF_COMPLETE_CB_ID
= 0x04UL
, /*!< I2S Rx Half Completed callback ID */
159 HAL_I2S_ERROR_CB_ID
= 0x06UL
, /*!< I2S Error callback ID */
160 HAL_I2S_MSPINIT_CB_ID
= 0x07UL
, /*!< I2S Msp Init callback ID */
161 HAL_I2S_MSPDEINIT_CB_ID
= 0x08UL
/*!< I2S Msp DeInit callback ID */
163 } HAL_I2S_CallbackIDTypeDef
;
166 * @brief HAL I2S Callback pointer definition
168 typedef void (*pI2S_CallbackTypeDef
)(I2S_HandleTypeDef
*hi2s
); /*!< pointer to an I2S callback function */
170 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
175 /* Exported constants --------------------------------------------------------*/
176 /** @defgroup I2S_Exported_Constants I2S Exported Constants
179 /** @defgroup I2S_Error I2S Error
182 #define HAL_I2S_ERROR_NONE (0x00000000UL) /*!< No error */
183 #define HAL_I2S_ERROR_TIMEOUT (0x00000001UL) /*!< Timeout error */
184 #define HAL_I2S_ERROR_OVR (0x00000002UL) /*!< OVR error */
185 #define HAL_I2S_ERROR_UDR (0x00000004UL) /*!< UDR error */
186 #define HAL_I2S_ERROR_DMA (0x00000008UL) /*!< DMA transfer error */
187 #define HAL_I2S_ERROR_PRESCALER (0x00000010UL) /*!< Prescaler Calculation error */
188 #define HAL_I2S_ERROR_FRE (0x00000020UL) /*!< FRE error */
189 #define HAL_I2S_ERROR_NO_OGT (0x00000040UL) /*!< No On Going Transfer error */
190 #define HAL_I2S_ERROR_NOT_SUPPORTED (0x00000080UL) /*!< Requested operation not supported */
191 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
192 #define HAL_I2S_ERROR_INVALID_CALLBACK (0x00000100UL) /*!< Invalid Callback error */
193 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
198 /** @defgroup I2S_Mode I2S Mode
201 #define I2S_MODE_SLAVE_TX (0x00000000UL)
202 #define I2S_MODE_SLAVE_RX (SPI_I2SCFGR_I2SCFG_0)
203 #define I2S_MODE_MASTER_TX (SPI_I2SCFGR_I2SCFG_1)
204 #define I2S_MODE_MASTER_RX (SPI_I2SCFGR_I2SCFG_0 | SPI_I2SCFGR_I2SCFG_1)
205 #define I2S_MODE_SLAVE_FULLDUPLEX (SPI_I2SCFGR_I2SCFG_2)
206 #define I2S_MODE_MASTER_FULLDUPLEX (SPI_I2SCFGR_I2SCFG_2 | SPI_I2SCFGR_I2SCFG_0)
211 /** @defgroup I2S_Standard I2S Standard
214 #define I2S_STANDARD_PHILIPS (0x00000000UL)
215 #define I2S_STANDARD_MSB (SPI_I2SCFGR_I2SSTD_0)
216 #define I2S_STANDARD_LSB (SPI_I2SCFGR_I2SSTD_1)
217 #define I2S_STANDARD_PCM_SHORT (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1)
218 #define I2S_STANDARD_PCM_LONG (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1 | SPI_I2SCFGR_PCMSYNC)
223 /** @defgroup I2S_Data_Format I2S Data Format
226 #define I2S_DATAFORMAT_16B (0x00000000UL)
227 #define I2S_DATAFORMAT_16B_EXTENDED (SPI_I2SCFGR_CHLEN)
228 #define I2S_DATAFORMAT_24B (SPI_I2SCFGR_DATLEN_0)
229 #define I2S_DATAFORMAT_32B (SPI_I2SCFGR_DATLEN_1)
234 /** @defgroup I2S_MCLK_Output I2S MCLK Output
237 #define I2S_MCLKOUTPUT_ENABLE (SPI_I2SCFGR_MCKOE)
238 #define I2S_MCLKOUTPUT_DISABLE (0x00000000UL)
243 /** @defgroup I2S_Audio_Frequency I2S Audio Frequency
246 #define I2S_AUDIOFREQ_192K (192000UL)
247 #define I2S_AUDIOFREQ_96K (96000UL)
248 #define I2S_AUDIOFREQ_48K (48000UL)
249 #define I2S_AUDIOFREQ_44K (44100UL)
250 #define I2S_AUDIOFREQ_32K (32000UL)
251 #define I2S_AUDIOFREQ_22K (22050UL)
252 #define I2S_AUDIOFREQ_16K (16000UL)
253 #define I2S_AUDIOFREQ_11K (11025UL)
254 #define I2S_AUDIOFREQ_8K (8000UL)
255 #define I2S_AUDIOFREQ_DEFAULT (2UL)
260 /** @defgroup I2S_FullDuplex_Mode I2S FullDuplex Mode
263 #define I2S_CPOL_LOW (0x00000000UL)
264 #define I2S_CPOL_HIGH (SPI_I2SCFGR_CKPOL)
269 /** @defgroup I2S_MSB_LSB_Transmission I2S MSB LSB Transmission
272 #define I2S_FIRSTBIT_MSB (0x00000000UL)
273 #define I2S_FIRSTBIT_LSB SPI_CFG2_LSBFRST
278 /** @defgroup I2S_WSInversion I2S Word Select Inversion
281 #define I2S_WS_INVERSION_DISABLE (0x00000000UL)
282 #define I2S_WS_INVERSION_ENABLE SPI_I2SCFGR_WSINV
287 /** @defgroup I2S_Data_24Bit_Alignment Data Padding 24Bit
290 #define I2S_DATA_24BIT_ALIGNMENT_RIGHT (0x00000000UL)
291 #define I2S_DATA_24BIT_ALIGNMENT_LEFT SPI_I2SCFGR_DATFMT
296 /** @defgroup I2S_Master_Keep_IO_State Keep IO State
299 #define I2S_MASTER_KEEP_IO_STATE_DISABLE (0x00000000U)
300 #define I2S_MASTER_KEEP_IO_STATE_ENABLE SPI_CFG2_AFCNTR
305 /** @defgroup I2S_Interrupts_Definition I2S Interrupts Definition
308 #define I2S_IT_RXP SPI_IER_RXPIE
309 #define I2S_IT_TXP SPI_IER_TXPIE
310 #define I2S_IT_UDR SPI_IER_UDRIE
311 #define I2S_IT_OVR SPI_IER_OVRIE
312 #define I2S_IT_FRE SPI_IER_TIFREIE
313 #define I2S_IT_ERR (SPI_IER_UDRIE | SPI_IER_OVRIE | SPI_IER_TIFREIE)
318 /** @defgroup I2S_Flags_Definition I2S Flags Definition
321 #define I2S_FLAG_RXP SPI_SR_RXP /* I2S status flag : Rx-Packet available flag */
322 #define I2S_FLAG_TXP SPI_SR_TXP /* I2S status flag : Tx-Packet space available flag */
323 #define I2S_FLAG_UDR SPI_SR_UDR /* I2S Error flag : Underrun flag */
324 #define I2S_FLAG_OVR SPI_SR_OVR /* I2S Error flag : Overrun flag */
325 #define I2S_FLAG_FRE SPI_SR_TIFRE /* I2S Error flag : TI mode frame format error flag */
327 #define I2S_FLAG_MASK (SPI_SR_RXP | SPI_SR_TXP | SPI_SR_UDR | SPI_SR_OVR | SPI_SR_TIFRE)
336 /* Exported macros -----------------------------------------------------------*/
337 /** @defgroup I2S_Exported_macros I2S Exported Macros
341 /** @brief Reset I2S handle state
342 * @param __HANDLE__ specifies the I2S Handle.
345 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
346 #define __HAL_I2S_RESET_HANDLE_STATE(__HANDLE__) do{ \
347 (__HANDLE__)->State = HAL_I2S_STATE_RESET; \
348 (__HANDLE__)->MspInitCallback = NULL; \
349 (__HANDLE__)->MspDeInitCallback = NULL; \
352 #define __HAL_I2S_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2S_STATE_RESET)
355 /** @brief Enable the specified SPI peripheral (in I2S mode).
356 * @param __HANDLE__ specifies the I2S Handle.
359 #define __HAL_I2S_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE))
361 /** @brief Disable the specified SPI peripheral (in I2S mode).
362 * @param __HANDLE__ specifies the I2S Handle.
365 #define __HAL_I2S_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE))
367 /** @brief Enable the specified I2S interrupts.
368 * @param __HANDLE__ specifies the I2S Handle.
369 * This parameter can be I2S where x: 1, 2 or 3 to select the I2S peripheral.
370 * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
371 * This parameter can be one of the following values:
372 * @arg I2S_IT_RXP : Rx-Packet available interrupt
373 * @arg I2S_IT_TXP : Tx-Packet space available interrupt
374 * @arg I2S_IT_UDR : Underrun interrupt
375 * @arg I2S_IT_OVR : Overrun interrupt
376 * @arg I2S_IT_FRE : TI mode frame format error interrupt
377 * @arg I2S_IT_ERR : Error interrupt enable
380 #define __HAL_I2S_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER |= (__INTERRUPT__))
382 /** @brief Disable the specified I2S interrupts.
383 * @param __HANDLE__ specifies the I2S Handle.
384 * This parameter can be I2S where x: 1, 2 or 3 to select the I2S peripheral.
385 * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
386 * This parameter can be one of the following values:
387 * @arg I2S_IT_RXP : Rx-Packet available interrupt
388 * @arg I2S_IT_TXP : Tx-Packet space available interrupt
389 * @arg I2S_IT_UDR : Underrun interrupt
390 * @arg I2S_IT_OVR : Overrun interrupt
391 * @arg I2S_IT_FRE : TI mode frame format error interrupt
392 * @arg I2S_IT_ERR : Error interrupt enable
395 #define __HAL_I2S_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER &= (~(__INTERRUPT__)))
397 /** @brief Check if the specified I2S interrupt source is enabled or disabled.
398 * @param __HANDLE__ specifies the I2S Handle.
399 * This parameter can be I2S where x: 1, 2 or 3 to select the I2S peripheral.
400 * @param __INTERRUPT__ specifies the I2S interrupt source to check.
401 * This parameter can be one of the following values:
402 * @arg I2S_IT_RXP : Rx-Packet available interrupt
403 * @arg I2S_IT_TXP : Tx-Packet space available interrupt
404 * @arg I2S_IT_UDR : Underrun interrupt
405 * @arg I2S_IT_OVR : Overrun interrupt
406 * @arg I2S_IT_FRE : TI mode frame format error interrupt
407 * @arg I2S_IT_ERR : Error interrupt enable
408 * @retval The new state of __IT__ (TRUE or FALSE).
410 #define __HAL_I2S_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
412 /** @brief Check whether the specified I2S flag is set or not.
413 * @param __HANDLE__ specifies the I2S Handle.
414 * This parameter can be I2S where x: 1, 2 or 3 to select the I2S peripheral.
415 * @param __FLAG__ specifies the flag to check.
416 * This parameter can be one of the following values:
417 * @arg I2S_FLAG_RXP : Rx-Packet available flag
418 * @arg I2S_FLAG_TXP : Tx-Packet space available flag
419 * @arg I2S_FLAG_UDR : Underrun flag
420 * @arg I2S_FLAG_OVR : Overrun flag
421 * @arg I2S_FLAG_FRE : TI mode frame format error flag
422 * @retval The new state of __FLAG__ (TRUE or FALSE).
424 #define __HAL_I2S_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
426 /** @brief Clear the I2S OVR pending flag.
427 * @param __HANDLE__ specifies the I2S Handle.
430 #define __HAL_I2S_CLEAR_OVRFLAG(__HANDLE__) SET_BIT((__HANDLE__)->Instance->IFCR , SPI_IFCR_OVRC)
432 /** @brief Clear the I2S UDR pending flag.
433 * @param __HANDLE__ specifies the I2S Handle.
436 #define __HAL_I2S_CLEAR_UDRFLAG(__HANDLE__) SET_BIT((__HANDLE__)->Instance->IFCR , SPI_IFCR_UDRC)
438 /** @brief Clear the I2S FRE pending flag.
439 * @param __HANDLE__: specifies the I2S Handle.
442 #define __HAL_I2S_CLEAR_TIFREFLAG(__HANDLE__) SET_BIT((__HANDLE__)->Instance->IFCR , SPI_IFCR_TIFREC)
448 /* Exported functions --------------------------------------------------------*/
449 /** @addtogroup I2S_Exported_Functions
453 /** @addtogroup I2S_Exported_Functions_Group1
456 /* Initialization/de-initialization functions ********************************/
457 HAL_StatusTypeDef
HAL_I2S_Init(I2S_HandleTypeDef
*hi2s
);
458 HAL_StatusTypeDef
HAL_I2S_DeInit(I2S_HandleTypeDef
*hi2s
);
459 void HAL_I2S_MspInit(I2S_HandleTypeDef
*hi2s
);
460 void HAL_I2S_MspDeInit(I2S_HandleTypeDef
*hi2s
);
462 /* Callbacks Register/UnRegister functions ***********************************/
463 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
464 HAL_StatusTypeDef
HAL_I2S_RegisterCallback(I2S_HandleTypeDef
*hi2s
, HAL_I2S_CallbackIDTypeDef CallbackID
, pI2S_CallbackTypeDef pCallback
);
465 HAL_StatusTypeDef
HAL_I2S_UnRegisterCallback(I2S_HandleTypeDef
*hi2s
, HAL_I2S_CallbackIDTypeDef CallbackID
);
466 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
471 /** @addtogroup I2S_Exported_Functions_Group2
474 /* I/O operation functions ***************************************************/
475 /* Blocking mode: Polling */
476 HAL_StatusTypeDef
HAL_I2S_Transmit(I2S_HandleTypeDef
*hi2s
, uint16_t *pData
, uint16_t Size
, uint32_t Timeout
);
477 HAL_StatusTypeDef
HAL_I2S_Receive(I2S_HandleTypeDef
*hi2s
, uint16_t *pData
, uint16_t Size
, uint32_t Timeout
);
479 /* Non-Blocking mode: Interrupt */
480 HAL_StatusTypeDef
HAL_I2S_Transmit_IT(I2S_HandleTypeDef
*hi2s
, uint16_t *pData
, uint16_t Size
);
481 HAL_StatusTypeDef
HAL_I2S_Receive_IT(I2S_HandleTypeDef
*hi2s
, uint16_t *pData
, uint16_t Size
);
482 void HAL_I2S_IRQHandler(I2S_HandleTypeDef
*hi2s
);
484 /* Non-Blocking mode: DMA */
485 HAL_StatusTypeDef
HAL_I2S_Transmit_DMA(I2S_HandleTypeDef
*hi2s
, uint16_t *pData
, uint16_t Size
);
486 HAL_StatusTypeDef
HAL_I2S_Receive_DMA(I2S_HandleTypeDef
*hi2s
, uint16_t *pData
, uint16_t Size
);
488 HAL_StatusTypeDef
HAL_I2S_DMAPause(I2S_HandleTypeDef
*hi2s
);
489 HAL_StatusTypeDef
HAL_I2S_DMAResume(I2S_HandleTypeDef
*hi2s
);
490 HAL_StatusTypeDef
HAL_I2S_DMAStop(I2S_HandleTypeDef
*hi2s
);
492 /* Callbacks used in non blocking modes (Interrupt and DMA) *******************/
493 void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef
*hi2s
);
494 void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef
*hi2s
);
495 void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef
*hi2s
);
496 void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef
*hi2s
);
497 void HAL_I2S_ErrorCallback(I2S_HandleTypeDef
*hi2s
);
502 /** @addtogroup I2S_Exported_Functions_Group3
505 /* Peripheral Control and State functions ************************************/
506 HAL_I2S_StateTypeDef
HAL_I2S_GetState(I2S_HandleTypeDef
*hi2s
);
507 uint32_t HAL_I2S_GetError(I2S_HandleTypeDef
*hi2s
);
516 /* Private types -------------------------------------------------------------*/
517 /* Private variables ---------------------------------------------------------*/
518 /* Private constants ---------------------------------------------------------*/
519 /** @defgroup I2S_Private_Constants I2S Private Constants
527 /* Private macros ------------------------------------------------------------*/
528 /** @defgroup I2S_Private_Macros I2S Private Macros
532 /** @brief Check whether the specified SPI flag is set or not.
533 * @param __SR__ copy of I2S SR register.
534 * @param __FLAG__ specifies the flag to check.
535 * This parameter can be one of the following values:
536 * @arg I2S_FLAG_RXP : Rx-Packet available flag
537 * @arg I2S_FLAG_TXP : Tx-Packet space available flag
538 * @arg I2S_FLAG_UDR : Underrun flag
539 * @arg I2S_FLAG_OVR : Overrun flag
540 * @arg I2S_FLAG_FRE : TI mode frame format error flag
541 * @retval SET or RESET.
543 #define I2S_CHECK_FLAG(__SR__, __FLAG__) ((((__SR__) & ((__FLAG__) & I2S_FLAG_MASK)) == ((__FLAG__) & I2S_FLAG_MASK)) ? SET : RESET)
545 /** @brief Check whether the specified SPI Interrupt is set or not.
546 * @param __IER__ copy of I2S IER register.
547 * @param __INTERRUPT__ specifies the SPI interrupt source to check.
548 * This parameter can be one of the following values:
549 * @arg I2S_IT_RXP : Rx-Packet available interrupt
550 * @arg I2S_IT_TXP : Tx-Packet space available interrupt
551 * @arg I2S_IT_UDR : Underrun interrupt
552 * @arg I2S_IT_OVR : Overrun interrupt
553 * @arg I2S_IT_FRE : TI mode frame format error interrupt
554 * @arg I2S_IT_ERR : Error interrupt enable
555 * @retval SET or RESET.
557 #define I2S_CHECK_IT_SOURCE(__IER__, __INTERRUPT__) ((((__IER__) & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
559 /** @brief Checks if I2S Mode parameter is in allowed range.
560 * @param __MODE__ specifies the I2S Mode.
561 * This parameter can be a value of @ref I2S_Mode
564 #define IS_I2S_MODE(__MODE__) (((__MODE__) == I2S_MODE_SLAVE_TX) || \
565 ((__MODE__) == I2S_MODE_SLAVE_RX) || \
566 ((__MODE__) == I2S_MODE_MASTER_TX) || \
567 ((__MODE__) == I2S_MODE_MASTER_RX) || \
568 ((__MODE__) == I2S_MODE_SLAVE_FULLDUPLEX) || \
569 ((__MODE__) == I2S_MODE_MASTER_FULLDUPLEX))
571 #define IS_I2S_MASTER(__MODE__) (((__MODE__) == I2S_MODE_MASTER_TX) || \
572 ((__MODE__) == I2S_MODE_MASTER_RX) || \
573 ((__MODE__) == I2S_MODE_MASTER_FULLDUPLEX))
575 #define IS_I2S_SLAVE(__MODE__) (((__MODE__) == I2S_MODE_SLAVE_TX) || \
576 ((__MODE__) == I2S_MODE_SLAVE_RX) || \
577 ((__MODE__) == I2S_MODE_SLAVE_FULLDUPLEX))
579 #define IS_I2S_STANDARD(__STANDARD__) (((__STANDARD__) == I2S_STANDARD_PHILIPS) || \
580 ((__STANDARD__) == I2S_STANDARD_MSB) || \
581 ((__STANDARD__) == I2S_STANDARD_LSB) || \
582 ((__STANDARD__) == I2S_STANDARD_PCM_SHORT) || \
583 ((__STANDARD__) == I2S_STANDARD_PCM_LONG))
585 #define IS_I2S_DATA_FORMAT(__FORMAT__) (((__FORMAT__) == I2S_DATAFORMAT_16B) || \
586 ((__FORMAT__) == I2S_DATAFORMAT_16B_EXTENDED) || \
587 ((__FORMAT__) == I2S_DATAFORMAT_24B) || \
588 ((__FORMAT__) == I2S_DATAFORMAT_32B))
590 #define IS_I2S_MCLK_OUTPUT(__OUTPUT__) (((__OUTPUT__) == I2S_MCLKOUTPUT_ENABLE) || \
591 ((__OUTPUT__) == I2S_MCLKOUTPUT_DISABLE))
593 #define IS_I2S_AUDIO_FREQ(__FREQ__) ((((__FREQ__) >= I2S_AUDIOFREQ_8K) && \
594 ((__FREQ__) <= I2S_AUDIOFREQ_192K)) || \
595 ((__FREQ__) == I2S_AUDIOFREQ_DEFAULT))
597 #define IS_I2S_CPOL(__CPOL__) (((__CPOL__) == I2S_CPOL_LOW) || \
598 ((__CPOL__) == I2S_CPOL_HIGH))
600 #define IS_I2S_FIRST_BIT(__BIT__) (((__BIT__) == I2S_FIRSTBIT_MSB) || \
601 ((__BIT__) == I2S_FIRSTBIT_LSB))
603 #define IS_I2S_WS_INVERSION(__WSINV__) (((__WSINV__) == I2S_WS_INVERSION_DISABLE) || \
604 ((__WSINV__) == I2S_WS_INVERSION_ENABLE))
606 #define IS_I2S_DATA_24BIT_ALIGNMENT(__ALIGNMENT__) (((__ALIGNMENT__) == I2S_DATA_24BIT_ALIGNMENT_RIGHT) || \
607 ((__ALIGNMENT__) == I2S_DATA_24BIT_ALIGNMENT_LEFT))
609 #define IS_I2S_MASTER_KEEP_IO_STATE(__AFCNTR__) (((__AFCNTR__) == I2S_MASTER_KEEP_IO_STATE_DISABLE) || \
610 ((__AFCNTR__) == I2S_MASTER_KEEP_IO_STATE_ENABLE))
629 #endif /* STM32H7xx_HAL_I2S_H */
631 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/