chen
2024-07-29 55579b9ada2fc22edcae817e7d6e65710c47edd3
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
/*
 * Copyright (c) 2019-2023 Beijing Hanwei Innovation Technology Ltd. Co. and
 * its subsidiaries and affiliates (collectly called MKSEMI).
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into an MKSEMI
 *    integrated circuit in a product or a software update for such product,
 *    must reproduce the above copyright notice, this list of conditions and
 *    the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 * 3. Neither the name of MKSEMI nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    MKSEMI integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be
 *    reverse engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY MKSEMI "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL MKSEMI OR CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
#ifndef MK_ACMP_H_
#define MK_ACMP_H_
#include "mk_common.h"
 
#ifndef ACMP_INT_MODE_EN
#define ACMP_INT_MODE_EN (1)
#endif
 
/**
 * @addtogroup MK8000_ACMP
 * @{
 */
 
#define ACMP_POSEDGE_INT 0  /*!< Rising edge trigger detection         */
#define ACMP_NEGEDGE_INT 1  /*!< Falling edge trigger detection        */
#define ACMP_BOTHEDGE_INT 2 /*!< Rising/Falling edge trigger detection */
 
/**
 * @brief ACMP device IDs enumeration
 */
enum ACMP_DEV_T
{
    ACMP_ID0 = 0,
    ACMP_ID1,
    ACMP_MAX_NUM
};
 
/**
 * @brief ACMP channel P/N configure enumeration
 */
enum ACMP_DEV_CH_T
{
    ACMP_VREF1 = 0, /*!< The P/N poles of ACMP can be connected to the internal reference voltage 0.25 * 0.9V */
    ACMP_VREF2,     /*!< The P/N poles of ACMP can be connected to the internal reference voltage 0.50 * 0.9V */
    ACMP_VREF3,     /*!< The P/N poles of ACMP can be connected to the internal reference voltage 0.75 * 0.9V */
    ACMP_VREF4,     /*!< The P/N poles of ACMP can be connected to the internal reference voltage 1.00 * 0.9V */
    ACMP_EXTPIN5,   /*!< The P/N poles of ACMP can be connected to external pin (ACMP_ID0-->GPIO3, ACMP_ID1-->GPIO0) */
    ACMP_EXTPIN6,   /*!< The P/N poles of ACMP can be connected to external pin (ACMP_ID0-->GPIO4, ACMP_ID1-->GPIO1) */
};
 
/**
 * @brief ACMP configure structure
 */
struct ACMP_CFG_T
{
    uint8_t channel_p;    /*!< The positive can be set to an internal reference voltage or an external input voltage.
                               This parameter can be a value of @ref ACMP_DEV_CH_T
                          */
    uint8_t channel_n;    /*!< The negative can be set to an internal reference voltage or an external input voltage.
                               This parameter can be a value of @ref ACMP_DEV_CH_T
                          */
    uint8_t int_en;       /*!< Specifies whether the interrupt is enabled or disabled
                               This parameter will be one of the following values:
                                   @arg true is enable
                                   @arg false is disable
                          */
    uint8_t edge_int : 4; /*!< Specifies interrupt edge trigger mode.
                               This parameter will be one of the following values:
                                   @arg @ref ACMP_POSEDGE_INT    Rising edge trigger
                                   @arg @ref ACMP_NEGEDGE_INT    Falling edge trigger
                                   @arg @ref ACMP_BOTHEDGE_INT   Rising/Falling edge trigger
                          */
 
    uint8_t hyst_en : 4;     /*!< Specifies whether the hysteresis is enabled or disabled.
                                  This parameter will be one of the following values:
                                      @arg true is enable
                                      @arg false is disable
                             */
    drv_callback_t callback; /*!< Callback function provided by the user */
};
 
/**
 * @brief ACMP handle Structure
 */
struct ACMP_HANDLE_T
{
    const IRQn_Type irq;
    struct ACMP_CFG_T config;
};
 
#ifdef __cplusplus
extern "C" {
#endif
/**
 * @brief Function for initializing the ACMP.
 *
 * @param[in] id            ACMP device ID.
 * @param[in] config        Pointer to a ACMP_CFG_T structure that contains the configuration information for ACMP.
 *                          If this config is NULL, this function will use the default config.
 * @return
 *         @arg DEV_ERROR   error id
 *         @arg DEV_OK      succeed
 */
int acmp_open(enum ACMP_DEV_T id, struct ACMP_CFG_T *config);
 
/**
 * @brief Function for uninitializing the ACMP.
 *
 * @param[in] id            ACMP device ID.
 * @return
 *         @arg DEV_ERROR   error id
 *         @arg DEV_OK      succeed
 */
int acmp_close(enum ACMP_DEV_T id);
 
/**
 * @brief Function for getting the result of ACMP output.
 *
 * @param[in] id            ACMP device ID.
 * @return
 *         @arg RESULT   0 or 1
 *         @arg DRV_DEV_UNAVAILABLE   error id
 */
int acmp_get(enum ACMP_DEV_T id);
 
/**
 * @brief Function for Interrupt handler for ACMP0.
 */
void ACMP0_IRQHandler(void);
 
/**
 * @brief Function for Interrupt handler for ACMP1.
 */
void ACMP1_IRQHandler(void);
 
#ifdef __cplusplus
}
#endif
 
/**
 * @}
 */
 
#endif /* MK_ACMP_H_ */