]>
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
2 ******************************************************************************
3 * @file stm32f4xx_hal_i2c_ex.c
4 * @author MCD Application Team
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
13 ==============================================================================
14 ##### I2C peripheral extension features #####
15 ==============================================================================
17 [..] Comparing to other previous devices, the I2C interface for STM32F427xx/437xx/
18 429xx/439xx devices contains the following additional features :
20 (+) Possibility to disable or enable Analog Noise Filter
21 (+) Use of a configured Digital Noise Filter
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()
30 ******************************************************************************
33 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
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.
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.
57 ******************************************************************************
60 /* Includes ------------------------------------------------------------------*/
61 #include "stm32f4xx_hal.h"
63 /** @addtogroup STM32F4xx_HAL_Driver
68 * @brief I2C HAL module driver
72 #ifdef HAL_I2C_MODULE_ENABLED
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 ---------------------------------------------------------*/
83 /** @defgroup I2CEx_Private_Functions
88 /** @defgroup I2CEx_Group1 Extension features functions
89 * @brief Extension features functions
92 ===============================================================================
93 ##### Extension features functions #####
94 ===============================================================================
95 [..] This section provides functions allowing to:
96 (+) Configure Noise Filters
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.
109 HAL_StatusTypeDef
HAL_I2CEx_AnalogFilter_Config(I2C_HandleTypeDef
*hi2c
, uint32_t AnalogFilter
)
113 /* Check the parameters */
114 assert_param(IS_I2C_ALL_INSTANCE(hi2c
->Instance
));
115 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter
));
118 if((tmp
== HAL_I2C_STATE_BUSY
) || (tmp
== HAL_I2C_STATE_BUSY_TX
) || (tmp
== HAL_I2C_STATE_BUSY_RX
))
123 hi2c
->State
= HAL_I2C_STATE_BUSY
;
125 /* Disable the selected I2C peripheral */
126 __HAL_I2C_DISABLE(hi2c
);
128 /* Reset I2Cx ANOFF bit */
129 hi2c
->Instance
->FLTR
&= ~(I2C_FLTR_ANOFF
);
131 /* Disable the analog filter */
132 hi2c
->Instance
->FLTR
|= AnalogFilter
;
134 __HAL_I2C_ENABLE(hi2c
);
136 hi2c
->State
= HAL_I2C_STATE_READY
;
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.
148 HAL_StatusTypeDef
HAL_I2CEx_DigitalFilter_Config(I2C_HandleTypeDef
*hi2c
, uint32_t DigitalFilter
)
153 /* Check the parameters */
154 assert_param(IS_I2C_ALL_INSTANCE(hi2c
->Instance
));
155 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter
));
158 if((tmp
== HAL_I2C_STATE_BUSY
) || (tmp
== HAL_I2C_STATE_BUSY_TX
) || (tmp
== HAL_I2C_STATE_BUSY_RX
))
163 hi2c
->State
= HAL_I2C_STATE_BUSY
;
165 /* Disable the selected I2C peripheral */
166 __HAL_I2C_DISABLE(hi2c
);
168 /* Get the old register value */
169 tmpreg
= hi2c
->Instance
->FLTR
;
171 /* Reset I2Cx DNF bit [3:0] */
172 tmpreg
&= ~(I2C_FLTR_DNF
);
174 /* Set I2Cx DNF coefficient */
175 tmpreg
|= DigitalFilter
;
177 /* Store the new register value */
178 hi2c
->Instance
->FLTR
= tmpreg
;
180 __HAL_I2C_ENABLE(hi2c
);
182 hi2c
->State
= HAL_I2C_STATE_READY
;
194 #endif /* STM32F427xx || STM32F429xx || STM32F437xx || STM32F439xx || STM32F401xC || STM32F401xE */
196 #endif /* HAL_I2C_MODULE_ENABLED */
205 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/