1 | /** |
---|
2 | ****************************************************************************** |
---|
3 | * @file stm32f7xx_hal_i2c_ex.c |
---|
4 | * @author MCD Application Team |
---|
5 | * @version V1.0.1 |
---|
6 | * @date 25-June-2015 |
---|
7 | * @brief I2C Extended HAL module driver. |
---|
8 | * This file provides firmware functions to manage the following |
---|
9 | * functionalities of I2C Extended peripheral: |
---|
10 | * + Extended features functions |
---|
11 | * |
---|
12 | @verbatim |
---|
13 | ============================================================================== |
---|
14 | ##### I2C peripheral Extended features ##### |
---|
15 | ============================================================================== |
---|
16 | |
---|
17 | [..] Comparing to other previous devices, the I2C interface for STM32L4XX |
---|
18 | 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 | (+) Disable or enable wakeup from Stop mode |
---|
23 | |
---|
24 | ##### How to use this driver ##### |
---|
25 | ============================================================================== |
---|
26 | [..] This driver provides functions to: |
---|
27 | (#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter() |
---|
28 | (#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter() |
---|
29 | @endverbatim |
---|
30 | ****************************************************************************** |
---|
31 | * @attention |
---|
32 | * |
---|
33 | * <h2><center>© COPYRIGHT(c) 2015 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 "stm32f7xx_hal.h" |
---|
62 | |
---|
63 | /** @addtogroup STM32F7xx_HAL_Driver |
---|
64 | * @{ |
---|
65 | */ |
---|
66 | |
---|
67 | /** @defgroup I2CEx I2C Extended HAL module driver |
---|
68 | * @brief I2C Extended HAL module driver |
---|
69 | * @{ |
---|
70 | */ |
---|
71 | |
---|
72 | #ifdef HAL_I2C_MODULE_ENABLED |
---|
73 | |
---|
74 | /* Private typedef -----------------------------------------------------------*/ |
---|
75 | /* Private define ------------------------------------------------------------*/ |
---|
76 | /* Private macro -------------------------------------------------------------*/ |
---|
77 | /* Private variables ---------------------------------------------------------*/ |
---|
78 | /* Private function prototypes -----------------------------------------------*/ |
---|
79 | /* Private functions ---------------------------------------------------------*/ |
---|
80 | |
---|
81 | /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions |
---|
82 | * @{ |
---|
83 | */ |
---|
84 | |
---|
85 | /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions |
---|
86 | * @brief Extended features functions |
---|
87 | * |
---|
88 | @verbatim |
---|
89 | =============================================================================== |
---|
90 | ##### Extended features functions ##### |
---|
91 | =============================================================================== |
---|
92 | [..] This section provides functions allowing to: |
---|
93 | (+) Configure Noise Filters |
---|
94 | |
---|
95 | @endverbatim |
---|
96 | * @{ |
---|
97 | */ |
---|
98 | |
---|
99 | /** |
---|
100 | * @brief Configures I2C Analog noise filter. |
---|
101 | * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains |
---|
102 | * the configuration information for the specified I2Cx peripheral. |
---|
103 | * @param AnalogFilter : new state of the Analog filter. |
---|
104 | * @retval HAL status |
---|
105 | */ |
---|
106 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter) |
---|
107 | { |
---|
108 | /* Check the parameters */ |
---|
109 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); |
---|
110 | assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter)); |
---|
111 | |
---|
112 | if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX) |
---|
113 | || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX)) |
---|
114 | { |
---|
115 | return HAL_BUSY; |
---|
116 | } |
---|
117 | |
---|
118 | /* Process Locked */ |
---|
119 | __HAL_LOCK(hi2c); |
---|
120 | |
---|
121 | hi2c->State = HAL_I2C_STATE_BUSY; |
---|
122 | |
---|
123 | /* Disable the selected I2C peripheral */ |
---|
124 | __HAL_I2C_DISABLE(hi2c); |
---|
125 | |
---|
126 | /* Reset I2Cx ANOFF bit */ |
---|
127 | hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF); |
---|
128 | |
---|
129 | /* Set analog filter bit*/ |
---|
130 | hi2c->Instance->CR1 |= AnalogFilter; |
---|
131 | |
---|
132 | __HAL_I2C_ENABLE(hi2c); |
---|
133 | |
---|
134 | hi2c->State = HAL_I2C_STATE_READY; |
---|
135 | |
---|
136 | /* Process Unlocked */ |
---|
137 | __HAL_UNLOCK(hi2c); |
---|
138 | |
---|
139 | return HAL_OK; |
---|
140 | } |
---|
141 | |
---|
142 | /** |
---|
143 | * @brief Configures I2C Digital noise filter. |
---|
144 | * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains |
---|
145 | * the configuration information for the specified I2Cx peripheral. |
---|
146 | * @param DigitalFilter : Coefficient of digital noise filter between 0x00 and 0x0F. |
---|
147 | * @retval HAL status |
---|
148 | */ |
---|
149 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter) |
---|
150 | { |
---|
151 | uint32_t tmpreg = 0; |
---|
152 | |
---|
153 | /* Check the parameters */ |
---|
154 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); |
---|
155 | assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter)); |
---|
156 | |
---|
157 | if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX) |
---|
158 | || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX)) |
---|
159 | { |
---|
160 | return HAL_BUSY; |
---|
161 | } |
---|
162 | |
---|
163 | /* Process Locked */ |
---|
164 | __HAL_LOCK(hi2c); |
---|
165 | |
---|
166 | hi2c->State = HAL_I2C_STATE_BUSY; |
---|
167 | |
---|
168 | /* Disable the selected I2C peripheral */ |
---|
169 | __HAL_I2C_DISABLE(hi2c); |
---|
170 | |
---|
171 | /* Get the old register value */ |
---|
172 | tmpreg = hi2c->Instance->CR1; |
---|
173 | |
---|
174 | /* Reset I2Cx DNF bits [11:8] */ |
---|
175 | tmpreg &= ~(I2C_CR1_DFN); |
---|
176 | |
---|
177 | /* Set I2Cx DNF coefficient */ |
---|
178 | tmpreg |= DigitalFilter << 8; |
---|
179 | |
---|
180 | /* Store the new register value */ |
---|
181 | hi2c->Instance->CR1 = tmpreg; |
---|
182 | |
---|
183 | __HAL_I2C_ENABLE(hi2c); |
---|
184 | |
---|
185 | hi2c->State = HAL_I2C_STATE_READY; |
---|
186 | |
---|
187 | /* Process Unlocked */ |
---|
188 | __HAL_UNLOCK(hi2c); |
---|
189 | |
---|
190 | return HAL_OK; |
---|
191 | } |
---|
192 | |
---|
193 | /** |
---|
194 | * @} |
---|
195 | */ |
---|
196 | |
---|
197 | /** |
---|
198 | * @} |
---|
199 | */ |
---|
200 | |
---|
201 | #endif /* HAL_I2C_MODULE_ENABLED */ |
---|
202 | /** |
---|
203 | * @} |
---|
204 | */ |
---|
205 | |
---|
206 | /** |
---|
207 | * @} |
---|
208 | */ |
---|
209 | |
---|
210 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
---|