src/daemon/peripheral_bus_gdbus_pwm.c
src/daemon/peripheral_bus_gdbus_spi.c
src/daemon/peripheral_bus_gdbus_uart.c
- src/daemon/peripheral_bus_gdbus_adc.c
src/daemon/peripheral_bus_pwm.c
- src/daemon/peripheral_bus_adc.c
src/daemon/peripheral_bus_i2c.c
src/daemon/peripheral_bus_gpio.c
src/daemon/peripheral_bus_uart.c
src/daemon/peripheral_bus_spi.c
src/daemon/peripheral_bus_board.c
src/daemon/peripheral_io_gdbus.c
- src/interface/adc.c
src/interface/gpio.c
src/interface/i2c.c
src/interface/pwm.c
PERIPHERAL_BUS_TYPE_GPIO = 0,
PERIPHERAL_BUS_TYPE_I2C,
PERIPHERAL_BUS_TYPE_PWM,
- PERIPHERAL_BUS_TYPE_ADC,
PERIPHERAL_BUS_TYPE_UART,
PERIPHERAL_BUS_TYPE_SPI,
} peripheral_bus_type_e;
typedef struct {
pb_board_s *board;
- /* daemon variable */
- char *adc_path;
/* devices */
GList *gpio_list;
GList *i2c_list;
PeripheralIoGdbusGpio *gpio_skeleton;
PeripheralIoGdbusI2c *i2c_skeleton;
PeripheralIoGdbusPwm *pwm_skeleton;
- PeripheralIoGdbusAdc *adc_skeleton;
PeripheralIoGdbusUart *uart_skeleton;
PeripheralIoGdbusSpi *spi_skeleton;
} peripheral_bus_s;
+++ /dev/null
-/*
- * Copyright (c) 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_BUS_ADC_H__
-#define __PERIPHERAL_BUS_ADC_H__
-
-char *peripheral_bus_adc_get_path(unsigned int device);
-int peripheral_bus_adc_read(unsigned int device, unsigned int channel, char *path, int *data);
-
-#endif /* __PERIPHERAL_BUS_ADC_H__ */
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,
+++ /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_BUS_GDBUS_ADC_H__
-#define __PERIPHERAL_BUS_GDBUS_ADC_H__
-
-#include "peripheral_io_gdbus.h"
-
-gboolean handle_adc_read(
- PeripheralIoGdbusAdc *adc,
- GDBusMethodInvocation *invocation,
- guint device,
- guint channel,
- gpointer user_data);
-
-#endif /* __PERIPHERAL_BUS_GDBUS_ADC_H__ */
#include "peripheral_bus_gdbus_pwm.h"
#include "peripheral_bus_gdbus_spi.h"
#include "peripheral_bus_gdbus_uart.h"
-#include "peripheral_bus_gdbus_adc.h"
static gboolean __gpio_init(peripheral_bus_s *pb_data)
{
return true;
}
-static gboolean __adc_init(peripheral_bus_s *pb_data)
-{
- GDBusObjectManagerServer *manager;
- gboolean ret = FALSE;
- GError *error = NULL;
-
- /* Add interface to default object path */
- pb_data->adc_skeleton = peripheral_io_gdbus_adc_skeleton_new();
- g_signal_connect(pb_data->adc_skeleton,
- "handle-read",
- G_CALLBACK(handle_adc_read),
- pb_data);
-
- manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_ADC_PATH);
-
- /* Set connection to 'manager' */
- g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
-
- /* Export 'manager' interface on peripheral-io DBUS */
- ret = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(pb_data->adc_skeleton),
- pb_data->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_bus_s *pb_data)
{
GDBusObjectManagerServer *manager;
if (__pwm_init(pb_data) == FALSE)
_E("Can not signal connect");
- if (__adc_init(pb_data) == FALSE)
- _E("Can not signal connect");
-
if (__uart_init(pb_data) == FALSE)
_E("Can not signal connect");
return -1;
}
- pb_data->adc_path = NULL;
pb_data->board = peripheral_bus_board_init();
if (pb_data->board == NULL) {
_E("failed to init board");
if (pb_data) {
peripheral_bus_board_deinit(pb_data->board);
- if (pb_data->adc_path)
- free(pb_data->adc_path);
free(pb_data);
}
+++ /dev/null
-/*
- * Copyright (c) 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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <gio/gio.h>
-
-#include <peripheral_io.h>
-
-#include "adc.h"
-#include "peripheral_bus.h"
-#include "peripheral_common.h"
-#include "peripheral_bus_util.h"
-
-#define SYSFS_ADC_PATH_MAX 128
-
-char *peripheral_bus_adc_get_path(unsigned int device)
-{
- char *path;
- int ret;
-
- path = calloc(1, SYSFS_ADC_PATH_MAX);
- if (path == NULL) {
- _E("failed to allocate path buffer");
- return NULL;
- }
-
- ret = adc_get_path(device, path, SYSFS_ADC_PATH_MAX);
- if (ret < 0) {
- _E("failed to get adc path");
- free(path);
- return NULL;
- }
-
- return path;
-}
-
-int peripheral_bus_adc_read(unsigned int device, unsigned int channel, char *path, int *data)
-{
- if (path == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
-
- return adc_read(device, channel, path, data);
-}
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", &args[0], &args[1]);
- break;
case PB_BOARD_DEV_UART:
sscanf(string, "%*50[^0-9]%d", &args[0]);
break;
RETV_IF(board == NULL, false);
args[0] = arg;
- if (dev_type == PB_BOARD_DEV_PWM || dev_type == PB_BOARD_DEV_ADC || dev_type == PB_BOARD_DEV_SPI) {
+ if (dev_type == PB_BOARD_DEV_PWM || dev_type == PB_BOARD_DEV_SPI) {
va_start(ap, arg);
args[1] = va_arg(ap, int);
va_end(ap);
+++ /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.
- */
-
-#include <peripheral_io.h>
-
-#include "peripheral_io_gdbus.h"
-#include "peripheral_bus.h"
-#include "peripheral_bus_adc.h"
-#include "peripheral_common.h"
-#include "peripheral_bus_util.h"
-#include "peripheral_bus_gdbus_adc.h"
-
-gboolean handle_adc_read(
- PeripheralIoGdbusAdc *adc,
- GDBusMethodInvocation *invocation,
- guint device,
- guint channel,
- gpointer user_data)
-{
- peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- int data = 0;
-
- if (pb_data->adc_path == NULL) {
- pb_data->adc_path = peripheral_bus_adc_get_path(device);
- if (pb_data->adc_path == NULL) {
- ret = PERIPHERAL_ERROR_UNKNOWN;
- goto out;
- }
- }
-
- ret = peripheral_bus_adc_read(device, channel, pb_data->adc_path, &data);
-
-out:
- peripheral_io_gdbus_adc_complete_read(adc, invocation, data, ret);
-
- return true;
-}
<arg type="i" name="result" direction="out"/>
</method>
</interface>
- <interface name="org.tizen.peripheral_io.adc">
- <method name="Read">
- <arg type="u" name="device" direction="in"/>
- <arg type="u" name="channel" direction="in"/>
- <arg type="i" name="value" direction="out"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- </interface>
<interface name="org.tizen.peripheral_io.uart">
<method name="Open">
<arg type="i" name="port" direction="in"/>
+++ /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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include "adc.h"
-#include "peripheral_common.h"
-
-#define SYSFS_ADC_PATH "/sys/bus/iio/devices/iio:device"
-#define SYSFS_ADC_PATH_OLD "/sys/bus/iio/devices/device"
-
-#define PATH_BUF_MAX 64
-#define ADC_BUF_MAX 16
-#define MAX_ERR_LEN 255
-
-int adc_get_path(unsigned int device, char *path, int length)
-{
- char adc_dev[PATH_BUF_MAX] = {0};
-
- snprintf(adc_dev, PATH_BUF_MAX, "%s%d", SYSFS_ADC_PATH, device);
- if (access(adc_dev, F_OK) == 0) {
- strncpy(path, SYSFS_ADC_PATH, length);
- return 0;
- } else {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Can't Open %s, errmsg : %s", adc_dev, errmsg);
- }
-
- snprintf(adc_dev, PATH_BUF_MAX, "%s%d", SYSFS_ADC_PATH_OLD, device);
- if (access(adc_dev, F_OK) == 0) {
- strncpy(path, SYSFS_ADC_PATH_OLD, length);
- return 0;
- } else {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Can't Open %s, errmsg : %s", adc_dev, errmsg);
- }
-
- return -ENXIO;
-}
-
-int adc_read(unsigned int device, unsigned int channel, char *path, int *data)
-{
- int fd, result, status;
- char adc_buf[ADC_BUF_MAX] = {0};
- char adc_dev[PATH_BUF_MAX] = {0};
-
- snprintf(adc_dev, PATH_BUF_MAX, "%s%d%s%d%s", path, device, "/in_voltage", channel, "_raw");
- fd = open(adc_dev, O_RDONLY);
- if (fd < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Can't Open %s, errmsg : %s", adc_dev, errmsg);
- return -ENXIO;
- }
-
- status = read(fd, adc_buf, ADC_BUF_MAX);
- if (status < 0) {
- close(fd);
- _E("Failed to get adc, path : %s", adc_dev);
- return -EIO;
- }
- result = atoi(adc_buf);
- *data = result;
- close(fd);
-
- return 0;
-}
+++ /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 __ADC_H__
-#define __ADC_H__
-
-/**
-* @brief adc_get_path() get adc device path.
-*
-* @param[in] device The adc device number
-* @param[in] channel The adc channel number
-* @param[out] *path The buffer for the adc device path
-* @param[in] length The max length of the path buffer
-* @return 0 on success, otherwise a negative error value
-*/
-int adc_get_path(unsigned int device, char *path, int length);
-
-/**
-* @brief adc_read() get adc data.
-*
-* @param[in] device The adc device number
-* @param[in] channel The adc channel number
-* @param[in] *path The adc device path
-* @param[in] *data The adc value
-* @return 0 on success, otherwise a negative error value
-*/
-int adc_read(unsigned int device, unsigned int channel, char *path, int *data);
-
-#endif /* __ADC_H__ */