TUKS MCU Introductory course / TUKS-COURSE-TIMER
Committer:
elmot
Date:
Fri Feb 24 21:13:56 2017 +0000
Revision:
1:d0dfbce63a89
Ready-to-copy

Who changed what in which revision?

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