1 /** 2 ****************************************************************************** 3 * @file stm32l1xx_hal_opamp_ex.h 4 * @author MCD Application Team 5 * @brief Header file of OPAMP HAL Extension module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2017 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef STM32L1xx_HAL_OPAMP_EX_H 21 #define STM32L1xx_HAL_OPAMP_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #if defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L151xE) || defined (STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) || defined (STM32L162xC) || defined (STM32L152xC) || defined (STM32L151xC) 28 29 /* Includes ------------------------------------------------------------------*/ 30 #include "stm32l1xx_hal_def.h" 31 32 /** @addtogroup STM32L1xx_HAL_Driver 33 * @{ 34 */ 35 36 /** @addtogroup OPAMPEx 37 * @{ 38 */ 39 /* Exported types ------------------------------------------------------------*/ 40 /* Exported constants ---------------------------------------------------------*/ 41 /** @defgroup OPAMPEx_Exported_Constants OPAMPEx Exported Constants 42 * @{ 43 */ 44 #if defined (STM32L151xD) || defined (STM32L152xD) || defined (STM32L162xD) 45 #define OPAMP_CSR_OPAXPD_ALL \ 46 (OPAMP_CSR_OPA1PD | OPAMP_CSR_OPA2PD | OPAMP_CSR_OPA3PD) 47 48 #define OPAMP_CSR_OPAXCAL_L_ALL \ 49 (OPAMP_CSR_OPA1CAL_L | OPAMP_CSR_OPA2CAL_L | OPAMP_CSR_OPA3CAL_L) 50 51 #define OPAMP_CSR_OPAXCAL_H_ALL \ 52 (OPAMP_CSR_OPA1CAL_H | OPAMP_CSR_OPA2CAL_H | OPAMP_CSR_OPA3CAL_H) 53 54 #define OPAMP_CSR_ALL_SWITCHES_ALL_OPAMPS \ 55 (OPAMP_CSR_S3SEL1 | OPAMP_CSR_S4SEL1 | OPAMP_CSR_S5SEL1 | OPAMP_CSR_S6SEL1 | \ 56 OPAMP_CSR_ANAWSEL1 | \ 57 OPAMP_CSR_S3SEL2 | OPAMP_CSR_S4SEL2 | OPAMP_CSR_S5SEL2 | OPAMP_CSR_S6SEL2 | \ 58 OPAMP_CSR_ANAWSEL2 | OPAMP_CSR_S7SEL2 | \ 59 OPAMP_CSR_S3SEL3 | OPAMP_CSR_S4SEL3 | OPAMP_CSR_S5SEL3 | OPAMP_CSR_S6SEL3 | \ 60 OPAMP_CSR_ANAWSEL3 ) 61 #else 62 #define OPAMP_CSR_OPAXPD_ALL \ 63 (OPAMP_CSR_OPA1PD | OPAMP_CSR_OPA2PD) 64 65 #define OPAMP_CSR_OPAXCAL_L_ALL \ 66 (OPAMP_CSR_OPA1CAL_L | OPAMP_CSR_OPA2CAL_L) 67 68 #define OPAMP_CSR_OPAXCAL_H_ALL \ 69 (OPAMP_CSR_OPA1CAL_H | OPAMP_CSR_OPA2CAL_H) 70 71 #define OPAMP_CSR_ALL_SWITCHES_ALL_OPAMPS \ 72 (OPAMP_CSR_S3SEL1 | OPAMP_CSR_S4SEL1 | OPAMP_CSR_S5SEL1 | OPAMP_CSR_S6SEL1 | \ 73 OPAMP_CSR_ANAWSEL1 | \ 74 OPAMP_CSR_S3SEL2 | OPAMP_CSR_S4SEL2 | OPAMP_CSR_S5SEL2 | OPAMP_CSR_S6SEL2 | \ 75 OPAMP_CSR_ANAWSEL2 | OPAMP_CSR_S7SEL2 ) 76 #endif /* STM32L151xD || STM32L152xD || STM32L162xD */ 77 78 /** 79 * @} 80 */ 81 82 /* Exported macro ------------------------------------------------------------*/ 83 84 /** @defgroup OPAMPEx_Exported_Macro OPAMPEx Exported Macro 85 * @{ 86 */ 87 88 #if defined (STM32L151xD) || defined (STM32L152xD) || defined (STM32L162xD) 89 /** 90 * @brief Enable internal analog switch SW1 to connect OPAMP3 output to ADC 91 * switch matrix (ADC channel VCOMP, channel 26) and COMP1 non-inverting input 92 * (OPAMP3 available on STM32L1 devices Cat.4 only). 93 * @retval None 94 */ 95 #define __HAL_OPAMP_OPAMP3OUT_CONNECT_ADC_COMP1() __HAL_RI_SWITCH_COMP1_SW1_CLOSE() 96 97 /** 98 * @brief Disable internal analog switch SW1 to disconnect OPAMP3 output from 99 * ADC switch matrix (ADC channel VCOMP, channel 26) and COMP1 non-inverting 100 * input. 101 * @retval None 102 */ 103 #define __HAL_OPAMP_OPAMP3OUT_DISCONNECT_ADC_COMP1() __HAL_RI_SWITCH_COMP1_SW1_OPEN() 104 #endif /* STM32L151xD || STM32L152xD || STM32L162xD */ 105 106 /** 107 * @} 108 */ 109 110 /* Private macro -------------------------------------------------------------*/ 111 112 /** @defgroup OPAMPEx_Private_Macro OPAMPEx Private Macro 113 * @{ 114 */ 115 116 #if defined (STM32L151xD) || defined (STM32L152xD) || defined (STM32L162xD) 117 /** 118 * @brief Get the OPAMP instance in decimal number for further 119 * processing needs by HAL OPAMP driver functions. 120 * @param __HANDLE__: OPAMP handle 121 * @retval "0" for OPAMP1, "1" for OPAMP2, "2" for OPAMP3 122 */ 123 #define OPAMP_INSTANCE_DECIMAL(__HANDLE__) \ 124 ( ( ((__HANDLE__)->Instance == OPAMP1) \ 125 )? \ 126 ((uint32_t)0UL) \ 127 : \ 128 ( ( ((__HANDLE__)->Instance == OPAMP2) \ 129 )? \ 130 ((uint32_t)1UL) \ 131 : \ 132 ((uint32_t)2UL) \ 133 ) \ 134 ) 135 #else 136 /** 137 * @brief Get the OPAMP instance in decimal number for further 138 * processing needs by HAL OPAMP driver functions. 139 * @param __HANDLE__: OPAMP handle 140 * @retval "0" for OPAMP1, "1" for OPAMP2 141 */ 142 #define OPAMP_INSTANCE_DECIMAL(__HANDLE__) \ 143 ( ( ((__HANDLE__)->Instance == OPAMP1) \ 144 )? \ 145 ((uint32_t)0UL) \ 146 : \ 147 ((uint32_t)1UL) \ 148 ) 149 #endif /* STM32L151xD || STM32L152xD || STM32L162xD */ 150 151 #if defined (STM32L151xD) || defined (STM32L152xD) || defined (STM32L162xD) 152 153 /** 154 * @brief Check OPAMP non-inverting input in function of OPAMPx instance 155 * @param __HANDLE__: OPAMP handle 156 * @param INPUT: OPAMP non-inverting input 157 * @retval None 158 */ 159 #define IS_OPAMP_NONINVERTING_INPUT_CHECK_INSTANCE(__HANDLE__, INPUT) \ 160 ( ( ((__HANDLE__)->Instance == OPAMP1) \ 161 )? \ 162 ( \ 163 ((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \ 164 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH1) \ 165 ) \ 166 : \ 167 ( ( ((__HANDLE__)->Instance == OPAMP2) \ 168 )? \ 169 ( \ 170 ((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \ 171 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH1) || \ 172 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH2) \ 173 ) \ 174 : \ 175 ( \ 176 ((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \ 177 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH2) \ 178 ) \ 179 ) \ 180 ) 181 #else 182 /** 183 * @brief Check OPAMP non-inverting input in function of OPAMPx instance 184 * @param __HANDLE__: OPAMP handle 185 * @param INPUT: OPAMP non-inverting input 186 * @retval None 187 */ 188 #define IS_OPAMP_NONINVERTING_INPUT_CHECK_INSTANCE(__HANDLE__, INPUT) \ 189 ( ( ((__HANDLE__)->Instance == OPAMP1) \ 190 )? \ 191 ( \ 192 ((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \ 193 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH1) \ 194 ) \ 195 : \ 196 ( \ 197 ((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \ 198 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH1) || \ 199 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH2) \ 200 ) \ 201 ) 202 #endif /* STM32L151xD || STM32L152xD || STM32L162xD */ 203 204 /** 205 * @} 206 */ 207 208 /* Exported functions --------------------------------------------------------*/ 209 /** @addtogroup OPAMPEx_Exported_Functions 210 * @{ 211 */ 212 213 /* I/O operation functions *****************************************************/ 214 /** @defgroup OPAMPEx_Exported_Functions_Group1 Extended Input and Output operation functions 215 * @{ 216 */ 217 #if defined (STM32L151xD) || defined (STM32L152xD) || defined (STM32L162xD) 218 HAL_StatusTypeDef HAL_OPAMPEx_SelfCalibrateAll(OPAMP_HandleTypeDef *hopamp1, OPAMP_HandleTypeDef *hopamp2, OPAMP_HandleTypeDef *hopamp3); 219 #else 220 HAL_StatusTypeDef HAL_OPAMPEx_SelfCalibrateAll(OPAMP_HandleTypeDef *hopamp1, OPAMP_HandleTypeDef *hopamp2); 221 #endif /* STM32L151xD || STM32L152xD || STM32L162xD */ 222 /** 223 * @} 224 */ 225 /* Peripheral Control functions ************************************************/ 226 /** @addtogroup OPAMPEx_Exported_Functions_Group2 227 * @{ 228 */ 229 HAL_StatusTypeDef HAL_OPAMPEx_Unlock(OPAMP_HandleTypeDef *hopamp); 230 /** 231 * @} 232 */ 233 234 /** 235 * @} 236 */ 237 238 /** 239 * @} 240 */ 241 242 /** 243 * @} 244 */ 245 246 #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX || STM32L162xC || STM32L152xC || STM32L151xC */ 247 248 #ifdef __cplusplus 249 } 250 #endif 251 252 253 #endif /* STM32L1xx_HAL_OPAMP_EX_H */ 254 255