• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "adc_if.h"
10 #include "adc_core.h"
11 #include "hdf_log.h"
12 #include "osal_mem.h"
13 #include "securec.h"
14 #define HDF_LOG_TAG adc_if_c
15 #define ADC_SERVICE_NAME "HDF_PLATFORM_ADC_MANAGER"
16 
AdcOpen(uint32_t number)17 DevHandle AdcOpen(uint32_t number)
18 {
19     int32_t ret;
20     struct AdcDevice *device = NULL;
21 
22     device = AdcDeviceGet(number);
23     if (device == NULL) {
24         HDF_LOGE("AdcOpen: device is null!");
25         return NULL;
26     }
27 
28     ret = AdcDeviceStart(device);
29     if (ret != HDF_SUCCESS) {
30         HDF_LOGE("AdcOpen: adc device start fail!");
31         return NULL;
32     }
33 
34     return (DevHandle)device;
35 }
36 
AdcClose(DevHandle handle)37 void AdcClose(DevHandle handle)
38 {
39     struct AdcDevice *device = (struct AdcDevice *)handle;
40 
41     if (device == NULL) {
42         HDF_LOGE("AdcClose: device is null!");
43         return;
44     }
45 
46     (void)AdcDeviceStop(device);
47     AdcDevicePut(device);
48 }
49 
AdcRead(DevHandle handle,uint32_t channel,uint32_t * val)50 int32_t AdcRead(DevHandle handle, uint32_t channel, uint32_t *val)
51 {
52     if (handle == NULL) {
53         HDF_LOGE("AdcRead: invalid handle!");
54         return HDF_ERR_INVALID_PARAM;
55     }
56     return AdcDeviceRead((struct AdcDevice *)handle, channel, val);
57 }
58