Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /** |
| 2 | ****************************************************************************** |
||
| 3 | * @file stm32f0xx_hal_i2c_ex.c |
||
| 4 | * @author MCD Application Team |
||
| 5 | * @brief I2C Extended HAL module driver. |
||
| 6 | * This file provides firmware functions to manage the following |
||
| 7 | * functionalities of I2C Extended peripheral: |
||
| 8 | * + Extended features functions |
||
| 9 | * |
||
| 10 | @verbatim |
||
| 11 | ============================================================================== |
||
| 12 | ##### I2C peripheral Extended features ##### |
||
| 13 | ============================================================================== |
||
| 14 | |||
| 15 | [..] Comparing to other previous devices, the I2C interface for STM32F0xx |
||
| 16 | devices contains the following additional features |
||
| 17 | |||
| 18 | (+) Possibility to disable or enable Analog Noise Filter |
||
| 19 | (+) Use of a configured Digital Noise Filter |
||
| 20 | (+) Disable or enable wakeup from Stop mode(s) |
||
| 21 | (+) Disable or enable Fast Mode Plus |
||
| 22 | |||
| 23 | ##### How to use this driver ##### |
||
| 24 | ============================================================================== |
||
| 25 | [..] This driver provides functions to configure Noise Filter and Wake Up Feature |
||
| 26 | (#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter() |
||
| 27 | (#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter() |
||
| 28 | (#) Configure the enable or disable of I2C Wake Up Mode using the functions : |
||
| 29 | (++) HAL_I2CEx_EnableWakeUp() |
||
| 30 | (++) HAL_I2CEx_DisableWakeUp() |
||
| 31 | (#) Configure the enable or disable of fast mode plus driving capability using the functions : |
||
| 32 | (++) HAL_I2CEx_EnableFastModePlus() |
||
| 33 | (++) HAL_I2CEx_DisableFastModePlus() |
||
| 34 | @endverbatim |
||
| 35 | ****************************************************************************** |
||
| 36 | * @attention |
||
| 37 | * |
||
| 38 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
||
| 39 | * All rights reserved.</center></h2> |
||
| 40 | * |
||
| 41 | * This software component is licensed by ST under BSD 3-Clause license, |
||
| 42 | * the "License"; You may not use this file except in compliance with the |
||
| 43 | * License. You may obtain a copy of the License at: |
||
| 44 | * opensource.org/licenses/BSD-3-Clause |
||
| 45 | * |
||
| 46 | ****************************************************************************** |
||
| 47 | */ |
||
| 48 | |||
| 49 | /* Includes ------------------------------------------------------------------*/ |
||
| 50 | #include "stm32f0xx_hal.h" |
||
| 51 | |||
| 52 | /** @addtogroup STM32F0xx_HAL_Driver |
||
| 53 | * @{ |
||
| 54 | */ |
||
| 55 | |||
| 56 | /** @defgroup I2CEx I2CEx |
||
| 57 | * @brief I2C Extended HAL module driver |
||
| 58 | * @{ |
||
| 59 | */ |
||
| 60 | |||
| 61 | #ifdef HAL_I2C_MODULE_ENABLED |
||
| 62 | |||
| 63 | /* Private typedef -----------------------------------------------------------*/ |
||
| 64 | /* Private define ------------------------------------------------------------*/ |
||
| 65 | /* Private macro -------------------------------------------------------------*/ |
||
| 66 | /* Private variables ---------------------------------------------------------*/ |
||
| 67 | /* Private function prototypes -----------------------------------------------*/ |
||
| 68 | /* Private functions ---------------------------------------------------------*/ |
||
| 69 | |||
| 70 | /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions |
||
| 71 | * @{ |
||
| 72 | */ |
||
| 73 | |||
| 74 | /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions |
||
| 75 | * @brief Extended features functions |
||
| 76 | * |
||
| 77 | @verbatim |
||
| 78 | =============================================================================== |
||
| 79 | ##### Extended features functions ##### |
||
| 80 | =============================================================================== |
||
| 81 | [..] This section provides functions allowing to: |
||
| 82 | (+) Configure Noise Filters |
||
| 83 | (+) Configure Wake Up Feature |
||
| 84 | (+) Configure Fast Mode Plus |
||
| 85 | |||
| 86 | @endverbatim |
||
| 87 | * @{ |
||
| 88 | */ |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @brief Configure I2C Analog noise filter. |
||
| 92 | * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains |
||
| 93 | * the configuration information for the specified I2Cx peripheral. |
||
| 94 | * @param AnalogFilter New state of the Analog filter. |
||
| 95 | * @retval HAL status |
||
| 96 | */ |
||
| 97 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter) |
||
| 98 | { |
||
| 99 | /* Check the parameters */ |
||
| 100 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); |
||
| 101 | assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter)); |
||
| 102 | |||
| 103 | if (hi2c->State == HAL_I2C_STATE_READY) |
||
| 104 | { |
||
| 105 | /* Process Locked */ |
||
| 106 | __HAL_LOCK(hi2c); |
||
| 107 | |||
| 108 | hi2c->State = HAL_I2C_STATE_BUSY; |
||
| 109 | |||
| 110 | /* Disable the selected I2C peripheral */ |
||
| 111 | __HAL_I2C_DISABLE(hi2c); |
||
| 112 | |||
| 113 | /* Reset I2Cx ANOFF bit */ |
||
| 114 | hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF); |
||
| 115 | |||
| 116 | /* Set analog filter bit*/ |
||
| 117 | hi2c->Instance->CR1 |= AnalogFilter; |
||
| 118 | |||
| 119 | __HAL_I2C_ENABLE(hi2c); |
||
| 120 | |||
| 121 | hi2c->State = HAL_I2C_STATE_READY; |
||
| 122 | |||
| 123 | /* Process Unlocked */ |
||
| 124 | __HAL_UNLOCK(hi2c); |
||
| 125 | |||
| 126 | return HAL_OK; |
||
| 127 | } |
||
| 128 | else |
||
| 129 | { |
||
| 130 | return HAL_BUSY; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @brief Configure I2C Digital noise filter. |
||
| 136 | * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains |
||
| 137 | * the configuration information for the specified I2Cx peripheral. |
||
| 138 | * @param DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F. |
||
| 139 | * @retval HAL status |
||
| 140 | */ |
||
| 141 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter) |
||
| 142 | { |
||
| 143 | uint32_t tmpreg; |
||
| 144 | |||
| 145 | /* Check the parameters */ |
||
| 146 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); |
||
| 147 | assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter)); |
||
| 148 | |||
| 149 | if (hi2c->State == HAL_I2C_STATE_READY) |
||
| 150 | { |
||
| 151 | /* Process Locked */ |
||
| 152 | __HAL_LOCK(hi2c); |
||
| 153 | |||
| 154 | hi2c->State = HAL_I2C_STATE_BUSY; |
||
| 155 | |||
| 156 | /* Disable the selected I2C peripheral */ |
||
| 157 | __HAL_I2C_DISABLE(hi2c); |
||
| 158 | |||
| 159 | /* Get the old register value */ |
||
| 160 | tmpreg = hi2c->Instance->CR1; |
||
| 161 | |||
| 162 | /* Reset I2Cx DNF bits [11:8] */ |
||
| 163 | tmpreg &= ~(I2C_CR1_DNF); |
||
| 164 | |||
| 165 | /* Set I2Cx DNF coefficient */ |
||
| 166 | tmpreg |= DigitalFilter << 8U; |
||
| 167 | |||
| 168 | /* Store the new register value */ |
||
| 169 | hi2c->Instance->CR1 = tmpreg; |
||
| 170 | |||
| 171 | __HAL_I2C_ENABLE(hi2c); |
||
| 172 | |||
| 173 | hi2c->State = HAL_I2C_STATE_READY; |
||
| 174 | |||
| 175 | /* Process Unlocked */ |
||
| 176 | __HAL_UNLOCK(hi2c); |
||
| 177 | |||
| 178 | return HAL_OK; |
||
| 179 | } |
||
| 180 | else |
||
| 181 | { |
||
| 182 | return HAL_BUSY; |
||
| 183 | } |
||
| 184 | } |
||
| 185 | #if defined(I2C_CR1_WUPEN) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @brief Enable I2C wakeup from Stop mode(s). |
||
| 189 | * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains |
||
| 190 | * the configuration information for the specified I2Cx peripheral. |
||
| 191 | * @retval HAL status |
||
| 192 | */ |
||
| 193 | HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c) |
||
| 194 | { |
||
| 195 | /* Check the parameters */ |
||
| 196 | assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance)); |
||
| 197 | |||
| 198 | if (hi2c->State == HAL_I2C_STATE_READY) |
||
| 199 | { |
||
| 200 | /* Process Locked */ |
||
| 201 | __HAL_LOCK(hi2c); |
||
| 202 | |||
| 203 | hi2c->State = HAL_I2C_STATE_BUSY; |
||
| 204 | |||
| 205 | /* Disable the selected I2C peripheral */ |
||
| 206 | __HAL_I2C_DISABLE(hi2c); |
||
| 207 | |||
| 208 | /* Enable wakeup from stop mode */ |
||
| 209 | hi2c->Instance->CR1 |= I2C_CR1_WUPEN; |
||
| 210 | |||
| 211 | __HAL_I2C_ENABLE(hi2c); |
||
| 212 | |||
| 213 | hi2c->State = HAL_I2C_STATE_READY; |
||
| 214 | |||
| 215 | /* Process Unlocked */ |
||
| 216 | __HAL_UNLOCK(hi2c); |
||
| 217 | |||
| 218 | return HAL_OK; |
||
| 219 | } |
||
| 220 | else |
||
| 221 | { |
||
| 222 | return HAL_BUSY; |
||
| 223 | } |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @brief Disable I2C wakeup from Stop mode(s). |
||
| 228 | * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains |
||
| 229 | * the configuration information for the specified I2Cx peripheral. |
||
| 230 | * @retval HAL status |
||
| 231 | */ |
||
| 232 | HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c) |
||
| 233 | { |
||
| 234 | /* Check the parameters */ |
||
| 235 | assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance)); |
||
| 236 | |||
| 237 | if (hi2c->State == HAL_I2C_STATE_READY) |
||
| 238 | { |
||
| 239 | /* Process Locked */ |
||
| 240 | __HAL_LOCK(hi2c); |
||
| 241 | |||
| 242 | hi2c->State = HAL_I2C_STATE_BUSY; |
||
| 243 | |||
| 244 | /* Disable the selected I2C peripheral */ |
||
| 245 | __HAL_I2C_DISABLE(hi2c); |
||
| 246 | |||
| 247 | /* Enable wakeup from stop mode */ |
||
| 248 | hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN); |
||
| 249 | |||
| 250 | __HAL_I2C_ENABLE(hi2c); |
||
| 251 | |||
| 252 | hi2c->State = HAL_I2C_STATE_READY; |
||
| 253 | |||
| 254 | /* Process Unlocked */ |
||
| 255 | __HAL_UNLOCK(hi2c); |
||
| 256 | |||
| 257 | return HAL_OK; |
||
| 258 | } |
||
| 259 | else |
||
| 260 | { |
||
| 261 | return HAL_BUSY; |
||
| 262 | } |
||
| 263 | } |
||
| 264 | #endif |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @brief Enable the I2C fast mode plus driving capability. |
||
| 268 | * @param ConfigFastModePlus Selects the pin. |
||
| 269 | * This parameter can be one of the @ref I2CEx_FastModePlus values |
||
| 270 | * @note For I2C1, fast mode plus driving capability can be enabled on all selected |
||
| 271 | * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently |
||
| 272 | * on each one of the following pins PB6, PB7, PB8 and PB9. |
||
| 273 | * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability |
||
| 274 | * can be enabled only by using I2C_FASTMODEPLUS_I2C1 parameter. |
||
| 275 | * @note For all I2C2 pins fast mode plus driving capability can be enabled |
||
| 276 | * only by using I2C_FASTMODEPLUS_I2C2 parameter. |
||
| 277 | * @retval None |
||
| 278 | */ |
||
| 279 | void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus) |
||
| 280 | { |
||
| 281 | /* Check the parameter */ |
||
| 282 | assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus)); |
||
| 283 | |||
| 284 | /* Enable SYSCFG clock */ |
||
| 285 | __HAL_RCC_SYSCFG_CLK_ENABLE(); |
||
| 286 | |||
| 287 | /* Enable fast mode plus driving capability for selected pin */ |
||
| 288 | SET_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus); |
||
| 289 | } |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @brief Disable the I2C fast mode plus driving capability. |
||
| 293 | * @param ConfigFastModePlus Selects the pin. |
||
| 294 | * This parameter can be one of the @ref I2CEx_FastModePlus values |
||
| 295 | * @note For I2C1, fast mode plus driving capability can be disabled on all selected |
||
| 296 | * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently |
||
| 297 | * on each one of the following pins PB6, PB7, PB8 and PB9. |
||
| 298 | * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability |
||
| 299 | * can be disabled only by using I2C_FASTMODEPLUS_I2C1 parameter. |
||
| 300 | * @note For all I2C2 pins fast mode plus driving capability can be disabled |
||
| 301 | * only by using I2C_FASTMODEPLUS_I2C2 parameter. |
||
| 302 | * @retval None |
||
| 303 | */ |
||
| 304 | void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus) |
||
| 305 | { |
||
| 306 | /* Check the parameter */ |
||
| 307 | assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus)); |
||
| 308 | |||
| 309 | /* Enable SYSCFG clock */ |
||
| 310 | __HAL_RCC_SYSCFG_CLK_ENABLE(); |
||
| 311 | |||
| 312 | /* Disable fast mode plus driving capability for selected pin */ |
||
| 313 | CLEAR_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus); |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @} |
||
| 318 | */ |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @} |
||
| 322 | */ |
||
| 323 | |||
| 324 | #endif /* HAL_I2C_MODULE_ENABLED */ |
||
| 325 | /** |
||
| 326 | * @} |
||
| 327 | */ |
||
| 328 | |||
| 329 | /** |
||
| 330 | * @} |
||
| 331 | */ |
||
| 332 | |||
| 333 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |