• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-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 "i2c_if.h"
10 #include "devsvc_manager_clnt.h"
11 #include "hdf_base.h"
12 #include "hdf_log.h"
13 #include "i2c_core.h"
14 #include "osal_mem.h"
15 #include "securec.h"
16 
17 #define HDF_LOG_TAG i2c_if
18 
19 #define I2C_SERVICE_NAME "HDF_PLATFORM_I2C_MANAGER"
20 
I2cOpen(int16_t number)21 DevHandle I2cOpen(int16_t number)
22 {
23     return (DevHandle)I2cCntlrGet(number);
24 }
25 
I2cClose(DevHandle handle)26 void I2cClose(DevHandle handle)
27 {
28     if (handle != NULL) {
29         I2cCntlrPut((struct I2cCntlr *)handle);
30     }
31 }
32 
I2cTransfer(DevHandle handle,struct I2cMsg * msgs,int16_t count)33 int32_t I2cTransfer(DevHandle handle, struct I2cMsg *msgs, int16_t count)
34 {
35     if (handle == NULL) {
36         HDF_LOGE("I2cTransfer: handle is null!");
37         return HDF_ERR_INVALID_OBJECT;
38     }
39 
40     if (msgs == NULL || count <= 0) {
41         HDF_LOGE("I2cTransfer: err params! msgs:%s, count:%hd!", (msgs == NULL) ? "0" : "x", count);
42         return HDF_ERR_INVALID_PARAM;
43     }
44 
45     return I2cCntlrTransfer((struct I2cCntlr *)handle, msgs, count);
46 }
47