INCLUDE_DIRECTORIES(${INC_DIR})
INCLUDE_DIRECTORIES(${INC_DIR}/gdbus)
INCLUDE_DIRECTORIES(${INC_DIR}/interface)
+INCLUDE_DIRECTORIES(${INC_DIR}/direct)
SET(SRC_DIR src)
INCLUDE_DIRECTORIES(${SRC_DIR}/gdbus)
src/peripheral_adc.c
src/peripheral_uart.c
src/peripheral_spi.c
+ src/direct/peripheral_i2c_direct.c
src/interface/peripheral_interface_gpio.c
src/interface/peripheral_interface_i2c.c
src/interface/peripheral_interface_pwm.c
--- /dev/null
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PERIPHERAL_DIRECT_COMMON_H__
+#define __PERIPHERAL_DIRECT_COMMON_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <peripheral_io.h>
+
+#include "peripheral_log.h"
+
+#define MAX_ERR_LEN 255
+#define MAX_BUF_LEN 96
+
+#define IF_ERROR_RETURN(expr, func...) \
+ do { \
+ if (expr) { \
+ int temp = errno; \
+ func; \
+ if (temp == EAGAIN) \
+ return PERIPHERAL_ERROR_TRY_AGAIN; \
+ char errmsg[MAX_ERR_LEN]; \
+ strerror_r(temp, errmsg, sizeof(errmsg)); \
+ _E("Failed the %s(%d) function. errmsg: %s", __FUNCTION__, __LINE__, errmsg); \
+ return PERIPHERAL_ERROR_IO_ERROR; \
+ } \
+ } while (0)
+
+#endif /*__PERIPHERAL_DIRECT_COMMON_H__*/
--- /dev/null
+int peripheral_direct_i2c_open(int bus, int address, int *fd_out);
--- /dev/null
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+#include "peripheral_io.h"
+#include "peripheral_log.h"
+#include "peripheral_interface_i2c.h"
+#include "peripheral_direct_common.h"
+
+
+int peripheral_direct_i2c_open(int bus, int address, int *fd_out)
+{
+ RETVM_IF(bus < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c bus");
+ RETVM_IF(address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c address");
+ RETVM_IF(fd_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for i2c");
+
+ int ret;
+ int fd;
+ char path[MAX_BUF_LEN] = {0, };
+
+ snprintf(path, MAX_BUF_LEN, "/dev/i2c-%d", bus);
+ fd = open(path, O_RDWR);
+ IF_ERROR_RETURN(fd < 0);
+
+ ret = ioctl(fd, I2C_SLAVE, address);
+ IF_ERROR_RETURN(ret != 0, close(fd));
+
+ *fd_out = fd;
+
+ return PERIPHERAL_ERROR_NONE;
+}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
#include <stdlib.h>
#include <system_info.h>
#include "peripheral_handle.h"
#include "peripheral_gdbus_i2c.h"
#include "peripheral_interface_i2c.h"
+#include "peripheral_direct_i2c.h"
#include "peripheral_log.h"
#define PERIPHERAL_IO_I2C_FEATURE "http://tizen.org/feature/peripheral_io.i2c"
return PERIPHERAL_ERROR_OUT_OF_MEMORY;
}
- ret = peripheral_gdbus_i2c_open(handle, bus, address);
+ ret = peripheral_direct_i2c_open(bus, address, &handle->fd);
if (ret != PERIPHERAL_ERROR_NONE) {
_E("Failed to open i2c communication, ret : %d", ret);
free(handle);
RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
- ret = peripheral_gdbus_i2c_close(i2c);
- if (ret != PERIPHERAL_ERROR_NONE)
- _E("Failed to close i2c communcation, ret : %d", ret);
+ // ret = peripheral_gdbus_i2c_close(i2c);
+ // if (ret != PERIPHERAL_ERROR_NONE)
+ // _E("Failed to close i2c communcation, ret : %d", ret);
peripheral_interface_i2c_close(i2c);