siva surendar / mbed-dev

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Oct 28 11:17:30 2016 +0100
Revision:
149:156823d33999
Parent:
targets/cmsis/TARGET_STM/TARGET_STM32L4/stm32l4xx_ll_opamp.c@144:ef7eb2e8f9f7
This updates the lib to the mbed lib v128

NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.

Who changed what in which revision?

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