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_fmpi2c_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 FMPI2C Extended HAL module driver.
NYX 0:85b3fd62ea1a 8 * This file provides firmware functions to manage the following
NYX 0:85b3fd62ea1a 9 * functionalities of FMPI2C Extended peripheral:
NYX 0:85b3fd62ea1a 10 * + Extended features functions
NYX 0:85b3fd62ea1a 11 *
NYX 0:85b3fd62ea1a 12 @verbatim
NYX 0:85b3fd62ea1a 13 ==============================================================================
NYX 0:85b3fd62ea1a 14 ##### FMPI2C peripheral Extended features #####
NYX 0:85b3fd62ea1a 15 ==============================================================================
NYX 0:85b3fd62ea1a 16
NYX 0:85b3fd62ea1a 17 [..] Comparing to other previous devices, the FMPI2C interface for STM32F4xx
NYX 0:85b3fd62ea1a 18 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 (+) Disable or enable wakeup from Stop mode
NYX 0:85b3fd62ea1a 23
NYX 0:85b3fd62ea1a 24 ##### How to use this driver #####
NYX 0:85b3fd62ea1a 25 ==============================================================================
NYX 0:85b3fd62ea1a 26 [..] This driver provides functions to configure Noise Filter and Wake Up Feature
NYX 0:85b3fd62ea1a 27 (#) Configure FMPI2C Analog noise filter using the function HAL_FMPI2CEx_ConfigAnalogFilter()
NYX 0:85b3fd62ea1a 28 (#) Configure FMPI2C Digital noise filter using the function HAL_FMPI2CEx_ConfigDigitalFilter()
NYX 0:85b3fd62ea1a 29 (#) Configure the enable or disable of FMPI2C Wake Up Mode using the functions :
NYX 0:85b3fd62ea1a 30 (++) HAL_FMPI2CEx_EnableWakeUp()
NYX 0:85b3fd62ea1a 31 (++) HAL_FMPI2CEx_DisableWakeUp()
NYX 0:85b3fd62ea1a 32 (#) Configure the enable or disable of fast mode plus driving capability using the functions :
NYX 0:85b3fd62ea1a 33 (++) HAL_FMPI2CEx_EnableFastModePlus()
NYX 0:85b3fd62ea1a 34 (++) HAL_FMPI2CEx_DisbleFastModePlus()
NYX 0:85b3fd62ea1a 35 @endverbatim
NYX 0:85b3fd62ea1a 36 ******************************************************************************
NYX 0:85b3fd62ea1a 37 * @attention
NYX 0:85b3fd62ea1a 38 *
NYX 0:85b3fd62ea1a 39 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
NYX 0:85b3fd62ea1a 40 *
NYX 0:85b3fd62ea1a 41 * Redistribution and use in source and binary forms, with or without modification,
NYX 0:85b3fd62ea1a 42 * are permitted provided that the following conditions are met:
NYX 0:85b3fd62ea1a 43 * 1. Redistributions of source code must retain the above copyright notice,
NYX 0:85b3fd62ea1a 44 * this list of conditions and the following disclaimer.
NYX 0:85b3fd62ea1a 45 * 2. Redistributions in binary form must reproduce the above copyright notice,
NYX 0:85b3fd62ea1a 46 * this list of conditions and the following disclaimer in the documentation
NYX 0:85b3fd62ea1a 47 * and/or other materials provided with the distribution.
NYX 0:85b3fd62ea1a 48 * 3. Neither the name of STMicroelectronics nor the names of its contributors
NYX 0:85b3fd62ea1a 49 * may be used to endorse or promote products derived from this software
NYX 0:85b3fd62ea1a 50 * without specific prior written permission.
NYX 0:85b3fd62ea1a 51 *
NYX 0:85b3fd62ea1a 52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
NYX 0:85b3fd62ea1a 53 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
NYX 0:85b3fd62ea1a 54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NYX 0:85b3fd62ea1a 55 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
NYX 0:85b3fd62ea1a 56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
NYX 0:85b3fd62ea1a 57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
NYX 0:85b3fd62ea1a 58 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
NYX 0:85b3fd62ea1a 59 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
NYX 0:85b3fd62ea1a 60 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
NYX 0:85b3fd62ea1a 61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NYX 0:85b3fd62ea1a 62 *
NYX 0:85b3fd62ea1a 63 ******************************************************************************
NYX 0:85b3fd62ea1a 64 */
NYX 0:85b3fd62ea1a 65
NYX 0:85b3fd62ea1a 66 /* Includes ------------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 67 #include "stm32f4xx_hal.h"
NYX 0:85b3fd62ea1a 68
NYX 0:85b3fd62ea1a 69 /** @addtogroup STM32F4xx_HAL_Driver
NYX 0:85b3fd62ea1a 70 * @{
NYX 0:85b3fd62ea1a 71 */
NYX 0:85b3fd62ea1a 72
NYX 0:85b3fd62ea1a 73 /** @defgroup FMPI2CEx FMPI2CEx
NYX 0:85b3fd62ea1a 74 * @brief FMPI2C Extended HAL module driver
NYX 0:85b3fd62ea1a 75 * @{
NYX 0:85b3fd62ea1a 76 */
NYX 0:85b3fd62ea1a 77
NYX 0:85b3fd62ea1a 78 #ifdef HAL_FMPI2C_MODULE_ENABLED
NYX 0:85b3fd62ea1a 79
NYX 0:85b3fd62ea1a 80 #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
NYX 0:85b3fd62ea1a 81 defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
NYX 0:85b3fd62ea1a 82
NYX 0:85b3fd62ea1a 83 /* Private typedef -----------------------------------------------------------*/
NYX 0:85b3fd62ea1a 84 /* Private define ------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 85 /* Private macro -------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 86 /* Private variables ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 87 /* Private function prototypes -----------------------------------------------*/
NYX 0:85b3fd62ea1a 88 /* Private functions ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 89
NYX 0:85b3fd62ea1a 90 /** @defgroup FMPI2CEx_Exported_Functions FMPI2C Extended Exported Functions
NYX 0:85b3fd62ea1a 91 * @{
NYX 0:85b3fd62ea1a 92 */
NYX 0:85b3fd62ea1a 93
NYX 0:85b3fd62ea1a 94 /** @defgroup FMPI2CEx_Exported_Functions_Group1 Extended features functions
NYX 0:85b3fd62ea1a 95 * @brief Extended features functions
NYX 0:85b3fd62ea1a 96 *
NYX 0:85b3fd62ea1a 97 @verbatim
NYX 0:85b3fd62ea1a 98 ===============================================================================
NYX 0:85b3fd62ea1a 99 ##### Extended features functions #####
NYX 0:85b3fd62ea1a 100 ===============================================================================
NYX 0:85b3fd62ea1a 101 [..] This section provides functions allowing to:
NYX 0:85b3fd62ea1a 102 (+) Configure Noise Filters
NYX 0:85b3fd62ea1a 103 (+) Configure Wake Up Feature
NYX 0:85b3fd62ea1a 104
NYX 0:85b3fd62ea1a 105 @endverbatim
NYX 0:85b3fd62ea1a 106 * @{
NYX 0:85b3fd62ea1a 107 */
NYX 0:85b3fd62ea1a 108
NYX 0:85b3fd62ea1a 109 /**
NYX 0:85b3fd62ea1a 110 * @brief Configure FMPI2C Analog noise filter.
NYX 0:85b3fd62ea1a 111 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 112 * the configuration information for the specified FMPI2Cx peripheral.
NYX 0:85b3fd62ea1a 113 * @param AnalogFilter New state of the Analog filter.
NYX 0:85b3fd62ea1a 114 * @retval HAL status
NYX 0:85b3fd62ea1a 115 */
NYX 0:85b3fd62ea1a 116 HAL_StatusTypeDef HAL_FMPI2CEx_ConfigAnalogFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t AnalogFilter)
NYX 0:85b3fd62ea1a 117 {
NYX 0:85b3fd62ea1a 118 /* Check the parameters */
NYX 0:85b3fd62ea1a 119 assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
NYX 0:85b3fd62ea1a 120 assert_param(IS_FMPI2C_ANALOG_FILTER(AnalogFilter));
NYX 0:85b3fd62ea1a 121
NYX 0:85b3fd62ea1a 122 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
NYX 0:85b3fd62ea1a 123 {
NYX 0:85b3fd62ea1a 124 /* Process Locked */
NYX 0:85b3fd62ea1a 125 __HAL_LOCK(hfmpi2c);
NYX 0:85b3fd62ea1a 126
NYX 0:85b3fd62ea1a 127 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
NYX 0:85b3fd62ea1a 128
NYX 0:85b3fd62ea1a 129 /* Disable the selected FMPI2C peripheral */
NYX 0:85b3fd62ea1a 130 __HAL_FMPI2C_DISABLE(hfmpi2c);
NYX 0:85b3fd62ea1a 131
NYX 0:85b3fd62ea1a 132 /* Reset FMPI2Cx ANOFF bit */
NYX 0:85b3fd62ea1a 133 hfmpi2c->Instance->CR1 &= ~(FMPI2C_CR1_ANFOFF);
NYX 0:85b3fd62ea1a 134
NYX 0:85b3fd62ea1a 135 /* Set analog filter bit*/
NYX 0:85b3fd62ea1a 136 hfmpi2c->Instance->CR1 |= AnalogFilter;
NYX 0:85b3fd62ea1a 137
NYX 0:85b3fd62ea1a 138 __HAL_FMPI2C_ENABLE(hfmpi2c);
NYX 0:85b3fd62ea1a 139
NYX 0:85b3fd62ea1a 140 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
NYX 0:85b3fd62ea1a 141
NYX 0:85b3fd62ea1a 142 /* Process Unlocked */
NYX 0:85b3fd62ea1a 143 __HAL_UNLOCK(hfmpi2c);
NYX 0:85b3fd62ea1a 144
NYX 0:85b3fd62ea1a 145 return HAL_OK;
NYX 0:85b3fd62ea1a 146 }
NYX 0:85b3fd62ea1a 147 else
NYX 0:85b3fd62ea1a 148 {
NYX 0:85b3fd62ea1a 149 return HAL_BUSY;
NYX 0:85b3fd62ea1a 150 }
NYX 0:85b3fd62ea1a 151 }
NYX 0:85b3fd62ea1a 152
NYX 0:85b3fd62ea1a 153 /**
NYX 0:85b3fd62ea1a 154 * @brief Configure FMPI2C Digital noise filter.
NYX 0:85b3fd62ea1a 155 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 156 * the configuration information for the specified FMPI2Cx peripheral.
NYX 0:85b3fd62ea1a 157 * @param DigitalFilter Coefficient of digital noise filter between 0x00 and 0x0F.
NYX 0:85b3fd62ea1a 158 * @retval HAL status
NYX 0:85b3fd62ea1a 159 */
NYX 0:85b3fd62ea1a 160 HAL_StatusTypeDef HAL_FMPI2CEx_ConfigDigitalFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t DigitalFilter)
NYX 0:85b3fd62ea1a 161 {
NYX 0:85b3fd62ea1a 162 uint32_t tmpreg = 0U;
NYX 0:85b3fd62ea1a 163
NYX 0:85b3fd62ea1a 164 /* Check the parameters */
NYX 0:85b3fd62ea1a 165 assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
NYX 0:85b3fd62ea1a 166 assert_param(IS_FMPI2C_DIGITAL_FILTER(DigitalFilter));
NYX 0:85b3fd62ea1a 167
NYX 0:85b3fd62ea1a 168 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
NYX 0:85b3fd62ea1a 169 {
NYX 0:85b3fd62ea1a 170 /* Process Locked */
NYX 0:85b3fd62ea1a 171 __HAL_LOCK(hfmpi2c);
NYX 0:85b3fd62ea1a 172
NYX 0:85b3fd62ea1a 173 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
NYX 0:85b3fd62ea1a 174
NYX 0:85b3fd62ea1a 175 /* Disable the selected FMPI2C peripheral */
NYX 0:85b3fd62ea1a 176 __HAL_FMPI2C_DISABLE(hfmpi2c);
NYX 0:85b3fd62ea1a 177
NYX 0:85b3fd62ea1a 178 /* Get the old register value */
NYX 0:85b3fd62ea1a 179 tmpreg = hfmpi2c->Instance->CR1;
NYX 0:85b3fd62ea1a 180
NYX 0:85b3fd62ea1a 181 /* Reset FMPI2Cx DNF bits [11:8] */
NYX 0:85b3fd62ea1a 182 tmpreg &= ~(FMPI2C_CR1_DFN);
NYX 0:85b3fd62ea1a 183
NYX 0:85b3fd62ea1a 184 /* Set FMPI2Cx DNF coefficient */
NYX 0:85b3fd62ea1a 185 tmpreg |= DigitalFilter << 8U;
NYX 0:85b3fd62ea1a 186
NYX 0:85b3fd62ea1a 187 /* Store the new register value */
NYX 0:85b3fd62ea1a 188 hfmpi2c->Instance->CR1 = tmpreg;
NYX 0:85b3fd62ea1a 189
NYX 0:85b3fd62ea1a 190 __HAL_FMPI2C_ENABLE(hfmpi2c);
NYX 0:85b3fd62ea1a 191
NYX 0:85b3fd62ea1a 192 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
NYX 0:85b3fd62ea1a 193
NYX 0:85b3fd62ea1a 194 /* Process Unlocked */
NYX 0:85b3fd62ea1a 195 __HAL_UNLOCK(hfmpi2c);
NYX 0:85b3fd62ea1a 196
NYX 0:85b3fd62ea1a 197 return HAL_OK;
NYX 0:85b3fd62ea1a 198 }
NYX 0:85b3fd62ea1a 199 else
NYX 0:85b3fd62ea1a 200 {
NYX 0:85b3fd62ea1a 201 return HAL_BUSY;
NYX 0:85b3fd62ea1a 202 }
NYX 0:85b3fd62ea1a 203 }
NYX 0:85b3fd62ea1a 204
NYX 0:85b3fd62ea1a 205 /**
NYX 0:85b3fd62ea1a 206 * @brief Enable the FMPI2C fast mode plus driving capability.
NYX 0:85b3fd62ea1a 207 * @param ConfigFastModePlus Selects the pin.
NYX 0:85b3fd62ea1a 208 * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
NYX 0:85b3fd62ea1a 209 * @retval None
NYX 0:85b3fd62ea1a 210 */
NYX 0:85b3fd62ea1a 211 void HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
NYX 0:85b3fd62ea1a 212 {
NYX 0:85b3fd62ea1a 213 /* Check the parameter */
NYX 0:85b3fd62ea1a 214 assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
NYX 0:85b3fd62ea1a 215
NYX 0:85b3fd62ea1a 216 /* Enable SYSCFG clock */
NYX 0:85b3fd62ea1a 217 __HAL_RCC_SYSCFG_CLK_ENABLE();
NYX 0:85b3fd62ea1a 218
NYX 0:85b3fd62ea1a 219 /* Enable fast mode plus driving capability for selected pin */
NYX 0:85b3fd62ea1a 220 SET_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
NYX 0:85b3fd62ea1a 221 }
NYX 0:85b3fd62ea1a 222
NYX 0:85b3fd62ea1a 223 /**
NYX 0:85b3fd62ea1a 224 * @brief Disable the FMPI2C fast mode plus driving capability.
NYX 0:85b3fd62ea1a 225 * @param ConfigFastModePlus Selects the pin.
NYX 0:85b3fd62ea1a 226 * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
NYX 0:85b3fd62ea1a 227 * @retval None
NYX 0:85b3fd62ea1a 228 */
NYX 0:85b3fd62ea1a 229 void HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
NYX 0:85b3fd62ea1a 230 {
NYX 0:85b3fd62ea1a 231 /* Check the parameter */
NYX 0:85b3fd62ea1a 232 assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
NYX 0:85b3fd62ea1a 233
NYX 0:85b3fd62ea1a 234 /* Enable SYSCFG clock */
NYX 0:85b3fd62ea1a 235 __HAL_RCC_SYSCFG_CLK_ENABLE();
NYX 0:85b3fd62ea1a 236
NYX 0:85b3fd62ea1a 237 /* Disable fast mode plus driving capability for selected pin */
NYX 0:85b3fd62ea1a 238 CLEAR_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
NYX 0:85b3fd62ea1a 239 }
NYX 0:85b3fd62ea1a 240
NYX 0:85b3fd62ea1a 241 /**
NYX 0:85b3fd62ea1a 242 * @}
NYX 0:85b3fd62ea1a 243 */
NYX 0:85b3fd62ea1a 244
NYX 0:85b3fd62ea1a 245 /**
NYX 0:85b3fd62ea1a 246 * @}
NYX 0:85b3fd62ea1a 247 */
NYX 0:85b3fd62ea1a 248 #endif /* STM32F410xx || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx ||\
NYX 0:85b3fd62ea1a 249 STM32F413xx || STM32F423xx */
NYX 0:85b3fd62ea1a 250 #endif /* HAL_FMPI2C_MODULE_ENABLED */
NYX 0:85b3fd62ea1a 251 /**
NYX 0:85b3fd62ea1a 252 * @}
NYX 0:85b3fd62ea1a 253 */
NYX 0:85b3fd62ea1a 254
NYX 0:85b3fd62ea1a 255 /**
NYX 0:85b3fd62ea1a 256 * @}
NYX 0:85b3fd62ea1a 257 */
NYX 0:85b3fd62ea1a 258
NYX 0:85b3fd62ea1a 259 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/