1 /**
2   ******************************************************************************
3   * @file    stm32f3xx_hal_i2s_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of I2S HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32F3xx_HAL_I2S_EX_H
21 #define STM32F3xx_HAL_I2S_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f3xx_hal_def.h"
29 
30 /** @addtogroup STM32F3xx_HAL_Driver
31   * @{
32   */
33 #if defined(SPI_I2S_FULLDUPLEX_SUPPORT)
34 /** @addtogroup I2SEx I2SEx
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /* Exported constants --------------------------------------------------------*/
40 /* Exported macros -----------------------------------------------------------*/
41 /** @defgroup I2SEx_Exported_Macros I2S Extended Exported Macros
42   * @{
43   */
44 
45 #define I2SxEXT(__INSTANCE__) ((__INSTANCE__) == (SPI2)? (SPI_TypeDef *)(I2S2ext_BASE): (SPI_TypeDef *)(I2S3ext_BASE))
46 
47 /** @brief  Enable or disable the specified I2SExt peripheral.
48   * @param  __HANDLE__ specifies the I2S Handle.
49   * @retval None
50   */
51 #define __HAL_I2SEXT_ENABLE(__HANDLE__) (I2SxEXT((__HANDLE__)->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE)
52 #define __HAL_I2SEXT_DISABLE(__HANDLE__) (I2SxEXT((__HANDLE__)->Instance)->I2SCFGR &= ~SPI_I2SCFGR_I2SE)
53 
54 /** @brief  Enable or disable the specified I2SExt interrupts.
55   * @param  __HANDLE__ specifies the I2S Handle.
56   * @param  __INTERRUPT__ specifies the interrupt source to enable or disable.
57   *        This parameter can be one of the following values:
58   *            @arg I2S_IT_TXE: Tx buffer empty interrupt enable
59   *            @arg I2S_IT_RXNE: RX buffer not empty interrupt enable
60   *            @arg I2S_IT_ERR: Error interrupt enable
61   * @retval None
62   */
63 #define __HAL_I2SEXT_ENABLE_IT(__HANDLE__, __INTERRUPT__) (I2SxEXT((__HANDLE__)->Instance)->CR2 |= (__INTERRUPT__))
64 #define __HAL_I2SEXT_DISABLE_IT(__HANDLE__, __INTERRUPT__) (I2SxEXT((__HANDLE__)->Instance)->CR2 &= ~(__INTERRUPT__))
65 
66 /** @brief  Checks if the specified I2SExt interrupt source is enabled or disabled.
67   * @param  __HANDLE__ specifies the I2S Handle.
68   *         This parameter can be I2S where x: 1, 2, or 3 to select the I2S peripheral.
69   * @param  __INTERRUPT__ specifies the I2S interrupt source to check.
70   *          This parameter can be one of the following values:
71   *            @arg I2S_IT_TXE: Tx buffer empty interrupt enable
72   *            @arg I2S_IT_RXNE: RX buffer not empty interrupt enable
73   *            @arg I2S_IT_ERR: Error interrupt enable
74   * @retval The new state of __IT__ (TRUE or FALSE).
75   */
76 #define __HAL_I2SEXT_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((I2SxEXT((__HANDLE__)->Instance)->CR2\
77                                                                  & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
78 
79 /** @brief  Checks whether the specified I2SExt flag is set or not.
80   * @param  __HANDLE__ specifies the I2S Handle.
81   * @param  __FLAG__ specifies the flag to check.
82   *        This parameter can be one of the following values:
83   *            @arg I2S_FLAG_RXNE: Receive buffer not empty flag
84   *            @arg I2S_FLAG_TXE: Transmit buffer empty flag
85   *            @arg I2S_FLAG_UDR: Underrun flag
86   *            @arg I2S_FLAG_OVR: Overrun flag
87   *            @arg I2S_FLAG_FRE: Frame error flag
88   *            @arg I2S_FLAG_CHSIDE: Channel Side flag
89   *            @arg I2S_FLAG_BSY: Busy flag
90   * @retval The new state of __FLAG__ (TRUE or FALSE).
91   */
92 #define __HAL_I2SEXT_GET_FLAG(__HANDLE__, __FLAG__) (((I2SxEXT((__HANDLE__)->Instance)->SR) & (__FLAG__)) == (__FLAG__))
93 
94 /** @brief Clears the I2SExt OVR pending flag.
95   * @param  __HANDLE__ specifies the I2S Handle.
96   * @retval None
97   */
98 #define __HAL_I2SEXT_CLEAR_OVRFLAG(__HANDLE__) do{                                                 \
99                                                    __IO uint32_t tmpreg_ovr = 0x00U;                \
100                                                    tmpreg_ovr = I2SxEXT((__HANDLE__)->Instance)->DR;\
101                                                    tmpreg_ovr = I2SxEXT((__HANDLE__)->Instance)->SR;\
102                                                    UNUSED(tmpreg_ovr);                              \
103                                                   }while(0U)
104 /** @brief Clears the I2SExt UDR pending flag.
105   * @param  __HANDLE__ specifies the I2S Handle.
106   * @retval None
107   */
108 #define __HAL_I2SEXT_CLEAR_UDRFLAG(__HANDLE__) do{                                                 \
109                                                    __IO uint32_t tmpreg_udr = 0x00U;                \
110                                                    tmpreg_udr = I2SxEXT((__HANDLE__)->Instance)->SR;\
111                                                    UNUSED(tmpreg_udr);                              \
112                                                   }while(0U)
113 /** @brief Flush the I2S and I2SExt DR Registers.
114   * @param  __HANDLE__ specifies the I2S Handle.
115   * @retval None
116   */
117 #define __HAL_I2SEXT_FLUSH_RX_DR(__HANDLE__) do{                                                    \
118                                                    __IO uint32_t tmpreg_dr = 0x00U;                 \
119                                                    tmpreg_dr = I2SxEXT((__HANDLE__)->Instance)->DR; \
120                                                    tmpreg_dr = ((__HANDLE__)->Instance->DR);        \
121                                                    UNUSED(tmpreg_dr);                               \
122                                                   }while(0U)
123 /**
124   * @}
125   */
126 
127 /* Exported functions --------------------------------------------------------*/
128 /** @addtogroup I2SEx_Exported_Functions I2S Extended Exported Functions
129   * @{
130   */
131 
132 /** @addtogroup I2SEx_Exported_Functions_Group1 I2S Extended IO operation functions
133   * @{
134   */
135 
136 /* Extended features functions *************************************************/
137 /* Blocking mode: Polling */
138 HAL_StatusTypeDef HAL_I2SEx_TransmitReceive(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData,
139                                             uint16_t Size, uint32_t Timeout);
140 /* Non-Blocking mode: Interrupt */
141 HAL_StatusTypeDef HAL_I2SEx_TransmitReceive_IT(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData,
142                                                uint16_t Size);
143 /* Non-Blocking mode: DMA */
144 HAL_StatusTypeDef HAL_I2SEx_TransmitReceive_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData,
145                                                 uint16_t Size);
146 /* I2S IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
147 void HAL_I2SEx_FullDuplex_IRQHandler(I2S_HandleTypeDef *hi2s);
148 void HAL_I2SEx_TxRxHalfCpltCallback(I2S_HandleTypeDef *hi2s);
149 void HAL_I2SEx_TxRxCpltCallback(I2S_HandleTypeDef *hi2s);
150 /**
151   * @}
152   */
153 
154 /**
155   * @}
156   */
157 /* Private types -------------------------------------------------------------*/
158 /* Private variables ---------------------------------------------------------*/
159 /* Private constants ---------------------------------------------------------*/
160 /* Private macros ------------------------------------------------------------*/
161 
162 /**
163   * @}
164   */
165 
166 /* Private functions ---------------------------------------------------------*/
167 
168 /**
169   * @}
170   */
171 
172 #endif /* SPI_I2S_FULLDUPLEX_SUPPORT */
173 /**
174   * @}
175   */
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 
181 
182 #endif /* STM32F3xx_HAL_I2S_EX_H */
183 
184