1 /** 2 ****************************************************************************** 3 * @file stm32u5xx_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) 2021 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 STM32U5xx_HAL_I2C_EX_H 21 #define STM32U5xx_HAL_I2C_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32u5xx_hal_def.h" 29 30 /** @addtogroup STM32U5xx_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 #define I2C_TRIG_GRP1 (0x10000000U) /*!< Trigger Group for I2C1, I2C2, I2C4, I2C5, I2C6 (depends on Product) */ 103 #define I2C_TRIG_GRP2 (0x20000000U) /*!< Trigger Group for I2C3 */ 104 105 #define I2C_GRP1_GPDMA_CH0_TCF_TRG (uint32_t)(I2C_TRIG_GRP1 | (0x00000000U)) 106 /*!< HW Trigger signal is GPDMA_CH0_TRG */ 107 #define I2C_GRP1_GPDMA_CH1_TCF_TRG (uint32_t)(I2C_TRIG_GRP1 | (0x1U << I2C_AUTOCR_TRIGSEL_Pos)) 108 /*!< HW Trigger signal is GPDMA_CH1_TRG */ 109 #define I2C_GRP1_GPDMA_CH2_TCF_TRG (uint32_t)(I2C_TRIG_GRP1 | (0x2U << I2C_AUTOCR_TRIGSEL_Pos)) 110 /*!< HW Trigger signal is GPDMA_CH2_TRG */ 111 #define I2C_GRP1_GPDMA_CH3_TCF_TRG (uint32_t)(I2C_TRIG_GRP1 | (0x3U << I2C_AUTOCR_TRIGSEL_Pos)) 112 /*!< HW Trigger signal is GPDMA_CH3_TRG */ 113 #define I2C_GRP1_EXTI5_TRG (uint32_t)(I2C_TRIG_GRP1 | (0x4U << I2C_AUTOCR_TRIGSEL_Pos)) 114 /*!< HW Trigger signal is EXTI5_TRG */ 115 #define I2C_GRP1_EXTI9_TRG (uint32_t)(I2C_TRIG_GRP1 | (0x5U << I2C_AUTOCR_TRIGSEL_Pos)) 116 /*!< HW Trigger signal is EXTI9_TRG */ 117 #define I2C_GRP1_LPTIM1_CH1_TRG (uint32_t)(I2C_TRIG_GRP1 | (0x6U << I2C_AUTOCR_TRIGSEL_Pos)) 118 /*!< HW Trigger signal is LPTIM1_CH1_TRG */ 119 #define I2C_GRP1_LPTIM2_CH1_TRG (uint32_t)(I2C_TRIG_GRP1 | (0x7U << I2C_AUTOCR_TRIGSEL_Pos)) 120 /*!< HW Trigger signal is LPTIM2_CH1_TRG */ 121 #define I2C_GRP1_COMP1_TRG (uint32_t)(I2C_TRIG_GRP1 | (0x8U << I2C_AUTOCR_TRIGSEL_Pos)) 122 /*!< HW Trigger signal is COMP1_TRG */ 123 #define I2C_GRP1_COMP2_TRG (uint32_t)(I2C_TRIG_GRP1 | (0x9U << I2C_AUTOCR_TRIGSEL_Pos)) 124 /*!< HW Trigger signal is COMP2_TRG */ 125 #define I2C_GRP1_RTC_ALRA_TRG (uint32_t)(I2C_TRIG_GRP1 | (0xAU << I2C_AUTOCR_TRIGSEL_Pos)) 126 /*!< HW Trigger signal is RTC_ALRA_TRG */ 127 #define I2C_GRP1_RTC_WUT_TRG (uint32_t)(I2C_TRIG_GRP1 | (0xBU << I2C_AUTOCR_TRIGSEL_Pos)) 128 /*!< HW Trigger signal is RTC_WUT_TRG */ 129 130 #define I2C_GRP2_LPDMA_CH0_TCF_TRG (uint32_t)(I2C_TRIG_GRP2 | (0x00000000U)) 131 /*!< HW Trigger signal is LPDMA_CH0_TRG */ 132 #define I2C_GRP2_LPDMA_CH1_TCF_TRG (uint32_t)(I2C_TRIG_GRP2 | (0x1U << I2C_AUTOCR_TRIGSEL_Pos)) 133 /*!< HW Trigger signal is LPDMA_CH1_TRG */ 134 #define I2C_GRP2_LPDMA_CH2_TCF_TRG (uint32_t)(I2C_TRIG_GRP2 | (0x2U << I2C_AUTOCR_TRIGSEL_Pos)) 135 /*!< HW Trigger signal is LPDMA_CH2_TRG */ 136 #define I2C_GRP2_LPDMA_CH3_TCF_TRG (uint32_t)(I2C_TRIG_GRP2 | (0x3U << I2C_AUTOCR_TRIGSEL_Pos)) 137 /*!< HW Trigger signal is LPDMA_CH3_TRG */ 138 #define I2C_GRP2_EXTI5_TRG (uint32_t)(I2C_TRIG_GRP2 | (0x4U << I2C_AUTOCR_TRIGSEL_Pos)) 139 /*!< HW Trigger signal is EXTI5_TRG */ 140 #define I2C_GRP2_EXTI8_TRG (uint32_t)(I2C_TRIG_GRP2 | (0x5U << I2C_AUTOCR_TRIGSEL_Pos)) 141 /*!< HW Trigger signal is EXTI8_TRG */ 142 #define I2C_GRP2_LPTIM1_CH1_TRG (uint32_t)(I2C_TRIG_GRP2 | (0x6U << I2C_AUTOCR_TRIGSEL_Pos)) 143 /*!< HW Trigger signal is LPTIM1_CH1_TRG */ 144 #define I2C_GRP2_LPTIM3_CH1_TRG (uint32_t)(I2C_TRIG_GRP2 | (0x7U << I2C_AUTOCR_TRIGSEL_Pos)) 145 /*!< HW Trigger signal is LPTIM3_CH1_TRG */ 146 #define I2C_GRP2_COMP1_TRG (uint32_t)(I2C_TRIG_GRP2 | (0x8U << I2C_AUTOCR_TRIGSEL_Pos)) 147 /*!< HW Trigger signal is COMP1_TRG */ 148 #define I2C_GRP2_COMP2_TRG (uint32_t)(I2C_TRIG_GRP2 | (0x9U << I2C_AUTOCR_TRIGSEL_Pos)) 149 /*!< HW Trigger signal is COMP2_TRG */ 150 #define I2C_GRP2_RTC_ALRA_TRG (uint32_t)(I2C_TRIG_GRP2 | (0xAU << I2C_AUTOCR_TRIGSEL_Pos)) 151 /*!< HW Trigger signal is RTC_ALRA_TRG */ 152 #define I2C_GRP2_RTC_WUT_TRG (uint32_t)(I2C_TRIG_GRP2 | (0xBU << I2C_AUTOCR_TRIGSEL_Pos)) 153 /*!< HW Trigger signal is RTC_WUT_TRG */ 154 /** 155 * @} 156 */ 157 158 /** @defgroup I2CEx_AutonomousMode_TriggerPolarity Extended Autonomous Mode Trigger Polarity 159 * @{ 160 */ 161 #define I2C_TRIG_POLARITY_RISING (0x00000000U) /*!< I2C HW Trigger signal on rising edge */ 162 #define I2C_TRIG_POLARITY_FALLING I2C_AUTOCR_TRIGPOL /*!< I2C HW Trigger signal on falling edge */ 163 /** 164 * @} 165 */ 166 167 /** 168 * @} 169 */ 170 171 /* Exported macro ------------------------------------------------------------*/ 172 /** @defgroup I2CEx_Exported_Macros I2C Extended Exported Macros 173 * @{ 174 */ 175 176 /** 177 * @} 178 */ 179 180 /* Exported functions --------------------------------------------------------*/ 181 /** @addtogroup I2CEx_Exported_Functions I2C Extended Exported Functions 182 * @{ 183 */ 184 185 /** @addtogroup I2CEx_Exported_Functions_Group1 Filter Mode Functions 186 * @{ 187 */ 188 /* Peripheral Control functions ************************************************/ 189 HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter); 190 HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter); 191 /** 192 * @} 193 */ 194 195 /** @addtogroup I2CEx_Exported_Functions_Group2 WakeUp Mode Functions 196 * @{ 197 */ 198 HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c); 199 HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c); 200 /** 201 * @} 202 */ 203 204 /** @addtogroup I2CEx_Exported_Functions_Group3 Fast Mode Plus Functions 205 * @{ 206 */ 207 HAL_StatusTypeDef HAL_I2CEx_ConfigFastModePlus(I2C_HandleTypeDef *hi2c, uint32_t FastModePlus); 208 /** 209 * @} 210 */ 211 212 /** @addtogroup I2CEx_Exported_Functions_Group4 Autonomous Mode Functions 213 * @{ 214 */ 215 HAL_StatusTypeDef HAL_I2CEx_SetConfigAutonomousMode(I2C_HandleTypeDef *hi2c, 216 const I2C_AutonomousModeConfTypeDef *sConfig); 217 HAL_StatusTypeDef HAL_I2CEx_GetConfigAutonomousMode(const I2C_HandleTypeDef *hi2c, 218 I2C_AutonomousModeConfTypeDef *sConfig); 219 HAL_StatusTypeDef HAL_I2CEx_ClearConfigAutonomousMode(I2C_HandleTypeDef *hi2c); 220 /** 221 * @} 222 */ 223 224 /** 225 * @} 226 */ 227 228 /* Private constants ---------------------------------------------------------*/ 229 /** @defgroup I2CEx_Private_Constants I2C Extended Private Constants 230 * @{ 231 */ 232 233 /** 234 * @} 235 */ 236 237 /* Private macros ------------------------------------------------------------*/ 238 /** @defgroup I2CEx_Private_Macro I2C Extended Private Macros 239 * @{ 240 */ 241 #define IS_I2C_ANALOG_FILTER(FILTER) (((FILTER) == I2C_ANALOGFILTER_ENABLE) || \ 242 ((FILTER) == I2C_ANALOGFILTER_DISABLE)) 243 244 #define IS_I2C_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU) 245 246 #define IS_I2C_FASTMODEPLUS(__CONFIG__) (((__CONFIG__) == (I2C_FASTMODEPLUS_ENABLE)) || \ 247 ((__CONFIG__) == (I2C_FASTMODEPLUS_DISABLE))) 248 249 #define IS_I2C_AUTO_MODE(__MODE__) (((__MODE__) == I2C_AUTO_MODE_DISABLE) || \ 250 ((__MODE__) == I2C_AUTO_MODE_ENABLE)) 251 252 #define IS_I2C_TRIG_SOURCE(__INSTANCE__, __SOURCE__) (((__INSTANCE__) == I2C3) ? \ 253 IS_I2C_GRP2_TRIG_SOURCE(__SOURCE__) : \ 254 IS_I2C_GRP1_TRIG_SOURCE(__SOURCE__)) 255 256 #define IS_I2C_GRP1_TRIG_SOURCE(__SOURCE__) (((__SOURCE__) == I2C_GRP1_GPDMA_CH0_TCF_TRG ) || \ 257 ((__SOURCE__) == I2C_GRP1_GPDMA_CH1_TCF_TRG ) || \ 258 ((__SOURCE__) == I2C_GRP1_GPDMA_CH2_TCF_TRG ) || \ 259 ((__SOURCE__) == I2C_GRP1_GPDMA_CH3_TCF_TRG ) || \ 260 ((__SOURCE__) == I2C_GRP1_EXTI5_TRG ) || \ 261 ((__SOURCE__) == I2C_GRP1_EXTI9_TRG ) || \ 262 ((__SOURCE__) == I2C_GRP1_LPTIM1_CH1_TRG ) || \ 263 ((__SOURCE__) == I2C_GRP1_LPTIM2_CH1_TRG ) || \ 264 ((__SOURCE__) == I2C_GRP1_COMP1_TRG ) || \ 265 ((__SOURCE__) == I2C_GRP1_COMP2_TRG ) || \ 266 ((__SOURCE__) == I2C_GRP1_RTC_ALRA_TRG ) || \ 267 ((__SOURCE__) == I2C_GRP1_RTC_WUT_TRG )) 268 269 #define IS_I2C_GRP2_TRIG_SOURCE(__SOURCE__) (((__SOURCE__) == I2C_GRP2_LPDMA_CH0_TCF_TRG ) || \ 270 ((__SOURCE__) == I2C_GRP2_LPDMA_CH1_TCF_TRG ) || \ 271 ((__SOURCE__) == I2C_GRP2_LPDMA_CH2_TCF_TRG ) || \ 272 ((__SOURCE__) == I2C_GRP2_LPDMA_CH3_TCF_TRG ) || \ 273 ((__SOURCE__) == I2C_GRP2_EXTI5_TRG ) || \ 274 ((__SOURCE__) == I2C_GRP2_EXTI8_TRG ) || \ 275 ((__SOURCE__) == I2C_GRP2_LPTIM1_CH1_TRG ) || \ 276 ((__SOURCE__) == I2C_GRP2_LPTIM3_CH1_TRG ) || \ 277 ((__SOURCE__) == I2C_GRP2_COMP1_TRG ) || \ 278 ((__SOURCE__) == I2C_GRP2_COMP2_TRG ) || \ 279 ((__SOURCE__) == I2C_GRP2_RTC_ALRA_TRG ) || \ 280 ((__SOURCE__) == I2C_GRP2_RTC_WUT_TRG )) 281 282 #define IS_I2C_TRIG_INPUT_INSTANCE(__INSTANCE__) (IS_I2C_GRP1_INSTANCE(__INSTANCE__) || \ 283 IS_I2C_GRP2_INSTANCE(__INSTANCE__)) 284 285 #define IS_I2C_AUTO_MODE_TRG_POL(__POLARITY__) (((__POLARITY__) == I2C_TRIG_POLARITY_RISING) || \ 286 ((__POLARITY__) == I2C_TRIG_POLARITY_FALLING)) 287 /** 288 * @} 289 */ 290 291 /* Private Functions ---------------------------------------------------------*/ 292 /** @defgroup I2CEx_Private_Functions I2C Extended Private Functions 293 * @{ 294 */ 295 /* Private functions are defined in stm32u5xx_hal_i2c_ex.c file */ 296 /** 297 * @} 298 */ 299 300 /** 301 * @} 302 */ 303 304 /** 305 * @} 306 */ 307 308 #ifdef __cplusplus 309 } 310 #endif 311 312 #endif /* STM32U5xx_HAL_I2C_EX_H */ 313