Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of TUKS-COURSE-TIMER by
stm32l4xx_ll_comp.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_ll_comp.c 00004 * @author MCD Application Team 00005 * @version V1.5.1 00006 * @date 31-May-2016 00007 * @brief COMP LL module driver 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© 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 #if defined(USE_FULL_LL_DRIVER) 00038 00039 /* Includes ------------------------------------------------------------------*/ 00040 #include "stm32l4xx_ll_comp.h" 00041 00042 #ifdef USE_FULL_ASSERT 00043 #include "stm32_assert.h" 00044 #else 00045 #define assert_param(expr) ((void)0U) 00046 #endif 00047 00048 /** @addtogroup STM32L4xx_LL_Driver 00049 * @{ 00050 */ 00051 00052 #if defined (COMP1) || defined (COMP2) 00053 00054 /** @addtogroup COMP_LL COMP 00055 * @{ 00056 */ 00057 00058 /* Private types -------------------------------------------------------------*/ 00059 /* Private variables ---------------------------------------------------------*/ 00060 /* Private constants ---------------------------------------------------------*/ 00061 /* Private macros ------------------------------------------------------------*/ 00062 00063 /** @addtogroup COMP_LL_Private_Macros 00064 * @{ 00065 */ 00066 00067 /* Check of parameters for configuration of COMP hierarchical scope: */ 00068 /* COMP instance. */ 00069 00070 #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \ 00071 ( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \ 00072 || ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \ 00073 || ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \ 00074 ) 00075 00076 /* Note: On this STM32 serie, comparator input plus parameters are */ 00077 /* the same on all COMP instances. */ 00078 /* However, comparator instance kept as macro parameter for */ 00079 /* compatibility with other STM32 families. */ 00080 #if defined(COMP_CSR_INPSEL_1) 00081 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \ 00082 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \ 00083 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \ 00084 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO3) \ 00085 ) 00086 #else 00087 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \ 00088 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \ 00089 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \ 00090 ) 00091 #endif 00092 00093 /* Note: On this STM32 serie, comparator input minus parameters are */ 00094 /* the same on all COMP instances. */ 00095 /* However, comparator instance kept as macro parameter for */ 00096 /* compatibility with other STM32 families. */ 00097 #if defined(COMP_CSR_INMESEL_1) 00098 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \ 00099 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \ 00100 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \ 00101 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \ 00102 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \ 00103 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \ 00104 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \ 00105 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \ 00106 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \ 00107 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \ 00108 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \ 00109 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO5) \ 00110 ) 00111 #else 00112 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \ 00113 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \ 00114 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \ 00115 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \ 00116 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \ 00117 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \ 00118 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \ 00119 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \ 00120 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \ 00121 ) 00122 #endif 00123 00124 #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \ 00125 ( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \ 00126 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \ 00127 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \ 00128 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \ 00129 ) 00130 00131 #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \ 00132 ( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \ 00133 || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \ 00134 ) 00135 00136 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__OUTPUT_BLANKING_SOURCE__) \ 00137 ( ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \ 00138 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1) \ 00139 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1) \ 00140 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1) \ 00141 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2) \ 00142 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2) \ 00143 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2) \ 00144 ) 00145 00146 /** 00147 * @} 00148 */ 00149 00150 00151 /* Private function prototypes -----------------------------------------------*/ 00152 00153 /* Exported functions --------------------------------------------------------*/ 00154 /** @addtogroup COMP_LL_Exported_Functions 00155 * @{ 00156 */ 00157 00158 /** @addtogroup COMP_LL_EF_Init 00159 * @{ 00160 */ 00161 00162 /** 00163 * @brief De-initialize registers of the selected COMP instance 00164 * to their default reset values. 00165 * @note If comparator is locked, de-initialization by software is 00166 * not possible. 00167 * The only way to unlock the comparator is a device hardware reset. 00168 * @param COMPx COMP instance 00169 * @retval An ErrorStatus enumeration value: 00170 * - SUCCESS: COMP registers are de-initialized 00171 * - ERROR: COMP registers are not de-initialized 00172 */ 00173 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx) 00174 { 00175 ErrorStatus status = SUCCESS; 00176 00177 /* Check the parameters */ 00178 assert_param(IS_COMP_ALL_INSTANCE(COMPx)); 00179 00180 /* Note: Hardware constraint (refer to description of this function): */ 00181 /* COMP instance must not be locked. */ 00182 if(LL_COMP_IsLocked(COMPx) == 0U) 00183 { 00184 LL_COMP_WriteReg(COMPx, CSR, 0x00000000U); 00185 00186 } 00187 else 00188 { 00189 /* Comparator instance is locked: de-initialization by software is */ 00190 /* not possible. */ 00191 /* The only way to unlock the comparator is a device hardware reset. */ 00192 status = ERROR; 00193 } 00194 00195 return status; 00196 } 00197 00198 /** 00199 * @brief Initialize some features of COMP instance. 00200 * @note This function configures features of the selected COMP instance. 00201 * Some features are also available at scope COMP common instance 00202 * (common to several COMP instances). 00203 * Refer to functions having argument "COMPxy_COMMON" as parameter. 00204 * @param COMPx COMP instance 00205 * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure 00206 * @retval An ErrorStatus enumeration value: 00207 * - SUCCESS: COMP registers are initialized 00208 * - ERROR: COMP registers are not initialized 00209 */ 00210 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct) 00211 { 00212 ErrorStatus status = SUCCESS; 00213 00214 /* Check the parameters */ 00215 assert_param(IS_COMP_ALL_INSTANCE(COMPx)); 00216 assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct->PowerMode )); 00217 assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus )); 00218 assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus )); 00219 assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis )); 00220 assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity )); 00221 assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMP_InitStruct->OutputBlankingSource )); 00222 00223 /* Note: Hardware constraint (refer to description of this function) */ 00224 /* COMP instance must not be locked. */ 00225 if(LL_COMP_IsLocked(COMPx) == 0U) 00226 { 00227 /* Configuration of comparator instance : */ 00228 /* - PowerMode */ 00229 /* - InputPlus */ 00230 /* - InputMinus */ 00231 /* - InputHysteresis */ 00232 /* - OutputPolarity */ 00233 /* - OutputBlankingSource */ 00234 #if defined(COMP_CSR_INMESEL_1) 00235 MODIFY_REG(COMPx->CSR, 00236 COMP_CSR_PWRMODE 00237 | COMP_CSR_INPSEL 00238 | COMP_CSR_SCALEN 00239 | COMP_CSR_BRGEN 00240 | COMP_CSR_INMESEL 00241 | COMP_CSR_INMSEL 00242 | COMP_CSR_HYST 00243 | COMP_CSR_POLARITY 00244 | COMP_CSR_BLANKING 00245 , 00246 COMP_InitStruct->PowerMode 00247 | COMP_InitStruct->InputPlus 00248 | COMP_InitStruct->InputMinus 00249 | COMP_InitStruct->InputHysteresis 00250 | COMP_InitStruct->OutputPolarity 00251 | COMP_InitStruct->OutputBlankingSource 00252 ); 00253 #else 00254 MODIFY_REG(COMPx->CSR, 00255 COMP_CSR_PWRMODE 00256 | COMP_CSR_INPSEL 00257 | COMP_CSR_SCALEN 00258 | COMP_CSR_BRGEN 00259 | COMP_CSR_INMSEL 00260 | COMP_CSR_HYST 00261 | COMP_CSR_POLARITY 00262 | COMP_CSR_BLANKING 00263 , 00264 COMP_InitStruct->PowerMode 00265 | COMP_InitStruct->InputPlus 00266 | COMP_InitStruct->InputMinus 00267 | COMP_InitStruct->InputHysteresis 00268 | COMP_InitStruct->OutputPolarity 00269 | COMP_InitStruct->OutputBlankingSource 00270 ); 00271 #endif 00272 00273 } 00274 else 00275 { 00276 /* Initialization error: COMP instance is locked. */ 00277 status = ERROR; 00278 } 00279 00280 return status; 00281 } 00282 00283 /** 00284 * @brief Set each @ref LL_COMP_InitTypeDef field to default value. 00285 * @param COMP_InitStruct: pointer to a @ref LL_COMP_InitTypeDef structure 00286 * whose fields will be set to default values. 00287 * @retval None 00288 */ 00289 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct) 00290 { 00291 /* Set COMP_InitStruct fields to default values */ 00292 COMP_InitStruct->PowerMode = LL_COMP_POWERMODE_ULTRALOWPOWER; 00293 COMP_InitStruct->InputPlus = LL_COMP_INPUT_PLUS_IO1; 00294 COMP_InitStruct->InputMinus = LL_COMP_INPUT_MINUS_VREFINT; 00295 COMP_InitStruct->InputHysteresis = LL_COMP_HYSTERESIS_NONE; 00296 COMP_InitStruct->OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED; 00297 COMP_InitStruct->OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE; 00298 } 00299 00300 /** 00301 * @} 00302 */ 00303 00304 /** 00305 * @} 00306 */ 00307 00308 /** 00309 * @} 00310 */ 00311 00312 #endif /* COMP1 || COMP2 */ 00313 00314 /** 00315 * @} 00316 */ 00317 00318 #endif /* USE_FULL_LL_DRIVER */ 00319 00320 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 17:38:50 by
