|
STM32G474xx HAL用户手册
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32g4xx_hal_smbus_ex.c 00004 * @author MCD Application Team 00005 * @brief SMBUS Extended HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of SMBUS Extended peripheral: 00008 * + Extended features functions 00009 * + WakeUp Mode Functions 00010 * + FastModePlus Functions 00011 * 00012 ****************************************************************************** 00013 * @attention 00014 * 00015 * Copyright (c) 2019 STMicroelectronics. 00016 * All rights reserved. 00017 * 00018 * This software is licensed under terms that can be found in the LICENSE file 00019 * in the root directory of this software component. 00020 * If no LICENSE file comes with this software, it is provided AS-IS. 00021 * 00022 ****************************************************************************** 00023 @verbatim 00024 ============================================================================== 00025 ##### SMBUS peripheral Extended features ##### 00026 ============================================================================== 00028 00029 [..] Comparing to other previous devices, the SMBUS interface for STM32G4xx 00030 devices contains the following additional features 00031 00032 (+) Disable or enable wakeup from Stop mode(s) 00033 (+) Disable or enable Fast Mode Plus 00034 00035 ##### How to use this driver ##### 00036 ============================================================================== 00037 (#) Configure the enable or disable of SMBUS Wake Up Mode using the functions : 00038 (++) HAL_SMBUSEx_EnableWakeUp() 00039 (++) HAL_SMBUSEx_DisableWakeUp() 00040 (#) Configure the enable or disable of fast mode plus driving capability using the functions : 00041 (++) HAL_SMBUSEx_EnableFastModePlus() 00042 (++) HAL_SMBUSEx_DisableFastModePlus() 00043 @endverbatim 00043 */ 00044 00045 /* Includes ------------------------------------------------------------------*/ 00046 #include "stm32g4xx_hal.h" 00047 00048 /** @addtogroup STM32G4xx_HAL_Driver 00049 * @{ 00050 */ 00051 00052 /** @defgroup SMBUSEx SMBUSEx 00053 * @brief SMBUS Extended HAL module driver 00054 * @{ 00055 */ 00056 00057 #ifdef HAL_SMBUS_MODULE_ENABLED 00058 00059 /* Private typedef -----------------------------------------------------------*/ 00060 /* Private define ------------------------------------------------------------*/ 00061 /* Private macro -------------------------------------------------------------*/ 00062 /* Private variables ---------------------------------------------------------*/ 00063 /* Private function prototypes -----------------------------------------------*/ 00064 /* Private functions ---------------------------------------------------------*/ 00065 00066 /** @defgroup SMBUSEx_Exported_Functions SMBUS Extended Exported Functions 00067 * @{ 00068 */ 00069 00070 /** @defgroup SMBUSEx_Exported_Functions_Group2 WakeUp Mode Functions 00071 * @brief WakeUp Mode Functions 00073 * 00074 @verbatim 00075 =============================================================================== 00076 ##### WakeUp Mode Functions ##### 00077 =============================================================================== 00078 [..] This section provides functions allowing to: 00079 (+) Configure Wake Up Feature 00080 00081 @endverbatim 00081 * @{ 00082 */ 00083 00084 /** 00085 * @brief Enable SMBUS wakeup from Stop mode(s). 00086 * @param hsmbus Pointer to a SMBUS_HandleTypeDef structure that contains 00087 * the configuration information for the specified SMBUSx peripheral. 00088 * @retval HAL status 00089 */ 00090 HAL_StatusTypeDef HAL_SMBUSEx_EnableWakeUp(SMBUS_HandleTypeDef *hsmbus) 00091 { 00092 /* Check the parameters */ 00093 assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hsmbus->Instance)); 00094 00095 if (hsmbus->State == HAL_SMBUS_STATE_READY) 00096 { 00097 /* Process Locked */ 00098 __HAL_LOCK(hsmbus); 00099 00100 hsmbus->State = HAL_SMBUS_STATE_BUSY; 00101 00102 /* Disable the selected SMBUS peripheral */ 00103 __HAL_SMBUS_DISABLE(hsmbus); 00104 00105 /* Enable wakeup from stop mode */ 00106 hsmbus->Instance->CR1 |= I2C_CR1_WUPEN; 00107 00108 __HAL_SMBUS_ENABLE(hsmbus); 00109 00110 hsmbus->State = HAL_SMBUS_STATE_READY; 00111 00112 /* Process Unlocked */ 00113 __HAL_UNLOCK(hsmbus); 00114 00115 return HAL_OK; 00116 } 00117 else 00118 { 00119 return HAL_BUSY; 00121 } 00122 } 00123 00124 /** 00125 * @brief Disable SMBUS wakeup from Stop mode(s). 00126 * @param hsmbus Pointer to a SMBUS_HandleTypeDef structure that contains 00127 * the configuration information for the specified SMBUSx peripheral. 00128 * @retval HAL status 00129 */ 00130 HAL_StatusTypeDef HAL_SMBUSEx_DisableWakeUp(SMBUS_HandleTypeDef *hsmbus) 00131 { 00132 /* Check the parameters */ 00133 assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hsmbus->Instance)); 00134 00135 if (hsmbus->State == HAL_SMBUS_STATE_READY) 00136 { 00137 /* Process Locked */ 00138 __HAL_LOCK(hsmbus); 00139 00140 hsmbus->State = HAL_SMBUS_STATE_BUSY; 00141 00142 /* Disable the selected SMBUS peripheral */ 00143 __HAL_SMBUS_DISABLE(hsmbus); 00144 00145 /* Disable wakeup from stop mode */ 00146 hsmbus->Instance->CR1 &= ~(I2C_CR1_WUPEN); 00147 00148 __HAL_SMBUS_ENABLE(hsmbus); 00149 00150 hsmbus->State = HAL_SMBUS_STATE_READY; 00151 00152 /* Process Unlocked */ 00153 __HAL_UNLOCK(hsmbus); 00155 00156 return HAL_OK; 00158 } 00159 else 00160 { 00161 return HAL_BUSY; 00163 } 00165 } 00166 /** 00167 * @} 00168 */ 00169 00170 /** @defgroup SMBUSEx_Exported_Functions_Group3 Fast Mode Plus Functions 00171 * @brief Fast Mode Plus Functions 00173 * 00175 @verbatim 00176 =============================================================================== 00177 ##### Fast Mode Plus Functions ##### 00177 =============================================================================== 00178 [..] This section provides functions allowing to: 00179 (+) Configure Fast Mode Plus 00180 00181 @endverbatim 00182 * @{ 00183 */ 00184 00185 /** 00186 * @brief Enable the SMBUS fast mode plus driving capability. 00187 * @param ConfigFastModePlus Selects the pin. 00188 * This parameter can be one of the @ref SMBUSEx_FastModePlus values 00189 * @note For I2C1, fast mode plus driving capability can be enabled on all selected 00190 * I2C1 pins using SMBUS_FASTMODEPLUS_I2C1 parameter or independently 00191 * on each one of the following pins PB6, PB7, PB8 and PB9. 00192 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability 00193 * can be enabled only by using SMBUS_FASTMODEPLUS_I2C1 parameter. 00195 * @note For all I2C2 pins fast mode plus driving capability can be enabled 00196 * only by using SMBUS_FASTMODEPLUS_I2C2 parameter. 00197 * @note For all I2C3 pins fast mode plus driving capability can be enabled 00197 * only by using SMBUS_FASTMODEPLUS_I2C3 parameter. 00198 * @note For all I2C4 pins fast mode plus driving capability can be enabled 00199 * only by using SMBUS_FASTMODEPLUS_I2C4 parameter. 00200 * @retval None 00201 */ 00202 void HAL_SMBUSEx_EnableFastModePlus(uint32_t ConfigFastModePlus) 00203 { 00204 /* Check the parameter */ 00205 assert_param(IS_SMBUS_FASTMODEPLUS(ConfigFastModePlus)); 00206 00207 /* Enable SYSCFG clock */ 00208 __HAL_RCC_SYSCFG_CLK_ENABLE(); 00209 00210 /* Enable fast mode plus driving capability for selected pin */ 00211 SET_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus); 00212 } 00213 00214 /** 00215 * @brief Disable the SMBUS fast mode plus driving capability. 00216 * @param ConfigFastModePlus Selects the pin. 00217 * This parameter can be one of the @ref SMBUSEx_FastModePlus values 00218 * @note For I2C1, fast mode plus driving capability can be disabled on all selected 00219 * I2C1 pins using SMBUS_FASTMODEPLUS_I2C1 parameter or independently 00221 * on each one of the following pins PB6, PB7, PB8 and PB9. 00222 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability 00223 * can be disabled only by using SMBUS_FASTMODEPLUS_I2C1 parameter. 00224 * @note For all I2C2 pins fast mode plus driving capability can be disabled