001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

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