1 /**
2 ******************************************************************************
3 * @file stm32c0xx_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) 2022 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
28 [..] Comparing to other previous devices, the SMBUS interface for STM32C0xx
29 devices contains the following additional features
30
31 (+) Disable or enable wakeup from Stop mode(s)
32 (+) Disable or enable Fast Mode Plus
33
34 ##### How to use this driver #####
35 ==============================================================================
36 (#) Configure the enable or disable of SMBUS Wake Up Mode using the functions :
37 (++) HAL_SMBUSEx_EnableWakeUp()
38 (++) HAL_SMBUSEx_DisableWakeUp()
39 (#) Configure the enable or disable of fast mode plus driving capability using the functions :
40 (++) HAL_SMBUSEx_EnableFastModePlus()
41 (++) HAL_SMBUSEx_DisableFastModePlus()
42 @endverbatim
43 */
44
45 /* Includes ------------------------------------------------------------------*/
46 #include "stm32c0xx_hal.h"
47
48 /** @addtogroup STM32C0xx_HAL_Driver
49 * @{
50 */
51
52 /** @defgroup SMBUSEx SMBUSEx
53 * @brief SMBUS Extended HAL module driver
54 * @{
55 */
56
57 #ifdef HAL_SMBUS_MODULE_ENABLED
58
59 /* Private typedef -----------------------------------------------------------*/
60 /* Private define ------------------------------------------------------------*/
61 /* Private macro -------------------------------------------------------------*/
62 /* Private variables ---------------------------------------------------------*/
63 /* Private function prototypes -----------------------------------------------*/
64 /* Private functions ---------------------------------------------------------*/
65
66 /** @defgroup SMBUSEx_Exported_Functions SMBUS Extended Exported Functions
67 * @{
68 */
69 #if defined(I2C_CR1_WUPEN)
70
71 /** @defgroup SMBUSEx_Exported_Functions_Group2 WakeUp Mode Functions
72 * @brief WakeUp Mode Functions
73 *
74 @verbatim
75 ===============================================================================
76 ##### WakeUp Mode Functions #####
77 ===============================================================================
78 [..] This section provides functions allowing to:
79 (+) Configure Wake Up Feature
80
81 @endverbatim
82 * @{
83 */
84
85 /**
86 * @brief Enable SMBUS wakeup from Stop mode(s).
87 * @param hsmbus Pointer to a SMBUS_HandleTypeDef structure that contains
88 * the configuration information for the specified SMBUSx peripheral.
89 * @retval HAL status
90 */
HAL_SMBUSEx_EnableWakeUp(SMBUS_HandleTypeDef * hsmbus)91 HAL_StatusTypeDef HAL_SMBUSEx_EnableWakeUp(SMBUS_HandleTypeDef *hsmbus)
92 {
93 /* Check the parameters */
94 assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hsmbus->Instance));
95
96 if (hsmbus->State == HAL_SMBUS_STATE_READY)
97 {
98 /* Process Locked */
99 __HAL_LOCK(hsmbus);
100
101 hsmbus->State = HAL_SMBUS_STATE_BUSY;
102
103 /* Disable the selected SMBUS peripheral */
104 __HAL_SMBUS_DISABLE(hsmbus);
105
106 /* Enable wakeup from stop mode */
107 hsmbus->Instance->CR1 |= I2C_CR1_WUPEN;
108
109 __HAL_SMBUS_ENABLE(hsmbus);
110
111 hsmbus->State = HAL_SMBUS_STATE_READY;
112
113 /* Process Unlocked */
114 __HAL_UNLOCK(hsmbus);
115
116 return HAL_OK;
117 }
118 else
119 {
120 return HAL_BUSY;
121 }
122 }
123
124 /**
125 * @brief Disable SMBUS wakeup from Stop mode(s).
126 * @param hsmbus Pointer to a SMBUS_HandleTypeDef structure that contains
127 * the configuration information for the specified SMBUSx peripheral.
128 * @retval HAL status
129 */
HAL_SMBUSEx_DisableWakeUp(SMBUS_HandleTypeDef * hsmbus)130 HAL_StatusTypeDef HAL_SMBUSEx_DisableWakeUp(SMBUS_HandleTypeDef *hsmbus)
131 {
132 /* Check the parameters */
133 assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hsmbus->Instance));
134
135 if (hsmbus->State == HAL_SMBUS_STATE_READY)
136 {
137 /* Process Locked */
138 __HAL_LOCK(hsmbus);
139
140 hsmbus->State = HAL_SMBUS_STATE_BUSY;
141
142 /* Disable the selected SMBUS peripheral */
143 __HAL_SMBUS_DISABLE(hsmbus);
144
145 /* Disable wakeup from stop mode */
146 hsmbus->Instance->CR1 &= ~(I2C_CR1_WUPEN);
147
148 __HAL_SMBUS_ENABLE(hsmbus);
149
150 hsmbus->State = HAL_SMBUS_STATE_READY;
151
152 /* Process Unlocked */
153 __HAL_UNLOCK(hsmbus);
154
155 return HAL_OK;
156 }
157 else
158 {
159 return HAL_BUSY;
160 }
161 }
162 /**
163 * @}
164 */
165 #endif /* SMBUS_CR1_WUPEN */
166
167 /** @defgroup SMBUSEx_Exported_Functions_Group3 Fast Mode Plus Functions
168 * @brief Fast Mode Plus Functions
169 *
170 @verbatim
171 ===============================================================================
172 ##### Fast Mode Plus Functions #####
173 ===============================================================================
174 [..] This section provides functions allowing to:
175 (+) Configure Fast Mode Plus
176
177 @endverbatim
178 * @{
179 */
180
181 /**
182 * @brief Enable the SMBUS fast mode plus driving capability.
183 * @param ConfigFastModePlus Selects the pin.
184 * This parameter can be one of the @ref SMBUSEx_FastModePlus values
185 * @note For I2C1, fast mode plus driving capability can be enabled on all selected
186 * I2C1 pins using SMBUS_FASTMODEPLUS_I2C1 parameter or independently
187 * on each one of the following pins PB6, PB7, PB8 and PB9.
188 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
189 * can be enabled only by using SMBUS_FASTMODEPLUS_I2C1 parameter.
190 * @note For all I2C2 pins fast mode plus driving capability can be enabled
191 * only by using SMBUS_FASTMODEPLUS_I2C2 parameter.
192 * @retval None
193 */
HAL_SMBUSEx_EnableFastModePlus(uint32_t ConfigFastModePlus)194 void HAL_SMBUSEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
195 {
196 /* Check the parameter */
197 assert_param(IS_SMBUS_FASTMODEPLUS(ConfigFastModePlus));
198
199 /* Enable SYSCFG clock */
200 __HAL_RCC_SYSCFG_CLK_ENABLE();
201
202 /* Enable fast mode plus driving capability for selected pin */
203 SET_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus);
204 }
205
206 /**
207 * @brief Disable the SMBUS fast mode plus driving capability.
208 * @param ConfigFastModePlus Selects the pin.
209 * This parameter can be one of the @ref SMBUSEx_FastModePlus values
210 * @note For I2C1, fast mode plus driving capability can be disabled on all selected
211 * I2C1 pins using SMBUS_FASTMODEPLUS_I2C1 parameter or independently
212 * on each one of the following pins PB6, PB7, PB8 and PB9.
213 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
214 * can be disabled only by using SMBUS_FASTMODEPLUS_I2C1 parameter.
215 * @note For all I2C2 pins fast mode plus driving capability can be disabled
216 * only by using SMBUS_FASTMODEPLUS_I2C2 parameter.
217 * @retval None
218 */
HAL_SMBUSEx_DisableFastModePlus(uint32_t ConfigFastModePlus)219 void HAL_SMBUSEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
220 {
221 /* Check the parameter */
222 assert_param(IS_SMBUS_FASTMODEPLUS(ConfigFastModePlus));
223
224 /* Enable SYSCFG clock */
225 __HAL_RCC_SYSCFG_CLK_ENABLE();
226
227 /* Disable fast mode plus driving capability for selected pin */
228 CLEAR_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus);
229 }
230
231 /**
232 * @}
233 */
234
235 /**
236 * @}
237 */
238
239 /**
240 * @}
241 */
242
243 #endif /* HAL_SMBUS_MODULE_ENABLED */
244 /**
245 * @}
246 */
247
248 /**
249 * @}
250 */
251