2 ******************************************************************************
3 * @file stm32f7xx_hal_i2c_ex.c
4 * @author MCD Application Team
7 * @brief I2C Extended HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of I2C Extended peripheral:
10 * + Extended features functions
13 ==============================================================================
14 ##### I2C peripheral Extended features #####
15 ==============================================================================
17 [..] Comparing to other previous devices, the I2C interface for STM32F7XX
18 devices contains the following additional features
20 (+) Possibility to disable or enable Analog Noise Filter
21 (+) Use of a configured Digital Noise Filter
22 (+) Disable or enable Fast Mode Plus (available only for STM32F76xxx/STM32F77xxx
25 ##### How to use this driver #####
26 ==============================================================================
27 [..] This driver provides functions to:
28 (#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter()
29 (#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter()
30 (#) Configure the enable or disable of fast mode plus driving capability using the functions :
31 (++) HAL_I2CEx_EnableFastModePlus()
32 (++) HAL_I2CEx_DisbleFastModePlus()
34 ******************************************************************************
37 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
39 * Redistribution and use in source and binary forms, with or without modification,
40 * are permitted provided that the following conditions are met:
41 * 1. Redistributions of source code must retain the above copyright notice,
42 * this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright notice,
44 * this list of conditions and the following disclaimer in the documentation
45 * and/or other materials provided with the distribution.
46 * 3. Neither the name of STMicroelectronics nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
51 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
53 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
56 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
57 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
58 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 ******************************************************************************
64 /* Includes ------------------------------------------------------------------*/
65 #include "stm32f7xx_hal.h"
67 /** @addtogroup STM32F7xx_HAL_Driver
71 /** @defgroup I2CEx I2C Extended HAL module driver
72 * @brief I2C Extended HAL module driver
76 #ifdef HAL_I2C_MODULE_ENABLED
78 /* Private typedef -----------------------------------------------------------*/
79 /* Private define ------------------------------------------------------------*/
80 /* Private macro -------------------------------------------------------------*/
81 /* Private variables ---------------------------------------------------------*/
82 /* Private function prototypes -----------------------------------------------*/
83 /* Private functions ---------------------------------------------------------*/
85 /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions
89 /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions
90 * @brief Extended features functions
93 ===============================================================================
94 ##### Extended features functions #####
95 ===============================================================================
96 [..] This section provides functions allowing to:
97 (+) Configure Noise Filters
98 (+) Configure Fast Mode Plus
105 * @brief Configure I2C Analog noise filter.
106 * @param hi2c: Pointer to a I2C_HandleTypeDef structure that contains
107 * the configuration information for the specified I2Cx peripheral.
108 * @param AnalogFilter: New state of the Analog filter.
111 HAL_StatusTypeDef
HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef
*hi2c
, uint32_t AnalogFilter
)
113 /* Check the parameters */
114 assert_param(IS_I2C_ALL_INSTANCE(hi2c
->Instance
));
115 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter
));
117 if(hi2c
->State
== HAL_I2C_STATE_READY
)
122 hi2c
->State
= HAL_I2C_STATE_BUSY
;
124 /* Disable the selected I2C peripheral */
125 __HAL_I2C_DISABLE(hi2c
);
127 /* Reset I2Cx ANOFF bit */
128 hi2c
->Instance
->CR1
&= ~(I2C_CR1_ANFOFF
);
130 /* Set analog filter bit*/
131 hi2c
->Instance
->CR1
|= AnalogFilter
;
133 __HAL_I2C_ENABLE(hi2c
);
135 hi2c
->State
= HAL_I2C_STATE_READY
;
137 /* Process Unlocked */
149 * @brief Configure I2C Digital noise filter.
150 * @param hi2c: Pointer to a I2C_HandleTypeDef structure that contains
151 * the configuration information for the specified I2Cx peripheral.
152 * @param DigitalFilter: Coefficient of digital noise filter between 0x00 and 0x0F.
155 HAL_StatusTypeDef
HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef
*hi2c
, uint32_t DigitalFilter
)
159 /* Check the parameters */
160 assert_param(IS_I2C_ALL_INSTANCE(hi2c
->Instance
));
161 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter
));
163 if(hi2c
->State
== HAL_I2C_STATE_READY
)
168 hi2c
->State
= HAL_I2C_STATE_BUSY
;
170 /* Disable the selected I2C peripheral */
171 __HAL_I2C_DISABLE(hi2c
);
173 /* Get the old register value */
174 tmpreg
= hi2c
->Instance
->CR1
;
176 /* Reset I2Cx DNF bits [11:8] */
177 tmpreg
&= ~(I2C_CR1_DNF
);
179 /* Set I2Cx DNF coefficient */
180 tmpreg
|= DigitalFilter
<< 8;
182 /* Store the new register value */
183 hi2c
->Instance
->CR1
= tmpreg
;
185 __HAL_I2C_ENABLE(hi2c
);
187 hi2c
->State
= HAL_I2C_STATE_READY
;
189 /* Process Unlocked */
200 #if defined (STM32F765xx) || defined (STM32F767xx) || defined (STM32F769xx) || defined (STM32F777xx) || defined (STM32F779xx)
202 * @brief Enable the I2C fast mode plus driving capability.
203 * @param ConfigFastModePlus: Selects the pin.
204 * This parameter can be one of the @ref I2CEx_FastModePlus values
207 void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus
)
209 /* Check the parameter */
210 assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus
));
212 /* Enable SYSCFG clock */
213 __HAL_RCC_SYSCFG_CLK_ENABLE();
215 /* Enable fast mode plus driving capability for selected pin */
216 SET_BIT(SYSCFG
->PMC
, (uint32_t)ConfigFastModePlus
);
220 * @brief Disable the I2C fast mode plus driving capability.
221 * @param ConfigFastModePlus: Selects the pin.
222 * This parameter can be one of the @ref I2CEx_FastModePlus values
225 void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus
)
227 /* Check the parameter */
228 assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus
));
230 /* Enable SYSCFG clock */
231 __HAL_RCC_SYSCFG_CLK_ENABLE();
233 /* Disable fast mode plus driving capability for selected pin */
234 CLEAR_BIT(SYSCFG
->PMC
, (uint32_t)ConfigFastModePlus
);
236 #endif /* STM32F767xx || STM32F769xx || STM32F777xx || STM32F779xx */
246 #endif /* HAL_I2C_MODULE_ENABLED */
255 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/