[303] | 1 | /**
|
---|
| 2 | ******************************************************************************
|
---|
| 3 | * @file stm32f4xx_hal_fmpi2c_ex.c
|
---|
| 4 | * @author MCD Application Team
|
---|
| 5 | * @version V1.4.1
|
---|
| 6 | * @date 09-October-2015
|
---|
| 7 | * @brief Extended FMPI2C HAL module driver.
|
---|
| 8 | *
|
---|
| 9 | * This file provides firmware functions to manage the following
|
---|
| 10 | * functionalities of the Inter Integrated Circuit (FMPI2C) peripheral:
|
---|
| 11 | * + Extended Control methods
|
---|
| 12 | *
|
---|
| 13 | @verbatim
|
---|
| 14 | ==============================================================================
|
---|
| 15 | ##### FMPI2C peripheral extended features #####
|
---|
| 16 | ==============================================================================
|
---|
| 17 |
|
---|
| 18 | [..] Comparing to other previous devices, the FMPI2C interface for STM32L4XX
|
---|
| 19 | devices contains the following additional features
|
---|
| 20 |
|
---|
| 21 | (+) Possibility to disable or enable Analog Noise Filter
|
---|
| 22 | (+) Use of a configured Digital Noise Filter
|
---|
| 23 | (+) Disable or enable wakeup from Stop mode
|
---|
| 24 |
|
---|
| 25 | ##### How to use this driver #####
|
---|
| 26 | ==============================================================================
|
---|
| 27 | [..] This driver provides functions to configure Noise Filter
|
---|
| 28 |
|
---|
| 29 | @endverbatim
|
---|
| 30 | ******************************************************************************
|
---|
| 31 | * @attention
|
---|
| 32 | *
|
---|
| 33 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
---|
| 34 | *
|
---|
| 35 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
| 36 | * are permitted provided that the following conditions are met:
|
---|
| 37 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
| 38 | * this list of conditions and the following disclaimer.
|
---|
| 39 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
| 40 | * this list of conditions and the following disclaimer in the documentation
|
---|
| 41 | * and/or other materials provided with the distribution.
|
---|
| 42 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
---|
| 43 | * may be used to endorse or promote products derived from this software
|
---|
| 44 | * without specific prior written permission.
|
---|
| 45 | *
|
---|
| 46 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
---|
| 47 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 48 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
| 49 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
---|
| 50 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 51 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
---|
| 52 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
---|
| 53 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
| 54 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
| 55 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 56 | *
|
---|
| 57 | ******************************************************************************
|
---|
| 58 | */
|
---|
| 59 |
|
---|
| 60 | /* Includes ------------------------------------------------------------------*/
|
---|
| 61 | #include "stm32f4xx_hal.h"
|
---|
| 62 |
|
---|
| 63 | /** @addtogroup STM32F4xx_HAL_Driver
|
---|
| 64 | * @{
|
---|
| 65 | */
|
---|
| 66 |
|
---|
| 67 | /** @defgroup FMPI2CEx FMPI2CEx
|
---|
| 68 | * @brief FMPI2C HAL module driver
|
---|
| 69 | * @{
|
---|
| 70 | */
|
---|
| 71 |
|
---|
| 72 | #ifdef HAL_FMPI2C_MODULE_ENABLED
|
---|
| 73 |
|
---|
| 74 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx)
|
---|
| 75 |
|
---|
| 76 | /* Private typedef -----------------------------------------------------------*/
|
---|
| 77 | /* Private define ------------------------------------------------------------*/
|
---|
| 78 | /* Private macro -------------------------------------------------------------*/
|
---|
| 79 | /* Private variables ---------------------------------------------------------*/
|
---|
| 80 | /* Private function prototypes -----------------------------------------------*/
|
---|
| 81 | /* Exported functions --------------------------------------------------------*/
|
---|
| 82 |
|
---|
| 83 | /** @defgroup FMPI2CEx_Exported_Functions FMPI2C Extended Exported Functions
|
---|
| 84 | * @{
|
---|
| 85 | */
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | /** @defgroup FMPI2CEx_Exported_Functions_Group1 Peripheral Control methods
|
---|
| 89 | * @brief management functions
|
---|
| 90 | *
|
---|
| 91 | @verbatim
|
---|
| 92 | ===============================================================================
|
---|
| 93 | ##### Extension features functions #####
|
---|
| 94 | ===============================================================================
|
---|
| 95 | [..] This section provides functions allowing to:
|
---|
| 96 | (+) Configure Noise Filters
|
---|
| 97 |
|
---|
| 98 | @endverbatim
|
---|
| 99 | * @{
|
---|
| 100 | */
|
---|
| 101 |
|
---|
| 102 | /**
|
---|
| 103 | * @brief Configures FMPI2C Analog noise filter.
|
---|
| 104 | * @param hfmpi2c : pointer to a FMPI2C_HandleTypeDef structure that contains
|
---|
| 105 | * the configuration information for the specified FMPI2Cx peripheral.
|
---|
| 106 | * @param AnalogFilter : new state of the Analog filter.
|
---|
| 107 | * @retval HAL status
|
---|
| 108 | */
|
---|
| 109 | HAL_StatusTypeDef HAL_FMPI2CEx_AnalogFilter_Config(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t AnalogFilter)
|
---|
| 110 | {
|
---|
| 111 | /* Check the parameters */
|
---|
| 112 | assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
|
---|
| 113 | assert_param(IS_FMPI2C_ANALOG_FILTER(AnalogFilter));
|
---|
| 114 |
|
---|
| 115 | if((hfmpi2c->State == HAL_FMPI2C_STATE_BUSY) || (hfmpi2c->State == HAL_FMPI2C_STATE_MASTER_BUSY_TX) || (hfmpi2c->State == HAL_FMPI2C_STATE_MASTER_BUSY_RX)
|
---|
| 116 | || (hfmpi2c->State == HAL_FMPI2C_STATE_SLAVE_BUSY_TX) || (hfmpi2c->State == HAL_FMPI2C_STATE_SLAVE_BUSY_RX))
|
---|
| 117 | {
|
---|
| 118 | return HAL_BUSY;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | /* Process Locked */
|
---|
| 122 | __HAL_LOCK(hfmpi2c);
|
---|
| 123 |
|
---|
| 124 | hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
|
---|
| 125 |
|
---|
| 126 | /* Disable the selected FMPI2C peripheral */
|
---|
| 127 | __HAL_FMPI2C_DISABLE(hfmpi2c);
|
---|
| 128 |
|
---|
| 129 | /* Reset FMPI2Cx ANOFF bit */
|
---|
| 130 | hfmpi2c->Instance->CR1 &= ~(FMPI2C_CR1_ANFOFF);
|
---|
| 131 |
|
---|
| 132 | /* Set analog filter bit*/
|
---|
| 133 | hfmpi2c->Instance->CR1 |= AnalogFilter;
|
---|
| 134 |
|
---|
| 135 | __HAL_FMPI2C_ENABLE(hfmpi2c);
|
---|
| 136 |
|
---|
| 137 | hfmpi2c->State = HAL_FMPI2C_STATE_READY;
|
---|
| 138 |
|
---|
| 139 | /* Process Unlocked */
|
---|
| 140 | __HAL_UNLOCK(hfmpi2c);
|
---|
| 141 |
|
---|
| 142 | return HAL_OK;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | /**
|
---|
| 146 | * @brief Configures FMPI2C Digital noise filter.
|
---|
| 147 | * @param hfmpi2c : pointer to a FMPI2C_HandleTypeDef structure that contains
|
---|
| 148 | * the configuration information for the specified FMPI2Cx peripheral.
|
---|
| 149 | * @param DigitalFilter : Coefficient of digital noise filter between 0x00 and 0x0F.
|
---|
| 150 | * @retval HAL status
|
---|
| 151 | */
|
---|
| 152 | HAL_StatusTypeDef HAL_FMPI2CEx_DigitalFilter_Config(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t DigitalFilter)
|
---|
| 153 | {
|
---|
| 154 | uint32_t tmpreg = 0;
|
---|
| 155 |
|
---|
| 156 | /* Check the parameters */
|
---|
| 157 | assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
|
---|
| 158 | assert_param(IS_FMPI2C_DIGITAL_FILTER(DigitalFilter));
|
---|
| 159 |
|
---|
| 160 | if((hfmpi2c->State == HAL_FMPI2C_STATE_BUSY) || (hfmpi2c->State == HAL_FMPI2C_STATE_MASTER_BUSY_TX) || (hfmpi2c->State == HAL_FMPI2C_STATE_MASTER_BUSY_RX)
|
---|
| 161 | || (hfmpi2c->State == HAL_FMPI2C_STATE_SLAVE_BUSY_TX) || (hfmpi2c->State == HAL_FMPI2C_STATE_SLAVE_BUSY_RX))
|
---|
| 162 | {
|
---|
| 163 | return HAL_BUSY;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | /* Process Locked */
|
---|
| 167 | __HAL_LOCK(hfmpi2c);
|
---|
| 168 |
|
---|
| 169 | hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
|
---|
| 170 |
|
---|
| 171 | /* Disable the selected FMPI2C peripheral */
|
---|
| 172 | __HAL_FMPI2C_DISABLE(hfmpi2c);
|
---|
| 173 |
|
---|
| 174 | /* Get the old register value */
|
---|
| 175 | tmpreg = hfmpi2c->Instance->CR1;
|
---|
| 176 |
|
---|
| 177 | /* Reset FMPI2Cx DNF bits [11:8] */
|
---|
| 178 | tmpreg &= ~(FMPI2C_CR1_DFN);
|
---|
| 179 |
|
---|
| 180 | /* Set FMPI2Cx DNF coefficient */
|
---|
| 181 | tmpreg |= DigitalFilter << 8;
|
---|
| 182 |
|
---|
| 183 | /* Store the new register value */
|
---|
| 184 | hfmpi2c->Instance->CR1 = tmpreg;
|
---|
| 185 |
|
---|
| 186 | __HAL_FMPI2C_ENABLE(hfmpi2c);
|
---|
| 187 |
|
---|
| 188 | hfmpi2c->State = HAL_FMPI2C_STATE_READY;
|
---|
| 189 |
|
---|
| 190 | /* Process Unlocked */
|
---|
| 191 | __HAL_UNLOCK(hfmpi2c);
|
---|
| 192 |
|
---|
| 193 | return HAL_OK;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | /**
|
---|
| 197 | * @brief Enables FMPI2C wakeup from stop mode.
|
---|
| 198 | * @param hfmpi2c : pointer to a FMPI2C_HandleTypeDef structure that contains
|
---|
| 199 | * the configuration information for the specified FMPI2Cx peripheral.
|
---|
| 200 | * @retval HAL status
|
---|
| 201 | */
|
---|
| 202 | HAL_StatusTypeDef HAL_FMPI2CEx_EnableWakeUp (FMPI2C_HandleTypeDef *hfmpi2c)
|
---|
| 203 | {
|
---|
| 204 | /* Check the parameters */
|
---|
| 205 | assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
|
---|
| 206 |
|
---|
| 207 | if((hfmpi2c->State == HAL_FMPI2C_STATE_BUSY) || (hfmpi2c->State == HAL_FMPI2C_STATE_MASTER_BUSY_TX) || (hfmpi2c->State == HAL_FMPI2C_STATE_MASTER_BUSY_RX)
|
---|
| 208 | || (hfmpi2c->State == HAL_FMPI2C_STATE_SLAVE_BUSY_TX) || (hfmpi2c->State == HAL_FMPI2C_STATE_SLAVE_BUSY_RX))
|
---|
| 209 | {
|
---|
| 210 | return HAL_BUSY;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | /* Process Locked */
|
---|
| 214 | __HAL_LOCK(hfmpi2c);
|
---|
| 215 |
|
---|
| 216 | hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
|
---|
| 217 |
|
---|
| 218 | /* Disable the selected FMPI2C peripheral */
|
---|
| 219 | __HAL_FMPI2C_DISABLE(hfmpi2c);
|
---|
| 220 |
|
---|
| 221 | /* Enable wakeup from stop mode */
|
---|
| 222 | hfmpi2c->Instance->CR1 |= FMPI2C_CR1_WUPEN;
|
---|
| 223 |
|
---|
| 224 | __HAL_FMPI2C_ENABLE(hfmpi2c);
|
---|
| 225 |
|
---|
| 226 | hfmpi2c->State = HAL_FMPI2C_STATE_READY;
|
---|
| 227 |
|
---|
| 228 | /* Process Unlocked */
|
---|
| 229 | __HAL_UNLOCK(hfmpi2c);
|
---|
| 230 |
|
---|
| 231 | return HAL_OK;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 |
|
---|
| 235 | /**
|
---|
| 236 | * @brief Disables FMPI2C wakeup from stop mode.
|
---|
| 237 | * @param hfmpi2c : pointer to a FMPI2C_HandleTypeDef structure that contains
|
---|
| 238 | * the configuration information for the specified FMPI2Cx peripheral.
|
---|
| 239 | * @retval HAL status
|
---|
| 240 | */
|
---|
| 241 | HAL_StatusTypeDef HAL_FMPI2CEx_DisableWakeUp (FMPI2C_HandleTypeDef *hfmpi2c)
|
---|
| 242 | {
|
---|
| 243 | /* Check the parameters */
|
---|
| 244 | assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
|
---|
| 245 |
|
---|
| 246 | if((hfmpi2c->State == HAL_FMPI2C_STATE_BUSY) || (hfmpi2c->State == HAL_FMPI2C_STATE_MASTER_BUSY_TX) || (hfmpi2c->State == HAL_FMPI2C_STATE_MASTER_BUSY_RX)
|
---|
| 247 | || (hfmpi2c->State == HAL_FMPI2C_STATE_SLAVE_BUSY_TX) || (hfmpi2c->State == HAL_FMPI2C_STATE_SLAVE_BUSY_RX))
|
---|
| 248 | {
|
---|
| 249 | return HAL_BUSY;
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | /* Process Locked */
|
---|
| 253 | __HAL_LOCK(hfmpi2c);
|
---|
| 254 |
|
---|
| 255 | hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
|
---|
| 256 |
|
---|
| 257 | /* Disable the selected FMPI2C peripheral */
|
---|
| 258 | __HAL_FMPI2C_DISABLE(hfmpi2c);
|
---|
| 259 |
|
---|
| 260 | /* Enable wakeup from stop mode */
|
---|
| 261 | hfmpi2c->Instance->CR1 &= ~(FMPI2C_CR1_WUPEN);
|
---|
| 262 |
|
---|
| 263 | __HAL_FMPI2C_ENABLE(hfmpi2c);
|
---|
| 264 |
|
---|
| 265 | hfmpi2c->State = HAL_FMPI2C_STATE_READY;
|
---|
| 266 |
|
---|
| 267 | /* Process Unlocked */
|
---|
| 268 | __HAL_UNLOCK(hfmpi2c);
|
---|
| 269 |
|
---|
| 270 | return HAL_OK;
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | /**
|
---|
| 274 | * @brief Enable the FMPI2C1 fast mode plus driving capability.
|
---|
| 275 | * @param ConfigFastModePlus: selects the pin.
|
---|
| 276 | * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
|
---|
| 277 | * @retval None
|
---|
| 278 | */
|
---|
| 279 | void HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
|
---|
| 280 | {
|
---|
| 281 | /* Check the parameter */
|
---|
| 282 | assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
|
---|
| 283 |
|
---|
| 284 | /* Enable SYSCFG clock */
|
---|
| 285 | __HAL_RCC_SYSCFG_CLK_ENABLE();
|
---|
| 286 |
|
---|
| 287 | /* Enable fast mode plus driving capability for selected pin */
|
---|
| 288 | SET_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | /**
|
---|
| 292 | * @brief Disable the FMPI2C1 fast mode plus driving capability.
|
---|
| 293 | * @param ConfigFastModePlus: selects the pin.
|
---|
| 294 | * This parameter can be one of the @ref FMPI2CEx_FastModePlus values
|
---|
| 295 | * @retval None
|
---|
| 296 | */
|
---|
| 297 | void HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
|
---|
| 298 | {
|
---|
| 299 | /* Check the parameter */
|
---|
| 300 | assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus));
|
---|
| 301 |
|
---|
| 302 | /* Enable SYSCFG clock */
|
---|
| 303 | __HAL_RCC_SYSCFG_CLK_ENABLE();
|
---|
| 304 |
|
---|
| 305 | /* Disable fast mode plus driving capability for selected pin */
|
---|
| 306 | CLEAR_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus);
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | /**
|
---|
| 310 | * @}
|
---|
| 311 | */
|
---|
| 312 |
|
---|
| 313 | /**
|
---|
| 314 | * @}
|
---|
| 315 | */
|
---|
| 316 | #endif /* STM32F410xx || STM32F446xx */
|
---|
| 317 | #endif /* HAL_FMPI2C_MODULE_ENABLED */
|
---|
| 318 | /**
|
---|
| 319 | * @}
|
---|
| 320 | */
|
---|
| 321 |
|
---|
| 322 | /**
|
---|
| 323 | * @}
|
---|
| 324 | */
|
---|
| 325 |
|
---|
| 326 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
---|