src/gdbus/peripheral_gdbus_gpio.c
src/gdbus/peripheral_gdbus_i2c.c
src/gdbus/peripheral_gdbus_pwm.c
+ src/gdbus/peripheral_gdbus_adc.c
src/gdbus/peripheral_gdbus_spi.c
src/gdbus/peripheral_gdbus_uart.c
src/handle/peripheral_handle_common.c
src/handle/peripheral_handle_pwm.c
+ src/handle/peripheral_handle_adc.c
src/handle/peripheral_handle_i2c.c
src/handle/peripheral_handle_gpio.c
src/handle/peripheral_handle_uart.c
src/interface/peripheral_interface_gpio.c
src/interface/peripheral_interface_i2c.c
src/interface/peripheral_interface_pwm.c
+ src/interface/peripheral_interface_adc.c
src/interface/peripheral_interface_uart.c
src/interface/peripheral_interface_spi.c
src/util/peripheral_board.c
--- /dev/null
+/*
+ * Copyright (c) 2018 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_GDBUS_ADC_H__
+#define __PERIPHERAL_GDBUS_ADC_H__
+
+#include "peripheral_io_gdbus.h"
+
+gboolean peripheral_gdbus_adc_open(
+ PeripheralIoGdbusAdc *adc,
+ GDBusMethodInvocation *invocation,
+ GUnixFDList *fd_list,
+ gint device,
+ gint channel,
+ gpointer user_data);
+
+gboolean peripheral_gdbus_adc_close(
+ PeripheralIoGdbusAdc *adc,
+ GDBusMethodInvocation *invocation,
+ gint handle,
+ gpointer user_data);
+
+#endif /* __PERIPHERAL_GDBUS_ADC_H__ */
/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016-2018 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.
GList *gpio_list;
GList *i2c_list;
GList *pwm_list;
+ GList *adc_list;
GList *uart_list;
GList *spi_list;
/* gdbus variable */
PeripheralIoGdbusGpio *gpio_skeleton;
PeripheralIoGdbusI2c *i2c_skeleton;
PeripheralIoGdbusPwm *pwm_skeleton;
+ PeripheralIoGdbusAdc *adc_skeleton;
PeripheralIoGdbusUart *uart_skeleton;
PeripheralIoGdbusSpi *spi_skeleton;
} peripheral_info_s;
int pin;
} peripheral_handle_pwm_s;
+typedef struct {
+ int device;
+ int channel;
+} peripheral_handle_adc_s;
+
typedef struct {
int port;
} peripheral_handle_uart_s;
peripheral_handle_gpio_s gpio;
peripheral_handle_i2c_s i2c;
peripheral_handle_pwm_s pwm;
+ peripheral_handle_adc_s adc;
peripheral_handle_uart_s uart;
peripheral_handle_spi_s spi;
} type;
--- /dev/null
+/*
+ * Copyright (c) 2018 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_HANDLE_ADC_H__
+#define __PERIPHERAL_HANDLE_ADC_H__
+
+int peripheral_handle_adc_create(int device, int channel, peripheral_h *handle, gpointer user_data);
+int peripheral_handle_adc_destroy(peripheral_h handle);
+
+#endif /* __PERIPHERAL_HANDLE_ADC_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2018 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_INTERFACE_ADC_H__
+#define __PERIPHERAL_INTERFACE_ADC_H__
+
+#include <gio/gunixfdlist.h>
+
+int peripheral_interface_adc_fd_list_create(int device, int channel, GUnixFDList **list_out);
+void peripheral_interface_adc_fd_list_destroy(GUnixFDList *list);
+
+#endif /* __PERIPHERAL_INTERFACE_ADC_H__ */
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017-2018 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.
PB_BOARD_DEV_GPIO = 0,
PB_BOARD_DEV_I2C,
PB_BOARD_DEV_PWM,
+ PB_BOARD_DEV_ADC,
PB_BOARD_DEV_UART,
PB_BOARD_DEV_SPI,
PB_BOARD_DEV_MAX,
send_interface="org.tizen.peripheral_io.i2c"/>
<allow send_destination="org.tizen.peripheral_io"
send_interface="org.tizen.peripheral_io.pwm"/>
+ <allow send_destination="org.tizen.peripheral_io"
+ send_interface="org.tizen.peripheral_io.adc"/>
<allow send_destination="org.tizen.peripheral_io"
send_interface="org.tizen.peripheral_io.uart"/>
<allow send_destination="org.tizen.peripheral_io"
--- /dev/null
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#include <peripheral_io.h>
+#include <gio/gunixfdlist.h>
+
+#include "peripheral_log.h"
+#include "peripheral_privilege.h"
+#include "peripheral_io_gdbus.h"
+#include "peripheral_handle.h"
+#include "peripheral_handle_adc.h"
+#include "peripheral_interface_adc.h"
+#include "peripheral_gdbus_adc.h"
+
+static void __adc_on_name_vanished(GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ int ret = PERIPHERAL_ERROR_NONE;
+
+ peripheral_h adc_handle = (peripheral_h)user_data;
+ _D("appid [%s] vanished ", name);
+
+ g_bus_unwatch_name(adc_handle->watch_id);
+
+ ret = peripheral_handle_adc_destroy(adc_handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to destroy adc handle");
+}
+
+gboolean peripheral_gdbus_adc_open(
+ PeripheralIoGdbusAdc *adc,
+ GDBusMethodInvocation *invocation,
+ GUnixFDList *fd_list,
+ gint device,
+ gint channel,
+ gpointer user_data)
+{
+ int ret = PERIPHERAL_ERROR_NONE;
+
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h adc_handle = NULL;
+ GUnixFDList *adc_fd_list = NULL;
+
+ ret = peripheral_privilege_check(invocation, info->connection);
+ if (ret != 0) {
+ _E("Permission denied.");
+ ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
+ goto out;
+ }
+
+ ret = peripheral_interface_adc_fd_list_create(device, channel, &adc_fd_list);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to create adc fd list");
+ goto out;
+ }
+
+ ret = peripheral_handle_adc_create(device, channel, &adc_handle, user_data);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to create adc handle");
+ goto out;
+ }
+
+ adc_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+ g_dbus_method_invocation_get_sender(invocation),
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ NULL,
+ __adc_on_name_vanished,
+ adc_handle,
+ NULL);
+
+out:
+ peripheral_io_gdbus_adc_complete_open(adc, invocation, adc_fd_list, GPOINTER_TO_UINT(adc_handle), ret);
+ peripheral_interface_adc_fd_list_destroy(adc_fd_list);
+
+ return true;
+}
+
+gboolean peripheral_gdbus_adc_close(
+ PeripheralIoGdbusAdc *adc,
+ GDBusMethodInvocation *invocation,
+ gint handle,
+ gpointer user_data)
+{
+ int ret = PERIPHERAL_ERROR_NONE;
+
+ peripheral_h adc_handle = GUINT_TO_POINTER(handle);
+
+ g_bus_unwatch_name(adc_handle->watch_id);
+
+ ret = peripheral_handle_adc_destroy(adc_handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to destroy adc handle");
+
+ peripheral_io_gdbus_adc_complete_close(adc, invocation, ret);
+
+ return true;
+}
<arg type="i" name="result" direction="out"/>
</method>
</interface>
+ <interface name="org.tizen.peripheral_io.adc">
+ <method name="Open">
+ <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
+ <arg type="i" name="device" direction="in"/>
+ <arg type="i" name="channel" direction="in"/>
+ <arg type="u" name="handle" direction="out"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="Close">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ </interface>
<interface name="org.tizen.peripheral_io.uart">
<method name="Open">
<annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
--- /dev/null
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#include "peripheral_handle_common.h"
+
+static bool __peripheral_handle_adc_is_creatable(int device, int channel, peripheral_info_s *info)
+{
+ pb_board_dev_s *adc = NULL;
+ peripheral_h handle;
+ GList *link;
+
+ RETV_IF(info == NULL, false);
+ RETV_IF(info->board == NULL, false);
+
+ adc = peripheral_bus_board_find_device(PB_BOARD_DEV_ADC, info->board, device, channel);
+ if (adc == NULL) {
+ _E("Not supported ADC device : %d, channel : %d", device, channel);
+ return false;
+ }
+
+ link = info->adc_list;
+ while (link) {
+ handle = (peripheral_h)link->data;
+ if (handle->type.adc.device == device && handle->type.adc.channel == channel) {
+ _E("Resource is in use, device : %d, channel : %d", device, channel);
+ return false;
+ }
+ link = g_list_next(link);
+ }
+
+ return true;
+}
+
+int peripheral_handle_adc_destroy(peripheral_h handle)
+{
+ RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc handle");
+
+ int ret = PERIPHERAL_ERROR_NONE;
+
+ ret = peripheral_handle_free(handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to free adc handle");
+
+ return ret;
+}
+
+int peripheral_handle_adc_create(int device, int channel, peripheral_h *handle, gpointer user_data)
+{
+ RETVM_IF(device < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc device");
+ RETVM_IF(channel < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc channel");
+ RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc handle");
+
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+
+ peripheral_h adc_handle = NULL;
+ bool is_handle_creatable = false;
+
+ is_handle_creatable = __peripheral_handle_adc_is_creatable(device, channel, info);
+ if (is_handle_creatable == false) {
+ _E("device : %d, channel : 0x%x is not available", device, channel);
+ return PERIPHERAL_ERROR_RESOURCE_BUSY;
+ }
+
+ adc_handle = peripheral_handle_new(&info->adc_list);
+ if (adc_handle == NULL) {
+ _E("peripheral_handle_new error");
+ return PERIPHERAL_ERROR_OUT_OF_MEMORY;
+ }
+
+ adc_handle->list = &info->adc_list;
+ adc_handle->type.adc.device = device;
+ adc_handle->type.adc.channel = channel;
+
+ *handle = adc_handle;
+
+ return PERIPHERAL_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#include <sys/ioctl.h>
+
+#include "peripheral_interface_adc.h"
+#include "peripheral_interface_common.h"
+
+static int __peripheral_interface_adc_fd_open(int device, int channel, int *fd_out)
+{
+ RETVM_IF(device < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc device");
+ RETVM_IF(channel < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc channel");
+ RETVM_IF(fd_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for adc");
+
+ int fd;
+ char path[MAX_BUF_LEN] = {0, };
+
+ snprintf(path, MAX_BUF_LEN, "/sys/bus/iio/devices/iio:device%d/in_voltage%d_raw", device, channel);
+ fd = open(path, O_RDWR);
+ IF_ERROR_RETURN(fd < 0);
+
+ *fd_out = fd;
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_adc_fd_list_create(int device, int channel, GUnixFDList **list_out)
+{
+ RETVM_IF(device < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc device");
+ RETVM_IF(channel < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc channel");
+
+ int ret;
+
+ GUnixFDList *list = NULL;
+ int fd = -1;
+
+
+ ret = __peripheral_interface_adc_fd_open(device, channel, &fd);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to open adc fd");
+ }
+
+ list = g_unix_fd_list_new();
+ if (list == NULL) {
+ _E("Failed to create adc fd list");
+ ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ /* Do not change the order of the fd list */
+ g_unix_fd_list_append(list, fd, NULL);
+
+ *list_out = list;
+
+out:
+ close(fd);
+
+ return ret;
+}
+
+void peripheral_interface_adc_fd_list_destroy(GUnixFDList *list)
+{
+ if (list != NULL)
+ g_object_unref(list);
+}
/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016-2018 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.
#include "peripheral_gdbus_gpio.h"
#include "peripheral_gdbus_i2c.h"
#include "peripheral_gdbus_pwm.h"
+#include "peripheral_gdbus_adc.h"
#include "peripheral_gdbus_spi.h"
#include "peripheral_gdbus_uart.h"
#define PERIPHERAL_GDBUS_GPIO_PATH "/Org/Tizen/Peripheral_io/Gpio"
#define PERIPHERAL_GDBUS_I2C_PATH "/Org/Tizen/Peripheral_io/I2c"
#define PERIPHERAL_GDBUS_PWM_PATH "/Org/Tizen/Peripheral_io/Pwm"
+#define PERIPHERAL_GDBUS_ADC_PATH "/Org/Tizen/Peripheral_io/Adc"
#define PERIPHERAL_GDBUS_UART_PATH "/Org/Tizen/Peripheral_io/Uart"
#define PERIPHERAL_GDBUS_SPI_PATH "/Org/Tizen/Peripheral_io/Spi"
#define PERIPHERAL_GDBUS_NAME "org.tizen.peripheral_io"
return true;
}
+static gboolean __adc_init(peripheral_info_s *info)
+{
+ GDBusObjectManagerServer *manager;
+ gboolean ret = FALSE;
+ GError *error = NULL;
+
+ /* Add interface to default object path */
+ info->adc_skeleton = peripheral_io_gdbus_adc_skeleton_new();
+ g_signal_connect(info->adc_skeleton,
+ "handle-open",
+ G_CALLBACK(peripheral_gdbus_adc_open),
+ info);
+ g_signal_connect(info->adc_skeleton,
+ "handle-close",
+ G_CALLBACK(peripheral_gdbus_adc_close),
+ info);
+
+ manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_ADC_PATH);
+
+ /* Set connection to 'manager' */
+ g_dbus_object_manager_server_set_connection(manager, info->connection);
+
+ /* Export 'manager' interface on peripheral-io DBUS */
+ ret = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(info->adc_skeleton),
+ info->connection, PERIPHERAL_GDBUS_ADC_PATH, &error);
+
+ if (ret == FALSE) {
+ _E("Can not skeleton_export %s", error->message);
+ g_error_free(error);
+ }
+
+ return true;
+}
+
static gboolean __uart_init(peripheral_info_s *info)
{
GDBusObjectManagerServer *manager;
if (__pwm_init(info) == FALSE)
_E("Can not signal connect");
+ if (__adc_init(info) == FALSE)
+ _E("Can not signal connect");
+
if (__uart_init(info) == FALSE)
_E("Can not signal connect");
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017-2018 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.
return PB_BOARD_DEV_I2C;
else if (0 == strncmp(string, "pwm", strlen("pwm")))
return PB_BOARD_DEV_PWM;
+ else if (0 == strncmp(string, "adc", strlen("adc")))
+ return PB_BOARD_DEV_ADC;
else if (0 == strncmp(string, "uart", strlen("uart")))
return PB_BOARD_DEV_UART;
else if (0 == strncmp(string, "spi", strlen("spi")))
case PB_BOARD_DEV_PWM:
sscanf(string, "%*50[^0-9]%d%*50[^0-9]%d", &args[0], &args[1]);
break;
+ case PB_BOARD_DEV_ADC:
+ sscanf(string, "%*50[^0-9]%d%*50[^0-9]%d%*50[^0-9]", &args[0], &args[1]);
+ break;
case PB_BOARD_DEV_UART:
sscanf(string, "%*50[^0-9]%d", &args[0]);
break;