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

247 行
7.9 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_fmpi2c_ex.c
  4. * @author MCD Application Team
  5. * @brief FMPI2C Extended HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of FMPI2C Extended peripheral:
  8. * + Extended features functions
  9. *
  10. @verbatim
  11. ==============================================================================
  12. ##### FMPI2C peripheral Extended features #####
  13. ==============================================================================
  14. [..] Comparing to other previous devices, the FMPI2C interface for STM32F4xx
  15. devices contains the following additional features
  16. (+) Possibility to disable or enable Analog Noise Filter
  17. (+) Use of a configured Digital Noise Filter
  18. (+) Disable or enable Fast Mode Plus
  19. ##### How to use this driver #####
  20. ==============================================================================
  21. [..] This driver provides functions to:
  22. (#) Configure FMPI2C Analog noise filter using the function HAL_FMPI2CEx_ConfigAnalogFilter()
  23. (#) Configure FMPI2C Digital noise filter using the function HAL_FMPI2CEx_ConfigDigitalFilter()
  24. (#) Configure the enable or disable of fast mode plus driving capability using the functions :
  25. (++) HAL_FMPI2CEx_EnableFastModePlus()
  26. (++) HAL_FMPI2CEx_DisableFastModePlus()
  27. @endverbatim
  28. ******************************************************************************
  29. * @attention
  30. *
  31. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  32. * All rights reserved.</center></h2>
  33. *
  34. * This software component is licensed by ST under BSD 3-Clause license,
  35. * the "License"; You may not use this file except in compliance with the
  36. * License. You may obtain a copy of the License at:
  37. * opensource.org/licenses/BSD-3-Clause
  38. *
  39. ******************************************************************************
  40. */
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f4xx_hal.h"
  43. /** @addtogroup STM32F4xx_HAL_Driver
  44. * @{
  45. */
  46. /** @defgroup FMPI2CEx FMPI2CEx
  47. * @brief FMPI2C Extended HAL module driver
  48. * @{
  49. */
  50. #ifdef HAL_FMPI2C_MODULE_ENABLED
  51. #if defined(FMPI2C_CR1_PE)
  52. /* Private typedef -----------------------------------------------------------*/
  53. /* Private define ------------------------------------------------------------*/
  54. /* Private macro -------------------------------------------------------------*/
  55. /* Private variables ---------------------------------------------------------*/
  56. /* Private function prototypes -----------------------------------------------*/
  57. /* Private functions ---------------------------------------------------------*/
  58. /** @defgroup FMPI2CEx_Exported_Functions FMPI2C Extended Exported Functions
  59. * @{
  60. */
  61. /** @defgroup FMPI2CEx_Exported_Functions_Group1 Extended features functions
  62. * @brief Extended features functions
  63. *
  64. @verbatim
  65. ===============================================================================
  66. ##### Extended features functions #####
  67. ===============================================================================
  68. [..] This section provides functions allowing to:
  69. (+) Configure Noise Filters
  70. (+) Configure Fast Mode Plus
  71. @endverbatim
  72. * @{
  73. */
  74. /**
  75. * @brief Configure FMPI2C Analog noise filter.
  76. * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
  77. * the configuration information for the specified FMPI2Cx peripheral.
  78. * @param AnalogFilter New state of the Analog filter.
  79. * @retval HAL status
  80. */
  81. HAL_StatusTypeDef HAL_FMPI2CEx_ConfigAnalogFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t AnalogFilter)
  82. {
  83. /* Check the parameters */
  84. assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
  85. assert_param(IS_FMPI2C_ANALOG_FILTER(AnalogFilter));
  86. if (hfmpi2c->State == HAL_FMPI2C_STATE_READY)
  87. {
  88. /* Process Locked */
  89. __HAL_LOCK(hfmpi2c);
  90. hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
  91. /* Disable the selected FMPI2C peripheral */
  92. __HAL_FMPI2C_DISABLE(hfmpi2c);
  93. /* Reset FMPI2Cx ANOFF bit */
  94. hfmpi2c->Instance->CR1 &= ~(FMPI2C_CR1_ANFOFF);
  95. /* Set analog filter bit*/
  96. hfmpi2c->Instance->CR1 |= AnalogFilter;
  97. __HAL_FMPI2C_ENABLE(hfmpi2c);
  98. hfmpi2c->State = HAL_FMPI2C_STATE_READY;
  99. /* Process Unlocked */
  100. __HAL_UNLOCK(hfmpi2c);
  101. return HAL_OK;
  102. }
  103. else
  104. {
  105. return HAL_BUSY;
  106. }
  107. }
  108. /**
  109. * @brief Configure FMPI2C Digital noise filter.
  110. * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
  111. * the configuration information for the specified FMPI2Cx peripheral.
  112. * @param DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F.
  113. * @retval HAL status
  114. */
  115. HAL_StatusTypeDef HAL_FMPI2CEx_ConfigDigitalFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t DigitalFilter)
  116. {
  117. uint32_t tmpreg;
  118. /* Check the parameters */
  119. assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
  120. assert_param(IS_FMPI2C_DIGITAL_FILTER(DigitalFilter));
  121. if (hfmpi2c->State == HAL_FMPI2C_STATE_READY)
  122. {
  123. /* Process Locked */
  124. __HAL_LOCK(hfmpi2c);
  125. hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
  126. /* Disable the selected FMPI2C peripheral */
  127. __HAL_FMPI2C_DISABLE(hfmpi2c);
  128. /* Get the old register value */
  129. tmpreg = hfmpi2c->Instance->CR1;
  130. /* Reset FMPI2Cx DNF bits [11:8] */
  131. tmpreg &= ~(FMPI2C_CR1_DNF);
  132. /* Set FMPI2Cx DNF coefficient */
  133. tmpreg |= DigitalFilter << 8U;
  134. /* Store the new register value */
  135. hfmpi2c->Instance->CR1 = tmpreg;
  136. __HAL_FMPI2C_ENABLE(hfmpi2c);
  137. hfmpi2c->State = HAL_FMPI2C_STATE_READY;
  138. /* Process Unlocked */
  139. __HAL_UNLOCK(hfmpi2c);
  140. return HAL_OK;
  141. }
  142. else
  143. {
  144. return HAL_BUSY;
  145. }
  146. }
  147. /**
  148. * @brief Enable the FMPI2C fast mode plus driving capability.
  149. * @param ConfigFastModePlus Selects the pin.
  150. * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
  151. * @note For FMPI2C1, fast mode plus driving capability can be enabled on all selected
  152. * FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
  153. * on each one of the following pins PB6, PB7, PB8 and PB9.
  154. * @note For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
  155. * can be enabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
  156. * @retval None
  157. */
  158. void HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
  159. {
  160. /* Check the parameter */
  161. assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
  162. /* Enable SYSCFG clock */
  163. __HAL_RCC_SYSCFG_CLK_ENABLE();
  164. /* Enable fast mode plus driving capability for selected pin */
  165. SET_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
  166. }
  167. /**
  168. * @brief Disable the FMPI2C fast mode plus driving capability.
  169. * @param ConfigFastModePlus Selects the pin.
  170. * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
  171. * @note For FMPI2C1, fast mode plus driving capability can be disabled on all selected
  172. * FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
  173. * on each one of the following pins PB6, PB7, PB8 and PB9.
  174. * @note For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
  175. * can be disabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
  176. * @retval None
  177. */
  178. void HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
  179. {
  180. /* Check the parameter */
  181. assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
  182. /* Enable SYSCFG clock */
  183. __HAL_RCC_SYSCFG_CLK_ENABLE();
  184. /* Disable fast mode plus driving capability for selected pin */
  185. CLEAR_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
  186. }
  187. /**
  188. * @}
  189. */
  190. /**
  191. * @}
  192. */
  193. #endif /* FMPI2C_CR1_PE */
  194. #endif /* HAL_FMPI2C_MODULE_ENABLED */
  195. /**
  196. * @}
  197. */
  198. /**
  199. * @}
  200. */
  201. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/