STM32L486xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_i2c_ex.c 00004 * @author MCD Application Team 00005 * @brief I2C Extended HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of I2C Extended peripheral: 00008 * + Extended features functions 00009 * 00010 @verbatim 00011 ============================================================================== 00012 ##### I2C peripheral Extended features ##### 00013 ============================================================================== 00014 00015 [..] Comparing to other previous devices, the I2C interface for STM32L4xx 00016 devices contains the following additional features 00017 00018 (+) Possibility to disable or enable Analog Noise Filter 00019 (+) Use of a configured Digital Noise Filter 00020 (+) Disable or enable wakeup from Stop mode(s) 00021 (+) Disable or enable Fast Mode Plus 00022 00023 ##### How to use this driver ##### 00024 ============================================================================== 00025 [..] This driver provides functions to configure Noise Filter and Wake Up Feature 00026 (#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter() 00027 (#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter() 00028 (#) Configure the enable or disable of I2C Wake Up Mode using the functions : 00029 (++) HAL_I2CEx_EnableWakeUp() 00030 (++) HAL_I2CEx_DisableWakeUp() 00031 (#) Configure the enable or disable of fast mode plus driving capability using the functions : 00032 (++) HAL_I2CEx_EnableFastModePlus() 00033 (++) HAL_I2CEx_DisableFastModePlus() 00034 @endverbatim 00035 ****************************************************************************** 00036 * @attention 00037 * 00038 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00039 * 00040 * Redistribution and use in source and binary forms, with or without modification, 00041 * are permitted provided that the following conditions are met: 00042 * 1. Redistributions of source code must retain the above copyright notice, 00043 * this list of conditions and the following disclaimer. 00044 * 2. Redistributions in binary form must reproduce the above copyright notice, 00045 * this list of conditions and the following disclaimer in the documentation 00046 * and/or other materials provided with the distribution. 00047 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00048 * may be used to endorse or promote products derived from this software 00049 * without specific prior written permission. 00050 * 00051 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00052 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00053 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00054 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00055 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00056 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00057 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00058 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00059 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00060 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00061 * 00062 ****************************************************************************** 00063 */ 00064 00065 /* Includes ------------------------------------------------------------------*/ 00066 #include "stm32l4xx_hal.h" 00067 00068 /** @addtogroup STM32L4xx_HAL_Driver 00069 * @{ 00070 */ 00071 00072 /** @defgroup I2CEx I2CEx 00073 * @brief I2C Extended HAL module driver 00074 * @{ 00075 */ 00076 00077 #ifdef HAL_I2C_MODULE_ENABLED 00078 00079 /* Private typedef -----------------------------------------------------------*/ 00080 /* Private define ------------------------------------------------------------*/ 00081 /* Private macro -------------------------------------------------------------*/ 00082 /* Private variables ---------------------------------------------------------*/ 00083 /* Private function prototypes -----------------------------------------------*/ 00084 /* Private functions ---------------------------------------------------------*/ 00085 00086 /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions 00087 * @{ 00088 */ 00089 00090 /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions 00091 * @brief Extended features functions 00092 * 00093 @verbatim 00094 =============================================================================== 00095 ##### Extended features functions ##### 00096 =============================================================================== 00097 [..] This section provides functions allowing to: 00098 (+) Configure Noise Filters 00099 (+) Configure Wake Up Feature 00100 (+) Configure Fast Mode Plus 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 Min_Data=0x00 and Max_Data=0x0F. 00155 * @retval HAL status 00156 */ 00157 HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter) 00158 { 00159 uint32_t tmpreg; 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(s). 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 * @brief Disable I2C wakeup from Stop mode(s). 00243 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 00244 * the configuration information for the specified I2Cx peripheral. 00245 * @retval HAL status 00246 */ 00247 HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c) 00248 { 00249 /* Check the parameters */ 00250 assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance)); 00251 00252 if (hi2c->State == HAL_I2C_STATE_READY) 00253 { 00254 /* Process Locked */ 00255 __HAL_LOCK(hi2c); 00256 00257 hi2c->State = HAL_I2C_STATE_BUSY; 00258 00259 /* Disable the selected I2C peripheral */ 00260 __HAL_I2C_DISABLE(hi2c); 00261 00262 /* Enable wakeup from stop mode */ 00263 hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN); 00264 00265 __HAL_I2C_ENABLE(hi2c); 00266 00267 hi2c->State = HAL_I2C_STATE_READY; 00268 00269 /* Process Unlocked */ 00270 __HAL_UNLOCK(hi2c); 00271 00272 return HAL_OK; 00273 } 00274 else 00275 { 00276 return HAL_BUSY; 00277 } 00278 } 00279 00280 /** 00281 * @brief Enable the I2C fast mode plus driving capability. 00282 * @param ConfigFastModePlus Selects the pin. 00283 * This parameter can be one of the @ref I2CEx_FastModePlus values 00284 * @note For I2C1, fast mode plus driving capability can be enabled on all selected 00285 * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently 00286 * on each one of the following pins PB6, PB7, PB8 and PB9. 00287 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability 00288 * can be enabled only by using I2C_FASTMODEPLUS_I2C1 parameter. 00289 * @note For all I2C2 pins fast mode plus driving capability can be enabled 00290 * only by using I2C_FASTMODEPLUS_I2C2 parameter. 00291 * @note For all I2C3 pins fast mode plus driving capability can be enabled 00292 * only by using I2C_FASTMODEPLUS_I2C3 parameter. 00293 * @note For all I2C4 pins fast mode plus driving capability can be enabled 00294 * only by using I2C_FASTMODEPLUS_I2C4 parameter. 00295 * @retval None 00296 */ 00297 void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus) 00298 { 00299 /* Check the parameter */ 00300 assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus)); 00301 00302 /* Enable SYSCFG clock */ 00303 __HAL_RCC_SYSCFG_CLK_ENABLE(); 00304 00305 /* Enable fast mode plus driving capability for selected pin */ 00306 SET_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus); 00307 } 00308 00309 /** 00310 * @brief Disable the I2C fast mode plus driving capability. 00311 * @param ConfigFastModePlus Selects the pin. 00312 * This parameter can be one of the @ref I2CEx_FastModePlus values 00313 * @note For I2C1, fast mode plus driving capability can be disabled on all selected 00314 * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently 00315 * on each one of the following pins PB6, PB7, PB8 and PB9. 00316 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability 00317 * can be disabled only by using I2C_FASTMODEPLUS_I2C1 parameter. 00318 * @note For all I2C2 pins fast mode plus driving capability can be disabled 00319 * only by using I2C_FASTMODEPLUS_I2C2 parameter. 00320 * @note For all I2C3 pins fast mode plus driving capability can be disabled 00321 * only by using I2C_FASTMODEPLUS_I2C3 parameter. 00322 * @note For all I2C4 pins fast mode plus driving capability can be disabled 00323 * only by using I2C_FASTMODEPLUS_I2C4 parameter. 00324 * @retval None 00325 */ 00326 void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus) 00327 { 00328 /* Check the parameter */ 00329 assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus)); 00330 00331 /* Enable SYSCFG clock */ 00332 __HAL_RCC_SYSCFG_CLK_ENABLE(); 00333 00334 /* Disable fast mode plus driving capability for selected pin */ 00335 CLEAR_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus); 00336 } 00337 00338 /** 00339 * @} 00340 */ 00341 00342 /** 00343 * @} 00344 */ 00345 00346 #endif /* HAL_I2C_MODULE_ENABLED */ 00347 /** 00348 * @} 00349 */ 00350 00351 /** 00352 * @} 00353 */ 00354 00355 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/