TUKS MCU Introductory course / TUKS-COURSE-THERMOMETER

Fork of TUKS-COURSE-TIMER by TUKS MCU Introductory course

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_hal_opamp.h Source File

stm32l4xx_hal_opamp.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_opamp.h
00004   * @author  MCD Application Team
00005   * @version V1.5.1
00006   * @date    31-May-2016
00007   * @brief   Header file of OPAMP HAL module.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00012   *
00013   * Redistribution and use in source and binary forms, with or without modification,
00014   * are permitted provided that the following conditions are met:
00015   *   1. Redistributions of source code must retain the above copyright notice,
00016   *      this list of conditions and the following disclaimer.
00017   *   2. Redistributions in binary form must reproduce the above copyright notice,
00018   *      this list of conditions and the following disclaimer in the documentation
00019   *      and/or other materials provided with the distribution.
00020   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021   *      may be used to endorse or promote products derived from this software
00022   *      without specific prior written permission.
00023   *
00024   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034   *
00035   ******************************************************************************  
00036   */
00037 
00038 /* Define to prevent recursive inclusion -------------------------------------*/
00039 #ifndef __STM32L4xx_HAL_OPAMP_H
00040 #define __STM32L4xx_HAL_OPAMP_H
00041 
00042 #ifdef __cplusplus
00043  extern "C" {
00044 #endif
00045                   
00046 /* Includes ------------------------------------------------------------------*/
00047 #include "stm32l4xx_hal_def.h"
00048 
00049 /** @addtogroup STM32L4xx_HAL_Driver
00050   * @{
00051   */
00052 
00053 /** @addtogroup OPAMP
00054   * @{
00055   */ 
00056 
00057 /* Exported types ------------------------------------------------------------*/ 
00058 
00059 /** @defgroup OPAMP_Exported_Types OPAMP Exported Types
00060   * @{
00061   */
00062 
00063 /** 
00064   * @brief  OPAMP Init structure definition  
00065   */
00066   
00067 typedef struct
00068 {
00069   uint32_t PowerSupplyRange;            /*!< Specifies the power supply range: above or under 2.4V.
00070                                              This parameter must be a value of @ref OPAMP_PowerSupplyRange
00071                                              Caution: This parameter is common to all OPAMP instances: a modification of this parameter for the selected OPAMP impacts the other OPAMP instances. */
00072 
00073   uint32_t PowerMode;                   /*!< Specifies the power mode Normal or Low-Power.
00074                                              This parameter must be a value of @ref OPAMP_PowerMode */
00075   
00076   uint32_t Mode;                        /*!< Specifies the OPAMP mode
00077                                              This parameter must be a value of @ref OPAMP_Mode 
00078                                              mode is either Standalone, - Follower or PGA */
00079                                     
00080   uint32_t InvertingInput;              /*!< Specifies the inverting input in Standalone & PGA modes
00081                                                - In Standalone mode:   i.e. when mode is OPAMP_STANDALONE_MODE
00082                                                  & PGA mode:           i.e. when mode is OPAMP_PGA_MODE
00083                                                  This parameter must be a value of @ref OPAMP_InvertingInput 
00084                                                - In Follower mode    i.e. when mode is OPAMP_FOLLOWER_MODE
00085                                                  This parameter is Not Applicable */ 
00086 
00087   uint32_t NonInvertingInput;           /*!< Specifies the non inverting input of the opamp: 
00088                                              This parameter must be a value of @ref OPAMP_NonInvertingInput */                                   
00089   
00090   uint32_t PgaGain;                     /*!< Specifies the gain in PGA mode 
00091                                              i.e. when mode is OPAMP_PGA_MODE. 
00092                                              This parameter must be a value of @ref OPAMP_PgaGain (2, 4, 8 or 16 ) */
00093  
00094   uint32_t UserTrimming;                /*!< Specifies the trimming mode 
00095                                              This parameter must be a value of @ref OPAMP_UserTrimming 
00096                                              UserTrimming is either factory or user trimming.*/
00097                                                                                                                             
00098   uint32_t TrimmingValueP;              /*!< Specifies the offset trimming value (PMOS)
00099                                              i.e. when UserTrimming is OPAMP_TRIMMING_USER. 
00100                                              This parameter must be a number between Min_Data = 0 and Max_Data = 31 
00101                                              16 is typical default value */
00102                                         
00103   uint32_t TrimmingValueN;              /*!< Specifies the offset trimming value (NMOS)
00104                                              i.e. when UserTrimming is OPAMP_TRIMMING_USER. 
00105                                              This parameter must be a number between Min_Data = 0 and Max_Data = 31 
00106                                              16 is typical default value */
00107   
00108   uint32_t TrimmingValuePLowPower;      /*!< Specifies the offset trimming value (PMOS)
00109                                              i.e. when UserTrimming is OPAMP_TRIMMING_USER. 
00110                                              This parameter must be a number between Min_Data = 0 and Max_Data = 31  
00111                                              16 is typical default value */
00112 
00113   uint32_t TrimmingValueNLowPower;      /*!< Specifies the offset trimming value (NMOS)
00114                                              i.e. when UserTrimming is OPAMP_TRIMMING_USER. 
00115                                              This parameter must be a number between Min_Data = 0 and Max_Data = 31  
00116                                              16 is typical default value */
00117 
00118 }OPAMP_InitTypeDef;
00119 
00120 /** 
00121   * @brief  HAL State structures definition  
00122   */ 
00123 
00124 typedef enum
00125 {
00126   HAL_OPAMP_STATE_RESET               = 0x00000000, /*!< OPAMP is not yet Initialized          */
00127   
00128   HAL_OPAMP_STATE_READY               = 0x00000001, /*!< OPAMP is initialized and ready for use */
00129   HAL_OPAMP_STATE_CALIBBUSY           = 0x00000002, /*!< OPAMP is enabled in auto calibration mode */
00130  
00131   HAL_OPAMP_STATE_BUSY                = 0x00000004, /*!< OPAMP is enabled and running in normal mode */                                                                           
00132   HAL_OPAMP_STATE_BUSYLOCKED          = 0x00000005  /*!< OPAMP is locked
00133                                                          only system reset allows reconfiguring the opamp. */
00134     
00135 }HAL_OPAMP_StateTypeDef;
00136 
00137 /** 
00138   * @brief OPAMP Handle Structure definition
00139   */ 
00140 typedef struct
00141 {
00142   OPAMP_TypeDef       *Instance;                    /*!< OPAMP instance's registers base address   */
00143   OPAMP_InitTypeDef   Init;                         /*!< OPAMP required parameters */
00144   HAL_StatusTypeDef Status;                         /*!< OPAMP peripheral status   */
00145   HAL_LockTypeDef   Lock;                           /*!< Locking object          */
00146   __IO HAL_OPAMP_StateTypeDef  State;               /*!< OPAMP communication state */
00147   
00148 } OPAMP_HandleTypeDef;
00149 
00150 /** 
00151   * @brief HAl_OPAMP_TrimmingValueTypeDef definition 
00152   */ 
00153 
00154 typedef  uint32_t HAL_OPAMP_TrimmingValueTypeDef;
00155 
00156 /**
00157   * @}
00158   */
00159 
00160 /* Exported constants --------------------------------------------------------*/
00161 
00162 /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants
00163   * @{
00164   */      
00165 
00166 /** @defgroup OPAMP_Mode OPAMP Mode
00167   * @{
00168   */
00169 #define OPAMP_STANDALONE_MODE            ((uint32_t)0x00000000) /*!< standalone mode */
00170 #define OPAMP_PGA_MODE                   OPAMP_CSR_OPAMODE_1    /*!< PGA mode */
00171 #define OPAMP_FOLLOWER_MODE              OPAMP_CSR_OPAMODE      /*!< follower mode */
00172     
00173 /**
00174   * @}
00175   */                                        
00176                                                                              
00177 /** @defgroup OPAMP_NonInvertingInput OPAMP Non Inverting Input
00178   * @{
00179   */
00180 
00181 #define OPAMP_NONINVERTINGINPUT_IO0        ((uint32_t)0x00000000)  /*!< OPAMP non-inverting input connected to dedicated IO pin */
00182 #define OPAMP_NONINVERTINGINPUT_DAC_CH      OPAMP_CSR_VPSEL        /*!< OPAMP non-inverting input connected internally to DAC channel */
00183 
00184 /**
00185   * @}
00186   */
00187 
00188 /** @defgroup OPAMP_InvertingInput OPAMP Inverting Input
00189   * @{
00190   */
00191 
00192 #define OPAMP_INVERTINGINPUT_IO0              ((uint32_t)0x00000000)  /*!< OPAMP inverting input connected to dedicated IO pin low-leakage */
00193 #define OPAMP_INVERTINGINPUT_IO1              OPAMP_CSR_VMSEL_0       /*!< OPAMP inverting input connected to alternative IO pin available on some device packages */
00194 #define OPAMP_INVERTINGINPUT_CONNECT_NO       OPAMP_CSR_VMSEL_1       /*!< OPAMP inverting input not connected externally (PGA mode only) */
00195 
00196 /**
00197   * @}
00198   */
00199 
00200 /** @defgroup OPAMP_PgaGain OPAMP Pga Gain
00201   * @{
00202   */
00203 
00204 #define OPAMP_PGA_GAIN_2                ((uint32_t)0x00000000)                        /*!< PGA gain =  2 */
00205 #define OPAMP_PGA_GAIN_4                OPAMP_CSR_PGGAIN_0                            /*!< PGA gain =  4 */
00206 #define OPAMP_PGA_GAIN_8                OPAMP_CSR_PGGAIN_1                            /*!< PGA gain =  8 */
00207 #define OPAMP_PGA_GAIN_16              (OPAMP_CSR_PGGAIN_0 | OPAMP_CSR_PGGAIN_1)      /*!< PGA gain = 16 */
00208 
00209 /**
00210   * @}
00211   */
00212 
00213 /** @defgroup OPAMP_PowerMode OPAMP PowerMode
00214   * @{
00215   */
00216 #define OPAMP_POWERMODE_NORMAL        ((uint32_t)0x00000000)
00217 #define OPAMP_POWERMODE_LOWPOWER      OPAMP_CSR_OPALPM
00218 
00219 /**
00220   * @}
00221   */
00222 
00223 /** @defgroup OPAMP_PowerSupplyRange OPAMP PowerSupplyRange
00224   * @{
00225   */
00226 #define OPAMP_POWERSUPPLY_LOW          ((uint32_t)0x00000000)  /*!< Power supply range low (VDDA lower than 2.4V) */
00227 #define OPAMP_POWERSUPPLY_HIGH         OPAMP1_CSR_OPARANGE     /*!< Power supply range high (VDDA higher than 2.4V) */
00228 
00229 /**
00230   * @}
00231   */ 
00232 
00233 /** @defgroup OPAMP_UserTrimming OPAMP User Trimming
00234   * @{
00235   */
00236 #define OPAMP_TRIMMING_FACTORY        ((uint32_t)0x00000000)                          /*!< Factory trimming */
00237 #define OPAMP_TRIMMING_USER           OPAMP_CSR_USERTRIM                              /*!< User trimming */
00238 
00239 #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \
00240                                      ((TRIMMING) == OPAMP_TRIMMING_USER))
00241 /**
00242   * @}
00243   */
00244 
00245 /** @defgroup OPAMP_FactoryTrimming OPAMP Factory Trimming
00246   * @{
00247   */
00248 #define OPAMP_FACTORYTRIMMING_DUMMY    ((uint32_t)0xFFFFFFFF)                           /*!< Dummy value if trimming value could not be retrieved */
00249 
00250 #define OPAMP_FACTORYTRIMMING_N        ((uint32_t)0x00000000)                          /*!< Offset trimming N */
00251 #define OPAMP_FACTORYTRIMMING_P        ((uint32_t)0x00000001)                          /*!< Offset trimming P */
00252 
00253 /**
00254   * @}
00255   */           
00256 
00257  /**
00258   * @}
00259   */ 
00260 
00261 /* Private constants ---------------------------------------------------------*/
00262 /** @defgroup OPAMP_Private_Constants OPAMP Private Constants
00263   * @brief   OPAMP Private constants and defines
00264   * @{
00265   */
00266 
00267 /* NONINVERTING bit position in OTR & LPOTR */ 
00268 #define OPAMP_INPUT_NONINVERTING              ((uint32_t) 8) /*!< Non inverting input */  
00269 
00270 /* Offset trimming time: during calibration, minimum time needed between two  */
00271 /* steps to have 1 mV accuracy.                                               */
00272 /* Refer to datasheet, electrical characteristics: parameter tOFFTRIM Typ=1ms.*/
00273 /* Unit: ms.                                                                  */
00274 #define OPAMP_TRIMMING_DELAY               ((uint32_t) 1)
00275 
00276 /**
00277   * @}
00278   */
00279 
00280 /* Exported macros -----------------------------------------------------------*/
00281 /** @defgroup OPAMP_Exported_Macros OPAMP Exported Macros
00282   * @{
00283   */
00284 
00285 /** @brief Reset OPAMP handle state.
00286   * @param  __HANDLE__: OPAMP handle.
00287   * @retval None
00288   */
00289 #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET)
00290 
00291 /**
00292   * @}
00293   */ 
00294 
00295 /* Private macro -------------------------------------------------------------*/
00296 
00297 /** @defgroup OPAMP_Private_Macros OPAMP Private Macros
00298   * @{
00299   */
00300 
00301 #define IS_OPAMP_FUNCTIONAL_NORMALMODE(INPUT) (((INPUT) == OPAMP_STANDALONE_MODE) || \
00302                                                ((INPUT) == OPAMP_PGA_MODE) || \
00303                                                ((INPUT) == OPAMP_FOLLOWER_MODE))
00304 
00305 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx)
00306 #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \
00307                                                     ((INPUT) == OPAMP_INVERTINGINPUT_IO1))
00308 #endif
00309 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx)  || defined (STM32L442xx)  || defined (STM32L443xx)
00310 #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) ((INPUT) == OPAMP_INVERTINGINPUT_IO0)
00311 #endif
00312 
00313 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
00314                                             ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH))
00315 
00316 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx)
00317 #define IS_OPAMP_INVERTING_INPUT_PGA(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \
00318                                              ((INPUT) == OPAMP_INVERTINGINPUT_IO1)|| \
00319                                              ((INPUT) == OPAMP_INVERTINGINPUT_CONNECT_NO))
00320 #endif
00321 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx)  || defined (STM32L442xx)  || defined (STM32L443xx)
00322 #define IS_OPAMP_INVERTING_INPUT_PGA(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \
00323                                              ((INPUT) == OPAMP_INVERTINGINPUT_CONNECT_NO))
00324 #endif
00325 
00326 #define IS_OPAMP_PGA_GAIN(GAIN) (((GAIN) == OPAMP_PGA_GAIN_2) || \
00327                                  ((GAIN) == OPAMP_PGA_GAIN_4) || \
00328                                  ((GAIN) == OPAMP_PGA_GAIN_8) || \
00329                                  ((GAIN) == OPAMP_PGA_GAIN_16))
00330 
00331 #define IS_OPAMP_POWERMODE(TRIMMING) (((TRIMMING) == OPAMP_POWERMODE_NORMAL) || \
00332                                       ((TRIMMING) == OPAMP_POWERMODE_LOWPOWER) )
00333 
00334 #define IS_OPAMP_POWER_SUPPLY_RANGE(RANGE) (((RANGE) == OPAMP_POWERSUPPLY_LOW) || \
00335                                             ((RANGE) == OPAMP_POWERSUPPLY_HIGH)  )
00336 
00337 #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \
00338                                      ((TRIMMING) == OPAMP_TRIMMING_USER))
00339 
00340 
00341 #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1F)
00342 
00343 #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \
00344                                              ((TRIMMING) == OPAMP_FACTORYTRIMMING_P))
00345 
00346 /**
00347   * @}
00348   */ 
00349 
00350 /* Include OPAMP HAL Extended module */
00351 #include "stm32l4xx_hal_opamp_ex.h"
00352 
00353 /* Exported functions --------------------------------------------------------*/
00354 /** @addtogroup OPAMP_Exported_Functions
00355   * @{
00356   */
00357 
00358 /** @addtogroup OPAMP_Exported_Functions_Group1
00359   * @{
00360   */
00361 /* Initialization/de-initialization functions  **********************************/
00362 HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp);
00363 HAL_StatusTypeDef HAL_OPAMP_DeInit (OPAMP_HandleTypeDef *hopamp);
00364 void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp);
00365 void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp);
00366 /**
00367   * @}
00368   */
00369 
00370 /** @addtogroup OPAMP_Exported_Functions_Group2
00371   * @{
00372   */
00373 
00374 /* I/O operation functions  *****************************************************/
00375 HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp);
00376 HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp);
00377 HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp); 
00378 
00379 /**
00380   * @}
00381   */
00382 
00383 /** @addtogroup OPAMP_Exported_Functions_Group3
00384   * @{
00385   */
00386 
00387 /* Peripheral Control functions  ************************************************/
00388 HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp); 
00389 HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset);
00390 
00391 /**
00392   * @}
00393   */
00394 
00395 /** @addtogroup OPAMP_Exported_Functions_Group4
00396   * @{
00397   */
00398 
00399 /* Peripheral State functions  **************************************************/
00400 HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp);
00401 
00402 /**
00403   * @}
00404   */
00405 
00406 /**
00407   * @}
00408   */
00409 
00410 /**
00411   * @}
00412   */ 
00413 
00414 /**
00415   * @}
00416   */ 
00417 
00418 #ifdef __cplusplus
00419 }
00420 #endif
00421 
00422 #endif /* __STM32L4xx_HAL_OPAMP_H */
00423 
00424 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/