stm32g4xx_hal_smbus_ex.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_hal_smbus_ex.c
  4. * @author MCD Application Team
  5. * @brief SMBUS Extended HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of SMBUS Extended peripheral:
  8. * + Extended features functions
  9. * + WakeUp Mode Functions
  10. * + FastModePlus Functions
  11. *
  12. ******************************************************************************
  13. * @attention
  14. *
  15. * Copyright (c) 2019 STMicroelectronics.
  16. * All rights reserved.
  17. *
  18. * This software is licensed under terms that can be found in the LICENSE file
  19. * in the root directory of this software component.
  20. * If no LICENSE file comes with this software, it is provided AS-IS.
  21. *
  22. ******************************************************************************
  23. @verbatim
  24. ==============================================================================
  25. ##### SMBUS peripheral Extended features #####
  26. ==============================================================================
  27. [..] Comparing to other previous devices, the SMBUS interface for STM32G4xx
  28. devices contains the following additional features
  29. (+) Disable or enable wakeup from Stop mode(s)
  30. (+) Disable or enable Fast Mode Plus
  31. ##### How to use this driver #####
  32. ==============================================================================
  33. (#) Configure the enable or disable of SMBUS Wake Up Mode using the functions :
  34. (++) HAL_SMBUSEx_EnableWakeUp()
  35. (++) HAL_SMBUSEx_DisableWakeUp()
  36. (#) Configure the enable or disable of fast mode plus driving capability using the functions :
  37. (++) HAL_SMBUSEx_EnableFastModePlus()
  38. (++) HAL_SMBUSEx_DisableFastModePlus()
  39. @endverbatim
  40. */
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32g4xx_hal.h"
  43. /** @addtogroup STM32G4xx_HAL_Driver
  44. * @{
  45. */
  46. /** @defgroup SMBUSEx SMBUSEx
  47. * @brief SMBUS Extended HAL module driver
  48. * @{
  49. */
  50. #ifdef HAL_SMBUS_MODULE_ENABLED
  51. /* Private typedef -----------------------------------------------------------*/
  52. /* Private define ------------------------------------------------------------*/
  53. /* Private macro -------------------------------------------------------------*/
  54. /* Private variables ---------------------------------------------------------*/
  55. /* Private function prototypes -----------------------------------------------*/
  56. /* Private functions ---------------------------------------------------------*/
  57. /** @defgroup SMBUSEx_Exported_Functions SMBUS Extended Exported Functions
  58. * @{
  59. */
  60. /** @defgroup SMBUSEx_Exported_Functions_Group2 WakeUp Mode Functions
  61. * @brief WakeUp Mode Functions
  62. *
  63. @verbatim
  64. ===============================================================================
  65. ##### WakeUp Mode Functions #####
  66. ===============================================================================
  67. [..] This section provides functions allowing to:
  68. (+) Configure Wake Up Feature
  69. @endverbatim
  70. * @{
  71. */
  72. /**
  73. * @brief Enable SMBUS wakeup from Stop mode(s).
  74. * @param hsmbus Pointer to a SMBUS_HandleTypeDef structure that contains
  75. * the configuration information for the specified SMBUSx peripheral.
  76. * @retval HAL status
  77. */
  78. HAL_StatusTypeDef HAL_SMBUSEx_EnableWakeUp(SMBUS_HandleTypeDef *hsmbus)
  79. {
  80. /* Check the parameters */
  81. assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hsmbus->Instance));
  82. if (hsmbus->State == HAL_SMBUS_STATE_READY)
  83. {
  84. /* Process Locked */
  85. __HAL_LOCK(hsmbus);
  86. hsmbus->State = HAL_SMBUS_STATE_BUSY;
  87. /* Disable the selected SMBUS peripheral */
  88. __HAL_SMBUS_DISABLE(hsmbus);
  89. /* Enable wakeup from stop mode */
  90. hsmbus->Instance->CR1 |= I2C_CR1_WUPEN;
  91. __HAL_SMBUS_ENABLE(hsmbus);
  92. hsmbus->State = HAL_SMBUS_STATE_READY;
  93. /* Process Unlocked */
  94. __HAL_UNLOCK(hsmbus);
  95. return HAL_OK;
  96. }
  97. else
  98. {
  99. return HAL_BUSY;
  100. }
  101. }
  102. /**
  103. * @brief Disable SMBUS wakeup from Stop mode(s).
  104. * @param hsmbus Pointer to a SMBUS_HandleTypeDef structure that contains
  105. * the configuration information for the specified SMBUSx peripheral.
  106. * @retval HAL status
  107. */
  108. HAL_StatusTypeDef HAL_SMBUSEx_DisableWakeUp(SMBUS_HandleTypeDef *hsmbus)
  109. {
  110. /* Check the parameters */
  111. assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hsmbus->Instance));
  112. if (hsmbus->State == HAL_SMBUS_STATE_READY)
  113. {
  114. /* Process Locked */
  115. __HAL_LOCK(hsmbus);
  116. hsmbus->State = HAL_SMBUS_STATE_BUSY;
  117. /* Disable the selected SMBUS peripheral */
  118. __HAL_SMBUS_DISABLE(hsmbus);
  119. /* Disable wakeup from stop mode */
  120. hsmbus->Instance->CR1 &= ~(I2C_CR1_WUPEN);
  121. __HAL_SMBUS_ENABLE(hsmbus);
  122. hsmbus->State = HAL_SMBUS_STATE_READY;
  123. /* Process Unlocked */
  124. __HAL_UNLOCK(hsmbus);
  125. return HAL_OK;
  126. }
  127. else
  128. {
  129. return HAL_BUSY;
  130. }
  131. }
  132. /**
  133. * @}
  134. */
  135. /** @defgroup SMBUSEx_Exported_Functions_Group3 Fast Mode Plus Functions
  136. * @brief Fast Mode Plus Functions
  137. *
  138. @verbatim
  139. ===============================================================================
  140. ##### Fast Mode Plus Functions #####
  141. ===============================================================================
  142. [..] This section provides functions allowing to:
  143. (+) Configure Fast Mode Plus
  144. @endverbatim
  145. * @{
  146. */
  147. /**
  148. * @brief Enable the SMBUS fast mode plus driving capability.
  149. * @param ConfigFastModePlus Selects the pin.
  150. * This parameter can be one of the @ref SMBUSEx_FastModePlus values
  151. * @note For I2C1, fast mode plus driving capability can be enabled on all selected
  152. * I2C1 pins using SMBUS_FASTMODEPLUS_I2C1 parameter or independently
  153. * on each one of the following pins PB6, PB7, PB8 and PB9.
  154. * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
  155. * can be enabled only by using SMBUS_FASTMODEPLUS_I2C1 parameter.
  156. * @note For all I2C2 pins fast mode plus driving capability can be enabled
  157. * only by using SMBUS_FASTMODEPLUS_I2C2 parameter.
  158. * @note For all I2C3 pins fast mode plus driving capability can be enabled
  159. * only by using SMBUS_FASTMODEPLUS_I2C3 parameter.
  160. * @note For all I2C4 pins fast mode plus driving capability can be enabled
  161. * only by using SMBUS_FASTMODEPLUS_I2C4 parameter.
  162. * @retval None
  163. */
  164. void HAL_SMBUSEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
  165. {
  166. /* Check the parameter */
  167. assert_param(IS_SMBUS_FASTMODEPLUS(ConfigFastModePlus));
  168. /* Enable SYSCFG clock */
  169. __HAL_RCC_SYSCFG_CLK_ENABLE();
  170. /* Enable fast mode plus driving capability for selected pin */
  171. SET_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus);
  172. }
  173. /**
  174. * @brief Disable the SMBUS fast mode plus driving capability.
  175. * @param ConfigFastModePlus Selects the pin.
  176. * This parameter can be one of the @ref SMBUSEx_FastModePlus values
  177. * @note For I2C1, fast mode plus driving capability can be disabled on all selected
  178. * I2C1 pins using SMBUS_FASTMODEPLUS_I2C1 parameter or independently
  179. * on each one of the following pins PB6, PB7, PB8 and PB9.
  180. * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
  181. * can be disabled only by using SMBUS_FASTMODEPLUS_I2C1 parameter.
  182. * @note For all I2C2 pins fast mode plus driving capability can be disabled
  183. * only by using SMBUS_FASTMODEPLUS_I2C2 parameter.
  184. * @note For all I2C3 pins fast mode plus driving capability can be disabled
  185. * only by using SMBUS_FASTMODEPLUS_I2C3 parameter.
  186. * @note For all I2C4 pins fast mode plus driving capability can be disabled
  187. * only by using SMBUS_FASTMODEPLUS_I2C4 parameter.
  188. * @retval None
  189. */
  190. void HAL_SMBUSEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
  191. {
  192. /* Check the parameter */
  193. assert_param(IS_SMBUS_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->CFGR1, (uint32_t)ConfigFastModePlus);
  198. }
  199. /**
  200. * @}
  201. */
  202. /**
  203. * @}
  204. */
  205. /**
  206. * @}
  207. */
  208. #endif /* HAL_SMBUS_MODULE_ENABLED */
  209. /**
  210. * @}
  211. */
  212. /**
  213. * @}
  214. */