Initial commit
mbed-dev-master/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_fmpi2c_ex.c@0:bb348c97df44, 2020-09-16 (annotated)
- Committer:
- lypinator
- Date:
- Wed Sep 16 01:11:49 2020 +0000
- Revision:
- 0:bb348c97df44
Added PWM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lypinator | 0:bb348c97df44 | 1 | /** |
lypinator | 0:bb348c97df44 | 2 | ****************************************************************************** |
lypinator | 0:bb348c97df44 | 3 | * @file stm32f4xx_hal_fmpi2c_ex.c |
lypinator | 0:bb348c97df44 | 4 | * @author MCD Application Team |
lypinator | 0:bb348c97df44 | 5 | * @brief FMPI2C Extended HAL module driver. |
lypinator | 0:bb348c97df44 | 6 | * This file provides firmware functions to manage the following |
lypinator | 0:bb348c97df44 | 7 | * functionalities of FMPI2C Extended peripheral: |
lypinator | 0:bb348c97df44 | 8 | * + Extended features functions |
lypinator | 0:bb348c97df44 | 9 | * |
lypinator | 0:bb348c97df44 | 10 | @verbatim |
lypinator | 0:bb348c97df44 | 11 | ============================================================================== |
lypinator | 0:bb348c97df44 | 12 | ##### FMPI2C peripheral Extended features ##### |
lypinator | 0:bb348c97df44 | 13 | ============================================================================== |
lypinator | 0:bb348c97df44 | 14 | |
lypinator | 0:bb348c97df44 | 15 | [..] Comparing to other previous devices, the FMPI2C interface for STM32F4xx |
lypinator | 0:bb348c97df44 | 16 | devices contains the following additional features |
lypinator | 0:bb348c97df44 | 17 | |
lypinator | 0:bb348c97df44 | 18 | (+) Possibility to disable or enable Analog Noise Filter |
lypinator | 0:bb348c97df44 | 19 | (+) Use of a configured Digital Noise Filter |
lypinator | 0:bb348c97df44 | 20 | (+) Disable or enable Fast Mode Plus |
lypinator | 0:bb348c97df44 | 21 | |
lypinator | 0:bb348c97df44 | 22 | ##### How to use this driver ##### |
lypinator | 0:bb348c97df44 | 23 | ============================================================================== |
lypinator | 0:bb348c97df44 | 24 | [..] This driver provides functions to configure Noise Filter and Wake Up Feature |
lypinator | 0:bb348c97df44 | 25 | (#) Configure FMPI2C Analog noise filter using the function HAL_FMPI2CEx_ConfigAnalogFilter() |
lypinator | 0:bb348c97df44 | 26 | (#) Configure FMPI2C Digital noise filter using the function HAL_FMPI2CEx_ConfigDigitalFilter() |
lypinator | 0:bb348c97df44 | 27 | (#) Configure the enable or disable of fast mode plus driving capability using the functions : |
lypinator | 0:bb348c97df44 | 28 | (++) HAL_FMPI2CEx_EnableFastModePlus() |
lypinator | 0:bb348c97df44 | 29 | (++) HAL_FMPI2CEx_DisableFastModePlus() |
lypinator | 0:bb348c97df44 | 30 | @endverbatim |
lypinator | 0:bb348c97df44 | 31 | ****************************************************************************** |
lypinator | 0:bb348c97df44 | 32 | * @attention |
lypinator | 0:bb348c97df44 | 33 | * |
lypinator | 0:bb348c97df44 | 34 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
lypinator | 0:bb348c97df44 | 35 | * |
lypinator | 0:bb348c97df44 | 36 | * Redistribution and use in source and binary forms, with or without modification, |
lypinator | 0:bb348c97df44 | 37 | * are permitted provided that the following conditions are met: |
lypinator | 0:bb348c97df44 | 38 | * 1. Redistributions of source code must retain the above copyright notice, |
lypinator | 0:bb348c97df44 | 39 | * this list of conditions and the following disclaimer. |
lypinator | 0:bb348c97df44 | 40 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
lypinator | 0:bb348c97df44 | 41 | * this list of conditions and the following disclaimer in the documentation |
lypinator | 0:bb348c97df44 | 42 | * and/or other materials provided with the distribution. |
lypinator | 0:bb348c97df44 | 43 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
lypinator | 0:bb348c97df44 | 44 | * may be used to endorse or promote products derived from this software |
lypinator | 0:bb348c97df44 | 45 | * without specific prior written permission. |
lypinator | 0:bb348c97df44 | 46 | * |
lypinator | 0:bb348c97df44 | 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
lypinator | 0:bb348c97df44 | 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
lypinator | 0:bb348c97df44 | 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
lypinator | 0:bb348c97df44 | 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
lypinator | 0:bb348c97df44 | 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
lypinator | 0:bb348c97df44 | 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
lypinator | 0:bb348c97df44 | 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
lypinator | 0:bb348c97df44 | 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
lypinator | 0:bb348c97df44 | 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
lypinator | 0:bb348c97df44 | 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
lypinator | 0:bb348c97df44 | 57 | * |
lypinator | 0:bb348c97df44 | 58 | ****************************************************************************** |
lypinator | 0:bb348c97df44 | 59 | */ |
lypinator | 0:bb348c97df44 | 60 | |
lypinator | 0:bb348c97df44 | 61 | /* Includes ------------------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 62 | #include "stm32f4xx_hal.h" |
lypinator | 0:bb348c97df44 | 63 | |
lypinator | 0:bb348c97df44 | 64 | /** @addtogroup STM32F4xx_HAL_Driver |
lypinator | 0:bb348c97df44 | 65 | * @{ |
lypinator | 0:bb348c97df44 | 66 | */ |
lypinator | 0:bb348c97df44 | 67 | |
lypinator | 0:bb348c97df44 | 68 | /** @defgroup FMPI2CEx FMPI2CEx |
lypinator | 0:bb348c97df44 | 69 | * @brief FMPI2C Extended HAL module driver |
lypinator | 0:bb348c97df44 | 70 | * @{ |
lypinator | 0:bb348c97df44 | 71 | */ |
lypinator | 0:bb348c97df44 | 72 | |
lypinator | 0:bb348c97df44 | 73 | #ifdef HAL_FMPI2C_MODULE_ENABLED |
lypinator | 0:bb348c97df44 | 74 | |
lypinator | 0:bb348c97df44 | 75 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ |
lypinator | 0:bb348c97df44 | 76 | defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) |
lypinator | 0:bb348c97df44 | 77 | |
lypinator | 0:bb348c97df44 | 78 | /* Private typedef -----------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 79 | /* Private define ------------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 80 | /* Private macro -------------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 81 | /* Private variables ---------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 82 | /* Private function prototypes -----------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 83 | /* Private functions ---------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 84 | |
lypinator | 0:bb348c97df44 | 85 | /** @defgroup FMPI2CEx_Exported_Functions FMPI2C Extended Exported Functions |
lypinator | 0:bb348c97df44 | 86 | * @{ |
lypinator | 0:bb348c97df44 | 87 | */ |
lypinator | 0:bb348c97df44 | 88 | |
lypinator | 0:bb348c97df44 | 89 | /** @defgroup FMPI2CEx_Exported_Functions_Group1 Extended features functions |
lypinator | 0:bb348c97df44 | 90 | * @brief Extended features functions |
lypinator | 0:bb348c97df44 | 91 | * |
lypinator | 0:bb348c97df44 | 92 | @verbatim |
lypinator | 0:bb348c97df44 | 93 | =============================================================================== |
lypinator | 0:bb348c97df44 | 94 | ##### Extended features functions ##### |
lypinator | 0:bb348c97df44 | 95 | =============================================================================== |
lypinator | 0:bb348c97df44 | 96 | [..] This section provides functions allowing to: |
lypinator | 0:bb348c97df44 | 97 | (+) Configure Noise Filters |
lypinator | 0:bb348c97df44 | 98 | (+) Configure Fast Mode Plus |
lypinator | 0:bb348c97df44 | 99 | |
lypinator | 0:bb348c97df44 | 100 | @endverbatim |
lypinator | 0:bb348c97df44 | 101 | * @{ |
lypinator | 0:bb348c97df44 | 102 | */ |
lypinator | 0:bb348c97df44 | 103 | |
lypinator | 0:bb348c97df44 | 104 | /** |
lypinator | 0:bb348c97df44 | 105 | * @brief Configure FMPI2C Analog noise filter. |
lypinator | 0:bb348c97df44 | 106 | * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 107 | * the configuration information for the specified FMPI2Cx peripheral. |
lypinator | 0:bb348c97df44 | 108 | * @param AnalogFilter New state of the Analog filter. |
lypinator | 0:bb348c97df44 | 109 | * @retval HAL status |
lypinator | 0:bb348c97df44 | 110 | */ |
lypinator | 0:bb348c97df44 | 111 | HAL_StatusTypeDef HAL_FMPI2CEx_ConfigAnalogFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t AnalogFilter) |
lypinator | 0:bb348c97df44 | 112 | { |
lypinator | 0:bb348c97df44 | 113 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 114 | assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance)); |
lypinator | 0:bb348c97df44 | 115 | assert_param(IS_FMPI2C_ANALOG_FILTER(AnalogFilter)); |
lypinator | 0:bb348c97df44 | 116 | |
lypinator | 0:bb348c97df44 | 117 | if (hfmpi2c->State == HAL_FMPI2C_STATE_READY) |
lypinator | 0:bb348c97df44 | 118 | { |
lypinator | 0:bb348c97df44 | 119 | /* Process Locked */ |
lypinator | 0:bb348c97df44 | 120 | __HAL_LOCK(hfmpi2c); |
lypinator | 0:bb348c97df44 | 121 | |
lypinator | 0:bb348c97df44 | 122 | hfmpi2c->State = HAL_FMPI2C_STATE_BUSY; |
lypinator | 0:bb348c97df44 | 123 | |
lypinator | 0:bb348c97df44 | 124 | /* Disable the selected FMPI2C peripheral */ |
lypinator | 0:bb348c97df44 | 125 | __HAL_FMPI2C_DISABLE(hfmpi2c); |
lypinator | 0:bb348c97df44 | 126 | |
lypinator | 0:bb348c97df44 | 127 | /* Reset FMPI2Cx ANOFF bit */ |
lypinator | 0:bb348c97df44 | 128 | hfmpi2c->Instance->CR1 &= ~(FMPI2C_CR1_ANFOFF); |
lypinator | 0:bb348c97df44 | 129 | |
lypinator | 0:bb348c97df44 | 130 | /* Set analog filter bit*/ |
lypinator | 0:bb348c97df44 | 131 | hfmpi2c->Instance->CR1 |= AnalogFilter; |
lypinator | 0:bb348c97df44 | 132 | |
lypinator | 0:bb348c97df44 | 133 | __HAL_FMPI2C_ENABLE(hfmpi2c); |
lypinator | 0:bb348c97df44 | 134 | |
lypinator | 0:bb348c97df44 | 135 | hfmpi2c->State = HAL_FMPI2C_STATE_READY; |
lypinator | 0:bb348c97df44 | 136 | |
lypinator | 0:bb348c97df44 | 137 | /* Process Unlocked */ |
lypinator | 0:bb348c97df44 | 138 | __HAL_UNLOCK(hfmpi2c); |
lypinator | 0:bb348c97df44 | 139 | |
lypinator | 0:bb348c97df44 | 140 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 141 | } |
lypinator | 0:bb348c97df44 | 142 | else |
lypinator | 0:bb348c97df44 | 143 | { |
lypinator | 0:bb348c97df44 | 144 | return HAL_BUSY; |
lypinator | 0:bb348c97df44 | 145 | } |
lypinator | 0:bb348c97df44 | 146 | } |
lypinator | 0:bb348c97df44 | 147 | |
lypinator | 0:bb348c97df44 | 148 | /** |
lypinator | 0:bb348c97df44 | 149 | * @brief Configure FMPI2C Digital noise filter. |
lypinator | 0:bb348c97df44 | 150 | * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 151 | * the configuration information for the specified FMPI2Cx peripheral. |
lypinator | 0:bb348c97df44 | 152 | * @param DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F. |
lypinator | 0:bb348c97df44 | 153 | * @retval HAL status |
lypinator | 0:bb348c97df44 | 154 | */ |
lypinator | 0:bb348c97df44 | 155 | HAL_StatusTypeDef HAL_FMPI2CEx_ConfigDigitalFilter(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t DigitalFilter) |
lypinator | 0:bb348c97df44 | 156 | { |
lypinator | 0:bb348c97df44 | 157 | uint32_t tmpreg = 0U; |
lypinator | 0:bb348c97df44 | 158 | |
lypinator | 0:bb348c97df44 | 159 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 160 | assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance)); |
lypinator | 0:bb348c97df44 | 161 | assert_param(IS_FMPI2C_DIGITAL_FILTER(DigitalFilter)); |
lypinator | 0:bb348c97df44 | 162 | |
lypinator | 0:bb348c97df44 | 163 | if (hfmpi2c->State == HAL_FMPI2C_STATE_READY) |
lypinator | 0:bb348c97df44 | 164 | { |
lypinator | 0:bb348c97df44 | 165 | /* Process Locked */ |
lypinator | 0:bb348c97df44 | 166 | __HAL_LOCK(hfmpi2c); |
lypinator | 0:bb348c97df44 | 167 | |
lypinator | 0:bb348c97df44 | 168 | hfmpi2c->State = HAL_FMPI2C_STATE_BUSY; |
lypinator | 0:bb348c97df44 | 169 | |
lypinator | 0:bb348c97df44 | 170 | /* Disable the selected FMPI2C peripheral */ |
lypinator | 0:bb348c97df44 | 171 | __HAL_FMPI2C_DISABLE(hfmpi2c); |
lypinator | 0:bb348c97df44 | 172 | |
lypinator | 0:bb348c97df44 | 173 | /* Get the old register value */ |
lypinator | 0:bb348c97df44 | 174 | tmpreg = hfmpi2c->Instance->CR1; |
lypinator | 0:bb348c97df44 | 175 | |
lypinator | 0:bb348c97df44 | 176 | /* Reset FMPI2Cx DNF bits [11:8] */ |
lypinator | 0:bb348c97df44 | 177 | tmpreg &= ~(FMPI2C_CR1_DFN); |
lypinator | 0:bb348c97df44 | 178 | |
lypinator | 0:bb348c97df44 | 179 | /* Set FMPI2Cx DNF coefficient */ |
lypinator | 0:bb348c97df44 | 180 | tmpreg |= DigitalFilter << 8U; |
lypinator | 0:bb348c97df44 | 181 | |
lypinator | 0:bb348c97df44 | 182 | /* Store the new register value */ |
lypinator | 0:bb348c97df44 | 183 | hfmpi2c->Instance->CR1 = tmpreg; |
lypinator | 0:bb348c97df44 | 184 | |
lypinator | 0:bb348c97df44 | 185 | __HAL_FMPI2C_ENABLE(hfmpi2c); |
lypinator | 0:bb348c97df44 | 186 | |
lypinator | 0:bb348c97df44 | 187 | hfmpi2c->State = HAL_FMPI2C_STATE_READY; |
lypinator | 0:bb348c97df44 | 188 | |
lypinator | 0:bb348c97df44 | 189 | /* Process Unlocked */ |
lypinator | 0:bb348c97df44 | 190 | __HAL_UNLOCK(hfmpi2c); |
lypinator | 0:bb348c97df44 | 191 | |
lypinator | 0:bb348c97df44 | 192 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 193 | } |
lypinator | 0:bb348c97df44 | 194 | else |
lypinator | 0:bb348c97df44 | 195 | { |
lypinator | 0:bb348c97df44 | 196 | return HAL_BUSY; |
lypinator | 0:bb348c97df44 | 197 | } |
lypinator | 0:bb348c97df44 | 198 | } |
lypinator | 0:bb348c97df44 | 199 | |
lypinator | 0:bb348c97df44 | 200 | /** |
lypinator | 0:bb348c97df44 | 201 | * @brief Enable the FMPI2C fast mode plus driving capability. |
lypinator | 0:bb348c97df44 | 202 | * @param ConfigFastModePlus Selects the pin. |
lypinator | 0:bb348c97df44 | 203 | * This parameter can be one of the @ref FMPI2CEx_FastModePlus values |
lypinator | 0:bb348c97df44 | 204 | * @retval None |
lypinator | 0:bb348c97df44 | 205 | */ |
lypinator | 0:bb348c97df44 | 206 | void HAL_FMPI2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus) |
lypinator | 0:bb348c97df44 | 207 | { |
lypinator | 0:bb348c97df44 | 208 | /* Check the parameter */ |
lypinator | 0:bb348c97df44 | 209 | assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus)); |
lypinator | 0:bb348c97df44 | 210 | |
lypinator | 0:bb348c97df44 | 211 | /* Enable SYSCFG clock */ |
lypinator | 0:bb348c97df44 | 212 | __HAL_RCC_SYSCFG_CLK_ENABLE(); |
lypinator | 0:bb348c97df44 | 213 | |
lypinator | 0:bb348c97df44 | 214 | /* Enable fast mode plus driving capability for selected pin */ |
lypinator | 0:bb348c97df44 | 215 | SET_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus); |
lypinator | 0:bb348c97df44 | 216 | } |
lypinator | 0:bb348c97df44 | 217 | |
lypinator | 0:bb348c97df44 | 218 | /** |
lypinator | 0:bb348c97df44 | 219 | * @brief Disable the FMPI2C fast mode plus driving capability. |
lypinator | 0:bb348c97df44 | 220 | * @param ConfigFastModePlus Selects the pin. |
lypinator | 0:bb348c97df44 | 221 | * This parameter can be one of the @ref FMPI2CEx_FastModePlus values |
lypinator | 0:bb348c97df44 | 222 | * @retval None |
lypinator | 0:bb348c97df44 | 223 | */ |
lypinator | 0:bb348c97df44 | 224 | void HAL_FMPI2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus) |
lypinator | 0:bb348c97df44 | 225 | { |
lypinator | 0:bb348c97df44 | 226 | /* Check the parameter */ |
lypinator | 0:bb348c97df44 | 227 | assert_param(IS_FMPI2C_FASTMODEPLUS(ConfigFastModePlus)); |
lypinator | 0:bb348c97df44 | 228 | |
lypinator | 0:bb348c97df44 | 229 | /* Enable SYSCFG clock */ |
lypinator | 0:bb348c97df44 | 230 | __HAL_RCC_SYSCFG_CLK_ENABLE(); |
lypinator | 0:bb348c97df44 | 231 | |
lypinator | 0:bb348c97df44 | 232 | /* Disable fast mode plus driving capability for selected pin */ |
lypinator | 0:bb348c97df44 | 233 | CLEAR_BIT(SYSCFG->CFGR, (uint32_t)ConfigFastModePlus); |
lypinator | 0:bb348c97df44 | 234 | } |
lypinator | 0:bb348c97df44 | 235 | |
lypinator | 0:bb348c97df44 | 236 | /** |
lypinator | 0:bb348c97df44 | 237 | * @} |
lypinator | 0:bb348c97df44 | 238 | */ |
lypinator | 0:bb348c97df44 | 239 | |
lypinator | 0:bb348c97df44 | 240 | /** |
lypinator | 0:bb348c97df44 | 241 | * @} |
lypinator | 0:bb348c97df44 | 242 | */ |
lypinator | 0:bb348c97df44 | 243 | #endif /* STM32F410xx || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx ||\ |
lypinator | 0:bb348c97df44 | 244 | STM32F413xx || STM32F423xx */ |
lypinator | 0:bb348c97df44 | 245 | #endif /* HAL_FMPI2C_MODULE_ENABLED */ |
lypinator | 0:bb348c97df44 | 246 | /** |
lypinator | 0:bb348c97df44 | 247 | * @} |
lypinator | 0:bb348c97df44 | 248 | */ |
lypinator | 0:bb348c97df44 | 249 | |
lypinator | 0:bb348c97df44 | 250 | /** |
lypinator | 0:bb348c97df44 | 251 | * @} |
lypinator | 0:bb348c97df44 | 252 | */ |
lypinator | 0:bb348c97df44 | 253 | |
lypinator | 0:bb348c97df44 | 254 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |