2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_i2c_ex.c
\r
4 * @author MCD Application Team
\r
6 * @date 06-March-2015
\r
7 * @brief I2C Extended HAL module driver.
\r
8 * This file provides firmware functions to manage the following
\r
9 * functionalities of I2C Extended peripheral:
\r
10 * + Extended features functions
\r
13 ==============================================================================
\r
14 ##### I2C peripheral Extended features #####
\r
15 ==============================================================================
\r
17 [..] Comparing to other previous devices, the I2C interface for STM32L4XX
\r
18 devices contains the following additional features
\r
20 (+) Possibility to disable or enable Analog Noise Filter
\r
21 (+) Use of a configured Digital Noise Filter
\r
22 (+) Disable or enable wakeup from Stop mode
\r
24 ##### How to use this driver #####
\r
25 ==============================================================================
\r
26 [..] This driver provides functions to:
\r
27 (#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter()
\r
28 (#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter()
\r
30 ******************************************************************************
\r
33 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
\r
35 * Redistribution and use in source and binary forms, with or without modification,
\r
36 * are permitted provided that the following conditions are met:
\r
37 * 1. Redistributions of source code must retain the above copyright notice,
\r
38 * this list of conditions and the following disclaimer.
\r
39 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
40 * this list of conditions and the following disclaimer in the documentation
\r
41 * and/or other materials provided with the distribution.
\r
42 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
43 * may be used to endorse or promote products derived from this software
\r
44 * without specific prior written permission.
\r
46 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
47 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
49 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
52 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
53 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
54 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
55 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
57 ******************************************************************************
\r
60 /* Includes ------------------------------------------------------------------*/
\r
61 #include "stm32f7xx_hal.h"
\r
63 /** @addtogroup STM32F7xx_HAL_Driver
\r
67 /** @defgroup I2CEx I2C Extended HAL module driver
\r
68 * @brief I2C Extended HAL module driver
\r
72 #ifdef HAL_I2C_MODULE_ENABLED
\r
74 /* Private typedef -----------------------------------------------------------*/
\r
75 /* Private define ------------------------------------------------------------*/
\r
76 /* Private macro -------------------------------------------------------------*/
\r
77 /* Private variables ---------------------------------------------------------*/
\r
78 /* Private function prototypes -----------------------------------------------*/
\r
79 /* Private functions ---------------------------------------------------------*/
\r
81 /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions
\r
85 /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions
\r
86 * @brief Extended features functions
\r
89 ===============================================================================
\r
90 ##### Extended features functions #####
\r
91 ===============================================================================
\r
92 [..] This section provides functions allowing to:
\r
93 (+) Configure Noise Filters
\r
100 * @brief Configures I2C Analog noise filter.
\r
101 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
\r
102 * the configuration information for the specified I2Cx peripheral.
\r
103 * @param AnalogFilter : new state of the Analog filter.
\r
104 * @retval HAL status
\r
106 HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
\r
108 /* Check the parameters */
\r
109 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
\r
110 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
\r
112 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
\r
113 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
\r
118 /* Process Locked */
\r
121 hi2c->State = HAL_I2C_STATE_BUSY;
\r
123 /* Disable the selected I2C peripheral */
\r
124 __HAL_I2C_DISABLE(hi2c);
\r
126 /* Reset I2Cx ANOFF bit */
\r
127 hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF);
\r
129 /* Set analog filter bit*/
\r
130 hi2c->Instance->CR1 |= AnalogFilter;
\r
132 __HAL_I2C_ENABLE(hi2c);
\r
134 hi2c->State = HAL_I2C_STATE_READY;
\r
136 /* Process Unlocked */
\r
137 __HAL_UNLOCK(hi2c);
\r
143 * @brief Configures I2C Digital noise filter.
\r
144 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
\r
145 * the configuration information for the specified I2Cx peripheral.
\r
146 * @param DigitalFilter : Coefficient of digital noise filter between 0x00 and 0x0F.
\r
147 * @retval HAL status
\r
149 HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
\r
151 uint32_t tmpreg = 0;
\r
153 /* Check the parameters */
\r
154 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
\r
155 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
\r
157 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
\r
158 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
\r
163 /* Process Locked */
\r
166 hi2c->State = HAL_I2C_STATE_BUSY;
\r
168 /* Disable the selected I2C peripheral */
\r
169 __HAL_I2C_DISABLE(hi2c);
\r
171 /* Get the old register value */
\r
172 tmpreg = hi2c->Instance->CR1;
\r
174 /* Reset I2Cx DNF bits [11:8] */
\r
175 tmpreg &= ~(I2C_CR1_DFN);
\r
177 /* Set I2Cx DNF coefficient */
\r
178 tmpreg |= DigitalFilter << 8;
\r
180 /* Store the new register value */
\r
181 hi2c->Instance->CR1 = tmpreg;
\r
183 __HAL_I2C_ENABLE(hi2c);
\r
185 hi2c->State = HAL_I2C_STATE_READY;
\r
187 /* Process Unlocked */
\r
188 __HAL_UNLOCK(hi2c);
\r
201 #endif /* HAL_I2C_MODULE_ENABLED */
\r
210 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r