]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3/stm32f3xx_hal_i2c_ex.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F3 / stm32f3xx_hal_i2c_ex.c
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_hal_i2c_ex.c
4 * @author MCD Application Team
5 * @version V1.1.0
6 * @date 12-Sept-2014
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 STM32F3XX
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 configure Noise Filter
27 (#) Configure I2C Analog noise filter using the function HAL_I2CEx_AnalogFilter_Config()
28 (#) Configure I2C Digital noise filter using the function HAL_I2CEx_DigitalFilter_Config()
29 (#) Configure the enabling or disabling of I2C Wake Up Mode using the functions :
30 + HAL_I2CEx_EnableWakeUp()
31 + HAL_I2CEx_DisableWakeUp()
32
33 @endverbatim
34 ******************************************************************************
35 * @attention
36 *
37 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
38 *
39 * Redistribution and use in source and binary forms, with or without modification,
40 * are permitted provided that the following conditions are met:
41 * 1. Redistributions of source code must retain the above copyright notice,
42 * this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright notice,
44 * this list of conditions and the following disclaimer in the documentation
45 * and/or other materials provided with the distribution.
46 * 3. Neither the name of STMicroelectronics nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
51 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
53 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
56 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
57 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
58 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 *
61 ******************************************************************************
62 */
63
64 /* Includes ------------------------------------------------------------------*/
65 #include "stm32f3xx_hal.h"
66
67 /** @addtogroup STM32F3xx_HAL_Driver
68 * @{
69 */
70
71 /** @defgroup I2CEx I2C Extended HAL module driver
72 * @brief I2C Extended HAL module driver
73 * @{
74 */
75
76 #ifdef HAL_I2C_MODULE_ENABLED
77
78 /* Private typedef -----------------------------------------------------------*/
79 /* Private define ------------------------------------------------------------*/
80 /* Private macro -------------------------------------------------------------*/
81 /* Private variables ---------------------------------------------------------*/
82 /* Private function prototypes -----------------------------------------------*/
83 /* Private functions ---------------------------------------------------------*/
84
85 /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions
86 * @{
87 */
88
89 /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions
90 * @brief Extended features functions
91 *
92 @verbatim
93 ===============================================================================
94 ##### Extended features functions #####
95 ===============================================================================
96 [..] This section provides functions allowing to:
97 (+) Configure Noise Filters
98
99 @endverbatim
100 * @{
101 */
102
103 /**
104 * @brief Configures I2C Analog noise filter.
105 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
106 * the configuration information for the specified I2Cx peripheral.
107 * @param AnalogFilter : new state of the Analog filter.
108 * @retval HAL status
109 */
110 HAL_StatusTypeDef HAL_I2CEx_AnalogFilter_Config(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
111 {
112 /* Check the parameters */
113 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
114 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
115
116 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
117 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
118 {
119 return HAL_BUSY;
120 }
121
122 /* Process Locked */
123 __HAL_LOCK(hi2c);
124
125 hi2c->State = HAL_I2C_STATE_BUSY;
126
127 /* Disable the selected I2C peripheral */
128 __HAL_I2C_DISABLE(hi2c);
129
130 /* Reset I2Cx ANOFF bit */
131 hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF);
132
133 /* Set analog filter bit*/
134 hi2c->Instance->CR1 |= AnalogFilter;
135
136 __HAL_I2C_ENABLE(hi2c);
137
138 hi2c->State = HAL_I2C_STATE_READY;
139
140 /* Process Unlocked */
141 __HAL_UNLOCK(hi2c);
142
143 return HAL_OK;
144 }
145
146 /**
147 * @brief Configures I2C Digital noise filter.
148 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
149 * the configuration information for the specified I2Cx peripheral.
150 * @param DigitalFilter : Coefficient of digital noise filter between 0x00 and 0x0F.
151 * @retval HAL status
152 */
153 HAL_StatusTypeDef HAL_I2CEx_DigitalFilter_Config(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
154 {
155 uint32_t tmpreg = 0;
156
157 /* Check the parameters */
158 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
159 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
160
161 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
162 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
163 {
164 return HAL_BUSY;
165 }
166
167 /* Process Locked */
168 __HAL_LOCK(hi2c);
169
170 hi2c->State = HAL_I2C_STATE_BUSY;
171
172 /* Disable the selected I2C peripheral */
173 __HAL_I2C_DISABLE(hi2c);
174
175 /* Get the old register value */
176 tmpreg = hi2c->Instance->CR1;
177
178 /* Reset I2Cx DNF bits [11:8] */
179 tmpreg &= ~(I2C_CR1_DFN);
180
181 /* Set I2Cx DNF coefficient */
182 tmpreg |= DigitalFilter << 8;
183
184 /* Store the new register value */
185 hi2c->Instance->CR1 = tmpreg;
186
187 __HAL_I2C_ENABLE(hi2c);
188
189 hi2c->State = HAL_I2C_STATE_READY;
190
191 /* Process Unlocked */
192 __HAL_UNLOCK(hi2c);
193
194 return HAL_OK;
195 }
196
197 /**
198 * @brief Enables I2C wakeup from stop mode.
199 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
200 * the configuration information for the specified I2Cx peripheral.
201 * @retval HAL status
202 */
203 HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp (I2C_HandleTypeDef *hi2c)
204 {
205 /* Check the parameters */
206 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
207
208 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
209 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
210 {
211 return HAL_BUSY;
212 }
213
214 /* Process Locked */
215 __HAL_LOCK(hi2c);
216
217 hi2c->State = HAL_I2C_STATE_BUSY;
218
219 /* Disable the selected I2C peripheral */
220 __HAL_I2C_DISABLE(hi2c);
221
222 /* Enable wakeup from stop mode */
223 hi2c->Instance->CR1 |= I2C_CR1_WUPEN;
224
225 __HAL_I2C_ENABLE(hi2c);
226
227 hi2c->State = HAL_I2C_STATE_READY;
228
229 /* Process Unlocked */
230 __HAL_UNLOCK(hi2c);
231
232 return HAL_OK;
233 }
234
235
236 /**
237 * @brief Disables I2C wakeup from stop mode.
238 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
239 * the configuration information for the specified I2Cx peripheral.
240 * @retval HAL status
241 */
242 HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp (I2C_HandleTypeDef *hi2c)
243 {
244 /* Check the parameters */
245 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
246
247 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
248 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
249 {
250 return HAL_BUSY;
251 }
252
253 /* Process Locked */
254 __HAL_LOCK(hi2c);
255
256 hi2c->State = HAL_I2C_STATE_BUSY;
257
258 /* Disable the selected I2C peripheral */
259 __HAL_I2C_DISABLE(hi2c);
260
261 /* Enable wakeup from stop mode */
262 hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN);
263
264 __HAL_I2C_ENABLE(hi2c);
265
266 hi2c->State = HAL_I2C_STATE_READY;
267
268 /* Process Unlocked */
269 __HAL_UNLOCK(hi2c);
270
271 return HAL_OK;
272 }
273
274 /**
275 * @}
276 */
277
278 /**
279 * @}
280 */
281
282 #endif /* HAL_I2C_MODULE_ENABLED */
283 /**
284 * @}
285 */
286
287 /**
288 * @}
289 */
290
291 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Imprint / Impressum