训练营PLSR题目
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.
 
 
 
 
 
 

259 lines
8.2 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. ******************************************************************************
  12. * @attention
  13. *
  14. * Copyright (c) 2016 STMicroelectronics.
  15. * All rights reserved.
  16. *
  17. * This software is licensed under terms that can be found in the LICENSE file
  18. * in the root directory of this software component.
  19. * If no LICENSE file comes with this software, it is provided AS-IS.
  20. *
  21. ******************************************************************************
  22. @verbatim
  23. ==============================================================================
  24. ##### FMPI2C peripheral Extended features #####
  25. ==============================================================================
  26. [..] Comparing to other previous devices, the FMPI2C interface for STM32F4xx
  27. devices contains the following additional features
  28. (+) Possibility to disable or enable Analog Noise Filter
  29. (+) Use of a configured Digital Noise Filter
  30. (+) Disable or enable Fast Mode Plus
  31. ##### How to use this driver #####
  32. ==============================================================================
  33. [..] This driver provides functions to:
  34. (#) Configure FMPI2C Analog noise filter using the function HAL_FMPI2CEx_ConfigAnalogFilter()
  35. (#) Configure FMPI2C Digital noise filter using the function HAL_FMPI2CEx_ConfigDigitalFilter()
  36. (#) Configure the enable or disable of fast mode plus driving capability using the functions :
  37. (++) HAL_FMPI2CEx_EnableFastModePlus()
  38. (++) HAL_FMPI2CEx_DisableFastModePlus()
  39. @endverbatim
  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 Filter Mode Functions
  62. * @brief Filter Mode Functions
  63. *
  64. @verbatim
  65. ===============================================================================
  66. ##### Filter Mode Functions #####
  67. ===============================================================================
  68. [..] This section provides functions allowing to:
  69. (+) Configure Noise Filters
  70. @endverbatim
  71. * @{
  72. */
  73. /**
  74. * @brief Configure FMPI2C Analog noise filter.
  75. * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
  76. * the configuration information for the specified FMPI2Cx peripheral.
  77. * @param AnalogFilter New state of the Analog filter.
  78. * @retval HAL status
  79. */
  80. HAL_StatusTypeDef HAL_FMPI2CEx_ConfigAnalogFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t AnalogFilter)
  81. {
  82. /* Check the parameters */
  83. assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
  84. assert_param(IS_FMPI2C_ANALOG_FILTER(AnalogFilter));
  85. if (hfmpi2c->State == HAL_FMPI2C_STATE_READY)
  86. {
  87. /* Process Locked */
  88. __HAL_LOCK(hfmpi2c);
  89. hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
  90. /* Disable the selected FMPI2C peripheral */
  91. __HAL_FMPI2C_DISABLE(hfmpi2c);
  92. /* Reset FMPI2Cx ANOFF bit */
  93. hfmpi2c->Instance->CR1 &= ~(FMPI2C_CR1_ANFOFF);
  94. /* Set analog filter bit*/
  95. hfmpi2c->Instance->CR1 |= AnalogFilter;
  96. __HAL_FMPI2C_ENABLE(hfmpi2c);
  97. hfmpi2c->State = HAL_FMPI2C_STATE_READY;
  98. /* Process Unlocked */
  99. __HAL_UNLOCK(hfmpi2c);
  100. return HAL_OK;
  101. }
  102. else
  103. {
  104. return HAL_BUSY;
  105. }
  106. }
  107. /**
  108. * @brief Configure FMPI2C Digital noise filter.
  109. * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
  110. * the configuration information for the specified FMPI2Cx peripheral.
  111. * @param DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F.
  112. * @retval HAL status
  113. */
  114. HAL_StatusTypeDef HAL_FMPI2CEx_ConfigDigitalFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t DigitalFilter)
  115. {
  116. uint32_t tmpreg;
  117. /* Check the parameters */
  118. assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
  119. assert_param(IS_FMPI2C_DIGITAL_FILTER(DigitalFilter));
  120. if (hfmpi2c->State == HAL_FMPI2C_STATE_READY)
  121. {
  122. /* Process Locked */
  123. __HAL_LOCK(hfmpi2c);
  124. hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
  125. /* Disable the selected FMPI2C peripheral */
  126. __HAL_FMPI2C_DISABLE(hfmpi2c);
  127. /* Get the old register value */
  128. tmpreg = hfmpi2c->Instance->CR1;
  129. /* Reset FMPI2Cx DNF bits [11:8] */
  130. tmpreg &= ~(FMPI2C_CR1_DNF);
  131. /* Set FMPI2Cx DNF coefficient */
  132. tmpreg |= DigitalFilter << 8U;
  133. /* Store the new register value */
  134. hfmpi2c->Instance->CR1 = tmpreg;
  135. __HAL_FMPI2C_ENABLE(hfmpi2c);
  136. hfmpi2c->State = HAL_FMPI2C_STATE_READY;
  137. /* Process Unlocked */
  138. __HAL_UNLOCK(hfmpi2c);
  139. return HAL_OK;
  140. }
  141. else
  142. {
  143. return HAL_BUSY;
  144. }
  145. }
  146. /**
  147. * @}
  148. */
  149. /** @defgroup FMPI2CEx_Exported_Functions_Group3 Fast Mode Plus Functions
  150. * @brief Fast Mode Plus Functions
  151. *
  152. @verbatim
  153. ===============================================================================
  154. ##### Fast Mode Plus Functions #####
  155. ===============================================================================
  156. [..] This section provides functions allowing to:
  157. (+) Configure Fast Mode Plus
  158. @endverbatim
  159. * @{
  160. */
  161. /**
  162. * @brief Enable the FMPI2C fast mode plus driving capability.
  163. * @param ConfigFastModePlus Selects the pin.
  164. * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
  165. * @note For FMPI2C1, fast mode plus driving capability can be enabled on all selected
  166. * FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
  167. * on each one of the following pins PB6, PB7, PB8 and PB9.
  168. * @note For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
  169. * can be enabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
  170. * @retval None
  171. */
  172. void HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
  173. {
  174. /* Check the parameter */
  175. assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
  176. /* Enable SYSCFG clock */
  177. __HAL_RCC_SYSCFG_CLK_ENABLE();
  178. /* Enable fast mode plus driving capability for selected pin */
  179. SET_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
  180. }
  181. /**
  182. * @brief Disable the FMPI2C fast mode plus driving capability.
  183. * @param ConfigFastModePlus Selects the pin.
  184. * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
  185. * @note For FMPI2C1, fast mode plus driving capability can be disabled on all selected
  186. * FMPI2C1 pins using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter or independently
  187. * on each one of the following pins PB6, PB7, PB8 and PB9.
  188. * @note For remaining FMPI2C1 pins (PA14, PA15...) fast mode plus driving capability
  189. * can be disabled only by using FMPI2C_FASTMODEPLUS_FMPI2C1 parameter.
  190. * @retval None
  191. */
  192. void HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
  193. {
  194. /* Check the parameter */
  195. assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
  196. /* Enable SYSCFG clock */
  197. __HAL_RCC_SYSCFG_CLK_ENABLE();
  198. /* Disable fast mode plus driving capability for selected pin */
  199. CLEAR_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
  200. }
  201. /**
  202. * @}
  203. */
  204. /**
  205. * @}
  206. */
  207. #endif /* FMPI2C_CR1_PE */
  208. #endif /* HAL_FMPI2C_MODULE_ENABLED */
  209. /**
  210. * @}
  211. */
  212. /**
  213. * @}
  214. */