STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_i2c_ex.c
Go to the documentation of this file.
1 
49 /* Includes ------------------------------------------------------------------*/
50 #include "stm32l4xx_hal.h"
51 
61 #ifdef HAL_I2C_MODULE_ENABLED
62 
63 /* Private typedef -----------------------------------------------------------*/
64 /* Private define ------------------------------------------------------------*/
65 /* Private macro -------------------------------------------------------------*/
66 /* Private variables ---------------------------------------------------------*/
67 /* Private function prototypes -----------------------------------------------*/
68 /* Private functions ---------------------------------------------------------*/
69 
97 HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
98 {
99  /* Check the parameters */
100  assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
101  assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
102 
103  if (hi2c->State == HAL_I2C_STATE_READY)
104  {
105  /* Process Locked */
106  __HAL_LOCK(hi2c);
107 
108  hi2c->State = HAL_I2C_STATE_BUSY;
109 
110  /* Disable the selected I2C peripheral */
111  __HAL_I2C_DISABLE(hi2c);
112 
113  /* Reset I2Cx ANOFF bit */
114  hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF);
115 
116  /* Set analog filter bit*/
117  hi2c->Instance->CR1 |= AnalogFilter;
118 
119  __HAL_I2C_ENABLE(hi2c);
120 
121  hi2c->State = HAL_I2C_STATE_READY;
122 
123  /* Process Unlocked */
124  __HAL_UNLOCK(hi2c);
125 
126  return HAL_OK;
127  }
128  else
129  {
130  return HAL_BUSY;
131  }
132 }
133 
141 HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
142 {
143  uint32_t tmpreg;
144 
145  /* Check the parameters */
146  assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
147  assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
148 
149  if (hi2c->State == HAL_I2C_STATE_READY)
150  {
151  /* Process Locked */
152  __HAL_LOCK(hi2c);
153 
154  hi2c->State = HAL_I2C_STATE_BUSY;
155 
156  /* Disable the selected I2C peripheral */
157  __HAL_I2C_DISABLE(hi2c);
158 
159  /* Get the old register value */
160  tmpreg = hi2c->Instance->CR1;
161 
162  /* Reset I2Cx DNF bits [11:8] */
163  tmpreg &= ~(I2C_CR1_DNF);
164 
165  /* Set I2Cx DNF coefficient */
166  tmpreg |= DigitalFilter << 8U;
167 
168  /* Store the new register value */
169  hi2c->Instance->CR1 = tmpreg;
170 
171  __HAL_I2C_ENABLE(hi2c);
172 
173  hi2c->State = HAL_I2C_STATE_READY;
174 
175  /* Process Unlocked */
176  __HAL_UNLOCK(hi2c);
177 
178  return HAL_OK;
179  }
180  else
181  {
182  return HAL_BUSY;
183  }
184 }
185 
193 {
194  /* Check the parameters */
195  assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance));
196 
197  if (hi2c->State == HAL_I2C_STATE_READY)
198  {
199  /* Process Locked */
200  __HAL_LOCK(hi2c);
201 
202  hi2c->State = HAL_I2C_STATE_BUSY;
203 
204  /* Disable the selected I2C peripheral */
205  __HAL_I2C_DISABLE(hi2c);
206 
207  /* Enable wakeup from stop mode */
208  hi2c->Instance->CR1 |= I2C_CR1_WUPEN;
209 
210  __HAL_I2C_ENABLE(hi2c);
211 
212  hi2c->State = HAL_I2C_STATE_READY;
213 
214  /* Process Unlocked */
215  __HAL_UNLOCK(hi2c);
216 
217  return HAL_OK;
218  }
219  else
220  {
221  return HAL_BUSY;
222  }
223 }
224 
232 {
233  /* Check the parameters */
234  assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance));
235 
236  if (hi2c->State == HAL_I2C_STATE_READY)
237  {
238  /* Process Locked */
239  __HAL_LOCK(hi2c);
240 
241  hi2c->State = HAL_I2C_STATE_BUSY;
242 
243  /* Disable the selected I2C peripheral */
244  __HAL_I2C_DISABLE(hi2c);
245 
246  /* Enable wakeup from stop mode */
247  hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN);
248 
249  __HAL_I2C_ENABLE(hi2c);
250 
251  hi2c->State = HAL_I2C_STATE_READY;
252 
253  /* Process Unlocked */
254  __HAL_UNLOCK(hi2c);
255 
256  return HAL_OK;
257  }
258  else
259  {
260  return HAL_BUSY;
261  }
262 }
263 
281 void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
282 {
283  /* Check the parameter */
284  assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus));
285 
286  /* Enable SYSCFG clock */
287  __HAL_RCC_SYSCFG_CLK_ENABLE();
288 
289  /* Enable fast mode plus driving capability for selected pin */
290  SET_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus);
291 }
292 
310 void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
311 {
312  /* Check the parameter */
313  assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus));
314 
315  /* Enable SYSCFG clock */
316  __HAL_RCC_SYSCFG_CLK_ENABLE();
317 
318  /* Disable fast mode plus driving capability for selected pin */
319  CLEAR_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus);
320 }
321 
330 #endif /* HAL_I2C_MODULE_ENABLED */
331 
339 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
Configure I2C Analog noise filter.
void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
Enable the I2C fast mode plus driving capability.
This file contains all the functions prototypes for the HAL module driver.
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c)
Disable I2C wakeup from Stop mode(s).
void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
Disable the I2C fast mode plus driving capability.
HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c)
Enable I2C wakeup from Stop mode(s).
__IO HAL_I2C_StateTypeDef State
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
Configure I2C Digital noise filter.