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