001
targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_i2c_ex.c@0:13413ea9a877, 2022-06-12 (annotated)
- Committer:
- ganlikun
- Date:
- Sun Jun 12 14:02:44 2022 +0000
- Revision:
- 0:13413ea9a877
00
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ganlikun | 0:13413ea9a877 | 1 | /** |
ganlikun | 0:13413ea9a877 | 2 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 3 | * @file stm32f4xx_hal_i2c_ex.c |
ganlikun | 0:13413ea9a877 | 4 | * @author MCD Application Team |
ganlikun | 0:13413ea9a877 | 5 | * @version V1.7.1 |
ganlikun | 0:13413ea9a877 | 6 | * @date 14-April-2017 |
ganlikun | 0:13413ea9a877 | 7 | * @brief I2C Extension HAL module driver. |
ganlikun | 0:13413ea9a877 | 8 | * This file provides firmware functions to manage the following |
ganlikun | 0:13413ea9a877 | 9 | * functionalities of I2C extension peripheral: |
ganlikun | 0:13413ea9a877 | 10 | * + Extension features functions |
ganlikun | 0:13413ea9a877 | 11 | * |
ganlikun | 0:13413ea9a877 | 12 | @verbatim |
ganlikun | 0:13413ea9a877 | 13 | ============================================================================== |
ganlikun | 0:13413ea9a877 | 14 | ##### I2C peripheral extension features ##### |
ganlikun | 0:13413ea9a877 | 15 | ============================================================================== |
ganlikun | 0:13413ea9a877 | 16 | |
ganlikun | 0:13413ea9a877 | 17 | [..] Comparing to other previous devices, the I2C interface for STM32F427xx/437xx/ |
ganlikun | 0:13413ea9a877 | 18 | 429xx/439xx devices contains the following additional features : |
ganlikun | 0:13413ea9a877 | 19 | |
ganlikun | 0:13413ea9a877 | 20 | (+) Possibility to disable or enable Analog Noise Filter |
ganlikun | 0:13413ea9a877 | 21 | (+) Use of a configured Digital Noise Filter |
ganlikun | 0:13413ea9a877 | 22 | |
ganlikun | 0:13413ea9a877 | 23 | ##### How to use this driver ##### |
ganlikun | 0:13413ea9a877 | 24 | ============================================================================== |
ganlikun | 0:13413ea9a877 | 25 | [..] This driver provides functions to configure Noise Filter |
ganlikun | 0:13413ea9a877 | 26 | (#) Configure I2C Analog noise filter using the function HAL_I2C_AnalogFilter_Config() |
ganlikun | 0:13413ea9a877 | 27 | (#) Configure I2C Digital noise filter using the function HAL_I2C_DigitalFilter_Config() |
ganlikun | 0:13413ea9a877 | 28 | |
ganlikun | 0:13413ea9a877 | 29 | @endverbatim |
ganlikun | 0:13413ea9a877 | 30 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 31 | * @attention |
ganlikun | 0:13413ea9a877 | 32 | * |
ganlikun | 0:13413ea9a877 | 33 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
ganlikun | 0:13413ea9a877 | 34 | * |
ganlikun | 0:13413ea9a877 | 35 | * Redistribution and use in source and binary forms, with or without modification, |
ganlikun | 0:13413ea9a877 | 36 | * are permitted provided that the following conditions are met: |
ganlikun | 0:13413ea9a877 | 37 | * 1. Redistributions of source code must retain the above copyright notice, |
ganlikun | 0:13413ea9a877 | 38 | * this list of conditions and the following disclaimer. |
ganlikun | 0:13413ea9a877 | 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
ganlikun | 0:13413ea9a877 | 40 | * this list of conditions and the following disclaimer in the documentation |
ganlikun | 0:13413ea9a877 | 41 | * and/or other materials provided with the distribution. |
ganlikun | 0:13413ea9a877 | 42 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
ganlikun | 0:13413ea9a877 | 43 | * may be used to endorse or promote products derived from this software |
ganlikun | 0:13413ea9a877 | 44 | * without specific prior written permission. |
ganlikun | 0:13413ea9a877 | 45 | * |
ganlikun | 0:13413ea9a877 | 46 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
ganlikun | 0:13413ea9a877 | 47 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ganlikun | 0:13413ea9a877 | 48 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
ganlikun | 0:13413ea9a877 | 49 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
ganlikun | 0:13413ea9a877 | 50 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
ganlikun | 0:13413ea9a877 | 51 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
ganlikun | 0:13413ea9a877 | 52 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ganlikun | 0:13413ea9a877 | 53 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ganlikun | 0:13413ea9a877 | 54 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ganlikun | 0:13413ea9a877 | 55 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ganlikun | 0:13413ea9a877 | 56 | * |
ganlikun | 0:13413ea9a877 | 57 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 58 | */ |
ganlikun | 0:13413ea9a877 | 59 | |
ganlikun | 0:13413ea9a877 | 60 | /* Includes ------------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 61 | #include "stm32f4xx_hal.h" |
ganlikun | 0:13413ea9a877 | 62 | |
ganlikun | 0:13413ea9a877 | 63 | /** @addtogroup STM32F4xx_HAL_Driver |
ganlikun | 0:13413ea9a877 | 64 | * @{ |
ganlikun | 0:13413ea9a877 | 65 | */ |
ganlikun | 0:13413ea9a877 | 66 | |
ganlikun | 0:13413ea9a877 | 67 | /** @defgroup I2CEx I2CEx |
ganlikun | 0:13413ea9a877 | 68 | * @brief I2C HAL module driver |
ganlikun | 0:13413ea9a877 | 69 | * @{ |
ganlikun | 0:13413ea9a877 | 70 | */ |
ganlikun | 0:13413ea9a877 | 71 | |
ganlikun | 0:13413ea9a877 | 72 | #ifdef HAL_I2C_MODULE_ENABLED |
ganlikun | 0:13413ea9a877 | 73 | |
ganlikun | 0:13413ea9a877 | 74 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\ |
ganlikun | 0:13413ea9a877 | 75 | defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) ||\ |
ganlikun | 0:13413ea9a877 | 76 | defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx) |
ganlikun | 0:13413ea9a877 | 77 | /* Private typedef -----------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 78 | /* Private define ------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 79 | /* Private macro -------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 80 | /* Private variables ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 81 | /* Private function prototypes -----------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 82 | /* Exported functions --------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 83 | /** @defgroup I2CEx_Exported_Functions I2C Exported Functions |
ganlikun | 0:13413ea9a877 | 84 | * @{ |
ganlikun | 0:13413ea9a877 | 85 | */ |
ganlikun | 0:13413ea9a877 | 86 | |
ganlikun | 0:13413ea9a877 | 87 | |
ganlikun | 0:13413ea9a877 | 88 | /** @defgroup I2CEx_Exported_Functions_Group1 Extension features functions |
ganlikun | 0:13413ea9a877 | 89 | * @brief Extension features functions |
ganlikun | 0:13413ea9a877 | 90 | * |
ganlikun | 0:13413ea9a877 | 91 | @verbatim |
ganlikun | 0:13413ea9a877 | 92 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 93 | ##### Extension features functions ##### |
ganlikun | 0:13413ea9a877 | 94 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 95 | [..] This section provides functions allowing to: |
ganlikun | 0:13413ea9a877 | 96 | (+) Configure Noise Filters |
ganlikun | 0:13413ea9a877 | 97 | |
ganlikun | 0:13413ea9a877 | 98 | @endverbatim |
ganlikun | 0:13413ea9a877 | 99 | * @{ |
ganlikun | 0:13413ea9a877 | 100 | */ |
ganlikun | 0:13413ea9a877 | 101 | |
ganlikun | 0:13413ea9a877 | 102 | /** |
ganlikun | 0:13413ea9a877 | 103 | * @brief Configures I2C Analog noise filter. |
ganlikun | 0:13413ea9a877 | 104 | * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 105 | * the configuration information for the specified I2Cx peripheral. |
ganlikun | 0:13413ea9a877 | 106 | * @param AnalogFilter: new state of the Analog filter. |
ganlikun | 0:13413ea9a877 | 107 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 108 | */ |
ganlikun | 0:13413ea9a877 | 109 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter) |
ganlikun | 0:13413ea9a877 | 110 | { |
ganlikun | 0:13413ea9a877 | 111 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 112 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); |
ganlikun | 0:13413ea9a877 | 113 | assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter)); |
ganlikun | 0:13413ea9a877 | 114 | |
ganlikun | 0:13413ea9a877 | 115 | if(hi2c->State == HAL_I2C_STATE_READY) |
ganlikun | 0:13413ea9a877 | 116 | { |
ganlikun | 0:13413ea9a877 | 117 | hi2c->State = HAL_I2C_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 118 | |
ganlikun | 0:13413ea9a877 | 119 | /* Disable the selected I2C peripheral */ |
ganlikun | 0:13413ea9a877 | 120 | __HAL_I2C_DISABLE(hi2c); |
ganlikun | 0:13413ea9a877 | 121 | |
ganlikun | 0:13413ea9a877 | 122 | /* Reset I2Cx ANOFF bit */ |
ganlikun | 0:13413ea9a877 | 123 | hi2c->Instance->FLTR &= ~(I2C_FLTR_ANOFF); |
ganlikun | 0:13413ea9a877 | 124 | |
ganlikun | 0:13413ea9a877 | 125 | /* Disable the analog filter */ |
ganlikun | 0:13413ea9a877 | 126 | hi2c->Instance->FLTR |= AnalogFilter; |
ganlikun | 0:13413ea9a877 | 127 | |
ganlikun | 0:13413ea9a877 | 128 | __HAL_I2C_ENABLE(hi2c); |
ganlikun | 0:13413ea9a877 | 129 | |
ganlikun | 0:13413ea9a877 | 130 | hi2c->State = HAL_I2C_STATE_READY; |
ganlikun | 0:13413ea9a877 | 131 | |
ganlikun | 0:13413ea9a877 | 132 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 133 | } |
ganlikun | 0:13413ea9a877 | 134 | else |
ganlikun | 0:13413ea9a877 | 135 | { |
ganlikun | 0:13413ea9a877 | 136 | return HAL_BUSY; |
ganlikun | 0:13413ea9a877 | 137 | } |
ganlikun | 0:13413ea9a877 | 138 | } |
ganlikun | 0:13413ea9a877 | 139 | |
ganlikun | 0:13413ea9a877 | 140 | /** |
ganlikun | 0:13413ea9a877 | 141 | * @brief Configures I2C Digital noise filter. |
ganlikun | 0:13413ea9a877 | 142 | * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 143 | * the configuration information for the specified I2Cx peripheral. |
ganlikun | 0:13413ea9a877 | 144 | * @param DigitalFilter: Coefficient of digital noise filter between 0x00 and 0x0F. |
ganlikun | 0:13413ea9a877 | 145 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 146 | */ |
ganlikun | 0:13413ea9a877 | 147 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter) |
ganlikun | 0:13413ea9a877 | 148 | { |
ganlikun | 0:13413ea9a877 | 149 | uint16_t tmpreg = 0; |
ganlikun | 0:13413ea9a877 | 150 | |
ganlikun | 0:13413ea9a877 | 151 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 152 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); |
ganlikun | 0:13413ea9a877 | 153 | assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter)); |
ganlikun | 0:13413ea9a877 | 154 | |
ganlikun | 0:13413ea9a877 | 155 | if(hi2c->State == HAL_I2C_STATE_READY) |
ganlikun | 0:13413ea9a877 | 156 | { |
ganlikun | 0:13413ea9a877 | 157 | hi2c->State = HAL_I2C_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 158 | |
ganlikun | 0:13413ea9a877 | 159 | /* Disable the selected I2C peripheral */ |
ganlikun | 0:13413ea9a877 | 160 | __HAL_I2C_DISABLE(hi2c); |
ganlikun | 0:13413ea9a877 | 161 | |
ganlikun | 0:13413ea9a877 | 162 | /* Get the old register value */ |
ganlikun | 0:13413ea9a877 | 163 | tmpreg = hi2c->Instance->FLTR; |
ganlikun | 0:13413ea9a877 | 164 | |
ganlikun | 0:13413ea9a877 | 165 | /* Reset I2Cx DNF bit [3:0] */ |
ganlikun | 0:13413ea9a877 | 166 | tmpreg &= ~(I2C_FLTR_DNF); |
ganlikun | 0:13413ea9a877 | 167 | |
ganlikun | 0:13413ea9a877 | 168 | /* Set I2Cx DNF coefficient */ |
ganlikun | 0:13413ea9a877 | 169 | tmpreg |= DigitalFilter; |
ganlikun | 0:13413ea9a877 | 170 | |
ganlikun | 0:13413ea9a877 | 171 | /* Store the new register value */ |
ganlikun | 0:13413ea9a877 | 172 | hi2c->Instance->FLTR = tmpreg; |
ganlikun | 0:13413ea9a877 | 173 | |
ganlikun | 0:13413ea9a877 | 174 | __HAL_I2C_ENABLE(hi2c); |
ganlikun | 0:13413ea9a877 | 175 | |
ganlikun | 0:13413ea9a877 | 176 | hi2c->State = HAL_I2C_STATE_READY; |
ganlikun | 0:13413ea9a877 | 177 | |
ganlikun | 0:13413ea9a877 | 178 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 179 | } |
ganlikun | 0:13413ea9a877 | 180 | else |
ganlikun | 0:13413ea9a877 | 181 | { |
ganlikun | 0:13413ea9a877 | 182 | return HAL_BUSY; |
ganlikun | 0:13413ea9a877 | 183 | } |
ganlikun | 0:13413ea9a877 | 184 | } |
ganlikun | 0:13413ea9a877 | 185 | |
ganlikun | 0:13413ea9a877 | 186 | /** |
ganlikun | 0:13413ea9a877 | 187 | * @} |
ganlikun | 0:13413ea9a877 | 188 | */ |
ganlikun | 0:13413ea9a877 | 189 | |
ganlikun | 0:13413ea9a877 | 190 | /** |
ganlikun | 0:13413ea9a877 | 191 | * @} |
ganlikun | 0:13413ea9a877 | 192 | */ |
ganlikun | 0:13413ea9a877 | 193 | #endif /* STM32F427xx || STM32F429xx || STM32F437xx || STM32F439xx || STM32F401xC ||\ |
ganlikun | 0:13413ea9a877 | 194 | STM32F401xE || STM32F446xx || STM32F469xx || STM32F479xx || STM32F413xx ||\ |
ganlikun | 0:13413ea9a877 | 195 | STM32F423xx */ |
ganlikun | 0:13413ea9a877 | 196 | |
ganlikun | 0:13413ea9a877 | 197 | #endif /* HAL_I2C_MODULE_ENABLED */ |
ganlikun | 0:13413ea9a877 | 198 | /** |
ganlikun | 0:13413ea9a877 | 199 | * @} |
ganlikun | 0:13413ea9a877 | 200 | */ |
ganlikun | 0:13413ea9a877 | 201 | |
ganlikun | 0:13413ea9a877 | 202 | /** |
ganlikun | 0:13413ea9a877 | 203 | * @} |
ganlikun | 0:13413ea9a877 | 204 | */ |
ganlikun | 0:13413ea9a877 | 205 | |
ganlikun | 0:13413ea9a877 | 206 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
ganlikun | 0:13413ea9a877 | 207 |