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