1 /**
2   ******************************************************************************
3   * @file    stm32wbaxx_hal_i2c_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of I2C HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 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 STM32WBAxx_HAL_I2C_EX_H
21 #define STM32WBAxx_HAL_I2C_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32wbaxx_hal_def.h"
29 
30 /** @addtogroup STM32WBAxx_HAL_Driver
31   * @{
32   */
33 
34 /** @addtogroup I2CEx
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /** @defgroup I2C_Exported_Types I2C Exported Types
40   * @{
41   */
42 
43 /** @defgroup I2C_Autonomous_Mode_Configuration_Structure_definition Autonomous Mode Configuration Structure definition
44   * @brief  I2C Autonomous Mode Configuration structure definition
45   * @{
46   */
47 typedef struct
48 {
49   uint32_t TriggerState;        /*!< Specifies the trigger state. This parameter can be a value
50                                      of @ref I2CEx_AutonomousMode_FunctionalState */
51 
52   uint32_t TriggerSelection;    /*!< Specifies the autonomous mode trigger signal selection. This parameter
53                                      can be a value of @ref I2CEx_AutonomousMode_TriggerSelection */
54 
55   uint32_t TriggerPolarity;     /*!< Specifies the autonomous mode trigger signal polarity sensitivity. This parameter
56                                      can be a value of @ref I2CEx_AutonomousMode_TriggerPolarity */
57 
58 } I2C_AutonomousModeConfTypeDef;
59 /**
60   * @}
61   */
62 
63 /**
64   * @}
65   */
66 
67 /* Exported constants --------------------------------------------------------*/
68 /** @defgroup I2CEx_Exported_Constants I2C Extended Exported Constants
69   * @{
70   */
71 
72 /** @defgroup I2CEx_Analog_Filter I2C Extended Analog Filter
73   * @{
74   */
75 #define I2C_ANALOGFILTER_ENABLE         0x00000000U
76 #define I2C_ANALOGFILTER_DISABLE        I2C_CR1_ANFOFF
77 /**
78   * @}
79   */
80 
81 /** @defgroup I2CEx_FastModePlus I2C Extended Fast Mode Plus
82   * @{
83   */
84 #define I2C_FASTMODEPLUS_ENABLE         0x00000000U           /*!< Enable Fast Mode Plus                        */
85 #define I2C_FASTMODEPLUS_DISABLE        0x00000001U           /*!< Disable Fast Mode Plus                       */
86 /**
87   * @}
88   */
89 
90 /** @defgroup I2CEx_AutonomousMode_FunctionalState I2C Extended Autonomous Mode State
91   * @{
92   */
93 #define I2C_AUTO_MODE_DISABLE           (0x00000000U)                    /*!< Autonomous mode disable  */
94 #define I2C_AUTO_MODE_ENABLE            I2C_AUTOCR_TRIGEN                /*!< Autonomous mode enable   */
95 /**
96   * @}
97   */
98 
99 /** @defgroup I2CEx_AutonomousMode_TriggerSelection I2C Extended Autonomous Mode Trigger Selection
100   * @{
101   */
102 #if defined(I2C1)
103 #define I2C_TRIG_GRP1                   (0x10000000U)         /*!< Trigger Group for I2C1, I2C2 */
104 #endif /* I2C1, I2C2 */
105 #define I2C_TRIG_GRP2                   (0x20000000U)         /*!< Trigger Group for I2C3, I2C4 */
106 
107 #if defined(I2C_TRIG_GRP1)
108 #define I2C_GRP1_GPDMA_CH0_TCF_TRG      (uint32_t)(I2C_TRIG_GRP1 | (0x00000000U))
109 /*!< HW Trigger signal is GPDMA_CH0_TRG     */
110 #define I2C_GRP1_GPDMA_CH1_TCF_TRG      (uint32_t)(I2C_TRIG_GRP1 | (0x1U << I2C_AUTOCR_TRIGSEL_Pos))
111 /*!< HW Trigger signal is GPDMA_CH1_TRG     */
112 #define I2C_GRP1_GPDMA_CH2_TCF_TRG      (uint32_t)(I2C_TRIG_GRP1 | (0x2U << I2C_AUTOCR_TRIGSEL_Pos))
113 /*!< HW Trigger signal is GPDMA_CH2_TRG     */
114 #define I2C_GRP1_GPDMA_CH3_TCF_TRG      (uint32_t)(I2C_TRIG_GRP1 | (0x3U << I2C_AUTOCR_TRIGSEL_Pos))
115 /*!< HW Trigger signal is GPDMA_CH3_TRG     */
116 #define I2C_GRP1_EXTI5_TRG              (uint32_t)(I2C_TRIG_GRP1 | (0x4U << I2C_AUTOCR_TRIGSEL_Pos))
117 /*!< HW Trigger signal is EXTI5_TRG         */
118 #define I2C_GRP1_EXTI9_TRG              (uint32_t)(I2C_TRIG_GRP1 | (0x5U << I2C_AUTOCR_TRIGSEL_Pos))
119 /*!< HW Trigger signal is EXTI9_TRG         */
120 #define I2C_GRP1_LPTIM1_CH1_TRG         (uint32_t)(I2C_TRIG_GRP1 | (0x6U << I2C_AUTOCR_TRIGSEL_Pos))
121 /*!< HW Trigger signal is LPTIM1_CH1_TRG    */
122 #define I2C_GRP1_LPTIM2_CH1_TRG         (uint32_t)(I2C_TRIG_GRP1 | (0x7U << I2C_AUTOCR_TRIGSEL_Pos))
123 /*!< HW Trigger signal is LPTIM2_CH1_TRG    */
124 #if defined(COMP1)
125 #define I2C_GRP1_COMP1_TRG              (uint32_t)(I2C_TRIG_GRP1 | (0x8U << I2C_AUTOCR_TRIGSEL_Pos))
126 /*!< HW Trigger signal is COMP1_TRG         */
127 #endif /* COMP1 */
128 #if defined(COMP2)
129 #define I2C_GRP1_COMP2_TRG              (uint32_t)(I2C_TRIG_GRP1 | (0x9U << I2C_AUTOCR_TRIGSEL_Pos))
130 /*!< HW Trigger signal is COMP2_TRG         */
131 #endif /* COMP2 */
132 #define I2C_GRP1_RTC_ALRA_TRG           (uint32_t)(I2C_TRIG_GRP1 | (0xAU << I2C_AUTOCR_TRIGSEL_Pos))
133 /*!< HW Trigger signal is RTC_ALRA_TRG      */
134 #define I2C_GRP1_RTC_WUT_TRG            (uint32_t)(I2C_TRIG_GRP1 | (0xBU << I2C_AUTOCR_TRIGSEL_Pos))
135 /*!< HW Trigger signal is RTC_WUT_TRG       */
136 #endif /* I2C_TRIG_GRP1 */
137 
138 #define I2C_GRP2_GPDMA_CH0_TCF_TRG      (uint32_t)(I2C_TRIG_GRP2 | (0x00000000U))
139 /*!< HW Trigger signal is GPDMA_CH0_TRG     */
140 #define I2C_GRP2_GPDMA_CH1_TCF_TRG      (uint32_t)(I2C_TRIG_GRP2 | (0x1U << I2C_AUTOCR_TRIGSEL_Pos))
141 /*!< HW Trigger signal is GPDMA_CH1_TRG     */
142 #define I2C_GRP2_GPDMA_CH2_TCF_TRG      (uint32_t)(I2C_TRIG_GRP2 | (0x2U << I2C_AUTOCR_TRIGSEL_Pos))
143 /*!< HW Trigger signal is GPDMA_CH2_TRG     */
144 #define I2C_GRP2_GPDMA_CH3_TCF_TRG      (uint32_t)(I2C_TRIG_GRP2 | (0x3U << I2C_AUTOCR_TRIGSEL_Pos))
145 /*!< HW Trigger signal is GPDMA_CH3_TRG     */
146 #define I2C_GRP2_EXTI5_TRG              (uint32_t)(I2C_TRIG_GRP2 | (0x4U << I2C_AUTOCR_TRIGSEL_Pos))
147 /*!< HW Trigger signal is EXTI5_TRG         */
148 #define I2C_GRP2_EXTI8_TRG              (uint32_t)(I2C_TRIG_GRP2 | (0x5U << I2C_AUTOCR_TRIGSEL_Pos))
149 /*!< HW Trigger signal is EXTI8_TRG         */
150 #define I2C_GRP2_LPTIM1_CH1_TRG         (uint32_t)(I2C_TRIG_GRP2 | (0x6U << I2C_AUTOCR_TRIGSEL_Pos))
151 /*!< HW Trigger signal is LPTIM1_CH1_TRG    */
152 #if defined(COMP1)
153 #define I2C_GRP2_COMP1_TRG              (uint32_t)(I2C_TRIG_GRP2 | (0x8U << I2C_AUTOCR_TRIGSEL_Pos))
154 /*!< HW Trigger signal is COMP1_TRG         */
155 #endif /* COMP1 */
156 #if defined(COMP2)
157 #define I2C_GRP2_COMP2_TRG              (uint32_t)(I2C_TRIG_GRP2 | (0x9U << I2C_AUTOCR_TRIGSEL_Pos))
158 /*!< HW Trigger signal is COMP2_TRG         */
159 #endif /* COMP2 */
160 #define I2C_GRP2_RTC_ALRA_TRG           (uint32_t)(I2C_TRIG_GRP2 | (0xAU << I2C_AUTOCR_TRIGSEL_Pos))
161 /*!< HW Trigger signal is RTC_ALRA_TRG      */
162 #define I2C_GRP2_RTC_WUT_TRG            (uint32_t)(I2C_TRIG_GRP2 | (0xBU << I2C_AUTOCR_TRIGSEL_Pos))
163 /*!< HW Trigger signal is RTC_WUT_TRG       */
164 /**
165   * @}
166   */
167 
168 /** @defgroup I2CEx_AutonomousMode_TriggerPolarity Extended Autonomous Mode Trigger Polarity
169   * @{
170   */
171 #define I2C_TRIG_POLARITY_RISING        (0x00000000U)                    /*!< I2C HW Trigger signal on rising edge  */
172 #define I2C_TRIG_POLARITY_FALLING       I2C_AUTOCR_TRIGPOL               /*!< I2C HW Trigger signal on falling edge */
173 /**
174   * @}
175   */
176 
177 /**
178   * @}
179   */
180 
181 /* Exported macro ------------------------------------------------------------*/
182 /** @defgroup I2CEx_Exported_Macros I2C Extended Exported Macros
183   * @{
184   */
185 
186 /**
187   * @}
188   */
189 
190 /* Exported functions --------------------------------------------------------*/
191 /** @addtogroup I2CEx_Exported_Functions I2C Extended Exported Functions
192   * @{
193   */
194 
195 /** @addtogroup I2CEx_Exported_Functions_Group1 Filter Mode Functions
196   * @{
197   */
198 /* Peripheral Control functions  ************************************************/
199 HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter);
200 HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter);
201 /**
202   * @}
203   */
204 
205 /** @addtogroup I2CEx_Exported_Functions_Group2 WakeUp Mode Functions
206   * @{
207   */
208 HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c);
209 HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c);
210 /**
211   * @}
212   */
213 
214 /** @addtogroup I2CEx_Exported_Functions_Group3 Fast Mode Plus Functions
215   * @{
216   */
217 HAL_StatusTypeDef HAL_I2CEx_ConfigFastModePlus(I2C_HandleTypeDef *hi2c, uint32_t FastModePlus);
218 /**
219   * @}
220   */
221 
222 /** @addtogroup I2CEx_Exported_Functions_Group4 Autonomous Mode Functions
223   * @{
224   */
225 HAL_StatusTypeDef HAL_I2CEx_SetConfigAutonomousMode(I2C_HandleTypeDef *hi2c,
226                                                     const I2C_AutonomousModeConfTypeDef *sConfig);
227 HAL_StatusTypeDef HAL_I2CEx_GetConfigAutonomousMode(const I2C_HandleTypeDef *hi2c,
228                                                     I2C_AutonomousModeConfTypeDef *sConfig);
229 HAL_StatusTypeDef HAL_I2CEx_ClearConfigAutonomousMode(I2C_HandleTypeDef *hi2c);
230 /**
231   * @}
232   */
233 
234 /**
235   * @}
236   */
237 
238 /* Private constants ---------------------------------------------------------*/
239 /** @defgroup I2CEx_Private_Constants I2C Extended Private Constants
240   * @{
241   */
242 
243 /**
244   * @}
245   */
246 
247 /* Private macros ------------------------------------------------------------*/
248 /** @defgroup I2CEx_Private_Macro I2C Extended Private Macros
249   * @{
250   */
251 #define IS_I2C_ANALOG_FILTER(FILTER)    (((FILTER) == I2C_ANALOGFILTER_ENABLE) || \
252                                          ((FILTER) == I2C_ANALOGFILTER_DISABLE))
253 
254 #define IS_I2C_DIGITAL_FILTER(FILTER)   ((FILTER) <= 0x0000000FU)
255 
256 #define IS_I2C_FASTMODEPLUS(__CONFIG__) (((__CONFIG__) == (I2C_FASTMODEPLUS_ENABLE))   || \
257                                          ((__CONFIG__) == (I2C_FASTMODEPLUS_DISABLE)))
258 
259 #define IS_I2C_AUTO_MODE(__MODE__)                  (((__MODE__) == I2C_AUTO_MODE_DISABLE) || \
260                                                      ((__MODE__) == I2C_AUTO_MODE_ENABLE))
261 
262 #if defined(I2C_TRIG_GRP1)
263 #define IS_I2C_TRIG_SOURCE(__INSTANCE__, __SOURCE__)  (((__INSTANCE__) == I2C3) ? \
264                                                        IS_I2C_GRP2_TRIG_SOURCE(__SOURCE__) : \
265                                                        IS_I2C_GRP1_TRIG_SOURCE(__SOURCE__))
266 #else
267 #define IS_I2C_TRIG_SOURCE(__INSTANCE__, __SOURCE__)  (IS_I2C_GRP2_TRIG_SOURCE(__SOURCE__))
268 #endif /* I2C_TRIG_GRP1 */
269 
270 #if defined(COMP1) && defined(COMP2)
271 #if defined(I2C_TRIG_GRP1)
272 #define IS_I2C_GRP1_TRIG_SOURCE(__SOURCE__)  (((__SOURCE__) == I2C_GRP1_GPDMA_CH0_TCF_TRG  ) || \
273                                               ((__SOURCE__) == I2C_GRP1_GPDMA_CH1_TCF_TRG  ) || \
274                                               ((__SOURCE__) == I2C_GRP1_GPDMA_CH2_TCF_TRG  ) || \
275                                               ((__SOURCE__) == I2C_GRP1_GPDMA_CH3_TCF_TRG  ) || \
276                                               ((__SOURCE__) == I2C_GRP1_EXTI5_TRG          ) || \
277                                               ((__SOURCE__) == I2C_GRP1_EXTI9_TRG          ) || \
278                                               ((__SOURCE__) == I2C_GRP1_LPTIM1_CH1_TRG     ) || \
279                                               ((__SOURCE__) == I2C_GRP1_LPTIM2_CH1_TRG     ) || \
280                                               ((__SOURCE__) == I2C_GRP1_COMP1_TRG          ) || \
281                                               ((__SOURCE__) == I2C_GRP1_COMP2_TRG          ) || \
282                                               ((__SOURCE__) == I2C_GRP1_RTC_ALRA_TRG       ) || \
283                                               ((__SOURCE__) == I2C_GRP1_RTC_WUT_TRG        ))
284 #endif /* I2C_TRIG_GRP1 */
285 
286 #define IS_I2C_GRP2_TRIG_SOURCE(__SOURCE__)  (((__SOURCE__) == I2C_GRP2_GPDMA_CH0_TCF_TRG  ) || \
287                                               ((__SOURCE__) == I2C_GRP2_GPDMA_CH1_TCF_TRG  ) || \
288                                               ((__SOURCE__) == I2C_GRP2_GPDMA_CH2_TCF_TRG  ) || \
289                                               ((__SOURCE__) == I2C_GRP2_GPDMA_CH3_TCF_TRG  ) || \
290                                               ((__SOURCE__) == I2C_GRP2_EXTI5_TRG          ) || \
291                                               ((__SOURCE__) == I2C_GRP2_EXTI8_TRG          ) || \
292                                               ((__SOURCE__) == I2C_GRP2_LPTIM1_CH1_TRG     ) || \
293                                               ((__SOURCE__) == I2C_GRP2_COMP1_TRG          ) || \
294                                               ((__SOURCE__) == I2C_GRP2_COMP2_TRG          ) || \
295                                               ((__SOURCE__) == I2C_GRP2_RTC_ALRA_TRG       ) || \
296                                               ((__SOURCE__) == I2C_GRP2_RTC_WUT_TRG        ))
297 
298 #else
299 
300 #define IS_I2C_GRP1_TRIG_SOURCE(__SOURCE__)  (((__SOURCE__) == I2C_GRP1_GPDMA_CH0_TCF_TRG  ) || \
301                                               ((__SOURCE__) == I2C_GRP1_GPDMA_CH1_TCF_TRG  ) || \
302                                               ((__SOURCE__) == I2C_GRP1_GPDMA_CH2_TCF_TRG  ) || \
303                                               ((__SOURCE__) == I2C_GRP1_GPDMA_CH3_TCF_TRG  ) || \
304                                               ((__SOURCE__) == I2C_GRP1_EXTI5_TRG          ) || \
305                                               ((__SOURCE__) == I2C_GRP1_EXTI9_TRG          ) || \
306                                               ((__SOURCE__) == I2C_GRP1_LPTIM1_CH1_TRG     ) || \
307                                               ((__SOURCE__) == I2C_GRP1_LPTIM2_CH1_TRG     ) || \
308                                               ((__SOURCE__) == I2C_GRP1_RTC_ALRA_TRG       ) || \
309                                               ((__SOURCE__) == I2C_GRP1_RTC_WUT_TRG        ))
310 
311 #define IS_I2C_GRP2_TRIG_SOURCE(__SOURCE__)  (((__SOURCE__) == I2C_GRP2_GPDMA_CH0_TCF_TRG  ) || \
312                                               ((__SOURCE__) == I2C_GRP2_GPDMA_CH1_TCF_TRG  ) || \
313                                               ((__SOURCE__) == I2C_GRP2_GPDMA_CH2_TCF_TRG  ) || \
314                                               ((__SOURCE__) == I2C_GRP2_GPDMA_CH3_TCF_TRG  ) || \
315                                               ((__SOURCE__) == I2C_GRP2_EXTI5_TRG          ) || \
316                                               ((__SOURCE__) == I2C_GRP2_EXTI8_TRG          ) || \
317                                               ((__SOURCE__) == I2C_GRP2_LPTIM1_CH1_TRG     ) || \
318                                               ((__SOURCE__) == I2C_GRP2_RTC_ALRA_TRG       ) || \
319                                               ((__SOURCE__) == I2C_GRP2_RTC_WUT_TRG        ))
320 #endif /* COMP1 && COMP2 */
321 
322 #if defined(I2C_TRIG_GRP1)
323 #define IS_I2C_TRIG_INPUT_INSTANCE(__INSTANCE__)    (IS_I2C_GRP1_INSTANCE(__INSTANCE__) || \
324                                                      IS_I2C_GRP2_INSTANCE(__INSTANCE__))
325 #else
326 #define IS_I2C_TRIG_INPUT_INSTANCE(__INSTANCE__)    IS_I2C_GRP1_INSTANCE(__INSTANCE__)
327 #endif /* I2C_TRIG_GRP1 */
328 
329 #define IS_I2C_AUTO_MODE_TRG_POL(__POLARITY__)      (((__POLARITY__) == I2C_TRIG_POLARITY_RISING) || \
330                                                      ((__POLARITY__) == I2C_TRIG_POLARITY_FALLING))
331 /**
332   * @}
333   */
334 
335 /* Private Functions ---------------------------------------------------------*/
336 /** @defgroup I2CEx_Private_Functions I2C Extended Private Functions
337   * @{
338   */
339 /* Private functions are defined in stm32wbaxx_hal_i2c_ex.c file */
340 /**
341   * @}
342   */
343 
344 /**
345   * @}
346   */
347 
348 /**
349   * @}
350   */
351 
352 #ifdef __cplusplus
353 }
354 #endif
355 
356 #endif /* STM32WBAxx_HAL_I2C_EX_H */
357