2 * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include "peripheral_io.h"
23 #include "peripheral_dbus.h"
24 #include "peripheral_common.h"
30 #define I2C_NAME "i2c"
33 peripheral_i2c_context_h peripheral_i2c_init(int bus)
35 peripheral_i2c_context_h dev;
36 int ret = PERIPHERAL_ERROR_NONE;
40 /* Initialize peripheral_i2c_context_h */
41 dev = (peripheral_i2c_context_h)malloc(sizeof(struct _peripheral_i2c_s));
44 _E("Failed to allocate peripheral_i2c_context_h");
48 if (!get_dbus_connection())
49 set_dbus_connection();
51 ret = peripheral_dbus_i2c(dev, I2C_NAME, "INIT", bus, 0, I2C_Addr);
53 if (ret != PERIPHERAL_ERROR_NONE) {
55 _E("[PERIPHERAL] I2C init error\n");
62 int peripheral_i2c_stop(peripheral_i2c_context_h dev)
64 int ret = PERIPHERAL_ERROR_NONE;
65 /* Free peripheral_i2c_context_h */
68 ret = peripheral_dbus_i2c(dev, I2C_NAME, "STOP", 0, 0, I2C_Addr);
77 int peripheral_i2c_set_frequency(peripheral_i2c_context_h dev, peripheral_i2c_mode_e mode)
79 /* Set the clocking for the selected frequency */
80 return peripheral_dbus_i2c(dev, I2C_NAME, "SET_FREQ", mode, 0, I2C_Addr);
83 int peripheral_i2c_set_address(peripheral_i2c_context_h dev, int address)
85 /* Set the i2c slave address */
88 return peripheral_dbus_i2c(dev, I2C_NAME, "SET_ADDR", address, 0, I2C_Addr);
91 int peripheral_i2c_read(peripheral_i2c_context_h dev, uint8_t *data, int length)
94 return peripheral_dbus_i2c(dev, I2C_NAME, "READ", length, data, I2C_Addr);
97 int peripheral_i2c_write(peripheral_i2c_context_h dev, uint8_t *data, int length)
100 return peripheral_dbus_i2c(dev, I2C_NAME, "WRITE", length, data, I2C_Addr);