STM8L15x Standard Peripherals Drivers
|
stm8l15x_comp.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm8l15x_comp.c 00004 * @author MCD Application Team 00005 * @version V1.5.0 00006 * @date 13-May-2011 00007 * @brief This file provides firmware functions to manage the following 00008 * functionalities of the comparators (COMP1 and COMP2) peripheral: 00009 * - Comparators configuration 00010 * - Window mode control 00011 * - Internal Reference Voltage (VREFINT) output 00012 * - Comparator channels trigger configuration 00013 * - Interrupts and flags management 00014 * 00015 * @verbatim 00016 * 00017 * =================================================================== 00018 * How to use this driver 00019 * =================================================================== 00020 * 1- Enable comparators clock using CLK_PeripheralClockConfig(CLK_Peripheral_COMP, ENABLE); 00021 * 00022 * When using COMP1: 00023 * 2- Connect internal reference voltage to COMP1 inverting input 00024 * using COMP_VrefintToCOMP1Connect() 00025 * 3- Close the analog switch number 14 using SYSCFG_RIAnalogSwitchConfig() 00026 * 4- Close the analog switch that corresponds to the pin to be used as 00027 * non inverting input using SYSCFG_RIAnalogSwitchConfig() 00028 * 5- Close the I/O switch of the pin to be used as non inverting input 00029 * using SYSCFG_RIIOSwitchConfig() 00030 * 6- Configure the event detection using COMP_EdgeConfig() 00031 * 00032 * When using COMP2: 00033 * 2- Select the COMP2 inverting input, configure the speed and COMP2 00034 * output redirection using COMP_Init() 00035 * If the inverting input is an external pin, close the I/O channel 00036 * switch using SYSCFG_RIIOSwitchConfig() 00037 * 3- Close I/O Switch that corresponds to the selected pin as 00038 * comparator 2 non inverting input using SYSCFG_RIIOSwitchConfig() 00039 * 4- Configure the event detection using COMP_EdgeConfig() 00040 * 00041 * @note 00042 * 1- COMP1 comparator and ADC can't be used at the same time since 00043 * they share the same ADC switch matrix (analog switches). 00044 * 00045 * 2- When an I/O is used as comparator input, the corresponding GPIO 00046 * registers should be configured in input floating. 00047 * 00048 * 3- Comparators outputs (CMP1OUT and CMP2OUT) are not mapped on 00049 * GPIO pin. They are only internal. 00050 * To get the comparator output level, use COMP_GetOutputLevel() function 00051 * @endverbatim 00052 ****************************************************************************** 00053 * @attention 00054 * 00055 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 00056 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 00057 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 00058 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 00059 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 00060 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 00061 * 00062 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2> 00063 ****************************************************************************** 00064 */ 00065 00066 /* Includes ------------------------------------------------------------------*/ 00067 #include "stm8l15x_comp.h" 00068 00069 /** @addtogroup STM8L15x_StdPeriph_Driver 00070 * @{ 00071 */ 00072 00073 /** @defgroup COMP 00074 * @brief COMP driver modules 00075 * @{ 00076 */ 00077 /* Private typedef -----------------------------------------------------------*/ 00078 /* Private define ------------------------------------------------------------*/ 00079 /* Private macro -------------------------------------------------------------*/ 00080 /* Private variables ---------------------------------------------------------*/ 00081 /* Private function prototypes -----------------------------------------------*/ 00082 /* Private functions ---------------------------------------------------------*/ 00083 00084 /** @defgroup COMP_Private_Functions 00085 * @{ 00086 */ 00087 00088 /** @defgroup COMP_Group1 Initialization and Configuration functions 00089 * @brief Initialization and Configuration functions 00090 * 00091 @verbatim 00092 =============================================================================== 00093 Initialization and Configuration functions 00094 =============================================================================== 00095 00096 @endverbatim 00097 * @{ 00098 */ 00099 00100 /** 00101 * @brief Deinitializes the COMPx peripheral registers to their default reset values. 00102 * @param None. 00103 * @retval None. 00104 */ 00105 void COMP_DeInit(void) 00106 { 00107 /* Set COMP->CSR1 to reset value 0x00 */ 00108 COMP->CSR1 = (uint8_t) COMP_CSR1_RESET_VALUE; 00109 00110 /* Set COMP->CSR2 to reset value 0x00 */ 00111 COMP->CSR2 = (uint8_t) COMP_CSR2_RESET_VALUE; 00112 00113 /* Set COMP->CSR3 to reset value 0xC0 */ 00114 COMP->CSR3 = (uint8_t) COMP_CSR3_RESET_VALUE; 00115 00116 /* Set COMP->CSR4 to reset value 0x00 */ 00117 COMP->CSR4 = (uint8_t) COMP_CSR4_RESET_VALUE; 00118 00119 /* Set COMP->CSR5 to reset value 0x00 */ 00120 COMP->CSR5 = (uint8_t) COMP_CSR5_RESET_VALUE; 00121 } 00122 00123 /** 00124 * @brief Initializes the comparator inverting input, output and speed. 00125 * @note This function configures only COMP2. 00126 * @param COMP_InvertingInput : selects the comparator inverting input. 00127 * This parameter can be one of the following values: 00128 * @arg COMP_InvertingInput_IO: Input/Output on comparator inverting input enable 00129 * @arg COMP_InvertingInput_VREFINT: VREFINT on comparator inverting input enable 00130 * @arg COMP_InvertingInput_3_4VREFINT: 3/4 VREFINT on comparator inverting input enable 00131 * @arg COMP_InvertingInput_1_2VREFINT: 1/2 VREFINT on comparator inverting input enable 00132 * @arg COMP_InvertingInput_1_4VREFINT: 1/4 VREFINT on comparator inverting input enable 00133 * @arg COMP_InvertingInput_DAC1: DAC1 output on comparator inverting input enable 00134 * @arg COMP_InvertingInput_DAC2: DAC2 output on comparator inverting input enable 00135 * @param COMP_OutputSelect : selects the comparator output 00136 * This parameter can be one of the following values: 00137 * @arg COMP_OutputSelect_TIM2IC2: COMP2 output connected to TIM2 Input Capture 2 00138 * @arg COMP_OutputSelect_TIM3IC2: COMP2 output connected to TIM3 Input Capture 2 00139 * @arg COMP_OutputSelect_TIM1BRK: COMP2 output connected to TIM1 Break Input 00140 * @arg COMP_OutputSelect_TIM1OCREFCLR: COMP2 output connected to TIM1 OCREF Clear 00141 * @param COMP_Speed selects the comparator speed 00142 * This parameter can be one of the following values: 00143 * @arg COMP_Speed_Slow: Comparator speed: slow 00144 * @arg COMP_Speed_Fast: Comparator speed: fast 00145 * @retval None. 00146 */ 00147 void COMP_Init(COMP_InvertingInput_Typedef COMP_InvertingInput, 00148 COMP_OutputSelect_Typedef COMP_OutputSelect, COMP_Speed_TypeDef COMP_Speed) 00149 { 00150 /* Check the parameters */ 00151 assert_param(IS_COMP_INVERTING_INPUT(COMP_InvertingInput)); 00152 assert_param(IS_COMP_OUTPUT(COMP_OutputSelect)); 00153 assert_param(IS_COMP_SPEED(COMP_Speed)); 00154 00155 /* Reset the INSEL[2:0] bits in CSR3 register */ 00156 COMP->CSR3 &= (uint8_t) (~COMP_CSR3_INSEL); 00157 /* Select the comparator inverting input */ 00158 COMP->CSR3 |= (uint8_t) COMP_InvertingInput; 00159 00160 /* Reset the OUTSEL[1:0] bits in CSR3 register */ 00161 COMP->CSR3 &= (uint8_t) (~COMP_CSR3_OUTSEL); 00162 /* Redirect the comparator output */ 00163 COMP->CSR3 |= (uint8_t) COMP_OutputSelect; 00164 00165 /* Reset the comparator speed bit */ 00166 COMP->CSR2 &= (uint8_t) (~COMP_CSR2_SPEED); 00167 /* Select the comparator speed */ 00168 COMP->CSR2 |= (uint8_t) COMP_Speed; 00169 } 00170 00171 /** 00172 * @brief Enables or disables connection between VREFINT and COMP1 inverting input. 00173 * @param NewState new state of the VREFINT connection to COMP1 inverting input. 00174 * This parameter can be ENABLE or DISABLE. 00175 * @retval None 00176 */ 00177 void COMP_VrefintToCOMP1Connect(FunctionalState NewState) 00178 { 00179 /* Check the parameters */ 00180 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00181 00182 if (NewState != DISABLE) 00183 { 00184 /* Enable the comparator */ 00185 COMP->CSR3 |= COMP_CSR3_VREFEN; 00186 } 00187 else 00188 { 00189 /* Disable the comparator */ 00190 COMP->CSR3 &= (uint8_t)(~COMP_CSR3_VREFEN); 00191 } 00192 } 00193 00194 /** 00195 * @brief Configures the COMP edge detection. 00196 * @param COMP_Selection: selects the comparator. 00197 * This parameter can be one of the following values: 00198 * @arg COMP_Selection_COMP1: Selection of Comparator 1 00199 * @arg COMP_Selection_COMP2: Selection of Comparator 2 00200 * @param COMP_Edge: This parameter can be one of the following values: 00201 * @arg COMP_Edge_Falling: Falling edge selection 00202 * @arg COMP_Edge_Rising: Rising edge selection 00203 * @arg COMP_Edge_Rising_Falling: Rising and Falling edge selection 00204 * @retval None. 00205 */ 00206 void COMP_EdgeConfig(COMP_Selection_TypeDef COMP_Selection, COMP_Edge_TypeDef COMP_Edge) 00207 { 00208 /* Check the parameters */ 00209 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection)); 00210 assert_param(IS_COMP_EDGE(COMP_Edge)); 00211 00212 /* Check if comparator 1 is selected */ 00213 if (COMP_Selection == COMP_Selection_COMP1) 00214 { 00215 /* Reset the comparator 1 edge control bits */ 00216 COMP->CSR1 &= (uint8_t) (~COMP_CSR1_CMP1); 00217 00218 /* Select the edge detection of comparator 1 output */ 00219 COMP->CSR1 |= (uint8_t) COMP_Edge; 00220 } 00221 /* The comparator 2 is selected */ 00222 else 00223 { 00224 /* Reset the comparator 2 edge control bits */ 00225 COMP->CSR2 &= (uint8_t) (~COMP_CSR2_CMP2); 00226 00227 /* Select the edge detection of comparator 2 output */ 00228 COMP->CSR2 |= (uint8_t) COMP_Edge; 00229 } 00230 } 00231 00232 /** 00233 * @brief Returns the output level of the comparator. 00234 * @note Comparators outputs aren't available on GPIO (outputs levels are 00235 * only internal). 00236 * @param COMP_Selection: selects the comparator. 00237 * This parameter can be one of the following values: 00238 * @arg COMP_Selection_COMP1: Selection of Comparator 1 00239 * @arg COMP_Selection_COMP2: Selection of Comparator 2 00240 * @retval Returns the comparator output level 00241 * This value can be one of the following: 00242 * - COMP_OutputLevel_Low: Comparator output level is low 00243 * - COMP_OutputLevel_High: Comparator output level is high 00244 */ 00245 COMP_OutputLevel_TypeDef COMP_GetOutputLevel(COMP_Selection_TypeDef COMP_Selection) 00246 { 00247 uint8_t compout; 00248 00249 /* Check the parameters */ 00250 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection)); 00251 00252 /* Check if Comparator 1 is selected */ 00253 if (COMP_Selection == COMP_Selection_COMP1) 00254 { 00255 /* Check if comparator 1 output level is high */ 00256 if ((COMP->CSR1 & COMP_CSR1_CMP1OUT) != (uint8_t) RESET) 00257 { 00258 /* Get Comparator 1 output level */ 00259 compout = (COMP_OutputLevel_TypeDef) COMP_OutputLevel_High; 00260 } 00261 /* comparator 1 output level is low */ 00262 else 00263 { 00264 /* Get Comparator 1 output level */ 00265 compout = (COMP_OutputLevel_TypeDef) COMP_OutputLevel_Low; 00266 } 00267 } 00268 /* Comparator 2 is selected */ 00269 else 00270 { 00271 /* Check if comparator 2 output level is high */ 00272 if ((COMP->CSR2 & COMP_CSR2_CMP2OUT) != (uint8_t) RESET) 00273 { 00274 /* Get Comparator output level */ 00275 compout = (COMP_OutputLevel_TypeDef) COMP_OutputLevel_High; 00276 } 00277 /* comparator 2 output level is low */ 00278 else 00279 { 00280 /* Get Comparator 2 output level */ 00281 compout = (COMP_OutputLevel_TypeDef) COMP_OutputLevel_Low; 00282 } 00283 } 00284 00285 /* Return the comparator output level */ 00286 return (COMP_OutputLevel_TypeDef)(compout); 00287 } 00288 00289 /** 00290 * @} 00291 */ 00292 00293 /** @defgroup COMP_Group2 Window mode control function 00294 * @brief Window mode control function 00295 * 00296 @verbatim 00297 =============================================================================== 00298 Window mode control function 00299 =============================================================================== 00300 00301 In window mode: 00302 - COMP1 inverting input is fixed to VREFINT defining the first 00303 threshold 00304 - COMP2 inverting input is configurable (DAC_OUT1, VREFINT sub-multiples, ...) 00305 defining the second threshold 00306 - COMP1 and COMP2 non inverting inputs are connected together. 00307 00308 @endverbatim 00309 * @{ 00310 */ 00311 00312 /** 00313 * @brief Enables or disables the window mode. 00314 * @param NewState new state of the window mode. 00315 * This parameter can be ENABLE or DISABLE. 00316 * @retval None 00317 */ 00318 void COMP_WindowCmd(FunctionalState NewState) 00319 { 00320 /* Check the parameters */ 00321 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00322 00323 if (NewState != DISABLE) 00324 { 00325 /* Enable the window mode */ 00326 COMP->CSR3 |= (uint8_t) COMP_CSR3_WNDWE; 00327 } 00328 else 00329 { 00330 /* Disable the window mode */ 00331 COMP->CSR3 &= (uint8_t)(~COMP_CSR3_WNDWE); 00332 } 00333 } 00334 /** 00335 * @} 00336 */ 00337 00338 /** @defgroup COMP_Group3 Internal Reference Voltage output function 00339 * @brief Internal Reference Voltage (VREFINT) output function 00340 * 00341 @verbatim 00342 =============================================================================== 00343 Internal Reference Voltage (VREFINT) output function 00344 =============================================================================== 00345 00346 @endverbatim 00347 * @{ 00348 */ 00349 00350 /** 00351 * @brief Enables or disables the output of the internal reference voltage. 00352 * @param NewState : new state of the Vrefint output. 00353 * This parameter can be: ENABLE or DISABLE. 00354 * @retval None 00355 */ 00356 void COMP_VrefintOutputCmd(FunctionalState NewState) 00357 { 00358 /* Check the parameters */ 00359 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00360 00361 if (NewState != DISABLE) 00362 { 00363 /* Enable the output of internal reference voltage */ 00364 COMP->CSR3 |= (uint8_t) COMP_CSR3_VREFOUTEN; 00365 } 00366 else 00367 { 00368 /* Disable the output of internal reference voltage */ 00369 COMP->CSR3 &= (uint8_t) (~COMP_CSR3_VREFOUTEN); 00370 } 00371 } 00372 00373 /** 00374 * @} 00375 */ 00376 00377 /** @defgroup COMP_Group4 Comparator channels trigger configuration 00378 * @brief Comparator channels trigger configuration 00379 * 00380 @verbatim 00381 =============================================================================== 00382 Comparator channels trigger configuration 00383 =============================================================================== 00384 00385 @endverbatim 00386 * @{ 00387 */ 00388 00389 /** 00390 * @brief Enables or disables the schmitt trigger. 00391 * @param NewState : new state of the schmitt trigger. 00392 * This parameter can be: ENABLE or DISABLE. 00393 * @retval None 00394 */ 00395 void COMP_SchmittTriggerCmd(FunctionalState NewState) 00396 { 00397 /* Check the parameters */ 00398 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00399 00400 if (NewState != DISABLE) 00401 { 00402 /* Enable Schmitt trigger on Input Output switches Channels */ 00403 COMP->CSR1 |= (uint8_t) COMP_CSR1_STE; 00404 } 00405 else 00406 { 00407 /* Enable Schmitt trigger on Input Output switches Channels */ 00408 COMP->CSR1 &= (uint8_t) (~COMP_CSR1_STE); 00409 } 00410 } 00411 00412 /** 00413 * @brief Enables or disables trigger on the specified input/output group. 00414 * @param COMP_TriggerGroup : specifies the input/output group 00415 * This parameter can be one of the following values: 00416 * @arg COMP_TriggerGroup_InvertingInput: Trigger on comparator 2 inverting input 00417 * @arg COMP_TriggerGroup_NonInvertingInput: Trigger on comparator 2 non inverting input 00418 * @arg COMP_TriggerGroup_VREFINTOutput: Trigger on VREFINT output 00419 * @arg COMP_TriggerGroup_DACOutput: Trigger on DAC output 00420 * @param COMP_TriggerPin : specifies the pin(s) within the input/output group 00421 * This parameter can be one of the following values: 00422 * @arg COMP_TriggerPin_0: Trigger Pin 0 00423 * @arg COMP_TriggerPin_0: Trigger Pin 1 00424 * @arg COMP_TriggerPin_0: Trigger Pin 2 00425 * @param NewState : enable or disable the trigger on the selected pin(s) 00426 * This parameter can be: ENABLE or DISABLE. 00427 * @retval None 00428 */ 00429 void COMP_TriggerConfig(COMP_TriggerGroup_TypeDef COMP_TriggerGroup, 00430 COMP_TriggerPin_TypeDef COMP_TriggerPin, 00431 FunctionalState NewState) 00432 { 00433 /* Check the parameters */ 00434 assert_param(IS_COMP_TRIGGERGROUP(COMP_TriggerGroup)); 00435 assert_param(IS_COMP_TRIGGERPIN(COMP_TriggerPin)); 00436 00437 switch (COMP_TriggerGroup) 00438 { 00439 case COMP_TriggerGroup_InvertingInput: 00440 00441 if (NewState != DISABLE) 00442 { 00443 COMP->CSR4 &= (uint8_t) ~COMP_TriggerPin; 00444 } 00445 else 00446 { 00447 COMP->CSR4 |= (uint8_t) COMP_TriggerPin; 00448 } 00449 break; 00450 00451 case COMP_TriggerGroup_NonInvertingInput: 00452 if (NewState != DISABLE) 00453 { 00454 COMP->CSR4 &= (uint8_t) ~((uint8_t)(COMP_TriggerPin << 3)); 00455 } 00456 else 00457 { 00458 COMP->CSR4 |= (uint8_t) (COMP_TriggerPin << 3); 00459 } 00460 break; 00461 00462 case COMP_TriggerGroup_VREFINTOutput: 00463 if (NewState != DISABLE) 00464 { 00465 COMP->CSR5 &= (uint8_t) ~COMP_TriggerPin; 00466 } 00467 else 00468 { 00469 COMP->CSR5 |= (uint8_t) COMP_TriggerPin; 00470 } 00471 break; 00472 00473 case COMP_TriggerGroup_DACOutput: 00474 if (NewState != DISABLE) 00475 { 00476 COMP->CSR5 &= (uint8_t) ~((uint8_t)(COMP_TriggerPin << 3)); 00477 } 00478 else 00479 { 00480 COMP->CSR5 |= (uint8_t) (COMP_TriggerPin << 3); 00481 } 00482 break; 00483 00484 default: 00485 break; 00486 } 00487 } 00488 00489 /** 00490 * @} 00491 */ 00492 00493 /** @defgroup COMP_Group5 Interrupts and flags management functions 00494 * @brief Interrupts and flags management functions 00495 * 00496 @verbatim 00497 =============================================================================== 00498 Interrupts and flags management functions 00499 =============================================================================== 00500 00501 @endverbatim 00502 * @{ 00503 */ 00504 00505 /** 00506 * @brief Enables or disables the interrupt generation when an event is detected. 00507 * @param COMP_Selection : selects the comparator 00508 * This parameter can be one of the following values: 00509 * @arg COMP_Selection_COMP1: Selection of Comparator 1 00510 * @arg COMP_Selection_COMP2: Selection of Comparator 2 00511 * @param NewState : new state of the COMPx interrupt. 00512 * This parameter can be: ENABLE or DISABLE. 00513 * @retval None 00514 */ 00515 void COMP_ITConfig(COMP_Selection_TypeDef COMP_Selection, FunctionalState NewState) 00516 { 00517 /* Check the parameters */ 00518 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection)); 00519 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00520 00521 /* Check if Comparator 1 is selected */ 00522 if (COMP_Selection == COMP_Selection_COMP1) 00523 { 00524 if (NewState != DISABLE) 00525 { 00526 /* Enable the COMP1 Interrupt source */ 00527 COMP->CSR1 |= (uint8_t) COMP_CSR1_IE1; 00528 } 00529 else 00530 { 00531 /* Disable the COMP1 Interrupt source */ 00532 COMP->CSR1 &= (uint8_t)(~COMP_CSR1_IE1); 00533 } 00534 } 00535 else /* Comparator 2 is selected */ 00536 { 00537 if (NewState != DISABLE) 00538 { 00539 /* Enable the COMP2 Interrupt source */ 00540 COMP->CSR2 |= (uint8_t) COMP_CSR2_IE2; 00541 } 00542 else 00543 { 00544 /* Disable the COMP2 Interrupt source */ 00545 COMP->CSR2 &= (uint8_t)(~COMP_CSR2_IE2); 00546 } 00547 } 00548 } 00549 00550 /** 00551 * @brief Checks whether the comparator flag is set or not. 00552 * @param COMP_Selection : selects the comparator 00553 * This parameter can be one of the following values: 00554 * @arg COMP_Selection_COMP1: Selection of Comparator 1 00555 * @arg COMP_Selection_COMP2: Selection of Comparator 2 00556 * @retval The new state of COMPx event flag (SET or RESET). 00557 */ 00558 FlagStatus COMP_GetFlagStatus(COMP_Selection_TypeDef COMP_Selection) 00559 { 00560 FlagStatus bitstatus = RESET; 00561 00562 /* Check the parameters */ 00563 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection)); 00564 00565 /* Check if COMP1 is selected */ 00566 if (COMP_Selection == COMP_Selection_COMP1) 00567 { 00568 if ((COMP->CSR1 & COMP_CSR1_EF1) != (uint8_t) RESET) 00569 { 00570 /* The comparator 1 event flag is set */ 00571 bitstatus = SET; 00572 } 00573 else 00574 { 00575 /* The comparator 1 event flag is reset */ 00576 bitstatus = RESET; 00577 } 00578 } 00579 else /* COMP2 is selected */ 00580 { 00581 if ((COMP->CSR2 & COMP_CSR2_EF2) != (uint8_t) RESET) 00582 { 00583 /* The comparator 2 event flag is set */ 00584 bitstatus = SET; 00585 } 00586 else 00587 { 00588 /* The comparator 2 event flag is reset */ 00589 bitstatus = RESET; 00590 } 00591 } 00592 00593 /* return the comparator event flag status */ 00594 return (FlagStatus)(bitstatus); 00595 } 00596 00597 /** 00598 * @brief Clears the comparator�s pending flag. 00599 * @param COMP_Selection : selects the comparator 00600 * This parameter can be one of the following values: 00601 * @arg COMP_Selection_COMP1: Selection of Comparator 1 00602 * @arg COMP_Selection_COMP2: Selection of Comparator 2 00603 * @retval None. 00604 */ 00605 void COMP_ClearFlag(COMP_Selection_TypeDef COMP_Selection) 00606 { 00607 /* Check the parameters */ 00608 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection)); 00609 00610 if (COMP_Selection == COMP_Selection_COMP1) 00611 { 00612 /* Clear the flag EF1 (rc_w0) clear this bit by writing 0. */ 00613 COMP->CSR1 &= (uint8_t) (~COMP_CSR1_EF1); 00614 } 00615 else 00616 { 00617 /* Clear the flag EF2 (rc_w0) clear this bit by writing 0. */ 00618 COMP->CSR2 &= (uint8_t) (~COMP_CSR2_EF2); 00619 } 00620 } 00621 00622 /** 00623 * @brief Checks whether the comparator interrupt has occurred or not. 00624 * @param COMP_Selection : selects the comparator 00625 * This parameter can be one of the following values: 00626 * @arg COMP_Selection_COMP1: Selection of Comparator 1 00627 * @arg COMP_Selection_COMP2: Selection of Comparator 2 00628 * @retval ITStatus : The state of the COMPx event flag (SET or RESET). 00629 */ 00630 ITStatus COMP_GetITStatus(COMP_Selection_TypeDef COMP_Selection) 00631 { 00632 ITStatus bitstatus = RESET; 00633 uint8_t itstatus = 0x00, itenable = 0x00; 00634 00635 /* Check the parameters */ 00636 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection)); 00637 00638 if (COMP_Selection == COMP_Selection_COMP1) 00639 { 00640 /* Get the EF1 comparator event falg status */ 00641 itstatus = (uint8_t) (COMP->CSR1 & COMP_CSR1_EF1); 00642 00643 /* Get the IE1 interrupt enable bit status */ 00644 itenable = (uint8_t) (COMP->CSR1 & COMP_CSR1_IE1); 00645 00646 if ((itstatus != (uint8_t) RESET) && (itenable != (uint8_t) RESET)) 00647 { 00648 /* the EF1 and IE1 are set */ 00649 bitstatus = SET; 00650 } 00651 else 00652 { 00653 /* the EF1 or IE1 is reset */ 00654 bitstatus = RESET; 00655 } 00656 } 00657 else 00658 { 00659 /* Get the EF2 comparator event falg value */ 00660 itstatus = (uint8_t) (COMP->CSR2 & COMP_CSR2_EF2); 00661 00662 /* Get the IE2 interrupt enable bit value */ 00663 itenable = (uint8_t) (COMP->CSR2 & COMP_CSR2_IE2); 00664 00665 if ((itstatus != (uint8_t)RESET) && (itenable != (uint8_t)RESET)) 00666 { 00667 /* The EF2 and IE2 are set */ 00668 bitstatus = SET; 00669 } 00670 else 00671 { 00672 /* The EF2 or IE2 is reset */ 00673 bitstatus = RESET; 00674 } 00675 } 00676 00677 /* Return the COMP interrupt status */ 00678 return (ITStatus) bitstatus; 00679 } 00680 00681 /** 00682 * @brief Clears the interrupt pending bits of the comparator. 00683 * @param COMP_Selection : selects the comparator 00684 * This parameter can be one of the following values: 00685 * @arg COMP_Selection_COMP1: Selection of Comparator 1 00686 * @arg COMP_Selection_COMP2: Selection of Comparator 2 00687 * @retval None 00688 */ 00689 void COMP_ClearITPendingBit(COMP_Selection_TypeDef COMP_Selection) 00690 { 00691 /* Check the parameters */ 00692 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection)); 00693 00694 if (COMP_Selection == COMP_Selection_COMP1) 00695 { 00696 /* Clear the flag EF1 (rc_w0) clear this bit by writing 0. */ 00697 COMP->CSR1 &= (uint8_t) (~COMP_CSR1_EF1); 00698 } 00699 else 00700 { 00701 /* Clear the flag EF2 (rc_w0) clear this bit by writing 0. */ 00702 COMP->CSR2 &= (uint8_t) (~COMP_CSR2_EF2); 00703 } 00704 } 00705 00706 /** 00707 * @} 00708 */ 00709 00710 /** 00711 * @} 00712 */ 00713 00714 /** 00715 * @} 00716 */ 00717 00718 /** 00719 * @} 00720 */ 00721 00722 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/