選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

262 行
8.4 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. * + Filter Mode Functions
  9. * + FastModePlus Functions
  10. *
  11. @verbatim
  12. ==============================================================================
  13. ##### FMPI2C peripheral Extended features #####
  14. ==============================================================================
  15. [..] Comparing to other previous devices, the FMPI2C interface for STM32F4xx
  16. devices contains the following additional features
  17. (+) Possibility to disable or enable Analog Noise Filter
  18. (+) Use of a configured Digital Noise Filter
  19. (+) Disable or enable Fast Mode Plus
  20. ##### How to use this driver #####
  21. ==============================================================================
  22. [..] This driver provides functions to:
  23. (#) Configure FMPI2C Analog noise filter using the function HAL_FMPI2CEx_ConfigAnalogFilter()
  24. (#) Configure FMPI2C Digital noise filter using the function HAL_FMPI2CEx_ConfigDigitalFilter()
  25. (#) Configure the enable or disable of fast mode plus driving capability using the functions :
  26. (++) HAL_FMPI2CEx_EnableFastModePlus()
  27. (++) HAL_FMPI2CEx_DisableFastModePlus()
  28. @endverbatim
  29. ******************************************************************************
  30. * @attention
  31. *
  32. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  33. * All rights reserved.</center></h2>
  34. *
  35. * This software component is licensed by ST under BSD 3-Clause license,
  36. * the "License"; You may not use this file except in compliance with the
  37. * License. You may obtain a copy of the License at:
  38. * opensource.org/licenses/BSD-3-Clause
  39. *
  40. ******************************************************************************
  41. */
  42. /* Includes ------------------------------------------------------------------*/
  43. #include "stm32f4xx_hal.h"
  44. /** @addtogroup STM32F4xx_HAL_Driver
  45. * @{
  46. */
  47. /** @defgroup FMPI2CEx FMPI2CEx
  48. * @brief FMPI2C Extended HAL module driver
  49. * @{
  50. */
  51. #ifdef HAL_FMPI2C_MODULE_ENABLED
  52. #if defined(FMPI2C_CR1_PE)
  53. /* Private typedef -----------------------------------------------------------*/
  54. /* Private define ------------------------------------------------------------*/
  55. /* Private macro -------------------------------------------------------------*/
  56. /* Private variables ---------------------------------------------------------*/
  57. /* Private function prototypes -----------------------------------------------*/
  58. /* Private functions ---------------------------------------------------------*/
  59. /** @defgroup FMPI2CEx_Exported_Functions FMPI2C Extended Exported Functions
  60. * @{
  61. */
  62. /** @defgroup FMPI2CEx_Exported_Functions_Group1 Filter Mode Functions
  63. * @brief Filter Mode Functions
  64. *
  65. @verbatim
  66. ===============================================================================
  67. ##### Filter Mode Functions #####
  68. ===============================================================================
  69. [..] This section provides functions allowing to:
  70. (+) Configure Noise Filters
  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. * @}
  149. */
  150. /** @defgroup FMPI2CEx_Exported_Functions_Group3 Fast Mode Plus Functions
  151. * @brief Fast Mode Plus Functions
  152. *
  153. @verbatim
  154. ===============================================================================
  155. ##### Fast Mode Plus Functions #####
  156. ===============================================================================
  157. [..] This section provides functions allowing to:
  158. (+) Configure Fast Mode Plus
  159. @endverbatim
  160. * @{
  161. */
  162. /**
  163. * @brief Enable the FMPI2C fast mode plus driving capability.
  164. * @param ConfigFastModePlus Selects the pin.
  165. * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
  166. * @note For FMPI2C1, fast mode plus driving capability can be enabled on all selected
  167. * FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
  168. * on each one of the following pins PB6, PB7, PB8 and PB9.
  169. * @note For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
  170. * can be enabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
  171. * @retval None
  172. */
  173. void HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
  174. {
  175. /* Check the parameter */
  176. assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
  177. /* Enable SYSCFG clock */
  178. __HAL_RCC_SYSCFG_CLK_ENABLE();
  179. /* Enable fast mode plus driving capability for selected pin */
  180. SET_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
  181. }
  182. /**
  183. * @brief Disable the FMPI2C fast mode plus driving capability.
  184. * @param ConfigFastModePlus Selects the pin.
  185. * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
  186. * @note For FMPI2C1, fast mode plus driving capability can be disabled on all selected
  187. * FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
  188. * on each one of the following pins PB6, PB7, PB8 and PB9.
  189. * @note For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
  190. * can be disabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
  191. * @retval None
  192. */
  193. void HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
  194. {
  195. /* Check the parameter */
  196. assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
  197. /* Enable SYSCFG clock */
  198. __HAL_RCC_SYSCFG_CLK_ENABLE();
  199. /* Disable fast mode plus driving capability for selected pin */
  200. CLEAR_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
  201. }
  202. /**
  203. * @}
  204. */
  205. /**
  206. * @}
  207. */
  208. #endif /* FMPI2C_CR1_PE */
  209. #endif /* HAL_FMPI2C_MODULE_ENABLED */
  210. /**
  211. * @}
  212. */
  213. /**
  214. * @}
  215. */
  216. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/