]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_comp.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F0 / stm32f0xx_hal_comp.c
1 /**
2   ******************************************************************************
3   * @file    stm32f0xx_hal_comp.c
4   * @author  MCD Application Team
5   * @version V1.2.0
6   * @date    11-December-2014
7   * @brief   COMP HAL module driver.
8   *          This file provides firmware functions to manage the following 
9   *          functionalities of the COMP peripheral:
10   *           + Initialization/de-initialization functions
11   *           + I/O operation functions
12   *           + Peripheral Control functions 
13   *           + Peripheral State functions
14   *         
15   @verbatim
16 ================================================================================
17           ##### COMP Peripheral features #####
18 ================================================================================
19            
20   [..]       
21       The STM32F0xx device family integrates up to 2 analog comparators COMP1 and COMP2:
22       (#) The non inverting input and inverting input can be set to GPIO pins
23           as shown in table1. COMP Inputs below.
24   
25       (#) The COMP output is available using HAL_COMP_GetOutputLevel()
26           and can be set on GPIO pins. Refer to table 2. COMP Outputs below.
27   
28       (#) The COMP output can be redirected to embedded timers (TIM1, TIM2 and TIM3)
29           Refer to table 3. COMP Outputs redirection to embedded timers below.
30   
31       (#) The comparators COMP1 and COMP2 can be combined in window mode.
32   
33       (#) The comparators have interrupt capability with wake-up
34           from Sleep and Stop modes (through the EXTI controller):
35           (++) COMP1 is internally connected to EXTI Line 21
36           (++) COMP2 is internally connected to EXTI Line 22
37           From the corresponding IRQ handler, the right interrupt source can be retrieved with the 
38           macro __HAL_COMP_EXTI_GET_FLAG(). Possible values are:
39           (++) COMP_EXTI_LINE_COMP1_EVENT
40           (++) COMP_EXTI_LINE_COMP2_EVENT
41
42
43 [..] Table 1. COMP Inputs for the STM32F05x, STM32F07x and STM32F09x devices
44  +--------------------------------------------------+    
45  |                 |                | COMP1 | COMP2 |
46  |-----------------|----------------|---------------|
47  |                 | 1/4 VREFINT    |  OK   |  OK   |
48  |                 | 1/2 VREFINT    |  OK   |  OK   |
49  |                 | 3/4 VREFINT    |  OK   |  OK   |
50  | Inverting Input | VREFINT        |  OK   |  OK   |
51  |                 | DAC1 OUT (PA4) |  OK   |  OK   |
52  |                 | DAC2 OUT (PA5) |  OK   |  OK   |
53  |                 | IO1            |  PA0  |  PA2  |
54  |-----------------|----------------|-------|-------|
55  |  Non Inverting  |                |  PA1  |  PA3  |
56  |    Input        |                |       |       |
57  +--------------------------------------------------+  
58   
59  [..] Table 2. COMP Outputs for the STM32F05x, STM32F07x and STM32F09x devices
60  +---------------+     
61  | COMP1 | COMP2 |
62  |-------|-------|
63  |  PA0  |  PA2  |
64  |  PA6  |  PA7  |
65  |  PA11 |  PA12 |
66  +---------------+
67
68  [..] Table 3. COMP Outputs redirection to embedded timers for the STM32F05x, STM32F07x and STM32F09x devices
69  +---------------------------------+     
70  |     COMP1      |     COMP2      |
71  |----------------|----------------|
72  |  TIM1 BKIN     |  TIM1 BKIN     |
73  |                |                |
74  |  TIM1 OCREFCLR |  TIM1 OCREFCLR |
75  |                |                |
76  |  TIM1 IC1      |  TIM1 IC1      |
77  |                |                |
78  |  TIM2 IC4      |  TIM2 IC4      |
79  |                |                |
80  |  TIM2 OCREFCLR |  TIM2 OCREFCLR |
81  |                |                |
82  |  TIM3 IC1      |  TIM3 IC1      |
83  |                |                |
84  |  TIM3 OCREFCLR |  TIM3 OCREFCLR |
85  +---------------------------------+
86
87             ##### How to use this driver #####
88 ================================================================================
89   [..]
90       This driver provides functions to configure and program the Comparators of STM32F05x, STM32F07x and STM32F09x devices.
91
92       To use the comparator, perform the following steps:
93   
94       (#) Fill in the HAL_COMP_MspInit() to
95       (++) Configure the comparator input in analog mode using HAL_GPIO_Init()
96       (++) Configure the comparator output in alternate function mode using HAL_GPIO_Init() to map the comparator 
97            output to the GPIO pin
98       (++) If required enable the COMP interrupt by configuring and enabling EXTI line in Interrupt mode and 
99            selecting the desired sensitivity level using HAL_GPIO_Init() function. After that enable the comparator
100            interrupt vector using HAL_NVIC_EnableIRQ() function.
101   
102       (#) Configure the comparator using HAL_COMP_Init() function:
103       (++) Select the inverting input
104       (++) Select the non inverting input
105       (++) Select the output polarity  
106       (++) Select the output redirection
107       (++) Select the hysteresis level
108       (++) Select the power mode
109       (++) Select the event/interrupt mode
110   
111       (#) Enable the comparator using HAL_COMP_Start() function or HAL_COMP_Start_IT() function for interrupt mode
112     
113       (#) Read the comparator output level with HAL_COMP_GetOutputLevel()
114     
115   @endverbatim
116   ******************************************************************************
117   * @attention
118   *
119   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
120   *
121   * Redistribution and use in source and binary forms, with or without modification,
122   * are permitted provided that the following conditions are met:
123   *   1. Redistributions of source code must retain the above copyright notice,
124   *      this list of conditions and the following disclaimer.
125   *   2. Redistributions in binary form must reproduce the above copyright notice,
126   *      this list of conditions and the following disclaimer in the documentation
127   *      and/or other materials provided with the distribution.
128   *   3. Neither the name of STMicroelectronics nor the names of its contributors
129   *      may be used to endorse or promote products derived from this software
130   *      without specific prior written permission.
131   *
132   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
133   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
134   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
135   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
136   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
137   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
138   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
139   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
140   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
141   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
142   *
143   ******************************************************************************  
144   */
145
146 /* Includes ------------------------------------------------------------------*/
147 #include "stm32f0xx_hal.h"
148
149 #ifdef HAL_COMP_MODULE_ENABLED
150
151 #if defined(STM32F051x8) || defined(STM32F058xx) || \
152     defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
153     defined(STM32F091xC) || defined (STM32F098xx)
154
155 /** @addtogroup STM32F0xx_HAL_Driver
156   * @{
157   */
158
159 /** @defgroup COMP COMP HAL Module Driver 
160   * @brief COMP HAL module driver
161   * @{
162   */
163
164 /* Private typedef -----------------------------------------------------------*/
165 /* Private define ------------------------------------------------------------*/
166 /** @defgroup COMP_Private_Constants COMP Private Constants
167   * @{
168   */
169 /* CSR register reset value */ 
170 #define COMP_CSR_RESET_VALUE            ((uint32_t)0x00000000)
171 /* CSR register masks */ 
172 #define COMP_CSR_RESET_PARAMETERS_MASK   ((uint32_t)0x00003FFF)
173 #define COMP_CSR_UPDATE_PARAMETERS_MASK  ((uint32_t)0x00003FFE)
174 /* CSR COMPx non inverting input mask */ 
175 #define COMP_CSR_COMPxNONINSEL_MASK      ((uint16_t)COMP_CSR_COMP1SW1)
176 /* CSR COMP2 shift */ 
177 #define COMP_CSR_COMP1_SHIFT             0U
178 #define COMP_CSR_COMP2_SHIFT             16U
179 /**
180   * @}
181   */
182 /* Private macro -------------------------------------------------------------*/
183 /* Private variables ---------------------------------------------------------*/
184 /* Private function prototypes -----------------------------------------------*/
185 /* Private functions ---------------------------------------------------------*/
186
187 /** @defgroup COMP_Exported_Functions COMP Exported Functions
188   * @{
189   */
190
191 /** @defgroup COMP_Exported_Functions_Group1 Initialization/de-initialization functions 
192  *  @brief    Initialization and Configuration functions 
193  *
194 @verbatim    
195  ===============================================================================
196               ##### Initialization and Configuration functions #####
197  ===============================================================================
198     [..]  This section provides functions to initialize and de-initialize comparators 
199
200 @endverbatim
201   * @{
202   */
203
204 /**
205   * @brief  Initializes the COMP according to the specified
206   *         parameters in the COMP_InitTypeDef and create the associated handle.
207   * @note   If the selected comparator is locked, initialization can't be performed.
208   *         To unlock the configuration, perform a system reset.
209   * @param  hcomp: COMP handle
210   * @retval HAL status
211   */
212 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
213
214   HAL_StatusTypeDef status = HAL_OK;
215   uint32_t regshift = COMP_CSR_COMP1_SHIFT;
216   
217   /* Check the COMP handle allocation and lock status */
218   if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
219   {
220     status = HAL_ERROR;
221   }
222   else
223   {
224     /* Check the parameter */
225     assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
226     assert_param(IS_COMP_INVERTINGINPUT(hcomp->Init.InvertingInput));
227     assert_param(IS_COMP_NONINVERTINGINPUT(hcomp->Init.NonInvertingInput));
228     assert_param(IS_COMP_OUTPUT(hcomp->Init.Output));
229     assert_param(IS_COMP_OUTPUTPOL(hcomp->Init.OutputPol));
230     assert_param(IS_COMP_HYSTERESIS(hcomp->Init.Hysteresis));
231     assert_param(IS_COMP_MODE(hcomp->Init.Mode));
232     
233     if(hcomp->Init.NonInvertingInput == COMP_NONINVERTINGINPUT_DAC1SWITCHCLOSED)
234     {
235       assert_param(IS_COMP_DAC1SWITCH_INSTANCE(hcomp->Instance));
236     }
237   
238     if(hcomp->Init.WindowMode != COMP_WINDOWMODE_DISABLED)
239     {
240       assert_param(IS_COMP_WINDOWMODE_INSTANCE(hcomp->Instance));
241     }
242   
243     if(hcomp->State == HAL_COMP_STATE_RESET)
244     {
245       /* Init SYSCFG and the low level hardware to access comparators */
246       __SYSCFG_CLK_ENABLE();
247
248       HAL_COMP_MspInit(hcomp);
249     }
250   
251     /* Set COMP parameters */
252     /*     Set COMPxINSEL bits according to hcomp->Init.InvertingInput value        */
253     /*     Set COMPxOUTSEL bits according to hcomp->Init.Output value               */
254     /*     Set COMPxPOL bit according to hcomp->Init.OutputPol value                */
255     /*     Set COMPxHYST bits according to hcomp->Init.Hysteresis value             */
256     /*     Set COMPxMODE bits according to hcomp->Init.Mode value                   */
257     if(hcomp->Instance == COMP2)
258     {
259       regshift = COMP_CSR_COMP2_SHIFT;
260     }
261     MODIFY_REG(COMP->CSR, 
262                (uint32_t)(COMP_CSR_COMPxINSEL  | COMP_CSR_COMPxNONINSEL_MASK | \
263                 COMP_CSR_COMPxOUTSEL | COMP_CSR_COMPxPOL           | \
264                 COMP_CSR_COMPxHYST   | COMP_CSR_COMPxMODE) << regshift,
265                (hcomp->Init.InvertingInput    | \
266                 hcomp->Init.NonInvertingInput | \
267                 hcomp->Init.Output            | \
268                 hcomp->Init.OutputPol         | \
269                 hcomp->Init.Hysteresis        | \
270                 hcomp->Init.Mode) << regshift);   
271     
272     if(hcomp->Init.WindowMode != COMP_WINDOWMODE_DISABLED)
273     {
274       COMP->CSR |= COMP_CSR_WNDWEN;
275     }
276
277     /* Initialize the COMP state*/
278     if(hcomp->State == HAL_COMP_STATE_RESET)
279     {
280       hcomp->State = HAL_COMP_STATE_READY;
281     }
282   }
283   
284   return status;
285 }
286
287 /**
288   * @brief  DeInitializes the COMP peripheral 
289   * @note   Deinitialization can't be performed if the COMP configuration is locked.
290   *         To unlock the configuration, perform a system reset.
291   * @param  hcomp: COMP handle
292   * @retval HAL status
293   */
294 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
295 {
296   HAL_StatusTypeDef status = HAL_OK;
297   uint32_t regshift = COMP_CSR_COMP1_SHIFT;
298
299   /* Check the COMP handle allocation and lock status */
300   if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
301   {
302     status = HAL_ERROR;
303   }
304   else
305   {
306     /* Check the parameter */
307     assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
308
309     /* Set COMP_CSR register to reset value for the corresponding COMP instance */
310     if(hcomp->Instance == COMP2)
311     {
312       regshift = COMP_CSR_COMP2_SHIFT;
313     }
314     MODIFY_REG(COMP->CSR, 
315                COMP_CSR_RESET_PARAMETERS_MASK << regshift, 
316                COMP_CSR_RESET_VALUE << regshift);
317     
318     /* DeInit the low level hardware: SYSCFG, GPIO, CLOCK and NVIC */
319     HAL_COMP_MspDeInit(hcomp);
320
321     hcomp->State = HAL_COMP_STATE_RESET;
322   }
323   
324   return status;
325 }
326
327 /**
328   * @brief  Initializes the COMP MSP.
329   * @param  hcomp: COMP handle
330   * @retval None
331   */
332 __weak void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp)
333 {
334   /* NOTE : This function Should not be modified, when the callback is needed,
335             the HAL_COMP_MspInit could be implenetd in the user file
336    */
337 }
338
339 /**
340   * @brief  DeInitializes COMP MSP.
341   * @param  hcomp: COMP handle
342   * @retval None
343   */
344 __weak void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp)
345 {
346   /* NOTE : This function Should not be modified, when the callback is needed,
347             the HAL_COMP_MspDeInit could be implenetd in the user file
348    */
349 }
350
351 /**
352   * @}
353   */
354
355 /** @defgroup COMP_Exported_Functions_Group2 I/O operation functions 
356  *  @brief   Data transfers functions 
357  *
358 @verbatim   
359  ===============================================================================
360                       ##### IO operation functions #####
361  ===============================================================================  
362     [..]
363     This subsection provides a set of functions allowing to manage the COMP data 
364     transfers.
365
366 @endverbatim
367   * @{
368   */
369
370 /**
371   * @brief  Start the comparator 
372   * @param  hcomp: COMP handle
373   * @retval HAL status
374   */
375 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp)
376
377   HAL_StatusTypeDef status = HAL_OK;
378   uint32_t regshift = COMP_CSR_COMP1_SHIFT;
379   
380   /* Check the COMP handle allocation and lock status */
381   if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
382   {
383     status = HAL_ERROR;
384   }
385   else
386   {
387     /* Check the parameter */
388     assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
389
390     if(hcomp->State == HAL_COMP_STATE_READY)
391     {
392       /* Enable the selected comparator */
393       if(hcomp->Instance == COMP2)
394       {
395         regshift = COMP_CSR_COMP2_SHIFT;
396       }
397       SET_BIT(COMP->CSR, (uint32_t)COMP_CSR_COMPxEN << regshift);
398
399       hcomp->State = HAL_COMP_STATE_BUSY;      
400     }
401     else
402     {
403       status = HAL_ERROR;
404     }
405   }
406
407   return status;
408 }
409
410 /**
411   * @brief  Stop the comparator 
412   * @param  hcomp: COMP handle
413   * @retval HAL status
414   */
415 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp)
416
417   HAL_StatusTypeDef status = HAL_OK;
418   uint32_t regshift = COMP_CSR_COMP1_SHIFT;
419   
420   /* Check the COMP handle allocation and lock status */
421   if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
422   {
423     status = HAL_ERROR;
424   }
425   else
426   {
427     /* Check the parameter */
428     assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
429
430     if(hcomp->State == HAL_COMP_STATE_BUSY)
431     {
432       /* Disable the selected comparator */
433       if(hcomp->Instance == COMP2)
434       {
435         regshift = COMP_CSR_COMP2_SHIFT;
436       }
437       CLEAR_BIT(COMP->CSR, (uint32_t)COMP_CSR_COMPxEN << regshift);
438
439       hcomp->State = HAL_COMP_STATE_READY;
440     }
441     else
442     {
443       status = HAL_ERROR;
444     }
445   }
446   
447   return status;
448 }
449
450 /**
451   * @brief  Enables the interrupt and starts the comparator
452   * @param  hcomp: COMP handle
453   * @retval HAL status.
454   */
455 HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp)
456
457   HAL_StatusTypeDef status = HAL_OK;
458   uint32_t extiline = 0;
459   
460   /* Check the parameter */
461   assert_param(IS_COMP_TRIGGERMODE(hcomp->Init.TriggerMode));
462
463   status = HAL_COMP_Start(hcomp);
464   if(status == HAL_OK)
465   {
466     /* Check the Exti Line output configuration */
467     extiline = __HAL_COMP_GET_EXTI_LINE(hcomp->Instance);
468     /* Configure the rising edge */
469     if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_RISING) != RESET)
470     {
471       __HAL_COMP_EXTI_RISING_IT_ENABLE(extiline);
472     }
473     else
474     {
475       __HAL_COMP_EXTI_RISING_IT_DISABLE(extiline);
476     }
477     /* Configure the falling edge */
478     if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_FALLING) != RESET)
479     {
480       __HAL_COMP_EXTI_FALLING_IT_ENABLE(extiline);
481     }
482     else
483     {
484       __HAL_COMP_EXTI_FALLING_IT_DISABLE(extiline);
485     }
486     /* Enable Exti interrupt mode */
487     __HAL_COMP_EXTI_ENABLE_IT(extiline);
488     /* Clear COMP Exti pending bit */
489     __HAL_COMP_EXTI_CLEAR_FLAG(extiline);    
490   }
491
492   return status;
493 }
494
495 /**
496   * @brief  Disable the interrupt and Stop the comparator 
497   * @param  hcomp: COMP handle
498   * @retval HAL status
499   */
500 HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp)
501
502   HAL_StatusTypeDef status = HAL_OK;
503   
504   /* Disable the Exti Line interrupt mode */
505   __HAL_COMP_EXTI_DISABLE_IT(__HAL_COMP_GET_EXTI_LINE(hcomp->Instance));
506   
507   status = HAL_COMP_Stop(hcomp);
508   
509   return status;
510 }
511
512 /**
513   * @brief  Comparator IRQ Handler 
514   * @param  hcomp: COMP handle
515   * @retval HAL status
516   */
517 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp)
518 {
519   uint32_t extiline = __HAL_COMP_GET_EXTI_LINE(hcomp->Instance);
520   
521   /* Check COMP Exti flag */
522   if(__HAL_COMP_EXTI_GET_FLAG(extiline) != RESET)
523   {
524     /* Clear COMP Exti pending bit */
525     __HAL_COMP_EXTI_CLEAR_FLAG(extiline);
526
527     /* COMP trigger user callback */
528     HAL_COMP_TriggerCallback(hcomp);    
529   }  
530 }
531
532 /**
533   * @}
534   */
535
536 /** @defgroup COMP_Exported_Functions_Group3 Peripheral Control functions 
537  *  @brief   management functions 
538  *
539 @verbatim   
540  ===============================================================================
541                       ##### Peripheral Control functions #####
542  ===============================================================================  
543     [..]
544     This subsection provides a set of functions allowing to control the COMP data 
545     transfers.
546
547 @endverbatim
548   * @{
549   */
550
551 /**
552   * @brief  Lock the selected comparator configuration. 
553   * @param  hcomp: COMP handle
554   * @retval HAL status
555   */
556 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp)
557 {
558   HAL_StatusTypeDef status = HAL_OK;
559   uint32_t regshift = COMP_CSR_COMP1_SHIFT;
560
561   /* Check the COMP handle allocation and lock status */
562   if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
563   {
564     status = HAL_ERROR;
565   }
566   else
567   {
568     /* Check the parameter */
569     assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
570
571     /* Set lock flag */
572     hcomp->State |= COMP_STATE_BIT_LOCK;
573
574     /* Set the lock bit corresponding to selected comparator */
575     if(hcomp->Instance == COMP2)
576     {
577       regshift = COMP_CSR_COMP2_SHIFT;
578     }
579     SET_BIT(COMP->CSR, (uint32_t)COMP_CSR_COMPxLOCK << regshift);
580   }
581   
582   return status; 
583 }
584
585 /**
586   * @brief  Return the output level (high or low) of the selected comparator. 
587   *         The output level depends on the selected polarity.
588   *         If the polarity is not inverted:
589   *           - Comparator output is low when the non-inverting input is at a lower
590   *             voltage than the inverting input
591   *           - Comparator output is high when the non-inverting input is at a higher
592   *             voltage than the inverting input
593   *         If the polarity is inverted:
594   *           - Comparator output is high when the non-inverting input is at a lower
595   *             voltage than the inverting input
596   *           - Comparator output is low when the non-inverting input is at a higher
597   *             voltage than the inverting input
598   * @param  hcomp: COMP handle
599   * @retval Returns the selected comparator output level: COMP_OUTPUTLEVEL_LOW or COMP_OUTPUTLEVEL_HIGH.
600   *       
601   */
602 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp)
603 {
604   uint32_t level=0;
605   uint32_t regshift = COMP_CSR_COMP1_SHIFT;
606   
607   /* Check the parameter */
608   assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
609   
610   if(hcomp->Instance == COMP2)
611   {
612     regshift = COMP_CSR_COMP2_SHIFT;
613   }
614   level = READ_BIT(COMP->CSR, (uint32_t)COMP_CSR_COMPxOUT << regshift);
615   
616   if(level != 0)
617   {
618     return(COMP_OUTPUTLEVEL_HIGH);
619   }
620   return(COMP_OUTPUTLEVEL_LOW);
621 }
622
623 /**
624   * @brief  Comparator callback.
625   * @param  hcomp: COMP handle
626   * @retval None
627   */
628 __weak void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
629 {
630   /* NOTE : This function should not be modified, when the callback is needed,
631             the HAL_COMP_TriggerCallback should be implemented in the user file
632    */
633 }
634
635
636 /**
637   * @}
638   */
639
640 /** @defgroup COMP_Exported_Functions_Group4 Peripheral State functions 
641  *  @brief   Peripheral State functions 
642  *
643 @verbatim   
644  ===============================================================================
645                       ##### Peripheral State functions #####
646  ===============================================================================  
647     [..]
648     This subsection permit to get in run-time the status of the peripheral 
649     and the data flow.
650
651 @endverbatim
652   * @{
653   */
654
655 /**
656   * @brief  Return the COMP state
657   * @param  hcomp : COMP handle
658   * @retval HAL state
659   */
660 uint32_t HAL_COMP_GetState(COMP_HandleTypeDef *hcomp)
661 {
662   /* Check the COMP handle allocation */
663   if(hcomp == NULL)
664   {
665     return HAL_COMP_STATE_RESET;
666   }
667
668   /* Check the parameter */
669   assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
670
671   return hcomp->State;
672 }
673 /**
674   * @}
675   */
676
677 /**
678   * @}
679   */
680
681 /**
682   * @}
683   */
684
685 /**
686   * @}
687   */
688
689 #endif /* STM32F051x8 || STM32F058xx || */
690        /* STM32F071xB || STM32F072xB || STM32F078xx || */
691        /* STM32F091xC || defined (STM32F098xx) */
692
693 #endif /* HAL_COMP_MODULE_ENABLED */
694
695 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/