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