2 ******************************************************************************
\r
3 * @file stm32f7xx_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 STM32F7xx
\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 Fast Mode Plus
\r
22 ##### How to use this driver #####
\r
23 ==============================================================================
\r
24 [..] This driver provides functions to:
\r
25 (#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter()
\r
26 (#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter()
\r
27 (#) Configure the enable or disable of fast mode plus driving capability using the functions :
\r
28 (++) HAL_I2CEx_EnableFastModePlus()
\r
29 (++) HAL_I2CEx_DisableFastModePlus()
\r
31 ******************************************************************************
\r
34 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
35 * All rights reserved.</center></h2>
\r
37 * This software component is licensed by ST under BSD 3-Clause license,
\r
38 * the "License"; You may not use this file except in compliance with the
\r
39 * License. You may obtain a copy of the License at:
\r
40 * opensource.org/licenses/BSD-3-Clause
\r
42 ******************************************************************************
\r
45 /* Includes ------------------------------------------------------------------*/
\r
46 #include "stm32f7xx_hal.h"
\r
48 /** @addtogroup STM32F7xx_HAL_Driver
\r
52 /** @defgroup I2CEx I2CEx
\r
53 * @brief I2C Extended HAL module driver
\r
57 #ifdef HAL_I2C_MODULE_ENABLED
\r
59 /* Private typedef -----------------------------------------------------------*/
\r
60 /* Private define ------------------------------------------------------------*/
\r
61 /* Private macro -------------------------------------------------------------*/
\r
62 /* Private variables ---------------------------------------------------------*/
\r
63 /* Private function prototypes -----------------------------------------------*/
\r
64 /* Private functions ---------------------------------------------------------*/
\r
66 /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions
\r
70 /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions
\r
71 * @brief Extended features functions
\r
74 ===============================================================================
\r
75 ##### Extended features functions #####
\r
76 ===============================================================================
\r
77 [..] This section provides functions allowing to:
\r
78 (+) Configure Noise Filters
\r
79 (+) Configure Fast Mode Plus
\r
86 * @brief Configure I2C Analog noise filter.
\r
87 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
\r
88 * the configuration information for the specified I2Cx peripheral.
\r
89 * @param AnalogFilter New state of the Analog filter.
\r
90 * @retval HAL status
\r
92 HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
\r
94 /* Check the parameters */
\r
95 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
\r
96 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
\r
98 if (hi2c->State == HAL_I2C_STATE_READY)
\r
100 /* Process Locked */
\r
103 hi2c->State = HAL_I2C_STATE_BUSY;
\r
105 /* Disable the selected I2C peripheral */
\r
106 __HAL_I2C_DISABLE(hi2c);
\r
108 /* Reset I2Cx ANOFF bit */
\r
109 hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF);
\r
111 /* Set analog filter bit*/
\r
112 hi2c->Instance->CR1 |= AnalogFilter;
\r
114 __HAL_I2C_ENABLE(hi2c);
\r
116 hi2c->State = HAL_I2C_STATE_READY;
\r
118 /* Process Unlocked */
\r
119 __HAL_UNLOCK(hi2c);
\r
130 * @brief Configure I2C Digital noise filter.
\r
131 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
\r
132 * the configuration information for the specified I2Cx peripheral.
\r
133 * @param DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F.
\r
134 * @retval HAL status
\r
136 HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
\r
140 /* Check the parameters */
\r
141 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
\r
142 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
\r
144 if (hi2c->State == HAL_I2C_STATE_READY)
\r
146 /* Process Locked */
\r
149 hi2c->State = HAL_I2C_STATE_BUSY;
\r
151 /* Disable the selected I2C peripheral */
\r
152 __HAL_I2C_DISABLE(hi2c);
\r
154 /* Get the old register value */
\r
155 tmpreg = hi2c->Instance->CR1;
\r
157 /* Reset I2Cx DNF bits [11:8] */
\r
158 tmpreg &= ~(I2C_CR1_DNF);
\r
160 /* Set I2Cx DNF coefficient */
\r
161 tmpreg |= DigitalFilter << 8U;
\r
163 /* Store the new register value */
\r
164 hi2c->Instance->CR1 = tmpreg;
\r
166 __HAL_I2C_ENABLE(hi2c);
\r
168 hi2c->State = HAL_I2C_STATE_READY;
\r
170 /* Process Unlocked */
\r
171 __HAL_UNLOCK(hi2c);
\r
181 #if (defined(SYSCFG_PMC_I2C_PB6_FMP) || defined(SYSCFG_PMC_I2C_PB7_FMP)) || (defined(SYSCFG_PMC_I2C_PB8_FMP) || defined(SYSCFG_PMC_I2C_PB9_FMP)) || (defined(SYSCFG_PMC_I2C1_FMP)) || (defined(SYSCFG_PMC_I2C2_FMP)) || defined(SYSCFG_PMC_I2C3_FMP) || defined(SYSCFG_PMC_I2C4_FMP)
\r
183 * @brief Enable the I2C fast mode plus driving capability.
\r
184 * @param ConfigFastModePlus Selects the pin.
\r
185 * This parameter can be one of the @ref I2CEx_FastModePlus values
\r
186 * @note For I2C1, fast mode plus driving capability can be enabled on all selected
\r
187 * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently
\r
188 * on each one of the following pins PB6, PB7, PB8 and PB9.
\r
189 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
\r
190 * can be enabled only by using I2C_FASTMODEPLUS_I2C1 parameter.
\r
191 * @note For all I2C2 pins fast mode plus driving capability can be enabled
\r
192 * only by using I2C_FASTMODEPLUS_I2C2 parameter.
\r
193 * @note For all I2C3 pins fast mode plus driving capability can be enabled
\r
194 * only by using I2C_FASTMODEPLUS_I2C3 parameter.
\r
195 * @note For all I2C4 pins fast mode plus driving capability can be enabled
\r
196 * only by using I2C_FASTMODEPLUS_I2C4 parameter.
\r
199 void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
\r
201 /* Check the parameter */
\r
202 assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus));
\r
204 /* Enable SYSCFG clock */
\r
205 __HAL_RCC_SYSCFG_CLK_ENABLE();
\r
207 /* Enable fast mode plus driving capability for selected pin */
\r
208 SET_BIT(SYSCFG->PMC, (uint32_t)ConfigFastModePlus);
\r
212 * @brief Disable the I2C fast mode plus driving capability.
\r
213 * @param ConfigFastModePlus Selects the pin.
\r
214 * This parameter can be one of the @ref I2CEx_FastModePlus values
\r
215 * @note For I2C1, fast mode plus driving capability can be disabled on all selected
\r
216 * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently
\r
217 * on each one of the following pins PB6, PB7, PB8 and PB9.
\r
218 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
\r
219 * can be disabled only by using I2C_FASTMODEPLUS_I2C1 parameter.
\r
220 * @note For all I2C2 pins fast mode plus driving capability can be disabled
\r
221 * only by using I2C_FASTMODEPLUS_I2C2 parameter.
\r
222 * @note For all I2C3 pins fast mode plus driving capability can be disabled
\r
223 * only by using I2C_FASTMODEPLUS_I2C3 parameter.
\r
224 * @note For all I2C4 pins fast mode plus driving capability can be disabled
\r
225 * only by using I2C_FASTMODEPLUS_I2C4 parameter.
\r
228 void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
\r
230 /* Check the parameter */
\r
231 assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus));
\r
233 /* Enable SYSCFG clock */
\r
234 __HAL_RCC_SYSCFG_CLK_ENABLE();
\r
236 /* Disable fast mode plus driving capability for selected pin */
\r
237 CLEAR_BIT(SYSCFG->PMC, (uint32_t)ConfigFastModePlus);
\r
249 #endif /* HAL_I2C_MODULE_ENABLED */
\r
258 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r