STM32F479xx HAL User Manual
stm32f4xx_hal_fmpi2c_ex.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_fmpi2c_ex.c
00004   * @author  MCD Application Team
00005   * @brief   FMPI2C Extended HAL module driver.
00006   *          This file provides firmware functions to manage the following
00007   *          functionalities of FMPI2C Extended peripheral:
00008   *           + Filter Mode Functions
00009   *           + FastModePlus Functions
00010   *
00011   @verbatim
00012   ==============================================================================
00013                ##### FMPI2C peripheral Extended features  #####
00014   ==============================================================================
00015 
00016   [..] Comparing to other previous devices, the FMPI2C interface for STM32F4xx
00017        devices contains the following additional features
00018 
00019        (+) Possibility to disable or enable Analog Noise Filter
00020        (+) Use of a configured Digital Noise Filter
00021        (+) Disable or enable Fast Mode Plus
00022 
00023                      ##### How to use this driver #####
00024   ==============================================================================
00025   [..] This driver provides functions to:
00026     (#) Configure FMPI2C Analog noise filter using the function HAL_FMPI2CEx_ConfigAnalogFilter()
00027     (#) Configure FMPI2C Digital noise filter using the function HAL_FMPI2CEx_ConfigDigitalFilter()
00028     (#) Configure the enable or disable of fast mode plus driving capability using the functions :
00029           (++) HAL_FMPI2CEx_EnableFastModePlus()
00030           (++) HAL_FMPI2CEx_DisableFastModePlus()
00031   @endverbatim
00032   ******************************************************************************
00033   * @attention
00034   *
00035   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00036   * All rights reserved.</center></h2>
00037   *
00038   * This software component is licensed by ST under BSD 3-Clause license,
00039   * the "License"; You may not use this file except in compliance with the
00040   * License. You may obtain a copy of the License at:
00041   *                        opensource.org/licenses/BSD-3-Clause
00042   *
00043   ******************************************************************************
00044   */
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 #include "stm32f4xx_hal.h"
00048 
00049 /** @addtogroup STM32F4xx_HAL_Driver
00050   * @{
00051   */
00052 
00053 /** @defgroup FMPI2CEx FMPI2CEx
00054   * @brief FMPI2C Extended HAL module driver
00055   * @{
00056   */
00057 
00058 #ifdef HAL_FMPI2C_MODULE_ENABLED
00059 #if defined(FMPI2C_CR1_PE)
00060 
00061 /* Private typedef -----------------------------------------------------------*/
00062 /* Private define ------------------------------------------------------------*/
00063 /* Private macro -------------------------------------------------------------*/
00064 /* Private variables ---------------------------------------------------------*/
00065 /* Private function prototypes -----------------------------------------------*/
00066 /* Private functions ---------------------------------------------------------*/
00067 
00068 /** @defgroup FMPI2CEx_Exported_Functions FMPI2C Extended Exported Functions
00069   * @{
00070   */
00071 
00072 /** @defgroup FMPI2CEx_Exported_Functions_Group1 Filter Mode Functions
00073   * @brief    Filter Mode Functions
00074   *
00075 @verbatim
00076  ===============================================================================
00077                       ##### Filter Mode Functions #####
00078  ===============================================================================
00079     [..] This section provides functions allowing to:
00080       (+) Configure Noise Filters
00081 
00082 @endverbatim
00083   * @{
00084   */
00085 
00086 /**
00087   * @brief  Configure FMPI2C Analog noise filter.
00088   * @param  hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
00089   *                the configuration information for the specified FMPI2Cx peripheral.
00090   * @param  AnalogFilter New state of the Analog filter.
00091   * @retval HAL status
00092   */
00093 HAL_StatusTypeDef HAL_FMPI2CEx_ConfigAnalogFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t AnalogFilter)
00094 {
00095   /* Check the parameters */
00096   assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
00097   assert_param(IS_FMPI2C_ANALOG_FILTER(AnalogFilter));
00098 
00099   if (hfmpi2c->State == HAL_FMPI2C_STATE_READY)
00100   {
00101     /* Process Locked */
00102     __HAL_LOCK(hfmpi2c);
00103 
00104     hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
00105 
00106     /* Disable the selected FMPI2C peripheral */
00107     __HAL_FMPI2C_DISABLE(hfmpi2c);
00108 
00109     /* Reset FMPI2Cx ANOFF bit */
00110     hfmpi2c->Instance->CR1 &= ~(FMPI2C_CR1_ANFOFF);
00111 
00112     /* Set analog filter bit*/
00113     hfmpi2c->Instance->CR1 |= AnalogFilter;
00114 
00115     __HAL_FMPI2C_ENABLE(hfmpi2c);
00116 
00117     hfmpi2c->State = HAL_FMPI2C_STATE_READY;
00118 
00119     /* Process Unlocked */
00120     __HAL_UNLOCK(hfmpi2c);
00121 
00122     return HAL_OK;
00123   }
00124   else
00125   {
00126     return HAL_BUSY;
00127   }
00128 }
00129 
00130 /**
00131   * @brief  Configure FMPI2C Digital noise filter.
00132   * @param  hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
00133   *                the configuration information for the specified FMPI2Cx peripheral.
00134   * @param  DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F.
00135   * @retval HAL status
00136   */
00137 HAL_StatusTypeDef HAL_FMPI2CEx_ConfigDigitalFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t DigitalFilter)
00138 {
00139   uint32_t tmpreg;
00140 
00141   /* Check the parameters */
00142   assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
00143   assert_param(IS_FMPI2C_DIGITAL_FILTER(DigitalFilter));
00144 
00145   if (hfmpi2c->State == HAL_FMPI2C_STATE_READY)
00146   {
00147     /* Process Locked */
00148     __HAL_LOCK(hfmpi2c);
00149 
00150     hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
00151 
00152     /* Disable the selected FMPI2C peripheral */
00153     __HAL_FMPI2C_DISABLE(hfmpi2c);
00154 
00155     /* Get the old register value */
00156     tmpreg = hfmpi2c->Instance->CR1;
00157 
00158     /* Reset FMPI2Cx DNF bits [11:8] */
00159     tmpreg &= ~(FMPI2C_CR1_DNF);
00160 
00161     /* Set FMPI2Cx DNF coefficient */
00162     tmpreg |= DigitalFilter << 8U;
00163 
00164     /* Store the new register value */
00165     hfmpi2c->Instance->CR1 = tmpreg;
00166 
00167     __HAL_FMPI2C_ENABLE(hfmpi2c);
00168 
00169     hfmpi2c->State = HAL_FMPI2C_STATE_READY;
00170 
00171     /* Process Unlocked */
00172     __HAL_UNLOCK(hfmpi2c);
00173 
00174     return HAL_OK;
00175   }
00176   else
00177   {
00178     return HAL_BUSY;
00179   }
00180 }
00181 /**
00182   * @}
00183   */
00184 
00185 /** @defgroup FMPI2CEx_Exported_Functions_Group3 Fast Mode Plus Functions
00186   * @brief    Fast Mode Plus Functions
00187   *
00188 @verbatim
00189  ===============================================================================
00190                       ##### Fast Mode Plus Functions #####
00191  ===============================================================================
00192     [..] This section provides functions allowing to:
00193       (+) Configure Fast Mode Plus
00194 
00195 @endverbatim
00196   * @{
00197   */
00198 
00199 /**
00200   * @brief Enable the FMPI2C fast mode plus driving capability.
00201   * @param ConfigFastModePlus Selects the pin.
00202   *   This parameter can be one of the @ref FMPI2CEx_FastModePlus values
00203   * @note  For FMPI2C1, fast mode plus driving capability can be enabled on all selected
00204   *        FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
00205   *        on each one of the following pins PB6, PB7, PB8 and PB9.
00206   * @note  For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
00207   *        can be enabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
00208   * @retval None
00209   */
00210 void HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
00211 {
00212   /* Check the parameter */
00213   assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
00214 
00215   /* Enable SYSCFG clock */
00216   __HAL_RCC_SYSCFG_CLK_ENABLE();
00217 
00218   /* Enable fast mode plus driving capability for selected pin */
00219   SET_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
00220 }
00221 
00222 /**
00223   * @brief Disable the FMPI2C fast mode plus driving capability.
00224   * @param ConfigFastModePlus Selects the pin.
00225   *   This parameter can be one of the @ref FMPI2CEx_FastModePlus values
00226   * @note  For FMPI2C1, fast mode plus driving capability can be disabled on all selected
00227   *        FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
00228   *        on each one of the following pins PB6, PB7, PB8 and PB9.
00229   * @note  For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
00230   *        can be disabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
00231   * @retval None
00232   */
00233 void HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
00234 {
00235   /* Check the parameter */
00236   assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
00237 
00238   /* Enable SYSCFG clock */
00239   __HAL_RCC_SYSCFG_CLK_ENABLE();
00240 
00241   /* Disable fast mode plus driving capability for selected pin */
00242   CLEAR_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
00243 }
00244 /**
00245   * @}
00246   */
00247 /**
00248   * @}
00249   */
00250 
00251 #endif /* FMPI2C_CR1_PE */
00252 #endif /* HAL_FMPI2C_MODULE_ENABLED */
00253 /**
00254   * @}
00255   */
00256 
00257 /**
00258   * @}
00259   */
00260 
00261 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/