1 /*
2 * Copyright (c) 2021 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 return NULL;
25 }
26
27 ret = AdcDeviceStart(device);
28 if (ret != HDF_SUCCESS) {
29 return NULL;
30 }
31
32 return (DevHandle)device;
33 }
34
AdcClose(DevHandle handle)35 void AdcClose(DevHandle handle)
36 {
37 struct AdcDevice *device = (struct AdcDevice *)handle;
38
39 if (device == NULL) {
40 return;
41 }
42
43 (void)AdcDeviceStop(device);
44 AdcDevicePut(device);
45 }
46
AdcRead(DevHandle handle,uint32_t channel,uint32_t * val)47 int32_t AdcRead(DevHandle handle, uint32_t channel, uint32_t *val)
48 {
49 if (handle == NULL) {
50 HDF_LOGE("%s: invalid handle!", __func__);
51 return HDF_ERR_INVALID_PARAM;
52 }
53 return AdcDeviceRead((struct AdcDevice *)handle, channel, val);
54 }
55