1 /**
2   ******************************************************************************
3   * @file    lib_comp.h
4   * @author  Application Team
5   * @version V4.4.0
6   * @date    2018-09-27
7   * @brief   COMP library.
8   ******************************************************************************
9   * @attention
10   *
11   ******************************************************************************
12   */
13 #ifndef __LIB_COMP_H
14 #define __LIB_COMP_H
15 
16 #ifdef __cplusplus
17  extern "C" {
18 #endif
19 
20 #include "target.h"
21 
22 /* Macros --------------------------------------------------------------------*/
23 
24 /***** COMP_DEBConfig *****/
25 //COMPx
26 #define COMP_1                   (0x00U)
27 #define COMP_2                   (0x02U)
28 #define IS_COMP(__COMP__)  (((__COMP__) == COMP_1) || ((__COMP__) == COMP_2))
29 //Debounce
30 #define COMP_DEB_0                ANA_CTRL_CMP1DEB_0
31 #define COMP_DEB_1                ANA_CTRL_CMP1DEB_1
32 #define COMP_DEB_2                ANA_CTRL_CMP1DEB_2
33 #define COMP_DEB_3                ANA_CTRL_CMP1DEB_3
34 #define IS_COMP_DEB(__DEB__)  (((__DEB__) == COMP_DEB_0) ||\
35                                ((__DEB__) == COMP_DEB_1) ||\
36                                ((__DEB__) == COMP_DEB_2) ||\
37                                ((__DEB__) == COMP_DEB_3))
38 
39 /***** Mode (COMP_ModeConfig) *****/
40 #define COMP_MODE_OFF             ANA_CTRL_COMP1_SEL_0
41 #define COMP_MODE_RISING          ANA_CTRL_COMP1_SEL_1
42 #define COMP_MODE_FALLING         ANA_CTRL_COMP1_SEL_2
43 #define COMP_MODE_BOTH            ANA_CTRL_COMP1_SEL_3
44 #define IS_COMP_MODE(__MODE__)  (((__MODE__) == COMP_MODE_OFF)     ||\
45                                  ((__MODE__) == COMP_MODE_RISING)  ||\
46                                  ((__MODE__) == COMP_MODE_FALLING) ||\
47                                  ((__MODE__) == COMP_MODE_BOTH))
48 
49 /***** SourceSelect (COMP_ConfigSignalSource) *****/
50 #define COMP_SIGNALSRC_P_TO_REF   ANA_REG2_CMP1_SEL_0
51 #define COMP_SIGNALSRC_N_TO_REF   ANA_REG2_CMP1_SEL_1
52 #define COMP_SIGNALSRC_P_TO_N     ANA_REG2_CMP1_SEL_2
53 #define IS_COMP_SIGNALSRC(__SIGNALSRC__)  (((__SIGNALSRC__) == COMP_SIGNALSRC_P_TO_REF) ||\
54                                            ((__SIGNALSRC__) == COMP_SIGNALSRC_N_TO_REF) ||\
55                                            ((__SIGNALSRC__) == COMP_SIGNALSRC_P_TO_N))
56 
57 /***** REFSelect (COMP_ConfigREF) *****/
58 #define COMP_REF_VREF            (0)
59 #define COMP_REF_BGPREF           ANA_REG2_REFSEL_CMP1
60 #define IS_COMP_REF(__REF__)  (((__REF__) == COMP_REF_VREF)  ||\
61                                ((__REF__) == COMP_REF_BGPREF))
62 
63 /***** BiasSel (COMP_BiasConfig) *****/
64 #define COMP_BIAS_20nA             ANA_REG5_IT_CMP1_0
65 #define COMP_BIAS_100nA            ANA_REG5_IT_CMP1_1
66 #define COMP_BIAS_500nA            ANA_REG5_IT_CMP1_2
67 #define IS_COMP_BIAS(__BIAS__)  (((__BIAS__) == COMP_BIAS_20nA) ||\
68                                  ((__BIAS__) == COMP_BIAS_100nA)||\
69                                  ((__BIAS__) == COMP_BIAS_500nA))
70 
71 /* Exported Functions ------------------------------------------------------- */
72 
73 void COMP_DEBConfig(uint32_t COMPx, uint32_t Debounce);
74 void COMP_ModeConfig(uint32_t COMPx, uint32_t Mode);
75 void COMP_SignalSourceConfig(uint32_t COMPx, uint32_t SourceSelect);
76 void COMP_REFConfig(uint32_t COMPx, uint32_t REFSelect);
77 void COMP_BiasConfig(uint32_t COMPx, uint32_t BiasSel);
78 
79 void COMP_INTConfig(uint32_t COMPx, uint32_t NewState);
80 uint8_t COMP_GetINTStatus(uint32_t COMPx);
81 void COMP_ClearINTStatus(uint32_t COMPx);
82 
83 void COMP_Output_Cmd(uint32_t COMPx, uint32_t NewState);
84 void COMP_Cmd(uint32_t COMPx, uint32_t NewState);
85 
86 uint32_t COMP_GetCNTValue(uint32_t COMPx);
87 void COMP_ClearCNTValue(uint32_t COMPx);
88 uint8_t COMP1_GetOutputLevel(void);
89 uint8_t COMP2_GetOutputLevel(void);
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 #endif  /* __LIB_COMP_H */
96 
97 /*********************************** END OF FILE ******************************/
98