1 /** 2 ****************************************************************************** 3 * @file stm32f4xx_hal_i2c_ex.c 4 * @author MCD Application Team 5 * @brief I2C Extension HAL module driver. 6 * This file provides firmware functions to manage the following 7 * functionalities of I2C extension peripheral: 8 * + Extension features functions 9 * 10 @verbatim 11 ============================================================================== 12 ##### I2C peripheral extension features ##### 13 ============================================================================== 14 15 [..] Comparing to other previous devices, the I2C interface for STM32F427xx/437xx/ 16 429xx/439xx 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 21 ##### How to use this driver ##### 22 ============================================================================== 23 [..] This driver provides functions to configure Noise Filter 24 (#) Configure I2C Analog noise filter using the function HAL_I2C_AnalogFilter_Config() 25 (#) Configure I2C Digital noise filter using the function HAL_I2C_DigitalFilter_Config() 26 27 @endverbatim 28 ****************************************************************************** 29 * @attention 30 * 31 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 32 * All rights reserved.</center></h2> 33 * 34 * This software component is licensed by ST under BSD 3-Clause license, 35 * the "License"; You may not use this file except in compliance with the 36 * License. You may obtain a copy of the License at: 37 * opensource.org/licenses/BSD-3-Clause 38 * 39 ****************************************************************************** 40 */ 41 42 /* Includes ------------------------------------------------------------------*/ 43 #include "stm32f4xx_hal.h" 44 45 /** @addtogroup STM32F4xx_HAL_Driver 46 * @{ 47 */ 48 49 /** @defgroup I2CEx I2CEx 50 * @brief I2C HAL module driver 51 * @{ 52 */ 53 54 #ifdef HAL_I2C_MODULE_ENABLED 55 56 #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF) 57 /* Private typedef -----------------------------------------------------------*/ 58 /* Private define ------------------------------------------------------------*/ 59 /* Private macro -------------------------------------------------------------*/ 60 /* Private variables ---------------------------------------------------------*/ 61 /* Private function prototypes -----------------------------------------------*/ 62 /* Exported functions --------------------------------------------------------*/ 63 /** @defgroup I2CEx_Exported_Functions I2C Exported Functions 64 * @{ 65 */ 66 67 68 /** @defgroup I2CEx_Exported_Functions_Group1 Extension features functions 69 * @brief Extension features functions 70 * 71 @verbatim 72 =============================================================================== 73 ##### Extension features functions ##### 74 =============================================================================== 75 [..] This section provides functions allowing to: 76 (+) Configure Noise Filters 77 78 @endverbatim 79 * @{ 80 */ 81 82 /** 83 * @brief Configures I2C Analog noise filter. 84 * @param hi2c pointer to a I2C_HandleTypeDef structure that contains 85 * the configuration information for the specified I2Cx peripheral. 86 * @param AnalogFilter new state of the Analog filter. 87 * @retval HAL status 88 */ HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef * hi2c,uint32_t AnalogFilter)89HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter) 90 { 91 /* Check the parameters */ 92 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 93 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter)); 94 95 if (hi2c->State == HAL_I2C_STATE_READY) 96 { 97 hi2c->State = HAL_I2C_STATE_BUSY; 98 99 /* Disable the selected I2C peripheral */ 100 __HAL_I2C_DISABLE(hi2c); 101 102 /* Reset I2Cx ANOFF bit */ 103 hi2c->Instance->FLTR &= ~(I2C_FLTR_ANOFF); 104 105 /* Disable the analog filter */ 106 hi2c->Instance->FLTR |= AnalogFilter; 107 108 __HAL_I2C_ENABLE(hi2c); 109 110 hi2c->State = HAL_I2C_STATE_READY; 111 112 return HAL_OK; 113 } 114 else 115 { 116 return HAL_BUSY; 117 } 118 } 119 120 /** 121 * @brief Configures I2C Digital noise filter. 122 * @param hi2c pointer to a I2C_HandleTypeDef structure that contains 123 * the configuration information for the specified I2Cx peripheral. 124 * @param DigitalFilter Coefficient of digital noise filter between 0x00 and 0x0F. 125 * @retval HAL status 126 */ HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef * hi2c,uint32_t DigitalFilter)127HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter) 128 { 129 uint16_t tmpreg = 0; 130 131 /* Check the parameters */ 132 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 133 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter)); 134 135 if (hi2c->State == HAL_I2C_STATE_READY) 136 { 137 hi2c->State = HAL_I2C_STATE_BUSY; 138 139 /* Disable the selected I2C peripheral */ 140 __HAL_I2C_DISABLE(hi2c); 141 142 /* Get the old register value */ 143 tmpreg = hi2c->Instance->FLTR; 144 145 /* Reset I2Cx DNF bit [3:0] */ 146 tmpreg &= ~(I2C_FLTR_DNF); 147 148 /* Set I2Cx DNF coefficient */ 149 tmpreg |= DigitalFilter; 150 151 /* Store the new register value */ 152 hi2c->Instance->FLTR = tmpreg; 153 154 __HAL_I2C_ENABLE(hi2c); 155 156 hi2c->State = HAL_I2C_STATE_READY; 157 158 return HAL_OK; 159 } 160 else 161 { 162 return HAL_BUSY; 163 } 164 } 165 166 /** 167 * @} 168 */ 169 170 /** 171 * @} 172 */ 173 #endif 174 175 #endif /* HAL_I2C_MODULE_ENABLED */ 176 /** 177 * @} 178 */ 179 180 /** 181 * @} 182 */ 183 184 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 185