Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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