2 ******************************************************************************
\r
3 * @file stm32l4xx_hal_i2c_ex.c
\r
4 * @author MCD Application Team
\r
5 * @brief I2C Extended HAL module driver.
\r
6 * This file provides firmware functions to manage the following
\r
7 * functionalities of I2C Extended peripheral:
\r
8 * + Extended features functions
\r
11 ==============================================================================
\r
12 ##### I2C peripheral Extended features #####
\r
13 ==============================================================================
\r
15 [..] Comparing to other previous devices, the I2C interface for STM32L4xx
\r
16 devices contains the following additional features
\r
18 (+) Possibility to disable or enable Analog Noise Filter
\r
19 (+) Use of a configured Digital Noise Filter
\r
20 (+) Disable or enable wakeup from Stop mode(s)
\r
21 (+) Disable or enable Fast Mode Plus
\r
23 ##### How to use this driver #####
\r
24 ==============================================================================
\r
25 [..] This driver provides functions to configure Noise Filter and Wake Up Feature
\r
26 (#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter()
\r
27 (#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter()
\r
28 (#) Configure the enable or disable of I2C Wake Up Mode using the functions :
\r
29 (++) HAL_I2CEx_EnableWakeUp()
\r
30 (++) HAL_I2CEx_DisableWakeUp()
\r
31 (#) Configure the enable or disable of fast mode plus driving capability using the functions :
\r
32 (++) HAL_I2CEx_EnableFastModePlus()
\r
33 (++) HAL_I2CEx_DisableFastModePlus()
\r
35 ******************************************************************************
\r
38 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
39 * All rights reserved.</center></h2>
\r
41 * This software component is licensed by ST under BSD 3-Clause license,
\r
42 * the "License"; You may not use this file except in compliance with the
\r
43 * License. You may obtain a copy of the License at:
\r
44 * opensource.org/licenses/BSD-3-Clause
\r
46 ******************************************************************************
\r
49 /* Includes ------------------------------------------------------------------*/
\r
50 #include "stm32l4xx_hal.h"
\r
52 /** @addtogroup STM32L4xx_HAL_Driver
\r
56 /** @defgroup I2CEx I2CEx
\r
57 * @brief I2C Extended HAL module driver
\r
61 #ifdef HAL_I2C_MODULE_ENABLED
\r
63 /* Private typedef -----------------------------------------------------------*/
\r
64 /* Private define ------------------------------------------------------------*/
\r
65 /* Private macro -------------------------------------------------------------*/
\r
66 /* Private variables ---------------------------------------------------------*/
\r
67 /* Private function prototypes -----------------------------------------------*/
\r
68 /* Private functions ---------------------------------------------------------*/
\r
70 /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions
\r
74 /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions
\r
75 * @brief Extended features functions
\r
78 ===============================================================================
\r
79 ##### Extended features functions #####
\r
80 ===============================================================================
\r
81 [..] This section provides functions allowing to:
\r
82 (+) Configure Noise Filters
\r
83 (+) Configure Wake Up Feature
\r
84 (+) Configure Fast Mode Plus
\r
91 * @brief Configure I2C Analog noise filter.
\r
92 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
\r
93 * the configuration information for the specified I2Cx peripheral.
\r
94 * @param AnalogFilter New state of the Analog filter.
\r
95 * @retval HAL status
\r
97 HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
\r
99 /* Check the parameters */
\r
100 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
\r
101 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
\r
103 if (hi2c->State == HAL_I2C_STATE_READY)
\r
105 /* Process Locked */
\r
108 hi2c->State = HAL_I2C_STATE_BUSY;
\r
110 /* Disable the selected I2C peripheral */
\r
111 __HAL_I2C_DISABLE(hi2c);
\r
113 /* Reset I2Cx ANOFF bit */
\r
114 hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF);
\r
116 /* Set analog filter bit*/
\r
117 hi2c->Instance->CR1 |= AnalogFilter;
\r
119 __HAL_I2C_ENABLE(hi2c);
\r
121 hi2c->State = HAL_I2C_STATE_READY;
\r
123 /* Process Unlocked */
\r
124 __HAL_UNLOCK(hi2c);
\r
135 * @brief Configure I2C Digital noise filter.
\r
136 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
\r
137 * the configuration information for the specified I2Cx peripheral.
\r
138 * @param DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F.
\r
139 * @retval HAL status
\r
141 HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
\r
145 /* Check the parameters */
\r
146 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
\r
147 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
\r
149 if (hi2c->State == HAL_I2C_STATE_READY)
\r
151 /* Process Locked */
\r
154 hi2c->State = HAL_I2C_STATE_BUSY;
\r
156 /* Disable the selected I2C peripheral */
\r
157 __HAL_I2C_DISABLE(hi2c);
\r
159 /* Get the old register value */
\r
160 tmpreg = hi2c->Instance->CR1;
\r
162 /* Reset I2Cx DNF bits [11:8] */
\r
163 tmpreg &= ~(I2C_CR1_DNF);
\r
165 /* Set I2Cx DNF coefficient */
\r
166 tmpreg |= DigitalFilter << 8U;
\r
168 /* Store the new register value */
\r
169 hi2c->Instance->CR1 = tmpreg;
\r
171 __HAL_I2C_ENABLE(hi2c);
\r
173 hi2c->State = HAL_I2C_STATE_READY;
\r
175 /* Process Unlocked */
\r
176 __HAL_UNLOCK(hi2c);
\r
187 * @brief Enable I2C wakeup from Stop mode(s).
\r
188 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
\r
189 * the configuration information for the specified I2Cx peripheral.
\r
190 * @retval HAL status
\r
192 HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c)
\r
194 /* Check the parameters */
\r
195 assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance));
\r
197 if (hi2c->State == HAL_I2C_STATE_READY)
\r
199 /* Process Locked */
\r
202 hi2c->State = HAL_I2C_STATE_BUSY;
\r
204 /* Disable the selected I2C peripheral */
\r
205 __HAL_I2C_DISABLE(hi2c);
\r
207 /* Enable wakeup from stop mode */
\r
208 hi2c->Instance->CR1 |= I2C_CR1_WUPEN;
\r
210 __HAL_I2C_ENABLE(hi2c);
\r
212 hi2c->State = HAL_I2C_STATE_READY;
\r
214 /* Process Unlocked */
\r
215 __HAL_UNLOCK(hi2c);
\r
226 * @brief Disable I2C wakeup from Stop mode(s).
\r
227 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
\r
228 * the configuration information for the specified I2Cx peripheral.
\r
229 * @retval HAL status
\r
231 HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c)
\r
233 /* Check the parameters */
\r
234 assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance));
\r
236 if (hi2c->State == HAL_I2C_STATE_READY)
\r
238 /* Process Locked */
\r
241 hi2c->State = HAL_I2C_STATE_BUSY;
\r
243 /* Disable the selected I2C peripheral */
\r
244 __HAL_I2C_DISABLE(hi2c);
\r
246 /* Enable wakeup from stop mode */
\r
247 hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN);
\r
249 __HAL_I2C_ENABLE(hi2c);
\r
251 hi2c->State = HAL_I2C_STATE_READY;
\r
253 /* Process Unlocked */
\r
254 __HAL_UNLOCK(hi2c);
\r
265 * @brief Enable the I2C fast mode plus driving capability.
\r
266 * @param ConfigFastModePlus Selects the pin.
\r
267 * This parameter can be one of the @ref I2CEx_FastModePlus values
\r
268 * @note For I2C1, fast mode plus driving capability can be enabled on all selected
\r
269 * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently
\r
270 * on each one of the following pins PB6, PB7, PB8 and PB9.
\r
271 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
\r
272 * can be enabled only by using I2C_FASTMODEPLUS_I2C1 parameter.
\r
273 * @note For all I2C2 pins fast mode plus driving capability can be enabled
\r
274 * only by using I2C_FASTMODEPLUS_I2C2 parameter.
\r
275 * @note For all I2C3 pins fast mode plus driving capability can be enabled
\r
276 * only by using I2C_FASTMODEPLUS_I2C3 parameter.
\r
277 * @note For all I2C4 pins fast mode plus driving capability can be enabled
\r
278 * only by using I2C_FASTMODEPLUS_I2C4 parameter.
\r
281 void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
\r
283 /* Check the parameter */
\r
284 assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus));
\r
286 /* Enable SYSCFG clock */
\r
287 __HAL_RCC_SYSCFG_CLK_ENABLE();
\r
289 /* Enable fast mode plus driving capability for selected pin */
\r
290 SET_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus);
\r
294 * @brief Disable the I2C fast mode plus driving capability.
\r
295 * @param ConfigFastModePlus Selects the pin.
\r
296 * This parameter can be one of the @ref I2CEx_FastModePlus values
\r
297 * @note For I2C1, fast mode plus driving capability can be disabled on all selected
\r
298 * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently
\r
299 * on each one of the following pins PB6, PB7, PB8 and PB9.
\r
300 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
\r
301 * can be disabled only by using I2C_FASTMODEPLUS_I2C1 parameter.
\r
302 * @note For all I2C2 pins fast mode plus driving capability can be disabled
\r
303 * only by using I2C_FASTMODEPLUS_I2C2 parameter.
\r
304 * @note For all I2C3 pins fast mode plus driving capability can be disabled
\r
305 * only by using I2C_FASTMODEPLUS_I2C3 parameter.
\r
306 * @note For all I2C4 pins fast mode plus driving capability can be disabled
\r
307 * only by using I2C_FASTMODEPLUS_I2C4 parameter.
\r
310 void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
\r
312 /* Check the parameter */
\r
313 assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus));
\r
315 /* Enable SYSCFG clock */
\r
316 __HAL_RCC_SYSCFG_CLK_ENABLE();
\r
318 /* Disable fast mode plus driving capability for selected pin */
\r
319 CLEAR_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus);
\r
330 #endif /* HAL_I2C_MODULE_ENABLED */
\r
339 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r