inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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