tao_z
2022-06-01 73bf3cdb517b55f662ed5fa513cdaaf55c1fd0c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**
  ******************************************************************************
  * @file     xl_acmp.c
  * @author   kirk  ,xu.wang
  * @version  4.5.2
  * @date     Fri Mar 26 17:29:12 2021
  * @brief    This file provide function about ACMP firmware program 
  ******************************************************************************
  * @attention
    *
  * 2019 by Chipways Communications,Inc. All Rights Reserved.
  * This software is supplied under the terms of a license
  * agreement or non-disclosure agreement with Chipways.
  * Passing on and copying of this document,and communication
  * of its contents is not permitted without prior written
  * authorization.
  *
  * <h2><center>&copy; COPYRIGHT 2019 Chipways</center></h2>
  ******************************************************************************
  */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
 
/* Includes ---------------------------------------------------------------*/
#include "xl_acmp.h"
    
/** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @defgroup ACMP ACMP Module 
  * @brief ACMP Driver Modules Library
  * @{
  */
    
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/    
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
 
 
/** @defgroup ACMP_Private_Functions 
  * @{
  */ 
 
/**
  * @brief ÖØÐÂÉèÖÃACMP¼Ä´æÆ÷״̬.
  * @param ACMPx: ÉèÖÃACMPÍâÉè
  * @retval None
  */
void ACMP_DeInit(ACMP_Type *ACMPx)    
{
    /* set default values to each register.*/
    ACMPx->CS = 0u ;
    ACMPx->C0 = 0u ;
    ACMPx->C1 = 0u ;
    ACMPx->C2 = 0u ;
}
 
/**
  * @brief ³õʼ»¯ACMPµÄÖµ.
    * @param ACMPx: ÉèÖÃACMPÍâÉè
  * @param ACMP_InitStruct: Ö¸¶¨ACMP_InitTypeDef ½á¹¹°üº¬ACMPÍâÉèÅäÖÃÐÅ.
  * @retval None
  */
void ACMP_Init(ACMP_Type *ACMPx,const  ACMP_InitTypeDef *ACMP_InitStruct)
{
    uint8_t tmpreg;
 
    /*configure the register.*/
    
    /* set the C1 register.*/
    tmpreg = ((( ACMP_InitStruct->ACMP_DACRefVoltage << ACMP_C1_DACREF_SHIFT) & ACMP_C1_DACREF_MASK) | \
                            (ACMP_InitStruct->ACMP_DACValue & ACMP_C1_DACVAL_MASK));
    
    if(ACMP_InitStruct->ACMP_DACEN == ENABLE)
    {
        tmpreg |= ACMP_C1_DACEN_MASK;
    }
    else
    {
        tmpreg &= ~ACMP_C1_DACEN_MASK;
    }
    
    ACMPx->C1 = tmpreg;
 
     /*configure the register.*/
    /* Get the CS Register. */
    tmpreg = ACMPx ->CS ;
    /* clear the HYST and ACMOD bit.*/
    tmpreg &= (uint8_t)(~(ACMP_CS_HYST_MASK | ACMP_CS_ACMOD_MASK));
    /* Set the HYST and ACMOD bit.*/
    tmpreg |=  (( ACMP_InitStruct->ACMP_IntTrigMode & ACMP_CS_ACMOD_MASK) | \
                ( ( ACMP_InitStruct->ACMP_HystMode << ACMP_CS_HYST_SHIFT) & ACMP_CS_HYST_MASK) );
    
    
    /* Write to ACMP CS */
    ACMPx->CS = tmpreg ;
    
    /* select the positive input and negative input.*/
    ACMPx->C0 =(((ACMP_InitStruct->ACMP_InputP << ACMP_C0_ACPSEL_SHIFT) & ACMP_C0_ACPSEL_MASK) | \
                            (ACMP_InitStruct->ACMP_InputN & ACMP_C0_ACNSEL_MASK));
 
                
    /* ACMP Input pin enable.*/
    ACMPx->C2 = (ACMP_InitStruct->ACMP_InputPin & ACMP_C2_ACIPE_MASK);
}
 
/**
  * @brief ÆôÓÃACMPµÄÖµ.
    * @param ACMPx: ÉèÖÃACMPÍâÉè
  * @param NewState: Ê¹ÄܺÍʧÄÜÑ¡Ôñ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE £ºÊ¹ÄÜ
  *            @arg DISENABLE £ºÊ§ÄÜ
  * @retval None
  */
void ACMP_EnableCmd(ACMP_Type *ACMPx,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Enable ACMP. */
        ACMPx->CS |= ACMP_CS_ACE_MASK;
    }
    else 
    {
        /* Disable ACMP. */
        ACMPx->CS &= ~ACMP_CS_ACE_MASK;
    }
}
 
/**
  * @brief ÆôÓÃACMPÖжÏ.
  * @param  ACMPx: ÉèÖÃACMPÍâÉè
  * @param  NewState: Ê¹ÄܺÍʧÄÜÑ¡Ôñ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE £ºÊ¹ÄÜ
  *            @arg DISENABLE £ºÊ§ÄÜ
  * @retval None
  */
void ACMP_InterruptEn(ACMP_Type *ACMPx,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Enable ACMP Interrupt. */
        ACMPx ->CS |= ACMP_CS_ACIE_MASK;
    }
    else 
    {
        /* Disable ACMP Interrupt. */
        ACMPx ->CS &= ~ACMP_CS_ACIE_MASK;
    }
}
 
/**
  * @brief ÊÊÓöîÍâpinµÄÂß¼­Êä³ö.
  * @param  ACMPx: ÉèÖÃACMPÍâÉè
  * @param  NewState: Ê¹ÄܺÍʧÄÜÑ¡Ôñ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE £ºÊ¹ÄÜ
  *            @arg DISENABLE £ºÊ§ÄÜ
  * @retval None
  */
void ACMP_OutputPinEn(ACMP_Type *ACMPx,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* can be placed onto external pin. */
        ACMPx->CS |= ACMP_CS_ACOPE_MASK;
    }
    else 
    {
        /* cannot be placed onto external pin. */
        ACMPx->CS &= ~ACMP_CS_ACOPE_MASK;
    }
}
 
/**
  * @brief µÃµ½±È½ÏÂß¼­Êä³ö.
  * @param ACMPx: ÉèÖÃACMPÍâÉè
  * @retval ·µ»ØÂß¼­Êä³ö¸ßµÍµçƽ.
  */
uint8_t ACMP_GetOutPutLogic(const ACMP_Type *ACMPx)
{
    /* Return the output logic.*/
    return ((ACMPx->CS & ACMP_CS_ACO_MASK)>>ACMP_CS_ACO_SHIFT);
}
 
/**
  * @brief µÃµ½ACMPÖжϱê־λÊýÖµ.
  * @param ACMPx: ÉèÖÃACMPÍâÉè.
  * @retval ACMPÖжϱêÖ¾ 0/1
  */
uint8_t ACMP_GetIntFlag(const ACMP_Type *ACMPx)
{
    /* Return the output logic.*/
    return ((ACMPx->CS & ACMP_CS_ACF_MASK)>>ACMP_CS_ACF_SHIFT);
}
 
/**
  * @brief Çå³ýACMPÖжϱê־λÊýÖµ.
  * @param ACMPx: ÉèÖÃACMPÍâÉè
  * @retval None
  */
void ACMP_ClearIntFlag(ACMP_Type *ACMPx)
{
    /*  Clears the logic  ACMP Interrupt Flag Bit in the ACMP module.*/
  ACMPx->CS &= ~ACMP_CS_ACF_MASK;
}
 
/**
  * @}
  */
 
/**
  * @}
  */
 
/**
  * @}
  */
 
#ifdef __cplusplus
}
#endif /* __cplusplus */