mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F411RE/stm32f4xx_hal_i2c_ex.c@235:685d5f11838f, 2014-06-23 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Jun 23 14:00:09 2014 +0100
- Revision:
- 235:685d5f11838f
Synchronized with git revision 9728c76667962b289ee9c4c687ef9f115db48cd3
Full URL: https://github.com/mbedmicro/mbed/commit/9728c76667962b289ee9c4c687ef9f115db48cd3/
[NUCLEO_F411RE] Add all target files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 235:685d5f11838f | 1 | /** |
mbed_official | 235:685d5f11838f | 2 | ****************************************************************************** |
mbed_official | 235:685d5f11838f | 3 | * @file stm32f4xx_hal_i2c_ex.c |
mbed_official | 235:685d5f11838f | 4 | * @author MCD Application Team |
mbed_official | 235:685d5f11838f | 5 | * @version V1.1.0 |
mbed_official | 235:685d5f11838f | 6 | * @date 19-June-2014 |
mbed_official | 235:685d5f11838f | 7 | * @brief I2C Extension HAL module driver. |
mbed_official | 235:685d5f11838f | 8 | * This file provides firmware functions to manage the following |
mbed_official | 235:685d5f11838f | 9 | * functionalities of I2C extension peripheral: |
mbed_official | 235:685d5f11838f | 10 | * + Extension features functions |
mbed_official | 235:685d5f11838f | 11 | * |
mbed_official | 235:685d5f11838f | 12 | @verbatim |
mbed_official | 235:685d5f11838f | 13 | ============================================================================== |
mbed_official | 235:685d5f11838f | 14 | ##### I2C peripheral extension features ##### |
mbed_official | 235:685d5f11838f | 15 | ============================================================================== |
mbed_official | 235:685d5f11838f | 16 | |
mbed_official | 235:685d5f11838f | 17 | [..] Comparing to other previous devices, the I2C interface for STM32F427xx/437xx/ |
mbed_official | 235:685d5f11838f | 18 | 429xx/439xx devices contains the following additional features : |
mbed_official | 235:685d5f11838f | 19 | |
mbed_official | 235:685d5f11838f | 20 | (+) Possibility to disable or enable Analog Noise Filter |
mbed_official | 235:685d5f11838f | 21 | (+) Use of a configured Digital Noise Filter |
mbed_official | 235:685d5f11838f | 22 | |
mbed_official | 235:685d5f11838f | 23 | ##### How to use this driver ##### |
mbed_official | 235:685d5f11838f | 24 | ============================================================================== |
mbed_official | 235:685d5f11838f | 25 | [..] This driver provides functions to configure Noise Filter |
mbed_official | 235:685d5f11838f | 26 | (#) Configure I2C Analog noise filter using the function HAL_I2C_AnalogFilter_Config() |
mbed_official | 235:685d5f11838f | 27 | (#) Configure I2C Digital noise filter using the function HAL_I2C_DigitalFilter_Config() |
mbed_official | 235:685d5f11838f | 28 | |
mbed_official | 235:685d5f11838f | 29 | @endverbatim |
mbed_official | 235:685d5f11838f | 30 | ****************************************************************************** |
mbed_official | 235:685d5f11838f | 31 | * @attention |
mbed_official | 235:685d5f11838f | 32 | * |
mbed_official | 235:685d5f11838f | 33 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 235:685d5f11838f | 34 | * |
mbed_official | 235:685d5f11838f | 35 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 235:685d5f11838f | 36 | * are permitted provided that the following conditions are met: |
mbed_official | 235:685d5f11838f | 37 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 235:685d5f11838f | 38 | * this list of conditions and the following disclaimer. |
mbed_official | 235:685d5f11838f | 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 235:685d5f11838f | 40 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 235:685d5f11838f | 41 | * and/or other materials provided with the distribution. |
mbed_official | 235:685d5f11838f | 42 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 235:685d5f11838f | 43 | * may be used to endorse or promote products derived from this software |
mbed_official | 235:685d5f11838f | 44 | * without specific prior written permission. |
mbed_official | 235:685d5f11838f | 45 | * |
mbed_official | 235:685d5f11838f | 46 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 235:685d5f11838f | 47 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 235:685d5f11838f | 48 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 235:685d5f11838f | 49 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 235:685d5f11838f | 50 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 235:685d5f11838f | 51 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 235:685d5f11838f | 52 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 235:685d5f11838f | 53 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 235:685d5f11838f | 54 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 235:685d5f11838f | 55 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 235:685d5f11838f | 56 | * |
mbed_official | 235:685d5f11838f | 57 | ****************************************************************************** |
mbed_official | 235:685d5f11838f | 58 | */ |
mbed_official | 235:685d5f11838f | 59 | |
mbed_official | 235:685d5f11838f | 60 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 61 | #include "stm32f4xx_hal.h" |
mbed_official | 235:685d5f11838f | 62 | |
mbed_official | 235:685d5f11838f | 63 | /** @addtogroup STM32F4xx_HAL_Driver |
mbed_official | 235:685d5f11838f | 64 | * @{ |
mbed_official | 235:685d5f11838f | 65 | */ |
mbed_official | 235:685d5f11838f | 66 | |
mbed_official | 235:685d5f11838f | 67 | /** @defgroup I2CEx |
mbed_official | 235:685d5f11838f | 68 | * @brief I2C HAL module driver |
mbed_official | 235:685d5f11838f | 69 | * @{ |
mbed_official | 235:685d5f11838f | 70 | */ |
mbed_official | 235:685d5f11838f | 71 | |
mbed_official | 235:685d5f11838f | 72 | #ifdef HAL_I2C_MODULE_ENABLED |
mbed_official | 235:685d5f11838f | 73 | |
mbed_official | 235:685d5f11838f | 74 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) ||\ |
mbed_official | 235:685d5f11838f | 75 | defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) |
mbed_official | 235:685d5f11838f | 76 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 77 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 78 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 79 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 80 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 81 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 82 | |
mbed_official | 235:685d5f11838f | 83 | /** @defgroup I2CEx_Private_Functions |
mbed_official | 235:685d5f11838f | 84 | * @{ |
mbed_official | 235:685d5f11838f | 85 | */ |
mbed_official | 235:685d5f11838f | 86 | |
mbed_official | 235:685d5f11838f | 87 | |
mbed_official | 235:685d5f11838f | 88 | /** @defgroup I2CEx_Group1 Extension features functions |
mbed_official | 235:685d5f11838f | 89 | * @brief Extension features functions |
mbed_official | 235:685d5f11838f | 90 | * |
mbed_official | 235:685d5f11838f | 91 | @verbatim |
mbed_official | 235:685d5f11838f | 92 | =============================================================================== |
mbed_official | 235:685d5f11838f | 93 | ##### Extension features functions ##### |
mbed_official | 235:685d5f11838f | 94 | =============================================================================== |
mbed_official | 235:685d5f11838f | 95 | [..] This section provides functions allowing to: |
mbed_official | 235:685d5f11838f | 96 | (+) Configure Noise Filters |
mbed_official | 235:685d5f11838f | 97 | |
mbed_official | 235:685d5f11838f | 98 | @endverbatim |
mbed_official | 235:685d5f11838f | 99 | * @{ |
mbed_official | 235:685d5f11838f | 100 | */ |
mbed_official | 235:685d5f11838f | 101 | |
mbed_official | 235:685d5f11838f | 102 | /** |
mbed_official | 235:685d5f11838f | 103 | * @brief Configures I2C Analog noise filter. |
mbed_official | 235:685d5f11838f | 104 | * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 105 | * the configuration information for the specified I2Cx peripheral. |
mbed_official | 235:685d5f11838f | 106 | * @param AnalogFilter: new state of the Analog filter. |
mbed_official | 235:685d5f11838f | 107 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 108 | */ |
mbed_official | 235:685d5f11838f | 109 | HAL_StatusTypeDef HAL_I2CEx_AnalogFilter_Config(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter) |
mbed_official | 235:685d5f11838f | 110 | { |
mbed_official | 235:685d5f11838f | 111 | uint32_t tmp = 0; |
mbed_official | 235:685d5f11838f | 112 | |
mbed_official | 235:685d5f11838f | 113 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 114 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); |
mbed_official | 235:685d5f11838f | 115 | assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter)); |
mbed_official | 235:685d5f11838f | 116 | |
mbed_official | 235:685d5f11838f | 117 | tmp = hi2c->State; |
mbed_official | 235:685d5f11838f | 118 | if((tmp == HAL_I2C_STATE_BUSY) || (tmp == HAL_I2C_STATE_BUSY_TX) || (tmp == HAL_I2C_STATE_BUSY_RX)) |
mbed_official | 235:685d5f11838f | 119 | { |
mbed_official | 235:685d5f11838f | 120 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 121 | } |
mbed_official | 235:685d5f11838f | 122 | |
mbed_official | 235:685d5f11838f | 123 | hi2c->State = HAL_I2C_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 124 | |
mbed_official | 235:685d5f11838f | 125 | /* Disable the selected I2C peripheral */ |
mbed_official | 235:685d5f11838f | 126 | __HAL_I2C_DISABLE(hi2c); |
mbed_official | 235:685d5f11838f | 127 | |
mbed_official | 235:685d5f11838f | 128 | /* Reset I2Cx ANOFF bit */ |
mbed_official | 235:685d5f11838f | 129 | hi2c->Instance->FLTR &= ~(I2C_FLTR_ANOFF); |
mbed_official | 235:685d5f11838f | 130 | |
mbed_official | 235:685d5f11838f | 131 | /* Disable the analog filter */ |
mbed_official | 235:685d5f11838f | 132 | hi2c->Instance->FLTR |= AnalogFilter; |
mbed_official | 235:685d5f11838f | 133 | |
mbed_official | 235:685d5f11838f | 134 | __HAL_I2C_ENABLE(hi2c); |
mbed_official | 235:685d5f11838f | 135 | |
mbed_official | 235:685d5f11838f | 136 | hi2c->State = HAL_I2C_STATE_READY; |
mbed_official | 235:685d5f11838f | 137 | |
mbed_official | 235:685d5f11838f | 138 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 139 | } |
mbed_official | 235:685d5f11838f | 140 | |
mbed_official | 235:685d5f11838f | 141 | /** |
mbed_official | 235:685d5f11838f | 142 | * @brief Configures I2C Digital noise filter. |
mbed_official | 235:685d5f11838f | 143 | * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 144 | * the configuration information for the specified I2Cx peripheral. |
mbed_official | 235:685d5f11838f | 145 | * @param DigitalFilter: Coefficient of digital noise filter between 0x00 and 0x0F. |
mbed_official | 235:685d5f11838f | 146 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 147 | */ |
mbed_official | 235:685d5f11838f | 148 | HAL_StatusTypeDef HAL_I2CEx_DigitalFilter_Config(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter) |
mbed_official | 235:685d5f11838f | 149 | { |
mbed_official | 235:685d5f11838f | 150 | uint16_t tmpreg = 0; |
mbed_official | 235:685d5f11838f | 151 | uint32_t tmp = 0; |
mbed_official | 235:685d5f11838f | 152 | |
mbed_official | 235:685d5f11838f | 153 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 154 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); |
mbed_official | 235:685d5f11838f | 155 | assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter)); |
mbed_official | 235:685d5f11838f | 156 | |
mbed_official | 235:685d5f11838f | 157 | tmp = hi2c->State; |
mbed_official | 235:685d5f11838f | 158 | if((tmp == HAL_I2C_STATE_BUSY) || (tmp == HAL_I2C_STATE_BUSY_TX) || (tmp == HAL_I2C_STATE_BUSY_RX)) |
mbed_official | 235:685d5f11838f | 159 | { |
mbed_official | 235:685d5f11838f | 160 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 161 | } |
mbed_official | 235:685d5f11838f | 162 | |
mbed_official | 235:685d5f11838f | 163 | hi2c->State = HAL_I2C_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 164 | |
mbed_official | 235:685d5f11838f | 165 | /* Disable the selected I2C peripheral */ |
mbed_official | 235:685d5f11838f | 166 | __HAL_I2C_DISABLE(hi2c); |
mbed_official | 235:685d5f11838f | 167 | |
mbed_official | 235:685d5f11838f | 168 | /* Get the old register value */ |
mbed_official | 235:685d5f11838f | 169 | tmpreg = hi2c->Instance->FLTR; |
mbed_official | 235:685d5f11838f | 170 | |
mbed_official | 235:685d5f11838f | 171 | /* Reset I2Cx DNF bit [3:0] */ |
mbed_official | 235:685d5f11838f | 172 | tmpreg &= ~(I2C_FLTR_DNF); |
mbed_official | 235:685d5f11838f | 173 | |
mbed_official | 235:685d5f11838f | 174 | /* Set I2Cx DNF coefficient */ |
mbed_official | 235:685d5f11838f | 175 | tmpreg |= DigitalFilter; |
mbed_official | 235:685d5f11838f | 176 | |
mbed_official | 235:685d5f11838f | 177 | /* Store the new register value */ |
mbed_official | 235:685d5f11838f | 178 | hi2c->Instance->FLTR = tmpreg; |
mbed_official | 235:685d5f11838f | 179 | |
mbed_official | 235:685d5f11838f | 180 | __HAL_I2C_ENABLE(hi2c); |
mbed_official | 235:685d5f11838f | 181 | |
mbed_official | 235:685d5f11838f | 182 | hi2c->State = HAL_I2C_STATE_READY; |
mbed_official | 235:685d5f11838f | 183 | |
mbed_official | 235:685d5f11838f | 184 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 185 | } |
mbed_official | 235:685d5f11838f | 186 | |
mbed_official | 235:685d5f11838f | 187 | /** |
mbed_official | 235:685d5f11838f | 188 | * @} |
mbed_official | 235:685d5f11838f | 189 | */ |
mbed_official | 235:685d5f11838f | 190 | |
mbed_official | 235:685d5f11838f | 191 | /** |
mbed_official | 235:685d5f11838f | 192 | * @} |
mbed_official | 235:685d5f11838f | 193 | */ |
mbed_official | 235:685d5f11838f | 194 | #endif /* STM32F427xx || STM32F429xx || STM32F437xx || STM32F439xx || STM32F401xC || STM32F401xE */ |
mbed_official | 235:685d5f11838f | 195 | |
mbed_official | 235:685d5f11838f | 196 | #endif /* HAL_I2C_MODULE_ENABLED */ |
mbed_official | 235:685d5f11838f | 197 | /** |
mbed_official | 235:685d5f11838f | 198 | * @} |
mbed_official | 235:685d5f11838f | 199 | */ |
mbed_official | 235:685d5f11838f | 200 | |
mbed_official | 235:685d5f11838f | 201 | /** |
mbed_official | 235:685d5f11838f | 202 | * @} |
mbed_official | 235:685d5f11838f | 203 | */ |
mbed_official | 235:685d5f11838f | 204 | |
mbed_official | 235:685d5f11838f | 205 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |