Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of TUKS-COURSE-TIMER by
stm32l4xx_hal_i2c_ex.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_i2c_ex.c 00004 * @author MCD Application Team 00005 * @version V1.5.1 00006 * @date 31-May-2016 00007 * @brief I2C Extended HAL module driver. 00008 * This file provides firmware functions to manage the following 00009 * functionalities of I2C Extended peripheral: 00010 * + Extended features functions 00011 * 00012 @verbatim 00013 ============================================================================== 00014 ##### I2C peripheral Extended features ##### 00015 ============================================================================== 00016 00017 [..] Comparing to other previous devices, the I2C interface for STM32L4xx 00018 devices contains the following additional features 00019 00020 (+) Possibility to disable or enable Analog Noise Filter 00021 (+) Use of a configured Digital Noise Filter 00022 (+) Disable or enable wakeup from Stop modes 00023 00024 ##### How to use this driver ##### 00025 ============================================================================== 00026 [..] This driver provides functions to configure Noise Filter and Wake Up Feature 00027 (#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter() 00028 (#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter() 00029 (#) Configure the enable or disable of I2C Wake Up Mode using the functions : 00030 (++) HAL_I2CEx_EnableWakeUp() 00031 (++) HAL_I2CEx_DisableWakeUp() 00032 (#) Configure the enable or disable of fast mode plus driving capability using the functions : 00033 (++) HAL_I2CEx_EnableFastModePlus() 00034 (++) HAL_I2CEx_DisbleFastModePlus() 00035 @endverbatim 00036 ****************************************************************************** 00037 * @attention 00038 * 00039 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00040 * 00041 * Redistribution and use in source and binary forms, with or without modification, 00042 * are permitted provided that the following conditions are met: 00043 * 1. Redistributions of source code must retain the above copyright notice, 00044 * this list of conditions and the following disclaimer. 00045 * 2. Redistributions in binary form must reproduce the above copyright notice, 00046 * this list of conditions and the following disclaimer in the documentation 00047 * and/or other materials provided with the distribution. 00048 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00049 * may be used to endorse or promote products derived from this software 00050 * without specific prior written permission. 00051 * 00052 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00053 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00054 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00055 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00056 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00057 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00058 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00059 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00060 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00061 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00062 * 00063 ****************************************************************************** 00064 */ 00065 00066 /* Includes ------------------------------------------------------------------*/ 00067 #include "stm32l4xx_hal.h" 00068 00069 /** @addtogroup STM32L4xx_HAL_Driver 00070 * @{ 00071 */ 00072 00073 /** @defgroup I2CEx I2CEx 00074 * @brief I2C Extended HAL module driver 00075 * @{ 00076 */ 00077 00078 #ifdef HAL_I2C_MODULE_ENABLED 00079 00080 /* Private typedef -----------------------------------------------------------*/ 00081 /* Private define ------------------------------------------------------------*/ 00082 /* Private macro -------------------------------------------------------------*/ 00083 /* Private variables ---------------------------------------------------------*/ 00084 /* Private function prototypes -----------------------------------------------*/ 00085 /* Private functions ---------------------------------------------------------*/ 00086 00087 /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions 00088 * @{ 00089 */ 00090 00091 /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions 00092 * @brief Extended features functions 00093 * 00094 @verbatim 00095 =============================================================================== 00096 ##### Extended features functions ##### 00097 =============================================================================== 00098 [..] This section provides functions allowing to: 00099 (+) Configure Noise Filters 00100 (+) Configure Wake Up Feature 00101 00102 @endverbatim 00103 * @{ 00104 */ 00105 00106 /** 00107 * @brief Configure I2C Analog noise filter. 00108 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 00109 * the configuration information for the specified I2Cx peripheral. 00110 * @param AnalogFilter New state of the Analog filter. 00111 * @retval HAL status 00112 */ 00113 HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter) 00114 { 00115 /* Check the parameters */ 00116 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 00117 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter)); 00118 00119 if(hi2c->State == HAL_I2C_STATE_READY) 00120 { 00121 /* Process Locked */ 00122 __HAL_LOCK(hi2c); 00123 00124 hi2c->State = HAL_I2C_STATE_BUSY; 00125 00126 /* Disable the selected I2C peripheral */ 00127 __HAL_I2C_DISABLE(hi2c); 00128 00129 /* Reset I2Cx ANOFF bit */ 00130 hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF); 00131 00132 /* Set analog filter bit*/ 00133 hi2c->Instance->CR1 |= AnalogFilter; 00134 00135 __HAL_I2C_ENABLE(hi2c); 00136 00137 hi2c->State = HAL_I2C_STATE_READY; 00138 00139 /* Process Unlocked */ 00140 __HAL_UNLOCK(hi2c); 00141 00142 return HAL_OK; 00143 } 00144 else 00145 { 00146 return HAL_BUSY; 00147 } 00148 } 00149 00150 /** 00151 * @brief Configure I2C Digital noise filter. 00152 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 00153 * the configuration information for the specified I2Cx peripheral. 00154 * @param DigitalFilter Coefficient of digital noise filter between 0x00 and 0x0F. 00155 * @retval HAL status 00156 */ 00157 HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter) 00158 { 00159 uint32_t tmpreg = 0U; 00160 00161 /* Check the parameters */ 00162 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 00163 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter)); 00164 00165 if(hi2c->State == HAL_I2C_STATE_READY) 00166 { 00167 /* Process Locked */ 00168 __HAL_LOCK(hi2c); 00169 00170 hi2c->State = HAL_I2C_STATE_BUSY; 00171 00172 /* Disable the selected I2C peripheral */ 00173 __HAL_I2C_DISABLE(hi2c); 00174 00175 /* Get the old register value */ 00176 tmpreg = hi2c->Instance->CR1; 00177 00178 /* Reset I2Cx DNF bits [11:8] */ 00179 tmpreg &= ~(I2C_CR1_DNF); 00180 00181 /* Set I2Cx DNF coefficient */ 00182 tmpreg |= DigitalFilter << 8U; 00183 00184 /* Store the new register value */ 00185 hi2c->Instance->CR1 = tmpreg; 00186 00187 __HAL_I2C_ENABLE(hi2c); 00188 00189 hi2c->State = HAL_I2C_STATE_READY; 00190 00191 /* Process Unlocked */ 00192 __HAL_UNLOCK(hi2c); 00193 00194 return HAL_OK; 00195 } 00196 else 00197 { 00198 return HAL_BUSY; 00199 } 00200 } 00201 00202 /** 00203 * @brief Enable I2C wakeup from stop mode. 00204 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 00205 * the configuration information for the specified I2Cx peripheral. 00206 * @retval HAL status 00207 */ 00208 HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp (I2C_HandleTypeDef *hi2c) 00209 { 00210 /* Check the parameters */ 00211 assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance)); 00212 00213 if(hi2c->State == HAL_I2C_STATE_READY) 00214 { 00215 /* Process Locked */ 00216 __HAL_LOCK(hi2c); 00217 00218 hi2c->State = HAL_I2C_STATE_BUSY; 00219 00220 /* Disable the selected I2C peripheral */ 00221 __HAL_I2C_DISABLE(hi2c); 00222 00223 /* Enable wakeup from stop mode */ 00224 hi2c->Instance->CR1 |= I2C_CR1_WUPEN; 00225 00226 __HAL_I2C_ENABLE(hi2c); 00227 00228 hi2c->State = HAL_I2C_STATE_READY; 00229 00230 /* Process Unlocked */ 00231 __HAL_UNLOCK(hi2c); 00232 00233 return HAL_OK; 00234 } 00235 else 00236 { 00237 return HAL_BUSY; 00238 } 00239 } 00240 00241 00242 /** 00243 * @brief Disable I2C wakeup from stop mode. 00244 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 00245 * the configuration information for the specified I2Cx peripheral. 00246 * @retval HAL status 00247 */ 00248 HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp (I2C_HandleTypeDef *hi2c) 00249 { 00250 /* Check the parameters */ 00251 assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance)); 00252 00253 if(hi2c->State == HAL_I2C_STATE_READY) 00254 { 00255 /* Process Locked */ 00256 __HAL_LOCK(hi2c); 00257 00258 hi2c->State = HAL_I2C_STATE_BUSY; 00259 00260 /* Disable the selected I2C peripheral */ 00261 __HAL_I2C_DISABLE(hi2c); 00262 00263 /* Enable wakeup from stop mode */ 00264 hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN); 00265 00266 __HAL_I2C_ENABLE(hi2c); 00267 00268 hi2c->State = HAL_I2C_STATE_READY; 00269 00270 /* Process Unlocked */ 00271 __HAL_UNLOCK(hi2c); 00272 00273 return HAL_OK; 00274 } 00275 else 00276 { 00277 return HAL_BUSY; 00278 } 00279 } 00280 00281 /** 00282 * @brief Enable the I2C fast mode plus driving capability. 00283 * @param ConfigFastModePlus Selects the pin. 00284 * This parameter can be one of the @ref I2CEx_FastModePlus values 00285 * @note For I2C1, fast mode plus driving capability can be enabled on all selected 00286 * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently 00287 * on each one of the following pins PB6, PB7, PB8 and PB9. 00288 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability 00289 * can be enabled only by using I2C_FASTMODEPLUS_I2C1 parameter. 00290 * @note For all I2C2 pins fast mode plus driving capability can be enabled 00291 * only by using I2C_FASTMODEPLUS_I2C2 parameter. 00292 * @note For all I2C3 pins fast mode plus driving capability can be enabled 00293 * only by using I2C_FASTMODEPLUS_I2C3 parameter. 00294 * @retval None 00295 */ 00296 void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus) 00297 { 00298 /* Check the parameter */ 00299 assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus)); 00300 00301 /* Enable SYSCFG clock */ 00302 __HAL_RCC_SYSCFG_CLK_ENABLE(); 00303 00304 /* Enable fast mode plus driving capability for selected pin */ 00305 SET_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus); 00306 } 00307 00308 /** 00309 * @brief Disable the I2C fast mode plus driving capability. 00310 * @param ConfigFastModePlus Selects the pin. 00311 * This parameter can be one of the @ref I2CEx_FastModePlus values 00312 * @note For I2C1, fast mode plus driving capability can be disabled on all selected 00313 * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently 00314 * on each one of the following pins PB6, PB7, PB8 and PB9. 00315 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability 00316 * can be disabled only by using I2C_FASTMODEPLUS_I2C1 parameter. 00317 * @note For all I2C2 pins fast mode plus driving capability can be disabled 00318 * only by using I2C_FASTMODEPLUS_I2C2 parameter. 00319 * @note For all I2C3 pins fast mode plus driving capability can be disabled 00320 * only by using I2C_FASTMODEPLUS_I2C3 parameter. 00321 * @retval None 00322 */ 00323 void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus) 00324 { 00325 /* Check the parameter */ 00326 assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus)); 00327 00328 /* Enable SYSCFG clock */ 00329 __HAL_RCC_SYSCFG_CLK_ENABLE(); 00330 00331 /* Disable fast mode plus driving capability for selected pin */ 00332 CLEAR_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus); 00333 } 00334 00335 /** 00336 * @} 00337 */ 00338 00339 /** 00340 * @} 00341 */ 00342 00343 #endif /* HAL_I2C_MODULE_ENABLED */ 00344 /** 00345 * @} 00346 */ 00347 00348 /** 00349 * @} 00350 */ 00351 00352 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 17:38:49 by
