• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "dac_if.h"
10 #include "dac_core.h"
11 #include "hdf_log.h"
12 #define HDF_LOG_TAG dac_if_c
13 #define DAC_SERVICE_NAME "HDF_PLATFORM_DAC_MANAGER"
14 
DacOpen(uint32_t number)15 DevHandle DacOpen(uint32_t number)
16 {
17     int32_t ret;
18     struct DacDevice *device = NULL;
19 
20     device = DacDeviceGet(number);
21     if (device == NULL) {
22         HDF_LOGE("%s: Get device failed!", __func__);
23         return NULL;
24     }
25 
26     ret = DacDeviceStart(device);
27     if (ret != HDF_SUCCESS) {
28         HDF_LOGE("%s: start device failed!", __func__);
29         return NULL;
30     }
31 
32     return (DevHandle)device;
33 }
34 
DacClose(DevHandle handle)35 void DacClose(DevHandle handle)
36 {
37     struct DacDevice *device = (struct DacDevice *)handle;
38 
39     if (device == NULL) {
40         return;
41     }
42 
43     (void)DacDeviceStop(device);
44     DacDevicePut(device);
45 }
46 
DacWrite(DevHandle handle,uint32_t channel,uint32_t val)47 int32_t DacWrite(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 DacDeviceWrite((struct DacDevice *)handle, channel, val);
54 }
55