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