您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

185 行
5.4 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_i2c_ex.c
  4. * @author MCD Application Team
  5. * @brief I2C Extension HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of I2C extension peripheral:
  8. * + Extension features functions
  9. *
  10. @verbatim
  11. ==============================================================================
  12. ##### I2C peripheral extension features #####
  13. ==============================================================================
  14. [..] Comparing to other previous devices, the I2C interface for STM32F427xx/437xx/
  15. 429xx/439xx devices contains the following additional features :
  16. (+) Possibility to disable or enable Analog Noise Filter
  17. (+) Use of a configured Digital Noise Filter
  18. ##### How to use this driver #####
  19. ==============================================================================
  20. [..] This driver provides functions to configure Noise Filter
  21. (#) Configure I2C Analog noise filter using the function HAL_I2C_AnalogFilter_Config()
  22. (#) Configure I2C Digital noise filter using the function HAL_I2C_DigitalFilter_Config()
  23. @endverbatim
  24. ******************************************************************************
  25. * @attention
  26. *
  27. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  28. * All rights reserved.</center></h2>
  29. *
  30. * This software component is licensed by ST under BSD 3-Clause license,
  31. * the "License"; You may not use this file except in compliance with the
  32. * License. You may obtain a copy of the License at:
  33. * opensource.org/licenses/BSD-3-Clause
  34. *
  35. ******************************************************************************
  36. */
  37. /* Includes ------------------------------------------------------------------*/
  38. #include "stm32f4xx_hal.h"
  39. /** @addtogroup STM32F4xx_HAL_Driver
  40. * @{
  41. */
  42. /** @defgroup I2CEx I2CEx
  43. * @brief I2C HAL module driver
  44. * @{
  45. */
  46. #ifdef HAL_I2C_MODULE_ENABLED
  47. #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
  48. /* Private typedef -----------------------------------------------------------*/
  49. /* Private define ------------------------------------------------------------*/
  50. /* Private macro -------------------------------------------------------------*/
  51. /* Private variables ---------------------------------------------------------*/
  52. /* Private function prototypes -----------------------------------------------*/
  53. /* Exported functions --------------------------------------------------------*/
  54. /** @defgroup I2CEx_Exported_Functions I2C Exported Functions
  55. * @{
  56. */
  57. /** @defgroup I2CEx_Exported_Functions_Group1 Extension features functions
  58. * @brief Extension features functions
  59. *
  60. @verbatim
  61. ===============================================================================
  62. ##### Extension features functions #####
  63. ===============================================================================
  64. [..] This section provides functions allowing to:
  65. (+) Configure Noise Filters
  66. @endverbatim
  67. * @{
  68. */
  69. /**
  70. * @brief Configures I2C Analog noise filter.
  71. * @param hi2c pointer to a I2C_HandleTypeDef structure that contains
  72. * the configuration information for the specified I2Cx peripheral.
  73. * @param AnalogFilter new state of the Analog filter.
  74. * @retval HAL status
  75. */
  76. HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
  77. {
  78. /* Check the parameters */
  79. assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
  80. assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
  81. if (hi2c->State == HAL_I2C_STATE_READY)
  82. {
  83. hi2c->State = HAL_I2C_STATE_BUSY;
  84. /* Disable the selected I2C peripheral */
  85. __HAL_I2C_DISABLE(hi2c);
  86. /* Reset I2Cx ANOFF bit */
  87. hi2c->Instance->FLTR &= ~(I2C_FLTR_ANOFF);
  88. /* Disable the analog filter */
  89. hi2c->Instance->FLTR |= AnalogFilter;
  90. __HAL_I2C_ENABLE(hi2c);
  91. hi2c->State = HAL_I2C_STATE_READY;
  92. return HAL_OK;
  93. }
  94. else
  95. {
  96. return HAL_BUSY;
  97. }
  98. }
  99. /**
  100. * @brief Configures I2C Digital noise filter.
  101. * @param hi2c pointer to a I2C_HandleTypeDef structure that contains
  102. * the configuration information for the specified I2Cx peripheral.
  103. * @param DigitalFilter Coefficient of digital noise filter between 0x00 and 0x0F.
  104. * @retval HAL status
  105. */
  106. HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
  107. {
  108. uint16_t tmpreg = 0;
  109. /* Check the parameters */
  110. assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
  111. assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
  112. if (hi2c->State == HAL_I2C_STATE_READY)
  113. {
  114. hi2c->State = HAL_I2C_STATE_BUSY;
  115. /* Disable the selected I2C peripheral */
  116. __HAL_I2C_DISABLE(hi2c);
  117. /* Get the old register value */
  118. tmpreg = hi2c->Instance->FLTR;
  119. /* Reset I2Cx DNF bit [3:0] */
  120. tmpreg &= ~(I2C_FLTR_DNF);
  121. /* Set I2Cx DNF coefficient */
  122. tmpreg |= DigitalFilter;
  123. /* Store the new register value */
  124. hi2c->Instance->FLTR = tmpreg;
  125. __HAL_I2C_ENABLE(hi2c);
  126. hi2c->State = HAL_I2C_STATE_READY;
  127. return HAL_OK;
  128. }
  129. else
  130. {
  131. return HAL_BUSY;
  132. }
  133. }
  134. /**
  135. * @}
  136. */
  137. /**
  138. * @}
  139. */
  140. #endif
  141. #endif /* HAL_I2C_MODULE_ENABLED */
  142. /**
  143. * @}
  144. */
  145. /**
  146. * @}
  147. */
  148. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/