From 552f5ec036a31bcc09e2417055274daaab046213 Mon Sep 17 00:00:00 2001 From: Hyeongsik Min Date: Mon, 8 May 2017 20:15:55 +0900 Subject: [PATCH] Refactor gdbus interface codes Split peripheral_dbus.c into separate files per low-level interface. Change-Id: Ifdc6bba7d3d4628693e041882ee88b39c763629f Signed-off-by: Hyeongsik Min --- CMakeLists.txt | 10 +- include/peripheral_common.h | 12 +- include/peripheral_dbus.h | 66 ----- include/peripheral_gdbus.h | 27 ++ include/peripheral_gdbus_gpio.h | 34 +++ include/peripheral_gdbus_i2c.h | 28 ++ include/peripheral_gdbus_pwm.h | 31 ++ src/peripheral_dbus.c | 628 ---------------------------------------- src/peripheral_gdbus_gpio.c | 299 +++++++++++++++++++ src/peripheral_gdbus_i2c.c | 163 +++++++++++ src/peripheral_gdbus_pwm.c | 215 ++++++++++++++ src/peripheral_gpio.c | 22 +- src/peripheral_i2c.c | 10 +- src/peripheral_pwm.c | 16 +- 14 files changed, 833 insertions(+), 728 deletions(-) delete mode 100644 include/peripheral_dbus.h create mode 100644 include/peripheral_gdbus.h create mode 100644 include/peripheral_gdbus_gpio.h create mode 100644 include/peripheral_gdbus_i2c.h create mode 100644 include/peripheral_gdbus_pwm.h delete mode 100644 src/peripheral_dbus.c create mode 100644 src/peripheral_gdbus_gpio.c create mode 100644 src/peripheral_gdbus_i2c.c create mode 100644 src/peripheral_gdbus_pwm.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 45ec9ac..0bbc0bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,13 +42,15 @@ SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=%{_libdir}") -SET(SOURCES src/peripheral_adc.c - src/peripheral_gpio.c +SET(SOURCES src/peripheral_gpio.c + src/peripheral_i2c.c src/peripheral_pwm.c + src/peripheral_adc.c src/peripheral_uart.c - src/peripheral_dbus.c + src/peripheral_gdbus_gpio.c + src/peripheral_gdbus_i2c.c + src/peripheral_gdbus_pwm.c src/peripheral_io_gdbus.c - src/peripheral_i2c.c src/peripheral_spi.c) ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) diff --git a/include/peripheral_common.h b/include/peripheral_common.h index 2d2f960..19352be 100644 --- a/include/peripheral_common.h +++ b/include/peripheral_common.h @@ -31,28 +31,28 @@ if (expr) { \ _E("(%s)", #expr); \ return; \ - }\ - } while(0) + } \ + } while (0) #define RETV_IF(expr, val) \ do {\ if (expr) { \ _E("(%s)", #expr); \ return (val); \ } \ - } while(0) + } while (0) #define RETM_IF(expr, fmt, arg...) \ do {\ if (expr) { \ _E(fmt, ##arg); \ return; \ - }\ - } while(0) + } \ + } while (0) #define RETVM_IF(expr, val, fmt, arg...) \ do {\ if (expr) { \ _E(fmt, ##arg); \ return (val); \ } \ - } while(0) + } while (0) #endif /* __PERIPHERAL_COMMON_H__ */ diff --git a/include/peripheral_dbus.h b/include/peripheral_dbus.h deleted file mode 100644 index e1002fa..0000000 --- a/include/peripheral_dbus.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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_DBUS_H_ -#define __PERIPHERAL_DBUS_H_ - -#include - -#define PERIPHERAL_DBUS_INTERFACE "org.tizen.peripheral_io" -#define PERIPHERAL_DBUS_PATH "/Org/Tizen/Peripheral_io" -#define PERIPHERAL_DBUS_GPIO_PATH "/Org/Tizen/Peripheral_io/Gpio" -#define PERIPHERAL_DBUS_I2C_PATH "/Org/Tizen/Peripheral_io/I2c" -#define PERIPHERAL_DBUS_PWM_PATH "/Org/Tizen/Peripheral_io/Pwm" -#define PERIPHERAL_DBUS_NAME "org.tizen.peripheral_io" - -#define PERIPHERAL_METHOD_GPIO "gpio" -#define PERIPHERAL_METHOD_I2C "i2c" -#define PERIPHERAL_METHOD_PWM "pwm" -#define PERIPHERAL_METHOD_SPI "spi" -#define PERIPHERAL_METHOD_UART "uart" - -void gpio_proxy_init(void); -void i2c_proxy_init(void); -void pwm_proxy_init(void); - -void gpio_proxy_deinit(); -void i2c_proxy_deinit(); -void pwm_proxy_deinit(); - -int peripheral_dbus_gpio_open(peripheral_gpio_h gpio); -int peripheral_dbus_gpio_close(peripheral_gpio_h gpio); -int peripheral_dbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction); -int peripheral_dbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); -int peripheral_dbus_gpio_read(peripheral_gpio_h gpio, int *value); -int peripheral_dbus_gpio_write(peripheral_gpio_h gpio, int value); -int peripheral_dbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge); -int peripheral_dbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); -int peripheral_dbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data); -int peripheral_dbus_gpio_unregister_cb(peripheral_gpio_h gpio); - -int peripheral_dbus_i2c_open(peripheral_i2c_h i2c, int bus, int address); -int peripheral_dbus_i2c_close(peripheral_i2c_h i2c); -int peripheral_dbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length); -int peripheral_dbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length); - -int peripheral_dbus_pwm_open(peripheral_pwm_context_h dev, int device, int channel); -int peripheral_dbus_pwm_close(peripheral_pwm_context_h dev); -int peripheral_dbus_pwm_get_duty_cycle(peripheral_pwm_context_h dev, int *duty_cycle); -int peripheral_dbus_pwm_set_duty_cycle(peripheral_pwm_context_h dev, int duty_cycle); -int peripheral_dbus_pwm_get_period(peripheral_pwm_context_h dev, int *period); -int peripheral_dbus_pwm_set_period(peripheral_pwm_context_h dev, int period); -int peripheral_dbus_pwm_set_enable(peripheral_pwm_context_h dev, peripheral_pwm_state_e enable); - -#endif /* __PERIPHERAL_DBUS_H_ */ diff --git a/include/peripheral_gdbus.h b/include/peripheral_gdbus.h new file mode 100644 index 0000000..2195320 --- /dev/null +++ b/include/peripheral_gdbus.h @@ -0,0 +1,27 @@ +/* + * 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_GDBUS_H__ +#define __PERIPHERAL_GDBUS_H__ + +#include + +#define PERIPHERAL_GDBUS_INTERFACE "org.tizen.peripheral_io" +#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_NAME "org.tizen.peripheral_io" + +#endif /* __PERIPHERAL_GDBUS_H__ */ diff --git a/include/peripheral_gdbus_gpio.h b/include/peripheral_gdbus_gpio.h new file mode 100644 index 0000000..0d23b91 --- /dev/null +++ b/include/peripheral_gdbus_gpio.h @@ -0,0 +1,34 @@ +/* + * 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_GDBUS_GPIO_H__ +#define __PERIPHERAL_GDBUS_GPIO_H__ + +void gpio_proxy_init(void); +void gpio_proxy_deinit(void); + +int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio); +int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio); +int peripheral_gdbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction); +int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); +int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value); +int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value); +int peripheral_gdbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge); +int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); +int peripheral_gdbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data); +int peripheral_gdbus_gpio_unregister_cb(peripheral_gpio_h gpio); + +#endif /* __PERIPHERAL_GDBUS_GPIO_H__ */ diff --git a/include/peripheral_gdbus_i2c.h b/include/peripheral_gdbus_i2c.h new file mode 100644 index 0000000..c36cb04 --- /dev/null +++ b/include/peripheral_gdbus_i2c.h @@ -0,0 +1,28 @@ +/* + * 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_GDBUS_I2C_H__ +#define __PERIPHERAL_GDBUS_I2C_H__ + +void i2c_proxy_init(void); +void i2c_proxy_deinit(void); + +int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address); +int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c); +int peripheral_gdbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length); +int peripheral_gdbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length); + +#endif /* __PERIPHERAL_GDBUS_I2C_H__ */ diff --git a/include/peripheral_gdbus_pwm.h b/include/peripheral_gdbus_pwm.h new file mode 100644 index 0000000..2d28514 --- /dev/null +++ b/include/peripheral_gdbus_pwm.h @@ -0,0 +1,31 @@ +/* + * 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_GDBUS_PWM_H__ +#define __PERIPHERAL_GDBUS_PWM_H__ + +void pwm_proxy_init(void); +void pwm_proxy_deinit(void); + +int peripheral_gdbus_pwm_open(peripheral_pwm_context_h dev, int device, int channel); +int peripheral_gdbus_pwm_close(peripheral_pwm_context_h dev); +int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_context_h dev, int *duty_cycle); +int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_context_h dev, int duty_cycle); +int peripheral_gdbus_pwm_get_period(peripheral_pwm_context_h dev, int *period); +int peripheral_gdbus_pwm_set_period(peripheral_pwm_context_h dev, int period); +int peripheral_gdbus_pwm_set_enable(peripheral_pwm_context_h dev, peripheral_pwm_state_e enable); + +#endif /* __PERIPHERAL_GDBUS_PWM_H__ */ diff --git a/src/peripheral_dbus.c b/src/peripheral_dbus.c deleted file mode 100644 index b9af3d1..0000000 --- a/src/peripheral_dbus.c +++ /dev/null @@ -1,628 +0,0 @@ -/* - * 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 -#include -#include - -#include "peripheral_io.h" -#include "peripheral_dbus.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" - -extern int peripheral_gpio_isr_callback(int pin); -void handle_gpio_changed(PeripheralIoGdbusGpio *gpio, gint pin, gint state, gpointer user_data); - -PeripheralIoGdbusGpio *gpio_proxy = NULL; -PeripheralIoGdbusI2c *i2c_proxy = NULL; -PeripheralIoGdbusPwm *pwm_proxy = NULL; - -void gpio_proxy_init(void) -{ - GError *error = NULL; - - if (gpio_proxy != NULL) - return; - - gpio_proxy = peripheral_io_gdbus_gpio_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - PERIPHERAL_DBUS_NAME, - PERIPHERAL_DBUS_GPIO_PATH, - NULL, - &error); - if (gpio_proxy == NULL) { - _E("Can not create gpio proxy : %s", error->message); - g_error_free(error); - return; - } - - g_signal_connect(gpio_proxy, - "gpio-changed", - G_CALLBACK(handle_gpio_changed), - NULL); -} - -void i2c_proxy_init(void) -{ - GError *error = NULL; - - if (i2c_proxy != NULL) - return; - - i2c_proxy = peripheral_io_gdbus_i2c_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - PERIPHERAL_DBUS_NAME, - PERIPHERAL_DBUS_I2C_PATH, - NULL, - &error); -} - -void pwm_proxy_init(void) -{ - GError *error = NULL; - - if (pwm_proxy != NULL) - return; - - pwm_proxy = peripheral_io_gdbus_pwm_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - PERIPHERAL_DBUS_NAME, - PERIPHERAL_DBUS_PWM_PATH, - NULL, - &error); -} - -void gpio_proxy_deinit() -{ - if (gpio_proxy) { - g_object_unref(gpio_proxy); - gpio_proxy = NULL; - } -} - -void i2c_proxy_deinit() -{ - if (i2c_proxy) { - g_object_unref(i2c_proxy); - i2c_proxy = NULL; - } -} - -void pwm_proxy_deinit() -{ - if (pwm_proxy) { - g_object_unref(pwm_proxy); - pwm_proxy = NULL; - } -} - -void handle_gpio_changed( - PeripheralIoGdbusGpio *gpio, - gint pin, - gint state, - gpointer user_data) -{ - if (!gpio) - return; - - _D("gpio=%d state=%d", pin, state); - - peripheral_gpio_isr_callback(pin); -} - -int peripheral_dbus_gpio_open(peripheral_gpio_h gpio) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_open_sync( - gpio_proxy, - gpio->pin, - (gint*)&gpio->edge, - (gint*)&gpio->direction, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_gpio_close(peripheral_gpio_h gpio) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_close_sync( - gpio_proxy, - gpio->pin, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_get_direction_sync( - gpio_proxy, - gpio->pin, - (gint*)direction, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - gpio->direction = *direction; - - return ret; -} - -int peripheral_dbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_set_direction_sync( - gpio_proxy, - gpio->pin, - direction, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - gpio->direction = direction; - - return ret; -} - -int peripheral_dbus_gpio_read(peripheral_gpio_h gpio, int *value) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_read_sync( - gpio_proxy, - gpio->pin, - value, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_gpio_write(peripheral_gpio_h gpio, int value) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_write_sync( - gpio_proxy, - gpio->pin, - value, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_get_edge_mode_sync( - gpio_proxy, - gpio->pin, - (int*)edge, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - gpio->edge = *edge; - - return ret; -} - -int peripheral_dbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_set_edge_mode_sync( - gpio_proxy, - gpio->pin, - edge, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - gpio->edge = edge; - - return ret; -} - -int peripheral_dbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_register_irq_sync( - gpio_proxy, - gpio->pin, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_gpio_unregister_cb(peripheral_gpio_h gpio) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_unregister_irq_sync( - gpio_proxy, - gpio->pin, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_i2c_call_open_sync( - i2c_proxy, - bus, - address, - &i2c->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_i2c_close(peripheral_i2c_h i2c) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_i2c_call_close_sync( - i2c_proxy, - i2c->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariant *data_array; - GVariantIter *iter; - guint8 str; - int i = 0; - - if (i2c_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_i2c_call_read_sync( - i2c_proxy, - i2c->handle, - length, - &data_array, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - g_variant_get(data_array, "a(y)", &iter); - while (g_variant_iter_loop(iter, "(y)", &str)) { - data[i] = str; - if (i++ == length) break; - } - g_variant_iter_free(iter); - - return ret; -} - -int peripheral_dbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariantBuilder *builder; - GVariant *g_data; - int i = 0; - - if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); - - for (i = 0; i < length; i++) - g_variant_builder_add(builder, "(y)", data[i]); - g_variant_builder_add(builder, "(y)", 0x00); - - g_data = g_variant_new("a(y)", builder); - g_variant_builder_unref(builder); - - if (peripheral_io_gdbus_i2c_call_write_sync( - i2c_proxy, - i2c->handle, - length, - g_data, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_pwm_open(peripheral_pwm_context_h dev, int device, int channel) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - /* TODO: Need to reorganize arguments */ - if (peripheral_io_gdbus_pwm_call_open_sync( - pwm_proxy, - device, - channel, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_pwm_close(peripheral_pwm_context_h dev) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - /* TODO: Need to reorganize arguments */ - if (peripheral_io_gdbus_pwm_call_close_sync( - pwm_proxy, - dev->device, - dev->channel, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_pwm_get_duty_cycle(peripheral_pwm_context_h dev, int *duty_cycle) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - /* TODO: Need to reorganize arguments */ - if (peripheral_io_gdbus_pwm_call_get_duty_cycle_sync( - pwm_proxy, - dev->device, - dev->channel, - duty_cycle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} -int peripheral_dbus_pwm_set_duty_cycle(peripheral_pwm_context_h dev, int duty_cycle) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - /* TODO: Need to reorganize arguments */ - if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync( - pwm_proxy, - dev->device, - dev->channel, - duty_cycle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_pwm_get_period(peripheral_pwm_context_h dev, int *period) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - /* TODO: Need to reorganize arguments */ - if (peripheral_io_gdbus_pwm_call_get_period_sync( - pwm_proxy, - dev->device, - dev->channel, - period, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_pwm_set_period(peripheral_pwm_context_h dev, int period) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - /* TODO: Need to reorganize arguments */ - if (peripheral_io_gdbus_pwm_call_set_period_sync( - pwm_proxy, - dev->device, - dev->channel, - period, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_dbus_pwm_set_enable(peripheral_pwm_context_h dev, peripheral_pwm_state_e enable) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - /* TODO: Need to reorganize arguments */ - if (peripheral_io_gdbus_pwm_call_set_enable_sync( - pwm_proxy, - dev->device, - dev->channel, - enable, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s\n", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} diff --git a/src/peripheral_gdbus_gpio.c b/src/peripheral_gdbus_gpio.c new file mode 100644 index 0000000..2027f3d --- /dev/null +++ b/src/peripheral_gdbus_gpio.c @@ -0,0 +1,299 @@ +/* + * 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 +#include + +#include "peripheral_io.h" +#include "peripheral_gdbus.h" +#include "peripheral_common.h" +#include "peripheral_internal.h" +#include "peripheral_io_gdbus.h" + +extern int peripheral_gpio_isr_callback(int pin); +void handle_gpio_changed(PeripheralIoGdbusGpio *gpio, gint pin, gint state, gpointer user_data); + +PeripheralIoGdbusGpio *gpio_proxy = NULL; + +void gpio_proxy_init(void) +{ + GError *error = NULL; + + if (gpio_proxy != NULL) + return; + + gpio_proxy = peripheral_io_gdbus_gpio_proxy_new_for_bus_sync( + G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + PERIPHERAL_GDBUS_NAME, + PERIPHERAL_GDBUS_GPIO_PATH, + NULL, + &error); + if (gpio_proxy == NULL) { + _E("Can not create gpio proxy : %s", error->message); + g_error_free(error); + return; + } + + g_signal_connect(gpio_proxy, + "gpio-changed", + G_CALLBACK(handle_gpio_changed), + NULL); +} + +void gpio_proxy_deinit() +{ + if (gpio_proxy) { + g_object_unref(gpio_proxy); + gpio_proxy = NULL; + } +} + +void handle_gpio_changed( + PeripheralIoGdbusGpio *gpio, + gint pin, + gint state, + gpointer user_data) +{ + if (!gpio) + return; + + _D("gpio=%d state=%d", pin, state); + + peripheral_gpio_isr_callback(pin); +} + +int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_open_sync( + gpio_proxy, + gpio->pin, + (gint*)&gpio->edge, + (gint*)&gpio->direction, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_close_sync( + gpio_proxy, + gpio->pin, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_get_direction_sync( + gpio_proxy, + gpio->pin, + (gint*)direction, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + gpio->direction = *direction; + + return ret; +} + +int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_set_direction_sync( + gpio_proxy, + gpio->pin, + direction, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + gpio->direction = direction; + + return ret; +} + +int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_read_sync( + gpio_proxy, + gpio->pin, + value, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_write_sync( + gpio_proxy, + gpio->pin, + value, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_get_edge_mode_sync( + gpio_proxy, + gpio->pin, + (int*)edge, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + gpio->edge = *edge; + + return ret; +} + +int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_set_edge_mode_sync( + gpio_proxy, + gpio->pin, + edge, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + gpio->edge = edge; + + return ret; +} + +int peripheral_gdbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_register_irq_sync( + gpio_proxy, + gpio->pin, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_gpio_unregister_cb(peripheral_gpio_h gpio) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_unregister_irq_sync( + gpio_proxy, + gpio->pin, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} diff --git a/src/peripheral_gdbus_i2c.c b/src/peripheral_gdbus_i2c.c new file mode 100644 index 0000000..ce42ce5 --- /dev/null +++ b/src/peripheral_gdbus_i2c.c @@ -0,0 +1,163 @@ +/* + * 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 +#include + +#include "peripheral_io.h" +#include "peripheral_gdbus.h" +#include "peripheral_common.h" +#include "peripheral_internal.h" +#include "peripheral_io_gdbus.h" + +PeripheralIoGdbusI2c *i2c_proxy = NULL; + +void i2c_proxy_init(void) +{ + GError *error = NULL; + + if (i2c_proxy != NULL) + return; + + i2c_proxy = peripheral_io_gdbus_i2c_proxy_new_for_bus_sync( + G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + PERIPHERAL_GDBUS_NAME, + PERIPHERAL_GDBUS_I2C_PATH, + NULL, + &error); +} + +void i2c_proxy_deinit() +{ + if (i2c_proxy) { + g_object_unref(i2c_proxy); + i2c_proxy = NULL; + } +} + +int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_i2c_call_open_sync( + i2c_proxy, + bus, + address, + &i2c->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_i2c_call_close_sync( + i2c_proxy, + i2c->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GVariant *data_array; + GVariantIter *iter; + guint8 str; + int i = 0; + + if (i2c_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_i2c_call_read_sync( + i2c_proxy, + i2c->handle, + length, + &data_array, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + g_variant_get(data_array, "a(y)", &iter); + while (g_variant_iter_loop(iter, "(y)", &str)) { + data[i] = str; + if (i++ == length) break; + } + g_variant_iter_free(iter); + + return ret; +} + +int peripheral_gdbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GVariantBuilder *builder; + GVariant *g_data; + int i = 0; + + if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); + + for (i = 0; i < length; i++) + g_variant_builder_add(builder, "(y)", data[i]); + g_variant_builder_add(builder, "(y)", 0x00); + + g_data = g_variant_new("a(y)", builder); + g_variant_builder_unref(builder); + + if (peripheral_io_gdbus_i2c_call_write_sync( + i2c_proxy, + i2c->handle, + length, + g_data, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} diff --git a/src/peripheral_gdbus_pwm.c b/src/peripheral_gdbus_pwm.c new file mode 100644 index 0000000..db73dee --- /dev/null +++ b/src/peripheral_gdbus_pwm.c @@ -0,0 +1,215 @@ +/* + * 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 +#include + +#include "peripheral_io.h" +#include "peripheral_gdbus.h" +#include "peripheral_common.h" +#include "peripheral_internal.h" +#include "peripheral_io_gdbus.h" + +PeripheralIoGdbusPwm *pwm_proxy = NULL; + +void pwm_proxy_init(void) +{ + GError *error = NULL; + + if (pwm_proxy != NULL) + return; + + pwm_proxy = peripheral_io_gdbus_pwm_proxy_new_for_bus_sync( + G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + PERIPHERAL_GDBUS_NAME, + PERIPHERAL_GDBUS_PWM_PATH, + NULL, + &error); +} + +void pwm_proxy_deinit() +{ + if (pwm_proxy) { + g_object_unref(pwm_proxy); + pwm_proxy = NULL; + } +} + +int peripheral_gdbus_pwm_open(peripheral_pwm_context_h dev, int device, int channel) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + /* TODO: Need to reorganize arguments */ + if (peripheral_io_gdbus_pwm_call_open_sync( + pwm_proxy, + device, + channel, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_pwm_close(peripheral_pwm_context_h dev) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + /* TODO: Need to reorganize arguments */ + if (peripheral_io_gdbus_pwm_call_close_sync( + pwm_proxy, + dev->device, + dev->channel, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_context_h dev, int *duty_cycle) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + /* TODO: Need to reorganize arguments */ + if (peripheral_io_gdbus_pwm_call_get_duty_cycle_sync( + pwm_proxy, + dev->device, + dev->channel, + duty_cycle, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} +int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_context_h dev, int duty_cycle) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + /* TODO: Need to reorganize arguments */ + if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync( + pwm_proxy, + dev->device, + dev->channel, + duty_cycle, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_pwm_get_period(peripheral_pwm_context_h dev, int *period) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + /* TODO: Need to reorganize arguments */ + if (peripheral_io_gdbus_pwm_call_get_period_sync( + pwm_proxy, + dev->device, + dev->channel, + period, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_pwm_set_period(peripheral_pwm_context_h dev, int period) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + /* TODO: Need to reorganize arguments */ + if (peripheral_io_gdbus_pwm_call_set_period_sync( + pwm_proxy, + dev->device, + dev->channel, + period, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_pwm_set_enable(peripheral_pwm_context_h dev, peripheral_pwm_state_e enable) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + /* TODO: Need to reorganize arguments */ + if (peripheral_io_gdbus_pwm_call_set_enable_sync( + pwm_proxy, + dev->device, + dev->channel, + enable, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s\n", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index f942759..2b3bd20 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -20,7 +20,7 @@ #include #include "peripheral_io.h" -#include "peripheral_dbus.h" +#include "peripheral_gdbus_gpio.h" #include "peripheral_common.h" #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" @@ -128,7 +128,7 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio) gpio_proxy_init(); - ret = peripheral_dbus_gpio_open(handle); + ret = peripheral_gdbus_gpio_open(handle); if (ret != PERIPHERAL_ERROR_NONE) { free(handle); @@ -153,7 +153,7 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) return PERIPHERAL_ERROR_INVALID_PARAMETER; /* call gpio_close */ - ret = peripheral_dbus_gpio_close(gpio); + ret = peripheral_gdbus_gpio_close(gpio); if (ret) ret = TIZEN_ERROR_IO_ERROR; gpio_proxy_deinit(); @@ -175,7 +175,7 @@ int peripheral_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direct if (gpio == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - ret = peripheral_dbus_gpio_get_direction(gpio, direction); + ret = peripheral_gdbus_gpio_get_direction(gpio, direction); if (ret == PERIPHERAL_ERROR_NONE) gpio->direction = (*direction); @@ -198,7 +198,7 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct return PERIPHERAL_ERROR_INVALID_PARAMETER; /* call gpio_set_direction */ - ret = peripheral_dbus_gpio_set_direction(gpio, direction); + ret = peripheral_gdbus_gpio_set_direction(gpio, direction); if (ret == PERIPHERAL_ERROR_NONE) gpio->direction = direction; @@ -217,7 +217,7 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, int *value) return PERIPHERAL_ERROR_INVALID_PARAMETER; /* call gpio_read */ - ret = peripheral_dbus_gpio_read(gpio, value); + ret = peripheral_gdbus_gpio_read(gpio, value); return ret; } @@ -234,7 +234,7 @@ int peripheral_gpio_write(peripheral_gpio_h gpio, int value) return PERIPHERAL_ERROR_INVALID_PARAMETER; /* call gpio_write */ - ret = peripheral_dbus_gpio_write(gpio, value); + ret = peripheral_gdbus_gpio_write(gpio, value); return ret; } @@ -250,7 +250,7 @@ int peripheral_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e if (gpio == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - ret = peripheral_dbus_gpio_get_edge_mode(gpio, edge); + ret = peripheral_gdbus_gpio_get_edge_mode(gpio, edge); if (ret == PERIPHERAL_ERROR_NONE) gpio->edge = (*edge); @@ -272,7 +272,7 @@ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e return PERIPHERAL_ERROR_INVALID_PARAMETER; /* call gpio_set_edge_mode */ - ret = peripheral_dbus_gpio_set_edge_mode(gpio, edge); + ret = peripheral_gdbus_gpio_set_edge_mode(gpio, edge); if (ret == PERIPHERAL_ERROR_NONE) gpio->edge = edge; @@ -290,7 +290,7 @@ int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, vo if (gpio == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - ret = peripheral_dbus_gpio_register_cb(gpio, callback, user_data); + ret = peripheral_gdbus_gpio_register_cb(gpio, callback, user_data); if (ret != PERIPHERAL_ERROR_NONE) return ret; @@ -311,7 +311,7 @@ int peripheral_gpio_unregister_cb(peripheral_gpio_h gpio) if (gpio == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - ret = peripheral_dbus_gpio_unregister_cb(gpio); + ret = peripheral_gdbus_gpio_unregister_cb(gpio); if (ret != PERIPHERAL_ERROR_NONE) return ret; diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index b871014..fee3a32 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -20,7 +20,7 @@ #include #include "peripheral_io.h" -#include "peripheral_dbus.h" +#include "peripheral_gdbus_i2c.h" #include "peripheral_common.h" #include "peripheral_internal.h" @@ -41,7 +41,7 @@ int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c) i2c_proxy_init(); - ret = peripheral_dbus_i2c_open(handle, bus, address); + ret = peripheral_gdbus_i2c_open(handle, bus, address); if (ret != PERIPHERAL_ERROR_NONE) { _E("[PERIPHERAL] I2C init error\n"); @@ -59,7 +59,7 @@ int peripheral_i2c_close(peripheral_i2c_h i2c) if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - ret = peripheral_dbus_i2c_close(i2c); + ret = peripheral_gdbus_i2c_close(i2c); i2c_proxy_deinit(); free(i2c); @@ -74,7 +74,7 @@ int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length) if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - ret = peripheral_dbus_i2c_read(i2c, data, length); + ret = peripheral_gdbus_i2c_read(i2c, data, length); /* _D("I2C read data : "); for (int i = 0 ; i < length ; i++) @@ -87,5 +87,5 @@ int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length) { if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - return peripheral_dbus_i2c_write(i2c, data, length); + return peripheral_gdbus_i2c_write(i2c, data, length); } diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index d4d728a..b3fa3a7 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -20,7 +20,7 @@ #include #include "peripheral_io.h" -#include "peripheral_dbus.h" +#include "peripheral_gdbus_pwm.h" #include "peripheral_common.h" #define PWM_ENABLE 1 @@ -47,7 +47,7 @@ peripheral_pwm_context_h peripheral_pwm_open(int device, int channel) dev->device = device; dev->channel = channel; - ret = peripheral_dbus_pwm_open(dev, device, channel); + ret = peripheral_gdbus_pwm_open(dev, device, channel); if (ret != PERIPHERAL_ERROR_NONE) { free(dev); @@ -61,7 +61,7 @@ int peripheral_pwm_close(peripheral_pwm_context_h pwm) { int ret = PERIPHERAL_ERROR_NONE; - ret = peripheral_dbus_pwm_close(pwm); + ret = peripheral_gdbus_pwm_close(pwm); pwm_proxy_deinit(); if (ret == PERIPHERAL_ERROR_NONE) { @@ -77,7 +77,7 @@ int peripheral_pwm_set_duty_cycle(peripheral_pwm_context_h pwm, int duty_cycle) { int ret = PERIPHERAL_ERROR_NONE; - ret = peripheral_dbus_pwm_set_duty_cycle(pwm, duty_cycle); + ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle); if (ret != PERIPHERAL_ERROR_NONE) pwm->duty_cycle = duty_cycle; @@ -89,7 +89,7 @@ int peripheral_pwm_set_period(peripheral_pwm_context_h pwm, int period) { int ret = PERIPHERAL_ERROR_NONE; - ret = peripheral_dbus_pwm_set_period(pwm, period); + ret = peripheral_gdbus_pwm_set_period(pwm, period); if (ret != PERIPHERAL_ERROR_NONE) pwm->period = period; @@ -101,7 +101,7 @@ int peripheral_pwm_set_enabled(peripheral_pwm_context_h pwm, peripheral_pwm_stat { int ret = PERIPHERAL_ERROR_NONE; - ret = peripheral_dbus_pwm_set_enable(pwm, enable); + ret = peripheral_gdbus_pwm_set_enable(pwm, enable); if (ret != PERIPHERAL_ERROR_NONE) pwm->enabled = enable; @@ -121,7 +121,7 @@ int peripheral_pwm_get_duty_cycle(peripheral_pwm_context_h pwm, int *duty_cycle) { int ret = PERIPHERAL_ERROR_NONE; - ret = peripheral_dbus_pwm_get_duty_cycle(pwm, duty_cycle); + ret = peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle); if (ret != PERIPHERAL_ERROR_NONE) pwm->duty_cycle = *duty_cycle; @@ -133,7 +133,7 @@ int peripheral_pwm_get_period(peripheral_pwm_context_h pwm, int *period) { int ret = PERIPHERAL_ERROR_NONE; - ret = peripheral_dbus_pwm_get_period(pwm, period); + ret = peripheral_gdbus_pwm_get_period(pwm, period); if (ret != PERIPHERAL_ERROR_NONE) pwm->period = *period; -- 2.7.4