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