stm32f4xx_hal_fmpi2c_ex.c 9.0 KB

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