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 * + Extended features functions
9 *
10 @verbatim
11 ==============================================================================
12 ##### FMPI2C peripheral Extended features #####
13 ==============================================================================
14
15 [..] Comparing to other previous devices, the FMPI2C interface for STM32F4xx
16 devices contains the following additional features
17
18 (+) Possibility to disable or enable Analog Noise Filter
19 (+) Use of a configured Digital Noise Filter
20 (+) Disable or enable Fast Mode Plus
21
22 ##### How to use this driver #####
23 ==============================================================================
24 [..] This driver provides functions to:
25 (#) Configure FMPI2C Analog noise filter using the function HAL_FMPI2CEx_ConfigAnalogFilter()
26 (#) Configure FMPI2C Digital noise filter using the function HAL_FMPI2CEx_ConfigDigitalFilter()
27 (#) Configure the enable or disable of fast mode plus driving capability using the functions :
28 (++) HAL_FMPI2CEx_EnableFastModePlus()
29 (++) HAL_FMPI2CEx_DisableFastModePlus()
30 @endverbatim
31 ******************************************************************************
32 * @attention
33 *
34 * <h2><center>© Copyright (c) 2016 STMicroelectronics.
35 * All rights reserved.</center></h2>
36 *
37 * This software component is licensed by ST under BSD 3-Clause license,
38 * the "License"; You may not use this file except in compliance with the
39 * License. You may obtain a copy of the License at:
40 * opensource.org/licenses/BSD-3-Clause
41 *
42 ******************************************************************************
43 */
44
45 /* Includes ------------------------------------------------------------------*/
46 #include "stm32f4xx_hal.h"
47
48 /** @addtogroup STM32F4xx_HAL_Driver
49 * @{
50 */
51
52 /** @defgroup FMPI2CEx FMPI2CEx
53 * @brief FMPI2C Extended HAL module driver
54 * @{
55 */
56
57 #ifdef HAL_FMPI2C_MODULE_ENABLED
58 #if defined(FMPI2C_CR1_PE)
59
60 /* Private typedef -----------------------------------------------------------*/
61 /* Private define ------------------------------------------------------------*/
62 /* Private macro -------------------------------------------------------------*/
63 /* Private variables ---------------------------------------------------------*/
64 /* Private function prototypes -----------------------------------------------*/
65 /* Private functions ---------------------------------------------------------*/
66
67 /** @defgroup FMPI2CEx_Exported_Functions FMPI2C Extended Exported Functions
68 * @{
69 */
70
71 /** @defgroup FMPI2CEx_Exported_Functions_Group1 Extended features functions
72 * @brief Extended features functions
73 *
74 @verbatim
75 ===============================================================================
76 ##### Extended features functions #####
77 ===============================================================================
78 [..] This section provides functions allowing to:
79 (+) Configure Noise Filters
80 (+) Configure Fast Mode Plus
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 * @brief Enable the FMPI2C fast mode plus driving capability.
184 * @param ConfigFastModePlus Selects the pin.
185 * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
186 * @note For FMPI2C1, fast mode plus driving capability can be enabled on all selected
187 * FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
188 * on each one of the following pins PB6, PB7, PB8 and PB9.
189 * @note For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
190 * can be enabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
191 * @retval None
192 */
HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)193 void HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
194 {
195 /* Check the parameter */
196 assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
197
198 /* Enable SYSCFG clock */
199 __HAL_RCC_SYSCFG_CLK_ENABLE();
200
201 /* Enable fast mode plus driving capability for selected pin */
202 SET_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
203 }
204
205 /**
206 * @brief Disable the FMPI2C fast mode plus driving capability.
207 * @param ConfigFastModePlus Selects the pin.
208 * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
209 * @note For FMPI2C1, fast mode plus driving capability can be disabled on all selected
210 * FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
211 * on each one of the following pins PB6, PB7, PB8 and PB9.
212 * @note For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
213 * can be disabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
214 * @retval None
215 */
HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)216 void HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
217 {
218 /* Check the parameter */
219 assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
220
221 /* Enable SYSCFG clock */
222 __HAL_RCC_SYSCFG_CLK_ENABLE();
223
224 /* Disable fast mode plus driving capability for selected pin */
225 CLEAR_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
226 }
227
228 /**
229 * @}
230 */
231
232 /**
233 * @}
234 */
235
236 #endif /* FMPI2C_CR1_PE */
237 #endif /* HAL_FMPI2C_MODULE_ENABLED */
238 /**
239 * @}
240 */
241
242 /**
243 * @}
244 */
245
246 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
247