stm32g0xx_hal_smbus_ex.c 8.1 KB

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