MacroRat / MouseCode

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Wed May 24 01:57:01 2017 +0000
Revision:
29:ec2c5a69acd6
Parent:
18:6a4db94011d3
Need to change ir2-ir3 to now be ir1 - ir4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /**
sahilmgandhi 18:6a4db94011d3 2 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 3 * @file stm32f3xx_ll_opamp.c
sahilmgandhi 18:6a4db94011d3 4 * @author MCD Application Team
sahilmgandhi 18:6a4db94011d3 5 * @version V1.4.0
sahilmgandhi 18:6a4db94011d3 6 * @date 16-December-2016
sahilmgandhi 18:6a4db94011d3 7 * @brief OPAMP LL module driver
sahilmgandhi 18:6a4db94011d3 8 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 9 * @attention
sahilmgandhi 18:6a4db94011d3 10 *
sahilmgandhi 18:6a4db94011d3 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
sahilmgandhi 18:6a4db94011d3 12 *
sahilmgandhi 18:6a4db94011d3 13 * Redistribution and use in source and binary forms, with or without modification,
sahilmgandhi 18:6a4db94011d3 14 * are permitted provided that the following conditions are met:
sahilmgandhi 18:6a4db94011d3 15 * 1. Redistributions of source code must retain the above copyright notice,
sahilmgandhi 18:6a4db94011d3 16 * this list of conditions and the following disclaimer.
sahilmgandhi 18:6a4db94011d3 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
sahilmgandhi 18:6a4db94011d3 18 * this list of conditions and the following disclaimer in the documentation
sahilmgandhi 18:6a4db94011d3 19 * and/or other materials provided with the distribution.
sahilmgandhi 18:6a4db94011d3 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
sahilmgandhi 18:6a4db94011d3 21 * may be used to endorse or promote products derived from this software
sahilmgandhi 18:6a4db94011d3 22 * without specific prior written permission.
sahilmgandhi 18:6a4db94011d3 23 *
sahilmgandhi 18:6a4db94011d3 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
sahilmgandhi 18:6a4db94011d3 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sahilmgandhi 18:6a4db94011d3 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
sahilmgandhi 18:6a4db94011d3 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
sahilmgandhi 18:6a4db94011d3 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
sahilmgandhi 18:6a4db94011d3 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
sahilmgandhi 18:6a4db94011d3 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
sahilmgandhi 18:6a4db94011d3 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
sahilmgandhi 18:6a4db94011d3 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
sahilmgandhi 18:6a4db94011d3 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sahilmgandhi 18:6a4db94011d3 34 *
sahilmgandhi 18:6a4db94011d3 35 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 36 */
sahilmgandhi 18:6a4db94011d3 37 #if defined(USE_FULL_LL_DRIVER)
sahilmgandhi 18:6a4db94011d3 38
sahilmgandhi 18:6a4db94011d3 39 /* Includes ------------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 40 #include "stm32f3xx_ll_opamp.h"
sahilmgandhi 18:6a4db94011d3 41
sahilmgandhi 18:6a4db94011d3 42 #ifdef USE_FULL_ASSERT
sahilmgandhi 18:6a4db94011d3 43 #include "stm32_assert.h"
sahilmgandhi 18:6a4db94011d3 44 #else
sahilmgandhi 18:6a4db94011d3 45 #define assert_param(expr) ((void)0U)
sahilmgandhi 18:6a4db94011d3 46 #endif
sahilmgandhi 18:6a4db94011d3 47
sahilmgandhi 18:6a4db94011d3 48 /** @addtogroup STM32F3xx_LL_Driver
sahilmgandhi 18:6a4db94011d3 49 * @{
sahilmgandhi 18:6a4db94011d3 50 */
sahilmgandhi 18:6a4db94011d3 51
sahilmgandhi 18:6a4db94011d3 52 #if defined (OPAMP1) || defined (OPAMP2) || defined (OPAMP3) || defined (OPAMP4)
sahilmgandhi 18:6a4db94011d3 53
sahilmgandhi 18:6a4db94011d3 54 /** @addtogroup OPAMP_LL OPAMP
sahilmgandhi 18:6a4db94011d3 55 * @{
sahilmgandhi 18:6a4db94011d3 56 */
sahilmgandhi 18:6a4db94011d3 57
sahilmgandhi 18:6a4db94011d3 58 /* Private types -------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 59 /* Private variables ---------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 60 /* Private constants ---------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 61 /* Private macros ------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 62
sahilmgandhi 18:6a4db94011d3 63 /** @addtogroup OPAMP_LL_Private_Macros
sahilmgandhi 18:6a4db94011d3 64 * @{
sahilmgandhi 18:6a4db94011d3 65 */
sahilmgandhi 18:6a4db94011d3 66
sahilmgandhi 18:6a4db94011d3 67 /* Check of parameters for configuration of OPAMP hierarchical scope: */
sahilmgandhi 18:6a4db94011d3 68 /* OPAMP instance. */
sahilmgandhi 18:6a4db94011d3 69
sahilmgandhi 18:6a4db94011d3 70 #define IS_LL_OPAMP_FUNCTIONAL_MODE(__FUNCTIONAL_MODE__) \
sahilmgandhi 18:6a4db94011d3 71 ( ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_STANDALONE) \
sahilmgandhi 18:6a4db94011d3 72 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_FOLLOWER) \
sahilmgandhi 18:6a4db94011d3 73 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA) \
sahilmgandhi 18:6a4db94011d3 74 )
sahilmgandhi 18:6a4db94011d3 75
sahilmgandhi 18:6a4db94011d3 76 /* Note: Comparator non-inverting inputs parameters are the same on all */
sahilmgandhi 18:6a4db94011d3 77 /* OPAMP instances. */
sahilmgandhi 18:6a4db94011d3 78 /* However, comparator instance kept as macro parameter for */
sahilmgandhi 18:6a4db94011d3 79 /* compatibility with other STM32 families. */
sahilmgandhi 18:6a4db94011d3 80 #define IS_LL_OPAMP_INPUT_NONINVERTING(__OPAMPX__, __INPUT_NONINVERTING__) \
sahilmgandhi 18:6a4db94011d3 81 ( ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0) \
sahilmgandhi 18:6a4db94011d3 82 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO1) \
sahilmgandhi 18:6a4db94011d3 83 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO2) \
sahilmgandhi 18:6a4db94011d3 84 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO3) \
sahilmgandhi 18:6a4db94011d3 85 )
sahilmgandhi 18:6a4db94011d3 86
sahilmgandhi 18:6a4db94011d3 87 /* Note: Comparator non-inverting inputs parameters are the same on all */
sahilmgandhi 18:6a4db94011d3 88 /* OPAMP instances. */
sahilmgandhi 18:6a4db94011d3 89 /* However, comparator instance kept as macro parameter for */
sahilmgandhi 18:6a4db94011d3 90 /* compatibility with other STM32 families. */
sahilmgandhi 18:6a4db94011d3 91 #define IS_LL_OPAMP_INPUT_INVERTING(__OPAMPX__, __INPUT_INVERTING__) \
sahilmgandhi 18:6a4db94011d3 92 ( ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO0) \
sahilmgandhi 18:6a4db94011d3 93 || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO1) \
sahilmgandhi 18:6a4db94011d3 94 || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_CONNECT_NO) \
sahilmgandhi 18:6a4db94011d3 95 )
sahilmgandhi 18:6a4db94011d3 96
sahilmgandhi 18:6a4db94011d3 97 /**
sahilmgandhi 18:6a4db94011d3 98 * @}
sahilmgandhi 18:6a4db94011d3 99 */
sahilmgandhi 18:6a4db94011d3 100
sahilmgandhi 18:6a4db94011d3 101
sahilmgandhi 18:6a4db94011d3 102 /* Private function prototypes -----------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 103
sahilmgandhi 18:6a4db94011d3 104 /* Exported functions --------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 105 /** @addtogroup OPAMP_LL_Exported_Functions
sahilmgandhi 18:6a4db94011d3 106 * @{
sahilmgandhi 18:6a4db94011d3 107 */
sahilmgandhi 18:6a4db94011d3 108
sahilmgandhi 18:6a4db94011d3 109 /** @addtogroup OPAMP_LL_EF_Init
sahilmgandhi 18:6a4db94011d3 110 * @{
sahilmgandhi 18:6a4db94011d3 111 */
sahilmgandhi 18:6a4db94011d3 112
sahilmgandhi 18:6a4db94011d3 113 /**
sahilmgandhi 18:6a4db94011d3 114 * @brief De-initialize registers of the selected OPAMP instance
sahilmgandhi 18:6a4db94011d3 115 * to their default reset values.
sahilmgandhi 18:6a4db94011d3 116 * @note If comparator is locked, de-initialization by software is
sahilmgandhi 18:6a4db94011d3 117 * not possible.
sahilmgandhi 18:6a4db94011d3 118 * The only way to unlock the comparator is a device hardware reset.
sahilmgandhi 18:6a4db94011d3 119 * @param OPAMPx OPAMP instance
sahilmgandhi 18:6a4db94011d3 120 * @retval An ErrorStatus enumeration value:
sahilmgandhi 18:6a4db94011d3 121 * - SUCCESS: OPAMP registers are de-initialized
sahilmgandhi 18:6a4db94011d3 122 * - ERROR: OPAMP registers are not de-initialized
sahilmgandhi 18:6a4db94011d3 123 */
sahilmgandhi 18:6a4db94011d3 124 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef* OPAMPx)
sahilmgandhi 18:6a4db94011d3 125 {
sahilmgandhi 18:6a4db94011d3 126 ErrorStatus status = SUCCESS;
sahilmgandhi 18:6a4db94011d3 127
sahilmgandhi 18:6a4db94011d3 128 /* Check the parameters */
sahilmgandhi 18:6a4db94011d3 129 assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
sahilmgandhi 18:6a4db94011d3 130
sahilmgandhi 18:6a4db94011d3 131 /* Note: Hardware constraint (refer to description of this function): */
sahilmgandhi 18:6a4db94011d3 132 /* OPAMP instance must not be locked. */
sahilmgandhi 18:6a4db94011d3 133 if(LL_OPAMP_IsLocked(OPAMPx) == 0U)
sahilmgandhi 18:6a4db94011d3 134 {
sahilmgandhi 18:6a4db94011d3 135 LL_OPAMP_WriteReg(OPAMPx, CSR, 0x00000000U);
sahilmgandhi 18:6a4db94011d3 136 }
sahilmgandhi 18:6a4db94011d3 137 else
sahilmgandhi 18:6a4db94011d3 138 {
sahilmgandhi 18:6a4db94011d3 139 /* OPAMP instance is locked: de-initialization by software is */
sahilmgandhi 18:6a4db94011d3 140 /* not possible. */
sahilmgandhi 18:6a4db94011d3 141 /* The only way to unlock the OPAMP is a device hardware reset. */
sahilmgandhi 18:6a4db94011d3 142 status = ERROR;
sahilmgandhi 18:6a4db94011d3 143 }
sahilmgandhi 18:6a4db94011d3 144
sahilmgandhi 18:6a4db94011d3 145 return status;
sahilmgandhi 18:6a4db94011d3 146 }
sahilmgandhi 18:6a4db94011d3 147
sahilmgandhi 18:6a4db94011d3 148 /**
sahilmgandhi 18:6a4db94011d3 149 * @brief Initialize some features of OPAMP instance.
sahilmgandhi 18:6a4db94011d3 150 * @note This function reset bit of calibration mode to ensure
sahilmgandhi 18:6a4db94011d3 151 * to be in functional mode, in order to have OPAMP parameters
sahilmgandhi 18:6a4db94011d3 152 * (inputs selection, ...) set with the corresponding OPAMP mode
sahilmgandhi 18:6a4db94011d3 153 * to be effective.
sahilmgandhi 18:6a4db94011d3 154 * @param OPAMPx OPAMP instance
sahilmgandhi 18:6a4db94011d3 155 * @param OPAMP_InitStruct Pointer to a @ref LL_OPAMP_InitTypeDef structure
sahilmgandhi 18:6a4db94011d3 156 * @retval An ErrorStatus enumeration value:
sahilmgandhi 18:6a4db94011d3 157 * - SUCCESS: OPAMP registers are initialized
sahilmgandhi 18:6a4db94011d3 158 * - ERROR: OPAMP registers are not initialized
sahilmgandhi 18:6a4db94011d3 159 */
sahilmgandhi 18:6a4db94011d3 160 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
sahilmgandhi 18:6a4db94011d3 161 {
sahilmgandhi 18:6a4db94011d3 162 ErrorStatus status = SUCCESS;
sahilmgandhi 18:6a4db94011d3 163
sahilmgandhi 18:6a4db94011d3 164 /* Check the parameters */
sahilmgandhi 18:6a4db94011d3 165 assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
sahilmgandhi 18:6a4db94011d3 166 assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct->FunctionalMode));
sahilmgandhi 18:6a4db94011d3 167 assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMPx, OPAMP_InitStruct->InputNonInverting));
sahilmgandhi 18:6a4db94011d3 168
sahilmgandhi 18:6a4db94011d3 169 /* Note: OPAMP inverting input can be used with OPAMP in mode standalone */
sahilmgandhi 18:6a4db94011d3 170 /* or PGA with external capacitors for filtering circuit. */
sahilmgandhi 18:6a4db94011d3 171 /* Otherwise (OPAMP in mode follower), OPAMP inverting input is */
sahilmgandhi 18:6a4db94011d3 172 /* not used (not connected to GPIO pin). */
sahilmgandhi 18:6a4db94011d3 173 if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER)
sahilmgandhi 18:6a4db94011d3 174 {
sahilmgandhi 18:6a4db94011d3 175 assert_param(IS_LL_OPAMP_INPUT_INVERTING(OPAMPx, OPAMP_InitStruct->InputInverting));
sahilmgandhi 18:6a4db94011d3 176 }
sahilmgandhi 18:6a4db94011d3 177
sahilmgandhi 18:6a4db94011d3 178 /* Note: Hardware constraint (refer to description of this function): */
sahilmgandhi 18:6a4db94011d3 179 /* OPAMP instance must not be locked. */
sahilmgandhi 18:6a4db94011d3 180 if(LL_OPAMP_IsLocked(OPAMPx) == 0U)
sahilmgandhi 18:6a4db94011d3 181 {
sahilmgandhi 18:6a4db94011d3 182 /* Configuration of OPAMP instance : */
sahilmgandhi 18:6a4db94011d3 183 /* - Functional mode */
sahilmgandhi 18:6a4db94011d3 184 /* - Input non-inverting */
sahilmgandhi 18:6a4db94011d3 185 /* - Input inverting */
sahilmgandhi 18:6a4db94011d3 186 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode. */
sahilmgandhi 18:6a4db94011d3 187 if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER)
sahilmgandhi 18:6a4db94011d3 188 {
sahilmgandhi 18:6a4db94011d3 189 MODIFY_REG(OPAMPx->CSR,
sahilmgandhi 18:6a4db94011d3 190 OPAMP_CSR_CALON
sahilmgandhi 18:6a4db94011d3 191 | OPAMP_CSR_VMSEL
sahilmgandhi 18:6a4db94011d3 192 | OPAMP_CSR_VPSEL
sahilmgandhi 18:6a4db94011d3 193 ,
sahilmgandhi 18:6a4db94011d3 194 OPAMP_InitStruct->FunctionalMode
sahilmgandhi 18:6a4db94011d3 195 | OPAMP_InitStruct->InputNonInverting
sahilmgandhi 18:6a4db94011d3 196 | OPAMP_InitStruct->InputInverting
sahilmgandhi 18:6a4db94011d3 197 );
sahilmgandhi 18:6a4db94011d3 198 }
sahilmgandhi 18:6a4db94011d3 199 else
sahilmgandhi 18:6a4db94011d3 200 {
sahilmgandhi 18:6a4db94011d3 201 MODIFY_REG(OPAMPx->CSR,
sahilmgandhi 18:6a4db94011d3 202 OPAMP_CSR_CALON
sahilmgandhi 18:6a4db94011d3 203 | OPAMP_CSR_VMSEL
sahilmgandhi 18:6a4db94011d3 204 | OPAMP_CSR_VPSEL
sahilmgandhi 18:6a4db94011d3 205 ,
sahilmgandhi 18:6a4db94011d3 206 LL_OPAMP_MODE_FOLLOWER
sahilmgandhi 18:6a4db94011d3 207 | OPAMP_InitStruct->InputNonInverting
sahilmgandhi 18:6a4db94011d3 208 );
sahilmgandhi 18:6a4db94011d3 209 }
sahilmgandhi 18:6a4db94011d3 210 }
sahilmgandhi 18:6a4db94011d3 211 else
sahilmgandhi 18:6a4db94011d3 212 {
sahilmgandhi 18:6a4db94011d3 213 /* Initialization error: OPAMP instance is locked. */
sahilmgandhi 18:6a4db94011d3 214 status = ERROR;
sahilmgandhi 18:6a4db94011d3 215 }
sahilmgandhi 18:6a4db94011d3 216
sahilmgandhi 18:6a4db94011d3 217 return status;
sahilmgandhi 18:6a4db94011d3 218 }
sahilmgandhi 18:6a4db94011d3 219
sahilmgandhi 18:6a4db94011d3 220 /**
sahilmgandhi 18:6a4db94011d3 221 * @brief Set each @ref LL_OPAMP_InitTypeDef field to default value.
sahilmgandhi 18:6a4db94011d3 222 * @param OPAMP_InitStruct pointer to a @ref LL_OPAMP_InitTypeDef structure
sahilmgandhi 18:6a4db94011d3 223 * whose fields will be set to default values.
sahilmgandhi 18:6a4db94011d3 224 * @retval None
sahilmgandhi 18:6a4db94011d3 225 */
sahilmgandhi 18:6a4db94011d3 226 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
sahilmgandhi 18:6a4db94011d3 227 {
sahilmgandhi 18:6a4db94011d3 228 /* Set OPAMP_InitStruct fields to default values */
sahilmgandhi 18:6a4db94011d3 229 OPAMP_InitStruct->FunctionalMode = LL_OPAMP_MODE_FOLLOWER;
sahilmgandhi 18:6a4db94011d3 230 OPAMP_InitStruct->InputNonInverting = LL_OPAMP_INPUT_NONINVERT_IO0;
sahilmgandhi 18:6a4db94011d3 231 /* Note: Parameter discarded if OPAMP in functional mode follower, */
sahilmgandhi 18:6a4db94011d3 232 /* set anyway to its default value. */
sahilmgandhi 18:6a4db94011d3 233 OPAMP_InitStruct->InputInverting = LL_OPAMP_INPUT_INVERT_CONNECT_NO;
sahilmgandhi 18:6a4db94011d3 234 }
sahilmgandhi 18:6a4db94011d3 235
sahilmgandhi 18:6a4db94011d3 236 /**
sahilmgandhi 18:6a4db94011d3 237 * @}
sahilmgandhi 18:6a4db94011d3 238 */
sahilmgandhi 18:6a4db94011d3 239
sahilmgandhi 18:6a4db94011d3 240 /**
sahilmgandhi 18:6a4db94011d3 241 * @}
sahilmgandhi 18:6a4db94011d3 242 */
sahilmgandhi 18:6a4db94011d3 243
sahilmgandhi 18:6a4db94011d3 244 /**
sahilmgandhi 18:6a4db94011d3 245 * @}
sahilmgandhi 18:6a4db94011d3 246 */
sahilmgandhi 18:6a4db94011d3 247
sahilmgandhi 18:6a4db94011d3 248 #endif /* OPAMP1 || OPAMP2 || OPAMP3 || OPAMP4 */
sahilmgandhi 18:6a4db94011d3 249
sahilmgandhi 18:6a4db94011d3 250 /**
sahilmgandhi 18:6a4db94011d3 251 * @}
sahilmgandhi 18:6a4db94011d3 252 */
sahilmgandhi 18:6a4db94011d3 253
sahilmgandhi 18:6a4db94011d3 254 #endif /* USE_FULL_LL_DRIVER */
sahilmgandhi 18:6a4db94011d3 255
sahilmgandhi 18:6a4db94011d3 256 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/