• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2 * @file hi_adc.h
3 *
4 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * 描述:Analog-to-digital conversion (ADC) module interface.
18 * @li Provides 8 ADC channels.
19 CNcomment:提供8个ADC通道,通道7为参考电压,不能adc转换。CNend
20 * @li LSADC reading rate is slow, please avoid used in interruption.
21 CNcomment: LSADC读数速率较慢,请避免在中断使用。CNend
22 * Author: Hisilicon \n
23 * Create: 2019-4-3
24 */
25 
26 /**
27 * @defgroup iot_ls_adc ADC
28 * @ingroup drivers
29 */
30 
31 #ifndef __HI_ADC_H__
32 #define __HI_ADC_H__
33 
34 #include <hi_types.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /**
41  * @ingroup iot_ls_adc
42  *
43  * channel ID。CNcomment:通道编号.CNend
44  */
45 typedef enum {
46     HI_ADC_CHANNEL_0,
47     HI_ADC_CHANNEL_1,
48     HI_ADC_CHANNEL_2,
49     HI_ADC_CHANNEL_3,
50     HI_ADC_CHANNEL_4,
51     HI_ADC_CHANNEL_5,
52     HI_ADC_CHANNEL_6,
53     HI_ADC_CHANNEL_7,
54     HI_ADC_CHANNEL_BUTT,
55 } hi_adc_channel_index;
56 
57 /**
58  * @ingroup iot_ls_adc
59  *
60  * Analog power control. CNcomment:模拟电源控制。CNend
61  */
62 typedef enum {
63     HI_ADC_CUR_BAIS_DEFAULT,       /**< 0:Auto control.
64                                       CNcomment:自动识别模式 */
65     HI_ADC_CUR_BAIS_AUTO,          /**< 1:Auto control.
66                                       CNcomment:自动识别模式 */
67     HI_ADC_CUR_BAIS_1P8V,          /**< 2:Manual control, AVDD=1.8V.
68                                       CNcomment:手动控制,AVDD=1.8V */
69     HI_ADC_CUR_BAIS_3P3V,          /**< 3:Manual control, AVDD=3.3V.
70                                       CNcomment:手动控制,AVDD=3.3V */
71     HI_ADC_CUR_BAIS_BUTT,
72 } hi_adc_cur_bais;
73 
74 /**
75  * @ingroup iot_ls_adc
76  *
77  * Average algorithm mode CNcoment:平均算法模式。CNend
78  */
79 typedef enum {
80     HI_ADC_EQU_MODEL_1,            /**< 0:The average value is not used.
81                                       CNcomment:1次平均,即不进行
82                                       平均 CNend */
83     HI_ADC_EQU_MODEL_2,            /**< 1:2-time average algorithm mode.
84                                       CNcomment:2次平均算法模式 CNend */
85     HI_ADC_EQU_MODEL_4,            /**< 2:4-time average algorithm mode.
86                                       CNcomment:4次平均算法模式 CNend */
87     HI_ADC_EQU_MODEL_8,            /**< 3:8-time average algorithm mode.
88                                       CNcomment:8次平均算法模式 CNend */
89     HI_ADC_EQU_MODEL_BUTT,
90 } hi_adc_equ_model_sel;
91 
92 /**
93 * @ingroup  iot_ls_adc
94 * @brief  Read one data in single ADC channel. CNcomment:从一个ADC通道读一个数据。CNend
95 *
96 * @par 描述:
97 *           Read one data in single ADC channel.
98 CNcomment:从一个ADC通道读一个数据。CNend
99 *
100 * @attention None
101 * @param  channel      [IN] type #hi_adc_channel_index,channel to be read. CNcomment:要读的channel。CNend
102 * @param  data         [OUT] type #hi_u16 * ,data point to store the data.
103 CNcomment:读取的ADC数据保存地址。CNend
104 * @param  equ_model    [IN] type #hi_adc_equ_model_sel ,Average algorithm mode.
105 CNcomment:平均算法模式。CNend
106 * @param  cur_bais     [IN] type #hi_adc_cur_bais ,Analog power control.
107 CNcomment:模拟电源控制。CNend
108 * @param  delay_cnt      [IN] type #hi_u16 ,Countings from config to start collect,One count is 334ns,[0, 0xFF0].
109 CNcomment:从配置采样到启动采样的延时时间计数,一次计数是334ns,其值需在0~0xFF0之间。CNend
110 * @retval #HI_ERR_SUCCESS  Success.
111 * @retval #Other          Failure. See hi_errno.h for details.
112 * @par 依赖:
113 *            @li hi_adc.h:Describes ADC APIs.
114 CNcomment:文件用于描述ADC相关接口。CNend
115 * @see  hi_adc_read。
116 */
117 hi_u32 hi_adc_read(hi_adc_channel_index channel, hi_u16 *data, hi_adc_equ_model_sel equ_model,
118     hi_adc_cur_bais cur_bais, hi_u16 delay_cnt);
119 
120 
121 /**
122 * @ingroup  iot_ls_adc
123 * @brief  Convert adc read data to voltage. CNcomment:将ADC读取到的码字转换为电压。CNend
124 *
125 * @par 描述:
126 *           Convert adc read data to voltage.
127 CNcomment:将ADC读取到的码字转换为电压。CNend
128 *
129 * @attention None
130 * @param  data      [IN] type #hi_u16,data read by adc. CNcomment:ADC读取到的码字。CNend
131 * @retval votalge converted by data. CNcomment: 码字转换得到的电压。CNend
132 * @par 依赖:
133 *            @li hi_adc.h:Describes ADC APIs.
134 CNcomment:文件用于描述ADC相关接口。CNend
135 * @see  hi_adc_read。
136 */
137 hi_float hi_adc_convert_to_voltage(hi_u16 data);
138 
139 
140 #ifdef __cplusplus
141 }
142 #endif
143 #endif
144