stm32f4xx_hal_fmpi2c_ex.c 11 KB

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