]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_i2c_ex.c
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F4 / stm32f4xx_hal_i2c_ex.c
1 /**
2 ******************************************************************************
3 * @file stm32f4xx_hal_i2c_ex.c
4 * @author MCD Application Team
5 * @version V1.1.0
6 * @date 19-June-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>&copy; 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
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 /* Private functions ---------------------------------------------------------*/
82
83 /** @defgroup I2CEx_Private_Functions
84 * @{
85 */
86
87
88 /** @defgroup I2CEx_Group1 Extension features functions
89 * @brief Extension features functions
90 *
91 @verbatim
92 ===============================================================================
93 ##### Extension features functions #####
94 ===============================================================================
95 [..] This section provides functions allowing to:
96 (+) Configure Noise Filters
97
98 @endverbatim
99 * @{
100 */
101
102 /**
103 * @brief Configures I2C Analog noise filter.
104 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
105 * the configuration information for the specified I2Cx peripheral.
106 * @param AnalogFilter: new state of the Analog filter.
107 * @retval HAL status
108 */
109 HAL_StatusTypeDef HAL_I2CEx_AnalogFilter_Config(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
110 {
111 uint32_t tmp = 0;
112
113 /* Check the parameters */
114 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
115 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
116
117 tmp = hi2c->State;
118 if((tmp == HAL_I2C_STATE_BUSY) || (tmp == HAL_I2C_STATE_BUSY_TX) || (tmp == HAL_I2C_STATE_BUSY_RX))
119 {
120 return HAL_BUSY;
121 }
122
123 hi2c->State = HAL_I2C_STATE_BUSY;
124
125 /* Disable the selected I2C peripheral */
126 __HAL_I2C_DISABLE(hi2c);
127
128 /* Reset I2Cx ANOFF bit */
129 hi2c->Instance->FLTR &= ~(I2C_FLTR_ANOFF);
130
131 /* Disable the analog filter */
132 hi2c->Instance->FLTR |= AnalogFilter;
133
134 __HAL_I2C_ENABLE(hi2c);
135
136 hi2c->State = HAL_I2C_STATE_READY;
137
138 return HAL_OK;
139 }
140
141 /**
142 * @brief Configures I2C Digital noise filter.
143 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
144 * the configuration information for the specified I2Cx peripheral.
145 * @param DigitalFilter: Coefficient of digital noise filter between 0x00 and 0x0F.
146 * @retval HAL status
147 */
148 HAL_StatusTypeDef HAL_I2CEx_DigitalFilter_Config(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
149 {
150 uint16_t tmpreg = 0;
151 uint32_t tmp = 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 tmp = hi2c->State;
158 if((tmp == HAL_I2C_STATE_BUSY) || (tmp == HAL_I2C_STATE_BUSY_TX) || (tmp == HAL_I2C_STATE_BUSY_RX))
159 {
160 return HAL_BUSY;
161 }
162
163 hi2c->State = HAL_I2C_STATE_BUSY;
164
165 /* Disable the selected I2C peripheral */
166 __HAL_I2C_DISABLE(hi2c);
167
168 /* Get the old register value */
169 tmpreg = hi2c->Instance->FLTR;
170
171 /* Reset I2Cx DNF bit [3:0] */
172 tmpreg &= ~(I2C_FLTR_DNF);
173
174 /* Set I2Cx DNF coefficient */
175 tmpreg |= DigitalFilter;
176
177 /* Store the new register value */
178 hi2c->Instance->FLTR = tmpreg;
179
180 __HAL_I2C_ENABLE(hi2c);
181
182 hi2c->State = HAL_I2C_STATE_READY;
183
184 return HAL_OK;
185 }
186
187 /**
188 * @}
189 */
190
191 /**
192 * @}
193 */
194 #endif /* STM32F427xx || STM32F429xx || STM32F437xx || STM32F439xx || STM32F401xC || STM32F401xE */
195
196 #endif /* HAL_I2C_MODULE_ENABLED */
197 /**
198 * @}
199 */
200
201 /**
202 * @}
203 */
204
205 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Imprint / Impressum