• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_fmpi2c_ex.c
4   * @author  MCD Application Team
5   * @brief   FMPI2C Extended HAL module driver.
6   *          This file provides firmware functions to manage the following
7   *          functionalities of FMPI2C Extended peripheral:
8   *           + Filter Mode Functions
9   *           + FastModePlus Functions
10   *
11   @verbatim
12   ==============================================================================
13                ##### FMPI2C peripheral Extended features  #####
14   ==============================================================================
15 
16   [..] Comparing to other previous devices, the FMPI2C interface for STM32F4xx
17        devices contains the following additional features
18 
19        (+) Possibility to disable or enable Analog Noise Filter
20        (+) Use of a configured Digital Noise Filter
21        (+) Disable or enable Fast Mode Plus
22 
23                      ##### How to use this driver #####
24   ==============================================================================
25   [..] This driver provides functions to:
26     (#) Configure FMPI2C Analog noise filter using the function HAL_FMPI2CEx_ConfigAnalogFilter()
27     (#) Configure FMPI2C Digital noise filter using the function HAL_FMPI2CEx_ConfigDigitalFilter()
28     (#) Configure the enable or disable of fast mode plus driving capability using the functions :
29           (++) HAL_FMPI2CEx_EnableFastModePlus()
30           (++) HAL_FMPI2CEx_DisableFastModePlus()
31   @endverbatim
32   ******************************************************************************
33   * @attention
34   *
35   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
36   * All rights reserved.</center></h2>
37   *
38   * This software component is licensed by ST under BSD 3-Clause license,
39   * the "License"; You may not use this file except in compliance with the
40   * License. You may obtain a copy of the License at:
41   *                        opensource.org/licenses/BSD-3-Clause
42   *
43   ******************************************************************************
44   */
45 
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal.h"
48 
49 /** @addtogroup STM32F4xx_HAL_Driver
50   * @{
51   */
52 
53 /** @defgroup FMPI2CEx FMPI2CEx
54   * @brief FMPI2C Extended HAL module driver
55   * @{
56   */
57 
58 #ifdef HAL_FMPI2C_MODULE_ENABLED
59 #if defined(FMPI2C_CR1_PE)
60 
61 /* Private typedef -----------------------------------------------------------*/
62 /* Private define ------------------------------------------------------------*/
63 /* Private macro -------------------------------------------------------------*/
64 /* Private variables ---------------------------------------------------------*/
65 /* Private function prototypes -----------------------------------------------*/
66 /* Private functions ---------------------------------------------------------*/
67 
68 /** @defgroup FMPI2CEx_Exported_Functions FMPI2C Extended Exported Functions
69   * @{
70   */
71 
72 /** @defgroup FMPI2CEx_Exported_Functions_Group1 Filter Mode Functions
73   * @brief    Filter Mode Functions
74   *
75 @verbatim
76  ===============================================================================
77                       ##### Filter Mode Functions #####
78  ===============================================================================
79     [..] This section provides functions allowing to:
80       (+) Configure Noise Filters
81 
82 @endverbatim
83   * @{
84   */
85 
86 /**
87   * @brief  Configure FMPI2C Analog noise filter.
88   * @param  hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
89   *                the configuration information for the specified FMPI2Cx peripheral.
90   * @param  AnalogFilter New state of the Analog filter.
91   * @retval HAL status
92   */
HAL_FMPI2CEx_ConfigAnalogFilter(FMPI2C_HandleTypeDef * hfmpi2c,uint32_t AnalogFilter)93 HAL_StatusTypeDef HAL_FMPI2CEx_ConfigAnalogFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t AnalogFilter)
94 {
95   /* Check the parameters */
96   assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
97   assert_param(IS_FMPI2C_ANALOG_FILTER(AnalogFilter));
98 
99   if (hfmpi2c->State == HAL_FMPI2C_STATE_READY)
100   {
101     /* Process Locked */
102     __HAL_LOCK(hfmpi2c);
103 
104     hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
105 
106     /* Disable the selected FMPI2C peripheral */
107     __HAL_FMPI2C_DISABLE(hfmpi2c);
108 
109     /* Reset FMPI2Cx ANOFF bit */
110     hfmpi2c->Instance->CR1 &= ~(FMPI2C_CR1_ANFOFF);
111 
112     /* Set analog filter bit*/
113     hfmpi2c->Instance->CR1 |= AnalogFilter;
114 
115     __HAL_FMPI2C_ENABLE(hfmpi2c);
116 
117     hfmpi2c->State = HAL_FMPI2C_STATE_READY;
118 
119     /* Process Unlocked */
120     __HAL_UNLOCK(hfmpi2c);
121 
122     return HAL_OK;
123   }
124   else
125   {
126     return HAL_BUSY;
127   }
128 }
129 
130 /**
131   * @brief  Configure FMPI2C Digital noise filter.
132   * @param  hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
133   *                the configuration information for the specified FMPI2Cx peripheral.
134   * @param  DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F.
135   * @retval HAL status
136   */
HAL_FMPI2CEx_ConfigDigitalFilter(FMPI2C_HandleTypeDef * hfmpi2c,uint32_t DigitalFilter)137 HAL_StatusTypeDef HAL_FMPI2CEx_ConfigDigitalFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t DigitalFilter)
138 {
139   uint32_t tmpreg;
140 
141   /* Check the parameters */
142   assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
143   assert_param(IS_FMPI2C_DIGITAL_FILTER(DigitalFilter));
144 
145   if (hfmpi2c->State == HAL_FMPI2C_STATE_READY)
146   {
147     /* Process Locked */
148     __HAL_LOCK(hfmpi2c);
149 
150     hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
151 
152     /* Disable the selected FMPI2C peripheral */
153     __HAL_FMPI2C_DISABLE(hfmpi2c);
154 
155     /* Get the old register value */
156     tmpreg = hfmpi2c->Instance->CR1;
157 
158     /* Reset FMPI2Cx DNF bits [11:8] */
159     tmpreg &= ~(FMPI2C_CR1_DNF);
160 
161     /* Set FMPI2Cx DNF coefficient */
162     tmpreg |= DigitalFilter << 8U;
163 
164     /* Store the new register value */
165     hfmpi2c->Instance->CR1 = tmpreg;
166 
167     __HAL_FMPI2C_ENABLE(hfmpi2c);
168 
169     hfmpi2c->State = HAL_FMPI2C_STATE_READY;
170 
171     /* Process Unlocked */
172     __HAL_UNLOCK(hfmpi2c);
173 
174     return HAL_OK;
175   }
176   else
177   {
178     return HAL_BUSY;
179   }
180 }
181 /**
182   * @}
183   */
184 
185 /** @defgroup FMPI2CEx_Exported_Functions_Group3 Fast Mode Plus Functions
186   * @brief    Fast Mode Plus Functions
187   *
188 @verbatim
189  ===============================================================================
190                       ##### Fast Mode Plus Functions #####
191  ===============================================================================
192     [..] This section provides functions allowing to:
193       (+) Configure Fast Mode Plus
194 
195 @endverbatim
196   * @{
197   */
198 
199 /**
200   * @brief Enable the FMPI2C fast mode plus driving capability.
201   * @param ConfigFastModePlus Selects the pin.
202   *   This parameter can be one of the @ref FMPI2CEx_FastModePlus values
203   * @note  For FMPI2C1, fast mode plus driving capability can be enabled on all selected
204   *        FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
205   *        on each one of the following pins PB6, PB7, PB8 and PB9.
206   * @note  For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
207   *        can be enabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
208   * @retval None
209   */
HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)210 void HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
211 {
212   /* Check the parameter */
213   assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
214 
215   /* Enable SYSCFG clock */
216   __HAL_RCC_SYSCFG_CLK_ENABLE();
217 
218   /* Enable fast mode plus driving capability for selected pin */
219   SET_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
220 }
221 
222 /**
223   * @brief Disable the FMPI2C fast mode plus driving capability.
224   * @param ConfigFastModePlus Selects the pin.
225   *   This parameter can be one of the @ref FMPI2CEx_FastModePlus values
226   * @note  For FMPI2C1, fast mode plus driving capability can be disabled on all selected
227   *        FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
228   *        on each one of the following pins PB6, PB7, PB8 and PB9.
229   * @note  For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
230   *        can be disabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
231   * @retval None
232   */
HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)233 void HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
234 {
235   /* Check the parameter */
236   assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
237 
238   /* Enable SYSCFG clock */
239   __HAL_RCC_SYSCFG_CLK_ENABLE();
240 
241   /* Disable fast mode plus driving capability for selected pin */
242   CLEAR_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
243 }
244 /**
245   * @}
246   */
247 /**
248   * @}
249   */
250 
251 #endif /* FMPI2C_CR1_PE */
252 #endif /* HAL_FMPI2C_MODULE_ENABLED */
253 /**
254   * @}
255   */
256 
257 /**
258   * @}
259   */
260 
261 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
262