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