You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

207 lines
7.1 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_i2c_ex.c
  4. * @author MCD Application Team
  5. * @version V1.7.1
  6. * @date 14-April-2017
  7. * @brief I2C Extension HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of I2C extension peripheral:
  10. * + Extension features functions
  11. *
  12. @verbatim
  13. ==============================================================================
  14. ##### I2C peripheral extension features #####
  15. ==============================================================================
  16. [..] Comparing to other previous devices, the I2C interface for STM32F427xx/437xx/
  17. 429xx/439xx devices contains the following additional features :
  18. (+) Possibility to disable or enable Analog Noise Filter
  19. (+) Use of a configured Digital Noise Filter
  20. ##### How to use this driver #####
  21. ==============================================================================
  22. [..] This driver provides functions to configure Noise Filter
  23. (#) Configure I2C Analog noise filter using the function HAL_I2C_AnalogFilter_Config()
  24. (#) Configure I2C Digital noise filter using the function HAL_I2C_DigitalFilter_Config()
  25. @endverbatim
  26. ******************************************************************************
  27. * @attention
  28. *
  29. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  30. *
  31. * Redistribution and use in source and binary forms, with or without modification,
  32. * are permitted provided that the following conditions are met:
  33. * 1. Redistributions of source code must retain the above copyright notice,
  34. * this list of conditions and the following disclaimer.
  35. * 2. Redistributions in binary form must reproduce the above copyright notice,
  36. * this list of conditions and the following disclaimer in the documentation
  37. * and/or other materials provided with the distribution.
  38. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  39. * may be used to endorse or promote products derived from this software
  40. * without specific prior written permission.
  41. *
  42. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  43. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  44. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  45. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  46. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  47. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  48. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  49. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  50. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  51. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. *
  53. ******************************************************************************
  54. */
  55. /* Includes ------------------------------------------------------------------*/
  56. #include "stm32f4xx_hal.h"
  57. /** @addtogroup STM32F4xx_HAL_Driver
  58. * @{
  59. */
  60. /** @defgroup I2CEx I2CEx
  61. * @brief I2C HAL module driver
  62. * @{
  63. */
  64. #ifdef HAL_I2C_MODULE_ENABLED
  65. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  66. defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) ||\
  67. defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx)
  68. /* Private typedef -----------------------------------------------------------*/
  69. /* Private define ------------------------------------------------------------*/
  70. /* Private macro -------------------------------------------------------------*/
  71. /* Private variables ---------------------------------------------------------*/
  72. /* Private function prototypes -----------------------------------------------*/
  73. /* Exported functions --------------------------------------------------------*/
  74. /** @defgroup I2CEx_Exported_Functions I2C Exported Functions
  75. * @{
  76. */
  77. /** @defgroup I2CEx_Exported_Functions_Group1 Extension features functions
  78. * @brief Extension features functions
  79. *
  80. @verbatim
  81. ===============================================================================
  82. ##### Extension features functions #####
  83. ===============================================================================
  84. [..] This section provides functions allowing to:
  85. (+) Configure Noise Filters
  86. @endverbatim
  87. * @{
  88. */
  89. /**
  90. * @brief Configures I2C Analog noise filter.
  91. * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
  92. * the configuration information for the specified I2Cx peripheral.
  93. * @param AnalogFilter: new state of the Analog filter.
  94. * @retval HAL status
  95. */
  96. HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
  97. {
  98. /* Check the parameters */
  99. assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
  100. assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
  101. if(hi2c->State == HAL_I2C_STATE_READY)
  102. {
  103. hi2c->State = HAL_I2C_STATE_BUSY;
  104. /* Disable the selected I2C peripheral */
  105. __HAL_I2C_DISABLE(hi2c);
  106. /* Reset I2Cx ANOFF bit */
  107. hi2c->Instance->FLTR &= ~(I2C_FLTR_ANOFF);
  108. /* Disable the analog filter */
  109. hi2c->Instance->FLTR |= AnalogFilter;
  110. __HAL_I2C_ENABLE(hi2c);
  111. hi2c->State = HAL_I2C_STATE_READY;
  112. return HAL_OK;
  113. }
  114. else
  115. {
  116. return HAL_BUSY;
  117. }
  118. }
  119. /**
  120. * @brief Configures I2C Digital noise filter.
  121. * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
  122. * the configuration information for the specified I2Cx peripheral.
  123. * @param DigitalFilter: Coefficient of digital noise filter between 0x00 and 0x0F.
  124. * @retval HAL status
  125. */
  126. HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
  127. {
  128. uint16_t tmpreg = 0;
  129. /* Check the parameters */
  130. assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
  131. assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
  132. if(hi2c->State == HAL_I2C_STATE_READY)
  133. {
  134. hi2c->State = HAL_I2C_STATE_BUSY;
  135. /* Disable the selected I2C peripheral */
  136. __HAL_I2C_DISABLE(hi2c);
  137. /* Get the old register value */
  138. tmpreg = hi2c->Instance->FLTR;
  139. /* Reset I2Cx DNF bit [3:0] */
  140. tmpreg &= ~(I2C_FLTR_DNF);
  141. /* Set I2Cx DNF coefficient */
  142. tmpreg |= DigitalFilter;
  143. /* Store the new register value */
  144. hi2c->Instance->FLTR = tmpreg;
  145. __HAL_I2C_ENABLE(hi2c);
  146. hi2c->State = HAL_I2C_STATE_READY;
  147. return HAL_OK;
  148. }
  149. else
  150. {
  151. return HAL_BUSY;
  152. }
  153. }
  154. /**
  155. * @}
  156. */
  157. /**
  158. * @}
  159. */
  160. #endif /* STM32F427xx || STM32F429xx || STM32F437xx || STM32F439xx || STM32F401xC ||\
  161. STM32F401xE || STM32F446xx || STM32F469xx || STM32F479xx || STM32F413xx ||\
  162. STM32F423xx */
  163. #endif /* HAL_I2C_MODULE_ENABLED */
  164. /**
  165. * @}
  166. */
  167. /**
  168. * @}
  169. */
  170. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/