]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_MPU_STM32L4_Discovery_GCC_IAR_Keil/ST_Code/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c
Rename STM32Cube to GCC for STM32L4 Discovery projects as GCC is
[freertos] / FreeRTOS / Demo / CORTEX_MPU_STM32L4_Discovery_GCC_IAR_Keil / ST_Code / Drivers / STM32L4xx_HAL_Driver / Src / stm32l4xx_hal_i2c_ex.c
diff --git a/FreeRTOS/Demo/CORTEX_MPU_STM32L4_Discovery_GCC_IAR_Keil/ST_Code/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c b/FreeRTOS/Demo/CORTEX_MPU_STM32L4_Discovery_GCC_IAR_Keil/ST_Code/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c
new file mode 100644 (file)
index 0000000..54d74c7
--- /dev/null
@@ -0,0 +1,339 @@
+/**\r
+  ******************************************************************************\r
+  * @file    stm32l4xx_hal_i2c_ex.c\r
+  * @author  MCD Application Team\r
+  * @brief   I2C Extended HAL module driver.\r
+  *          This file provides firmware functions to manage the following\r
+  *          functionalities of I2C Extended peripheral:\r
+  *           + Extended features functions\r
+  *\r
+  @verbatim\r
+  ==============================================================================\r
+               ##### I2C peripheral Extended features  #####\r
+  ==============================================================================\r
+\r
+  [..] Comparing to other previous devices, the I2C interface for STM32L4xx\r
+       devices contains the following additional features\r
+\r
+       (+) Possibility to disable or enable Analog Noise Filter\r
+       (+) Use of a configured Digital Noise Filter\r
+       (+) Disable or enable wakeup from Stop mode(s)\r
+       (+) Disable or enable Fast Mode Plus\r
+\r
+                     ##### How to use this driver #####\r
+  ==============================================================================\r
+  [..] This driver provides functions to configure Noise Filter and Wake Up Feature\r
+    (#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter()\r
+    (#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter()\r
+    (#) Configure the enable or disable of I2C Wake Up Mode using the functions :\r
+          (++) HAL_I2CEx_EnableWakeUp()\r
+          (++) HAL_I2CEx_DisableWakeUp()\r
+    (#) Configure the enable or disable of fast mode plus driving capability using the functions :\r
+          (++) HAL_I2CEx_EnableFastModePlus()\r
+          (++) HAL_I2CEx_DisableFastModePlus()\r
+  @endverbatim\r
+  ******************************************************************************\r
+  * @attention\r
+  *\r
+  * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.\r
+  * All rights reserved.</center></h2>\r
+  *\r
+  * This software component is licensed by ST under BSD 3-Clause license,\r
+  * the "License"; You may not use this file except in compliance with the\r
+  * License. You may obtain a copy of the License at:\r
+  *                        opensource.org/licenses/BSD-3-Clause\r
+  *\r
+  ******************************************************************************\r
+  */\r
+\r
+/* Includes ------------------------------------------------------------------*/\r
+#include "stm32l4xx_hal.h"\r
+\r
+/** @addtogroup STM32L4xx_HAL_Driver\r
+  * @{\r
+  */\r
+\r
+/** @defgroup I2CEx I2CEx\r
+  * @brief I2C Extended HAL module driver\r
+  * @{\r
+  */\r
+\r
+#ifdef HAL_I2C_MODULE_ENABLED\r
+\r
+/* Private typedef -----------------------------------------------------------*/\r
+/* Private define ------------------------------------------------------------*/\r
+/* Private macro -------------------------------------------------------------*/\r
+/* Private variables ---------------------------------------------------------*/\r
+/* Private function prototypes -----------------------------------------------*/\r
+/* Private functions ---------------------------------------------------------*/\r
+\r
+/** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions\r
+  * @{\r
+  */\r
+\r
+/** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions\r
+  * @brief    Extended features functions\r
+ *\r
+@verbatim\r
+ ===============================================================================\r
+                      ##### Extended features functions #####\r
+ ===============================================================================\r
+    [..] This section provides functions allowing to:\r
+      (+) Configure Noise Filters\r
+      (+) Configure Wake Up Feature\r
+      (+) Configure Fast Mode Plus\r
+\r
+@endverbatim\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @brief  Configure I2C Analog noise filter.\r
+  * @param  hi2c Pointer to a I2C_HandleTypeDef structure that contains\r
+  *                the configuration information for the specified I2Cx peripheral.\r
+  * @param  AnalogFilter New state of the Analog filter.\r
+  * @retval HAL status\r
+  */\r
+HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));\r
+  assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));\r
+\r
+  if (hi2c->State == HAL_I2C_STATE_READY)\r
+  {\r
+    /* Process Locked */\r
+    __HAL_LOCK(hi2c);\r
+\r
+    hi2c->State = HAL_I2C_STATE_BUSY;\r
+\r
+    /* Disable the selected I2C peripheral */\r
+    __HAL_I2C_DISABLE(hi2c);\r
+\r
+    /* Reset I2Cx ANOFF bit */\r
+    hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF);\r
+\r
+    /* Set analog filter bit*/\r
+    hi2c->Instance->CR1 |= AnalogFilter;\r
+\r
+    __HAL_I2C_ENABLE(hi2c);\r
+\r
+    hi2c->State = HAL_I2C_STATE_READY;\r
+\r
+    /* Process Unlocked */\r
+    __HAL_UNLOCK(hi2c);\r
+\r
+    return HAL_OK;\r
+  }\r
+  else\r
+  {\r
+    return HAL_BUSY;\r
+  }\r
+}\r
+\r
+/**\r
+  * @brief  Configure I2C Digital noise filter.\r
+  * @param  hi2c Pointer to a I2C_HandleTypeDef structure that contains\r
+  *                the configuration information for the specified I2Cx peripheral.\r
+  * @param  DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F.\r
+  * @retval HAL status\r
+  */\r
+HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)\r
+{\r
+  uint32_t tmpreg;\r
+\r
+  /* Check the parameters */\r
+  assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));\r
+  assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));\r
+\r
+  if (hi2c->State == HAL_I2C_STATE_READY)\r
+  {\r
+    /* Process Locked */\r
+    __HAL_LOCK(hi2c);\r
+\r
+    hi2c->State = HAL_I2C_STATE_BUSY;\r
+\r
+    /* Disable the selected I2C peripheral */\r
+    __HAL_I2C_DISABLE(hi2c);\r
+\r
+    /* Get the old register value */\r
+    tmpreg = hi2c->Instance->CR1;\r
+\r
+    /* Reset I2Cx DNF bits [11:8] */\r
+    tmpreg &= ~(I2C_CR1_DNF);\r
+\r
+    /* Set I2Cx DNF coefficient */\r
+    tmpreg |= DigitalFilter << 8U;\r
+\r
+    /* Store the new register value */\r
+    hi2c->Instance->CR1 = tmpreg;\r
+\r
+    __HAL_I2C_ENABLE(hi2c);\r
+\r
+    hi2c->State = HAL_I2C_STATE_READY;\r
+\r
+    /* Process Unlocked */\r
+    __HAL_UNLOCK(hi2c);\r
+\r
+    return HAL_OK;\r
+  }\r
+  else\r
+  {\r
+    return HAL_BUSY;\r
+  }\r
+}\r
+\r
+/**\r
+  * @brief  Enable I2C wakeup from Stop mode(s).\r
+  * @param  hi2c Pointer to a I2C_HandleTypeDef structure that contains\r
+  *                the configuration information for the specified I2Cx peripheral.\r
+  * @retval HAL status\r
+  */\r
+HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance));\r
+\r
+  if (hi2c->State == HAL_I2C_STATE_READY)\r
+  {\r
+    /* Process Locked */\r
+    __HAL_LOCK(hi2c);\r
+\r
+    hi2c->State = HAL_I2C_STATE_BUSY;\r
+\r
+    /* Disable the selected I2C peripheral */\r
+    __HAL_I2C_DISABLE(hi2c);\r
+\r
+    /* Enable wakeup from stop mode */\r
+    hi2c->Instance->CR1 |= I2C_CR1_WUPEN;\r
+\r
+    __HAL_I2C_ENABLE(hi2c);\r
+\r
+    hi2c->State = HAL_I2C_STATE_READY;\r
+\r
+    /* Process Unlocked */\r
+    __HAL_UNLOCK(hi2c);\r
+\r
+    return HAL_OK;\r
+  }\r
+  else\r
+  {\r
+    return HAL_BUSY;\r
+  }\r
+}\r
+\r
+/**\r
+  * @brief  Disable I2C wakeup from Stop mode(s).\r
+  * @param  hi2c Pointer to a I2C_HandleTypeDef structure that contains\r
+  *                the configuration information for the specified I2Cx peripheral.\r
+  * @retval HAL status\r
+  */\r
+HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance));\r
+\r
+  if (hi2c->State == HAL_I2C_STATE_READY)\r
+  {\r
+    /* Process Locked */\r
+    __HAL_LOCK(hi2c);\r
+\r
+    hi2c->State = HAL_I2C_STATE_BUSY;\r
+\r
+    /* Disable the selected I2C peripheral */\r
+    __HAL_I2C_DISABLE(hi2c);\r
+\r
+    /* Enable wakeup from stop mode */\r
+    hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN);\r
+\r
+    __HAL_I2C_ENABLE(hi2c);\r
+\r
+    hi2c->State = HAL_I2C_STATE_READY;\r
+\r
+    /* Process Unlocked */\r
+    __HAL_UNLOCK(hi2c);\r
+\r
+    return HAL_OK;\r
+  }\r
+  else\r
+  {\r
+    return HAL_BUSY;\r
+  }\r
+}\r
+\r
+/**\r
+  * @brief Enable the I2C fast mode plus driving capability.\r
+  * @param ConfigFastModePlus Selects the pin.\r
+  *   This parameter can be one of the @ref I2CEx_FastModePlus values\r
+  * @note  For I2C1, fast mode plus driving capability can be enabled on all selected\r
+  *        I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently\r
+  *        on each one of the following pins PB6, PB7, PB8 and PB9.\r
+  * @note  For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability\r
+  *        can be enabled only by using I2C_FASTMODEPLUS_I2C1 parameter.\r
+  * @note  For all I2C2 pins fast mode plus driving capability can be enabled\r
+  *        only by using I2C_FASTMODEPLUS_I2C2 parameter.\r
+  * @note  For all I2C3 pins fast mode plus driving capability can be enabled\r
+  *        only by using I2C_FASTMODEPLUS_I2C3 parameter.\r
+  * @note  For all I2C4 pins fast mode plus driving capability can be enabled\r
+  *        only by using I2C_FASTMODEPLUS_I2C4 parameter.\r
+  * @retval None\r
+  */\r
+void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)\r
+{\r
+  /* Check the parameter */\r
+  assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus));\r
+\r
+  /* Enable SYSCFG clock */\r
+  __HAL_RCC_SYSCFG_CLK_ENABLE();\r
+\r
+  /* Enable fast mode plus driving capability for selected pin */\r
+  SET_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus);\r
+}\r
+\r
+/**\r
+  * @brief Disable the I2C fast mode plus driving capability.\r
+  * @param ConfigFastModePlus Selects the pin.\r
+  *   This parameter can be one of the @ref I2CEx_FastModePlus values\r
+  * @note  For I2C1, fast mode plus driving capability can be disabled on all selected\r
+  *        I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently\r
+  *        on each one of the following pins PB6, PB7, PB8 and PB9.\r
+  * @note  For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability\r
+  *        can be disabled only by using I2C_FASTMODEPLUS_I2C1 parameter.\r
+  * @note  For all I2C2 pins fast mode plus driving capability can be disabled\r
+  *        only by using I2C_FASTMODEPLUS_I2C2 parameter.\r
+  * @note  For all I2C3 pins fast mode plus driving capability can be disabled\r
+  *        only by using I2C_FASTMODEPLUS_I2C3 parameter.\r
+  * @note  For all I2C4 pins fast mode plus driving capability can be disabled\r
+  *        only by using I2C_FASTMODEPLUS_I2C4 parameter.\r
+  * @retval None\r
+  */\r
+void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)\r
+{\r
+  /* Check the parameter */\r
+  assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus));\r
+\r
+  /* Enable SYSCFG clock */\r
+  __HAL_RCC_SYSCFG_CLK_ENABLE();\r
+\r
+  /* Disable fast mode plus driving capability for selected pin */\r
+  CLEAR_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus);\r
+}\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+#endif /* HAL_I2C_MODULE_ENABLED */\r
+/**\r
+  * @}\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r