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 ******************************************************************************
12 * @attention
13 *
14 * Copyright (c) 2016 STMicroelectronics.
15 * All rights reserved.
16 *
17 * This software is licensed under terms that can be found in the LICENSE file
18 * in the root directory of this software component.
19 * If no LICENSE file comes with this software, it is provided AS-IS.
20 *
21 ******************************************************************************
22 @verbatim
23 ==============================================================================
24 ##### FMPI2C peripheral Extended features #####
25 ==============================================================================
26
27 [..] Comparing to other previous devices, the FMPI2C interface for STM32F4xx
28 devices contains the following additional features
29
30 (+) Possibility to disable or enable Analog Noise Filter
31 (+) Use of a configured Digital Noise Filter
32 (+) Disable or enable Fast Mode Plus
33
34 ##### How to use this driver #####
35 ==============================================================================
36 [..] This driver provides functions to:
37 (#) Configure FMPI2C Analog noise filter using the function HAL_FMPI2CEx_ConfigAnalogFilter()
38 (#) Configure FMPI2C Digital noise filter using the function HAL_FMPI2CEx_ConfigDigitalFilter()
39 (#) Configure the enable or disable of fast mode plus driving capability using the functions :
40 (++) HAL_FMPI2CEx_EnableFastModePlus()
41 (++) HAL_FMPI2CEx_DisableFastModePlus()
42 @endverbatim
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 Filter Mode Functions
72 * @brief Filter Mode Functions
73 *
74 @verbatim
75 ===============================================================================
76 ##### Filter Mode Functions #####
77 ===============================================================================
78 [..] This section provides functions allowing to:
79 (+) Configure Noise Filters
80
81 @endverbatim
82 * @{
83 */
84
85 /**
86 * @brief Configure FMPI2C Analog noise filter.
87 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
88 * the configuration information for the specified FMPI2Cx peripheral.
89 * @param AnalogFilter New state of the Analog filter.
90 * @retval HAL status
91 */
HAL_FMPI2CEx_ConfigAnalogFilter(FMPI2C_HandleTypeDef * hfmpi2c,uint32_t AnalogFilter)92 HAL_StatusTypeDef HAL_FMPI2CEx_ConfigAnalogFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t AnalogFilter)
93 {
94 /* Check the parameters */
95 assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
96 assert_param(IS_FMPI2C_ANALOG_FILTER(AnalogFilter));
97
98 if (hfmpi2c->State == HAL_FMPI2C_STATE_READY)
99 {
100 /* Process Locked */
101 __HAL_LOCK(hfmpi2c);
102
103 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
104
105 /* Disable the selected FMPI2C peripheral */
106 __HAL_FMPI2C_DISABLE(hfmpi2c);
107
108 /* Reset FMPI2Cx ANOFF bit */
109 hfmpi2c->Instance->CR1 &= ~(FMPI2C_CR1_ANFOFF);
110
111 /* Set analog filter bit*/
112 hfmpi2c->Instance->CR1 |= AnalogFilter;
113
114 __HAL_FMPI2C_ENABLE(hfmpi2c);
115
116 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
117
118 /* Process Unlocked */
119 __HAL_UNLOCK(hfmpi2c);
120
121 return HAL_OK;
122 }
123 else
124 {
125 return HAL_BUSY;
126 }
127 }
128
129 /**
130 * @brief Configure FMPI2C Digital noise filter.
131 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
132 * the configuration information for the specified FMPI2Cx peripheral.
133 * @param DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F.
134 * @retval HAL status
135 */
HAL_FMPI2CEx_ConfigDigitalFilter(FMPI2C_HandleTypeDef * hfmpi2c,uint32_t DigitalFilter)136 HAL_StatusTypeDef HAL_FMPI2CEx_ConfigDigitalFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t DigitalFilter)
137 {
138 uint32_t tmpreg;
139
140 /* Check the parameters */
141 assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
142 assert_param(IS_FMPI2C_DIGITAL_FILTER(DigitalFilter));
143
144 if (hfmpi2c->State == HAL_FMPI2C_STATE_READY)
145 {
146 /* Process Locked */
147 __HAL_LOCK(hfmpi2c);
148
149 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
150
151 /* Disable the selected FMPI2C peripheral */
152 __HAL_FMPI2C_DISABLE(hfmpi2c);
153
154 /* Get the old register value */
155 tmpreg = hfmpi2c->Instance->CR1;
156
157 /* Reset FMPI2Cx DNF bits [11:8] */
158 tmpreg &= ~(FMPI2C_CR1_DNF);
159
160 /* Set FMPI2Cx DNF coefficient */
161 tmpreg |= DigitalFilter << 8U;
162
163 /* Store the new register value */
164 hfmpi2c->Instance->CR1 = tmpreg;
165
166 __HAL_FMPI2C_ENABLE(hfmpi2c);
167
168 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
169
170 /* Process Unlocked */
171 __HAL_UNLOCK(hfmpi2c);
172
173 return HAL_OK;
174 }
175 else
176 {
177 return HAL_BUSY;
178 }
179 }
180 /**
181 * @}
182 */
183
184 /** @defgroup FMPI2CEx_Exported_Functions_Group3 Fast Mode Plus Functions
185 * @brief Fast Mode Plus Functions
186 *
187 @verbatim
188 ===============================================================================
189 ##### Fast Mode Plus Functions #####
190 ===============================================================================
191 [..] This section provides functions allowing to:
192 (+) Configure Fast Mode Plus
193
194 @endverbatim
195 * @{
196 */
197
198 /**
199 * @brief Enable the FMPI2C fast mode plus driving capability.
200 * @param ConfigFastModePlus Selects the pin.
201 * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
202 * @note For FMPI2C1, fast mode plus driving capability can be enabled on all selected
203 * FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
204 * on each one of the following pins PB6, PB7, PB8 and PB9.
205 * @note For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
206 * can be enabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
207 * @retval None
208 */
HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)209 void HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
210 {
211 /* Check the parameter */
212 assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
213
214 /* Enable SYSCFG clock */
215 __HAL_RCC_SYSCFG_CLK_ENABLE();
216
217 /* Enable fast mode plus driving capability for selected pin */
218 SET_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
219 }
220
221 /**
222 * @brief Disable the FMPI2C fast mode plus driving capability.
223 * @param ConfigFastModePlus Selects the pin.
224 * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
225 * @note For FMPI2C1, fast mode plus driving capability can be disabled on all selected
226 * FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
227 * on each one of the following pins PB6, PB7, PB8 and PB9.
228 * @note For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
229 * can be disabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
230 * @retval None
231 */
HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)232 void HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
233 {
234 /* Check the parameter */
235 assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
236
237 /* Enable SYSCFG clock */
238 __HAL_RCC_SYSCFG_CLK_ENABLE();
239
240 /* Disable fast mode plus driving capability for selected pin */
241 CLEAR_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
242 }
243 /**
244 * @}
245 */
246 /**
247 * @}
248 */
249
250 #endif /* FMPI2C_CR1_PE */
251 #endif /* HAL_FMPI2C_MODULE_ENABLED */
252 /**
253 * @}
254 */
255
256 /**
257 * @}
258 */
259