1 #ifndef _BFLB_ACOMP_H
2 #define _BFLB_ACOMP_H
3 
4 #include "bflb_core.h"
5 
6 /** @addtogroup LHAL
7   * @{
8   */
9 
10 /** @addtogroup ACOMP
11   * @{
12   */
13 
14 /** @defgroup Analog compare id type definition
15  * @{
16  */
17 #define AON_ACOMP0_ID   0
18 #define AON_ACOMP1_ID   1
19 
20 
21 /** @defgroup Analog compare scaling factor type definition
22  * @{
23  */
24 #define AON_ACOMP_SCALING_FACTOR_0P25           0x00    /*!< Analog compare level scaling factor 0.25 */
25 #define AON_ACOMP_SCALING_FACTOR_0P5            0x10    /*!< Analog compare level scaling factor 0.5 */
26 #define AON_ACOMP_SCALING_FACTOR_0P75           0x20    /*!< Analog compare level scaling factor 0.75 */
27 #define AON_ACOMP_SCALING_FACTOR_1              0x30    /*!< Analog compare level scaling factor 1 */
28 
29 /**
30  *  @brief Analog compare channel type definition
31  */
32 #define AON_ACOMP_CHAN_ADC0                     0   /*!< Analog compare channel,ADC input channel 0 */
33 #define AON_ACOMP_CHAN_ADC1                     1   /*!< Analog compare channel,ADC input channel 1 */
34 #define AON_ACOMP_CHAN_ADC2                     2   /*!< Analog compare channel,ADC input channel 2 */
35 #define AON_ACOMP_CHAN_ADC3                     3   /*!< Analog compare channel,ADC input channel 3 */
36 #define AON_ACOMP_CHAN_ADC4                     4   /*!< Analog compare channel,ADC input channel 4 */
37 #define AON_ACOMP_CHAN_ADC5                     5   /*!< Analog compare channel,ADC input channel 5 */
38 #define AON_ACOMP_CHAN_ADC6                     6   /*!< Analog compare channel,ADC input channel 6 */
39 #define AON_ACOMP_CHAN_ADC7                     7   /*!< Analog compare channel,ADC input channel 7 */
40 #define AON_ACOMP_CHAN_DACA                     8   /*!< Analog compare channel,DAC output channel A */
41 #define AON_ACOMP_CHAN_DACB                     9   /*!< Analog compare channel,DAC output channel B */
42 #define AON_ACOMP_CHAN_VREF_1P25V               10  /*!< Analog compare channel,1.25V ref voltage */
43 #define AON_ACOMP_CHAN_VIO_X_SCALING_FACTOR_1   11  /*!< Analog compare channel,first,VIO * scaling factor */
44 #define AON_ACOMP_CHAN_VIO_X_SCALING_FACTOR_2   12  /*!< Analog compare channel,second,VIO * scaling factor */
45 #define AON_ACOMP_CHAN_VIO_X_SCALING_FACTOR_3   13  /*!< Analog compare channel,third,VIO * scaling factor */
46 #define AON_ACOMP_CHAN_VIO_X_SCALING_FACTOR_4   14  /*!< Analog compare channel,forth,VIO * scaling factor */
47 #define AON_ACOMP_CHAN_VSS                      15  /*!< Analog compare channel,vss */
48 
49 /**
50  *  @brief Analog compare bias current control type definition
51  */
52 #define AON_ACOMP_BIAS_POWER_MODE1              0   /*!< Analog compare power mode 1,slow response mode */
53 #define AON_ACOMP_BIAS_POWER_MODE2              1   /*!< Analog compare power mode 2,medium response mode */
54 #define AON_ACOMP_BIAS_POWER_MODE3              2   /*!< Analog compare power mode 3,fast response mode */
55 #define AON_ACOMP_BIAS_POWER_NONE               3   /*!< Analog compare power mode none */
56 
57 /**
58  *  @brief Analog compare hysteresis voltage type definition
59  */
60 #define AON_ACOMP_HYSTERESIS_VOLT_NONE          0   /*!< Analog compare hysteresis voltage none */
61 #define AON_ACOMP_HYSTERESIS_VOLT_10MV          1   /*!< Analog compare hysteresis voltage 10mv */
62 #define AON_ACOMP_HYSTERESIS_VOLT_20MV          2   /*!< Analog compare hysteresis voltage 20mv */
63 #define AON_ACOMP_HYSTERESIS_VOLT_30MV          3   /*!< Analog compare hysteresis voltage 30mv */
64 #define AON_ACOMP_HYSTERESIS_VOLT_40MV          4   /*!< Analog compare hysteresis voltage 40mv */
65 #define AON_ACOMP_HYSTERESIS_VOLT_50MV          5   /*!< Analog compare hysteresis voltage 50mv */
66 #define AON_ACOMP_HYSTERESIS_VOLT_60MV          6   /*!< Analog compare hysteresis voltage 60mv */
67 #define AON_ACOMP_HYSTERESIS_VOLT_70MV          7   /*!< Analog compare hysteresis voltage 70mv */
68 
69 
70 /**
71  * @brief ACOMP configuration structure
72  *
73  * @param mux_en                    ACOMP mux enable
74  * @param pos_chan_sel              ACOMP positive channel select
75  * @param neg_chan_sel              ACOMP negtive channel select
76  * @param vio_sel                   ACOMP VIO voltage select, (vioSel/66)*avdd33
77  * @param scaling_factor            ACOMP scaling factor select factor
78  * @param bias_prog                 ACOMP bias current control
79  * @param hysteresis_pos_volt       ACOMP hysteresis voltage for positive
80  * @param hysteresis_neg_volt       ACOMP hysteresis voltage for negtive
81  */
82 struct bflb_acomp_config_s {
83     uint8_t mux_en;
84     uint8_t pos_chan_sel;
85     uint8_t neg_chan_sel;
86     uint8_t vio_sel;
87     uint8_t scaling_factor;
88     uint8_t bias_prog;
89     uint8_t hysteresis_pos_volt;
90     uint8_t hysteresis_neg_volt;
91 };
92 
93 
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97 
98 /**
99  * @brief Initialize acomp.
100  *
101  * @param [in] acomp_id acomp index
102  * @param [in] config pointer to save acomp configuration
103  */
104 void bflb_acomp_init(uint8_t acomp_id, const struct bflb_acomp_config_s *config);
105 
106 /**
107  * @brief Enable acomp.
108  *
109  * @param [in] acomp_id acomp index
110  */
111 void bflb_acomp_enable(uint8_t acomp_id);
112 
113 /**
114  * @brief Disable acomp.
115  *
116  * @param [in] acomp_id acomp index
117  */
118 void bflb_acomp_disable(uint8_t acomp_id);
119 
120 /**
121  * @brief Get acomp result.
122  *
123  * @param [in] acomp_id acomp index
124  * @return acomp result
125  */
126 uint32_t bflb_acomp_get_result(uint8_t acomp_id);
127 
128 /**
129  * @brief gpio change adc_chan_id.
130  *
131  * @param [in] pin gpio index
132  * @param [out] channel adc channel index
133  * @return Zero on success; a negated errno value on failure
134  */
135 uint32_t bflb_acomp_gpio_2_chanid(uint32_t pin, uint32_t* channel);
136 
137 /**
138  * @brief adc_chan_id change gpio index.
139  *
140  * @param [in] channel adc channel index
141  * @param [out] pin gpio index
142  * @return Zero on success; a negated errno value on failure
143  */
144 uint32_t bflb_acomp_chanid_2_gpio(uint32_t channel, uint32_t* pin);
145 
146 
147 #if 0
148 /**
149  * @brief Get acomp postive input.
150  *
151  * @param [in] acomp_id acomp index
152  * @return acomp postive input
153  */
154 uint32_t bflb_acomp_get_postive_input(uint8_t acomp_id);
155 #endif
156 
157 
158 #ifdef __cplusplus
159 }
160 #endif
161 
162 #endif
163