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.
 
 
 

260 lines
8.9 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_fmpi2c_ex.c
  4. * @author MCD Application Team
  5. * @version V1.7.1
  6. * @date 14-April-2017
  7. * @brief FMPI2C Extended HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of FMPI2C Extended peripheral:
  10. * + Extended features functions
  11. *
  12. @verbatim
  13. ==============================================================================
  14. ##### FMPI2C peripheral Extended features #####
  15. ==============================================================================
  16. [..] Comparing to other previous devices, the FMPI2C interface for STM32F4xx
  17. devices contains the following additional features
  18. (+) Possibility to disable or enable Analog Noise Filter
  19. (+) Use of a configured Digital Noise Filter
  20. (+) Disable or enable wakeup from Stop mode
  21. ##### How to use this driver #####
  22. ==============================================================================
  23. [..] This driver provides functions to configure Noise Filter and Wake Up Feature
  24. (#) Configure FMPI2C Analog noise filter using the function HAL_FMPI2CEx_ConfigAnalogFilter()
  25. (#) Configure FMPI2C Digital noise filter using the function HAL_FMPI2CEx_ConfigDigitalFilter()
  26. (#) Configure the enable or disable of FMPI2C Wake Up Mode using the functions :
  27. (++) HAL_FMPI2CEx_EnableWakeUp()
  28. (++) HAL_FMPI2CEx_DisableWakeUp()
  29. (#) Configure the enable or disable of fast mode plus driving capability using the functions :
  30. (++) HAL_FMPI2CEx_EnableFastModePlus()
  31. (++) HAL_FMPI2CEx_DisbleFastModePlus()
  32. @endverbatim
  33. ******************************************************************************
  34. * @attention
  35. *
  36. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  37. *
  38. * Redistribution and use in source and binary forms, with or without modification,
  39. * are permitted provided that the following conditions are met:
  40. * 1. Redistributions of source code must retain the above copyright notice,
  41. * this list of conditions and the following disclaimer.
  42. * 2. Redistributions in binary form must reproduce the above copyright notice,
  43. * this list of conditions and the following disclaimer in the documentation
  44. * and/or other materials provided with the distribution.
  45. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  46. * may be used to endorse or promote products derived from this software
  47. * without specific prior written permission.
  48. *
  49. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  50. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  52. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  53. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  54. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  55. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  56. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  58. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. ******************************************************************************
  61. */
  62. /* Includes ------------------------------------------------------------------*/
  63. #include "stm32f4xx_hal.h"
  64. /** @addtogroup STM32F4xx_HAL_Driver
  65. * @{
  66. */
  67. /** @defgroup FMPI2CEx FMPI2CEx
  68. * @brief FMPI2C Extended HAL module driver
  69. * @{
  70. */
  71. #ifdef HAL_FMPI2C_MODULE_ENABLED
  72. #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
  73. defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
  74. /* Private typedef -----------------------------------------------------------*/
  75. /* Private define ------------------------------------------------------------*/
  76. /* Private macro -------------------------------------------------------------*/
  77. /* Private variables ---------------------------------------------------------*/
  78. /* Private function prototypes -----------------------------------------------*/
  79. /* Private functions ---------------------------------------------------------*/
  80. /** @defgroup FMPI2CEx_Exported_Functions FMPI2C Extended Exported Functions
  81. * @{
  82. */
  83. /** @defgroup FMPI2CEx_Exported_Functions_Group1 Extended features functions
  84. * @brief Extended features functions
  85. *
  86. @verbatim
  87. ===============================================================================
  88. ##### Extended features functions #####
  89. ===============================================================================
  90. [..] This section provides functions allowing to:
  91. (+) Configure Noise Filters
  92. (+) Configure Wake Up Feature
  93. @endverbatim
  94. * @{
  95. */
  96. /**
  97. * @brief Configure FMPI2C Analog noise filter.
  98. * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
  99. * the configuration information for the specified FMPI2Cx peripheral.
  100. * @param AnalogFilter New state of the Analog filter.
  101. * @retval HAL status
  102. */
  103. HAL_StatusTypeDef HAL_FMPI2CEx_ConfigAnalogFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t AnalogFilter)
  104. {
  105. /* Check the parameters */
  106. assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
  107. assert_param(IS_FMPI2C_ANALOG_FILTER(AnalogFilter));
  108. if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
  109. {
  110. /* Process Locked */
  111. __HAL_LOCK(hfmpi2c);
  112. hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
  113. /* Disable the selected FMPI2C peripheral */
  114. __HAL_FMPI2C_DISABLE(hfmpi2c);
  115. /* Reset FMPI2Cx ANOFF bit */
  116. hfmpi2c->Instance->CR1 &= ~(FMPI2C_CR1_ANFOFF);
  117. /* Set analog filter bit*/
  118. hfmpi2c->Instance->CR1 |= AnalogFilter;
  119. __HAL_FMPI2C_ENABLE(hfmpi2c);
  120. hfmpi2c->State = HAL_FMPI2C_STATE_READY;
  121. /* Process Unlocked */
  122. __HAL_UNLOCK(hfmpi2c);
  123. return HAL_OK;
  124. }
  125. else
  126. {
  127. return HAL_BUSY;
  128. }
  129. }
  130. /**
  131. * @brief Configure FMPI2C Digital noise filter.
  132. * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
  133. * the configuration information for the specified FMPI2Cx peripheral.
  134. * @param DigitalFilter Coefficient of digital noise filter between 0x00 and 0x0F.
  135. * @retval HAL status
  136. */
  137. HAL_StatusTypeDef HAL_FMPI2CEx_ConfigDigitalFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t DigitalFilter)
  138. {
  139. uint32_t tmpreg = 0U;
  140. /* Check the parameters */
  141. assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
  142. assert_param(IS_FMPI2C_DIGITAL_FILTER(DigitalFilter));
  143. if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
  144. {
  145. /* Process Locked */
  146. __HAL_LOCK(hfmpi2c);
  147. hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
  148. /* Disable the selected FMPI2C peripheral */
  149. __HAL_FMPI2C_DISABLE(hfmpi2c);
  150. /* Get the old register value */
  151. tmpreg = hfmpi2c->Instance->CR1;
  152. /* Reset FMPI2Cx DNF bits [11:8] */
  153. tmpreg &= ~(FMPI2C_CR1_DFN);
  154. /* Set FMPI2Cx DNF coefficient */
  155. tmpreg |= DigitalFilter << 8U;
  156. /* Store the new register value */
  157. hfmpi2c->Instance->CR1 = tmpreg;
  158. __HAL_FMPI2C_ENABLE(hfmpi2c);
  159. hfmpi2c->State = HAL_FMPI2C_STATE_READY;
  160. /* Process Unlocked */
  161. __HAL_UNLOCK(hfmpi2c);
  162. return HAL_OK;
  163. }
  164. else
  165. {
  166. return HAL_BUSY;
  167. }
  168. }
  169. /**
  170. * @brief Enable the FMPI2C fast mode plus driving capability.
  171. * @param ConfigFastModePlus Selects the pin.
  172. * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
  173. * @retval None
  174. */
  175. void HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
  176. {
  177. /* Check the parameter */
  178. assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
  179. /* Enable SYSCFG clock */
  180. __HAL_RCC_SYSCFG_CLK_ENABLE();
  181. /* Enable fast mode plus driving capability for selected pin */
  182. SET_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
  183. }
  184. /**
  185. * @brief Disable the FMPI2C fast mode plus driving capability.
  186. * @param ConfigFastModePlus Selects the pin.
  187. * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
  188. * @retval None
  189. */
  190. void HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
  191. {
  192. /* Check the parameter */
  193. assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
  194. /* Enable SYSCFG clock */
  195. __HAL_RCC_SYSCFG_CLK_ENABLE();
  196. /* Disable fast mode plus driving capability for selected pin */
  197. CLEAR_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
  198. }
  199. /**
  200. * @}
  201. */
  202. /**
  203. * @}
  204. */
  205. #endif /* STM32F410xx || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx ||\
  206. STM32F413xx || STM32F423xx */
  207. #endif /* HAL_FMPI2C_MODULE_ENABLED */
  208. /**
  209. * @}
  210. */
  211. /**
  212. * @}
  213. */
  214. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/