FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
" \\
- --generate-c-code ${CMAKE_SOURCE_DIR}/src/peripheral_io_gdbus \\
+ --generate-c-code ${CMAKE_SOURCE_DIR}/src/gdbus/peripheral_io_gdbus \\
--c-namespace PeripheralIoGdbus \\
--interface-prefix org.tizen.peripheral_io. \\
- ${CMAKE_SOURCE_DIR}/src/peripheral_io.xml \\
+ ${CMAKE_SOURCE_DIR}/src/gdbus/peripheral_io.xml \\
")
SET(INC_DIR include)
INCLUDE_DIRECTORIES(${INC_DIR})
+INCLUDE_DIRECTORIES(${INC_DIR}/gdbus)
INCLUDE_DIRECTORIES(${INC_DIR}/interface)
INCLUDE(FindPkgConfig)
src/interface/peripheral_interface_pwm.c
src/interface/peripheral_interface_spi.c
src/interface/peripheral_interface_uart.c
- src/peripheral_gdbus_gpio.c
- src/peripheral_gdbus_i2c.c
- src/peripheral_gdbus_pwm.c
- src/peripheral_gdbus_uart.c
- src/peripheral_gdbus_spi.c
- src/peripheral_io_gdbus.c)
+ src/gdbus/peripheral_gdbus_gpio.c
+ src/gdbus/peripheral_gdbus_i2c.c
+ src/gdbus/peripheral_gdbus_pwm.c
+ src/gdbus/peripheral_gdbus_uart.c
+ src/gdbus/peripheral_gdbus_spi.c
+ src/gdbus/peripheral_io_gdbus.c)
ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
--- /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_GDBUS_H__
+#define __PERIPHERAL_GDBUS_H__
+
+#include <gio/gio.h>
+
+#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_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"
+
+#endif /* __PERIPHERAL_GDBUS_H__ */
--- /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_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_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction);
+int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge);
+int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data);
+int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio);
+int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value);
+int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value);
+
+#endif /* __PERIPHERAL_GDBUS_GPIO_H__ */
--- /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_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);
+int peripheral_gdbus_i2c_smbus_ioctl(peripheral_i2c_h i2c, uint8_t read_write, uint8_t command, uint32_t size, uint16_t data_in, uint16_t *data_out);
+
+#endif /* __PERIPHERAL_GDBUS_I2C_H__ */
--- /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_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_h pwm, int chip, int pin);
+int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm);
+int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period);
+int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns);
+int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity);
+int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable);
+
+#endif /* __PERIPHERAL_GDBUS_PWM_H__ */
--- /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_GDBUS_SPI_H_
+#define __PERIPHERAL_GDBUS_SPI_H_
+
+void spi_proxy_init(void);
+void spi_proxy_deinit();
+
+int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs);
+int peripheral_gdbus_spi_close(peripheral_spi_h spi);
+int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode);
+int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb);
+int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits);
+int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz);
+int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length);
+int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length);
+int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length);
+
+#endif /* __PERIPHERAL_GDBUS_SPI_H_ */
--- /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_GDBUS_UART_H_
+#define __PERIPHERAL_GDBUS_UART_H_
+
+void uart_proxy_init(void);
+void uart_proxy_deinit();
+
+int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port);
+int peripheral_gdbus_uart_close(peripheral_uart_h uart);
+int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud);
+int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size);
+int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity);
+int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits);
+int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts);
+int peripheral_gdbus_uart_read(peripheral_uart_h uart, uint8_t *data, int length);
+int peripheral_gdbus_uart_write(peripheral_uart_h uart, uint8_t *data, int length);
+
+#endif /* __PERIPHERAL_GDBUS_UART_H_ */
+++ /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_GDBUS_H__
-#define __PERIPHERAL_GDBUS_H__
-
-#include <gio/gio.h>
-
-#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_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"
-
-#endif /* __PERIPHERAL_GDBUS_H__ */
+++ /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_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_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction);
-int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge);
-int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data);
-int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio);
-int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value);
-int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value);
-
-#endif /* __PERIPHERAL_GDBUS_GPIO_H__ */
+++ /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_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);
-int peripheral_gdbus_i2c_smbus_ioctl(peripheral_i2c_h i2c, uint8_t read_write, uint8_t command, uint32_t size, uint16_t data_in, uint16_t *data_out);
-
-#endif /* __PERIPHERAL_GDBUS_I2C_H__ */
+++ /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_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_h pwm, int chip, int pin);
-int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm);
-int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period);
-int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns);
-int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity);
-int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable);
-
-#endif /* __PERIPHERAL_GDBUS_PWM_H__ */
+++ /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_GDBUS_SPI_H_
-#define __PERIPHERAL_GDBUS_SPI_H_
-
-void spi_proxy_init(void);
-void spi_proxy_deinit();
-
-int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs);
-int peripheral_gdbus_spi_close(peripheral_spi_h spi);
-int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode);
-int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb);
-int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits);
-int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz);
-int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length);
-int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length);
-int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length);
-
-#endif /* __PERIPHERAL_GDBUS_SPI_H_ */
+++ /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_GDBUS_UART_H_
-#define __PERIPHERAL_GDBUS_UART_H_
-
-void uart_proxy_init(void);
-void uart_proxy_deinit();
-
-int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port);
-int peripheral_gdbus_uart_close(peripheral_uart_h uart);
-int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud);
-int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size);
-int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity);
-int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits);
-int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts);
-int peripheral_gdbus_uart_read(peripheral_uart_h uart, uint8_t *data, int length);
-int peripheral_gdbus_uart_write(peripheral_uart_h uart, uint8_t *data, int length);
-
-#endif /* __PERIPHERAL_GDBUS_UART_H_ */
--- /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 "peripheral_io.h"
+#include "peripheral_gdbus.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+#include "peripheral_io_gdbus.h"
+
+extern int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int err);
+
+static PeripheralIoGdbusGpio *gpio_proxy = NULL;
+
+static void __peripheral_gpio_interrupted_cb(PeripheralIoGdbusGpio *gpio, gint pin, gint value, guint64 timestamp, gpointer user_data)
+{
+ int err = PERIPHERAL_ERROR_NONE;
+ if (!gpio)
+ err = PERIPHERAL_ERROR_IO_ERROR;
+
+ peripheral_gpio_interrupted_cb_handler(pin, value, timestamp, err);
+}
+
+void gpio_proxy_init(void)
+{
+ GError *error = NULL;
+
+ if (gpio_proxy != NULL) {
+ g_object_ref(gpio_proxy);
+ 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,
+ "interrupted-cb",
+ G_CALLBACK(__peripheral_gpio_interrupted_cb),
+ NULL);
+}
+
+void gpio_proxy_deinit()
+{
+ if (gpio_proxy) {
+ g_object_unref(gpio_proxy);
+ if (!G_IS_OBJECT(gpio_proxy))
+ gpio_proxy = NULL;
+ }
+}
+
+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,
+ &gpio->handle,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __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->handle,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ 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->handle,
+ direction,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ 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->handle,
+ edge,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_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_set_interrupted_cb_sync(
+ gpio_proxy,
+ gpio->handle,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_gpio_unset_interrupted_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_unset_interrupted_cb_sync(
+ gpio_proxy,
+ gpio->handle,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ 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->handle,
+ value,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __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->handle,
+ value,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
--- /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 "peripheral_io.h"
+#include "peripheral_gdbus.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+#include "peripheral_io_gdbus.h"
+
+static PeripheralIoGdbusI2c *i2c_proxy = NULL;
+
+void i2c_proxy_init(void)
+{
+ GError *error = NULL;
+
+ if (i2c_proxy != NULL) {
+ g_object_ref(i2c_proxy);
+ 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);
+ if (!G_IS_OBJECT(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", __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", __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", __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);
+ g_variant_unref(data_array);
+
+ 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", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_i2c_smbus_ioctl(peripheral_i2c_h i2c, uint8_t read_write, uint8_t command, uint32_t size, uint16_t data_in, uint16_t *data_out)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_i2c_call_smbus_ioctl_sync(
+ i2c_proxy,
+ i2c->handle,
+ read_write,
+ command,
+ size,
+ data_in,
+ data_out,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
--- /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 "peripheral_io.h"
+#include "peripheral_gdbus.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+#include "peripheral_io_gdbus.h"
+
+static PeripheralIoGdbusPwm *pwm_proxy = NULL;
+
+void pwm_proxy_init(void)
+{
+ GError *error = NULL;
+
+ if (pwm_proxy != NULL) {
+ g_object_ref(pwm_proxy);
+ 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);
+ if (!G_IS_OBJECT(pwm_proxy))
+ pwm_proxy = NULL;
+ }
+}
+
+int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_pwm_call_open_sync(
+ pwm_proxy,
+ chip,
+ pin,
+ &pwm->handle,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_pwm_call_close_sync(
+ pwm_proxy,
+ pwm->handle,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_pwm_call_set_period_sync(
+ pwm_proxy,
+ pwm->handle,
+ period,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync(
+ pwm_proxy,
+ pwm->handle,
+ duty_cycle_ns,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_pwm_call_set_polarity_sync(
+ pwm_proxy,
+ pwm->handle,
+ polarity,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_pwm_call_set_enable_sync(
+ pwm_proxy,
+ pwm->handle,
+ enable,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
--- /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 "peripheral_io.h"
+#include "peripheral_gdbus.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+#include "peripheral_io_gdbus.h"
+
+static PeripheralIoGdbusSpi *spi_proxy = NULL;
+
+void spi_proxy_init(void)
+{
+ GError *error = NULL;
+
+ if (spi_proxy != NULL) {
+ g_object_ref(spi_proxy);
+ return;
+ }
+
+ spi_proxy = peripheral_io_gdbus_spi_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ PERIPHERAL_GDBUS_NAME,
+ PERIPHERAL_GDBUS_SPI_PATH,
+ NULL,
+ &error);
+}
+
+void spi_proxy_deinit()
+{
+ if (spi_proxy) {
+ g_object_unref(spi_proxy);
+ if (!G_IS_OBJECT(spi_proxy))
+ spi_proxy = NULL;
+ }
+}
+
+int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_spi_call_open_sync(
+ spi_proxy,
+ bus,
+ cs,
+ &spi->handle,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_spi_close(peripheral_spi_h spi)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_spi_call_close_sync(
+ spi_proxy,
+ spi->handle,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_spi_call_set_mode_sync(
+ spi_proxy,
+ spi->handle,
+ (guchar)mode,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_spi_call_set_bit_order_sync(
+ spi_proxy,
+ spi->handle,
+ lsb,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_spi_call_set_bits_per_word_sync(
+ spi_proxy,
+ spi->handle,
+ bits,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_spi_call_set_frequency_sync(
+ spi_proxy,
+ spi->handle,
+ freq_hz,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+ GVariant *data_array;
+ GVariantIter *iter;
+ guint8 str;
+ int i = 0;
+
+ if (spi_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_spi_call_read_sync(
+ spi_proxy,
+ spi->handle,
+ length,
+ &data_array,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", 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);
+ g_variant_unref(data_array);
+
+ return ret;
+}
+
+int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+ GVariantBuilder *builder;
+ GVariant *data_array;
+ int i = 0;
+
+ if (spi_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);
+
+ data_array = g_variant_new("a(y)", builder);
+ g_variant_builder_unref(builder);
+
+ if (peripheral_io_gdbus_spi_call_write_sync(
+ spi_proxy,
+ spi->handle,
+ length,
+ data_array,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+ GVariantBuilder *builder;
+ GVariant *rx_data_array;
+ GVariant *tx_data_array;
+ GVariantIter *iter;
+ guint8 str;
+ int i = 0;
+
+ if (spi_proxy == NULL || !rx_data || !tx_data) 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)", tx_data[i]);
+ g_variant_builder_add(builder, "(y)", 0x00);
+
+ tx_data_array = g_variant_new("a(y)", builder);
+ g_variant_builder_unref(builder);
+
+ if (peripheral_io_gdbus_spi_call_transfer_sync(
+ spi_proxy,
+ spi->handle,
+ length,
+ tx_data_array,
+ &rx_data_array,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ i = 0;
+ g_variant_get(rx_data_array, "a(y)", &iter);
+ while (g_variant_iter_loop(iter, "(y)", &str)) {
+ rx_data[i] = str;
+ if (i++ == length) break;
+ }
+ g_variant_iter_free(iter);
+ g_variant_unref(rx_data_array);
+
+ return ret;
+}
--- /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 "peripheral_io.h"
+#include "peripheral_gdbus.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+#include "peripheral_io_gdbus.h"
+
+static PeripheralIoGdbusUart *uart_proxy = NULL;
+
+void uart_proxy_init(void)
+{
+ GError *error = NULL;
+
+ if (uart_proxy != NULL) {
+ g_object_ref(uart_proxy);
+ return;
+ }
+
+ uart_proxy = peripheral_io_gdbus_uart_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ PERIPHERAL_GDBUS_NAME,
+ PERIPHERAL_GDBUS_UART_PATH,
+ NULL,
+ &error);
+}
+
+void uart_proxy_deinit()
+{
+ if (uart_proxy) {
+ g_object_unref(uart_proxy);
+ if (!G_IS_OBJECT(uart_proxy))
+ uart_proxy = NULL;
+ }
+}
+
+int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_uart_call_open_sync(
+ uart_proxy,
+ port,
+ &uart->handle,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_uart_close(peripheral_uart_h uart)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_uart_call_close_sync(
+ uart_proxy,
+ uart->handle,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud)
+{
+ GError *error = NULL;
+ gint32 ret = PERIPHERAL_ERROR_NONE;
+
+ if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_uart_call_set_baud_rate_sync(
+ uart_proxy,
+ uart->handle,
+ baud,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size)
+{
+ GError *error = NULL;
+ gint32 ret = PERIPHERAL_ERROR_NONE;
+
+ if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_uart_call_set_byte_size_sync(
+ uart_proxy,
+ uart->handle,
+ byte_size,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity)
+{
+ GError *error = NULL;
+ gint32 ret = PERIPHERAL_ERROR_NONE;
+
+ if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_uart_call_set_parity_sync(
+ uart_proxy,
+ uart->handle,
+ parity,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits)
+{
+ GError *error = NULL;
+ gint32 ret = PERIPHERAL_ERROR_NONE;
+
+ if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_uart_call_set_stop_bits_sync(
+ uart_proxy,
+ uart->handle,
+ stop_bits,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts)
+{
+ GError *error = NULL;
+ gint32 ret = PERIPHERAL_ERROR_NONE;
+
+ if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_uart_call_set_flow_control_sync(
+ uart_proxy,
+ uart->handle,
+ xonxoff,
+ rtscts,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_uart_read(peripheral_uart_h uart, 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 (uart_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_uart_call_read_sync(
+ uart_proxy,
+ uart->handle,
+ length,
+ &data_array,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __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);
+ g_variant_unref(data_array);
+
+ return ret;
+}
+
+int peripheral_gdbus_uart_write(peripheral_uart_h uart, uint8_t *data, int length)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+ GVariantBuilder *builder;
+ GVariant *g_data;
+ int i = 0;
+
+ if (uart_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_uart_call_write_sync(
+ uart_proxy,
+ uart->handle,
+ length,
+ g_data,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<node>
+ <interface name="org.tizen.peripheral_io.gpio">
+ <method name="Open">
+ <arg type="i" name="pin" 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>
+ <method name="SetDirection">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="direction" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SetEdgeMode">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="edge" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SetInterruptedCb">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="UnsetInterruptedCb">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <signal name="InterruptedCb">
+ <arg type="i" name="pin"/>
+ <arg type="i" name="value"/>
+ <arg type="t" name="timestamp"/>
+ </signal>
+ <method name="Read">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="value" direction="out"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="Write">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="value" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ </interface>
+ <interface name="org.tizen.peripheral_io.i2c">
+ <method name="Open">
+ <arg type="i" name="bus" direction="in"/>
+ <arg type="i" name="address" 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>
+ <method name="Read">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="length" direction="in"/>
+ <arg type="a(y)" name="data" direction="out">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="Write">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="length" direction="in"/>
+ <arg type="a(y)" name="data" direction="in">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SmbusIoctl">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="y" name="read_write" direction="in"/>
+ <arg type="y" name="command" direction="in"/>
+ <arg type="u" name="size" direction="in"/>
+ <arg type="q" name="data_in" direction="in"/>
+ <arg type="q" name="data_out" direction="out"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ </interface>
+ <interface name="org.tizen.peripheral_io.pwm">
+ <method name="Open">
+ <arg type="i" name="chip" direction="in"/>
+ <arg type="i" name="pin" 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>
+ <method name="SetPeriod">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="period" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SetDutyCycle">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="duty_cycle" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SetPolarity">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="polarity" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SetEnable">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="b" name="enable" direction="in"/>
+ <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"/>
+ <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>
+ <method name="SetBaudRate">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="u" name="baudrate" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SetByteSize">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="u" name="byte_size" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SetParity">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="u" name="parity" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SetStopBits">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="u" name="stop_bits" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SetFlowControl">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="b" name="xonxoff" direction="in"/>
+ <arg type="b" name="rtscts" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="Read">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="length" direction="in"/>
+ <arg type="a(y)" name="data" direction="out">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="Write">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="length" direction="in"/>
+ <arg type="a(y)" name="data" direction="in">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ </interface>
+ <interface name="org.tizen.peripheral_io.spi">
+ <method name="Open">
+ <arg type="i" name="bus" direction="in"/>
+ <arg type="i" name="cs" 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>
+ <method name="SetMode">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="y" name="mode" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SetBitOrder">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="b" name="lsb" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SetBitsPerWord">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="y" name="bits" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="SetFrequency">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="u" name="freq" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="Read">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="length" direction="in"/>
+ <arg type="a(y)" name="data" direction="out">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="Write">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="length" direction="in"/>
+ <arg type="a(y)" name="data" direction="in">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="Transfer">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="length" direction="in"/>
+ <arg type="a(y)" name="tx_data" direction="in">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg type="a(y)" name="rx_data" direction="out">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ </interface>
+</node>
+++ /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 "peripheral_io.h"
-#include "peripheral_gdbus.h"
-#include "peripheral_common.h"
-#include "peripheral_internal.h"
-#include "peripheral_io_gdbus.h"
-
-extern int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int err);
-
-static PeripheralIoGdbusGpio *gpio_proxy = NULL;
-
-static void __peripheral_gpio_interrupted_cb(PeripheralIoGdbusGpio *gpio, gint pin, gint value, guint64 timestamp, gpointer user_data)
-{
- int err = PERIPHERAL_ERROR_NONE;
- if (!gpio)
- err = PERIPHERAL_ERROR_IO_ERROR;
-
- peripheral_gpio_interrupted_cb_handler(pin, value, timestamp, err);
-}
-
-void gpio_proxy_init(void)
-{
- GError *error = NULL;
-
- if (gpio_proxy != NULL) {
- g_object_ref(gpio_proxy);
- 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,
- "interrupted-cb",
- G_CALLBACK(__peripheral_gpio_interrupted_cb),
- NULL);
-}
-
-void gpio_proxy_deinit()
-{
- if (gpio_proxy) {
- g_object_unref(gpio_proxy);
- if (!G_IS_OBJECT(gpio_proxy))
- gpio_proxy = NULL;
- }
-}
-
-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,
- &gpio->handle,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __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->handle,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- 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->handle,
- direction,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- 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->handle,
- edge,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_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_set_interrupted_cb_sync(
- gpio_proxy,
- gpio->handle,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_gpio_unset_interrupted_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_unset_interrupted_cb_sync(
- gpio_proxy,
- gpio->handle,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- 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->handle,
- value,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __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->handle,
- value,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
+++ /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 "peripheral_io.h"
-#include "peripheral_gdbus.h"
-#include "peripheral_common.h"
-#include "peripheral_internal.h"
-#include "peripheral_io_gdbus.h"
-
-static PeripheralIoGdbusI2c *i2c_proxy = NULL;
-
-void i2c_proxy_init(void)
-{
- GError *error = NULL;
-
- if (i2c_proxy != NULL) {
- g_object_ref(i2c_proxy);
- 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);
- if (!G_IS_OBJECT(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", __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", __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", __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);
- g_variant_unref(data_array);
-
- 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", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_i2c_smbus_ioctl(peripheral_i2c_h i2c, uint8_t read_write, uint8_t command, uint32_t size, uint16_t data_in, uint16_t *data_out)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_i2c_call_smbus_ioctl_sync(
- i2c_proxy,
- i2c->handle,
- read_write,
- command,
- size,
- data_in,
- data_out,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
+++ /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 "peripheral_io.h"
-#include "peripheral_gdbus.h"
-#include "peripheral_common.h"
-#include "peripheral_internal.h"
-#include "peripheral_io_gdbus.h"
-
-static PeripheralIoGdbusPwm *pwm_proxy = NULL;
-
-void pwm_proxy_init(void)
-{
- GError *error = NULL;
-
- if (pwm_proxy != NULL) {
- g_object_ref(pwm_proxy);
- 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);
- if (!G_IS_OBJECT(pwm_proxy))
- pwm_proxy = NULL;
- }
-}
-
-int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_pwm_call_open_sync(
- pwm_proxy,
- chip,
- pin,
- &pwm->handle,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_pwm_call_close_sync(
- pwm_proxy,
- pwm->handle,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_pwm_call_set_period_sync(
- pwm_proxy,
- pwm->handle,
- period,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync(
- pwm_proxy,
- pwm->handle,
- duty_cycle_ns,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_pwm_call_set_polarity_sync(
- pwm_proxy,
- pwm->handle,
- polarity,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_pwm_call_set_enable_sync(
- pwm_proxy,
- pwm->handle,
- enable,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
+++ /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 "peripheral_io.h"
-#include "peripheral_gdbus.h"
-#include "peripheral_common.h"
-#include "peripheral_internal.h"
-#include "peripheral_io_gdbus.h"
-
-static PeripheralIoGdbusSpi *spi_proxy = NULL;
-
-void spi_proxy_init(void)
-{
- GError *error = NULL;
-
- if (spi_proxy != NULL) {
- g_object_ref(spi_proxy);
- return;
- }
-
- spi_proxy = peripheral_io_gdbus_spi_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- PERIPHERAL_GDBUS_NAME,
- PERIPHERAL_GDBUS_SPI_PATH,
- NULL,
- &error);
-}
-
-void spi_proxy_deinit()
-{
- if (spi_proxy) {
- g_object_unref(spi_proxy);
- if (!G_IS_OBJECT(spi_proxy))
- spi_proxy = NULL;
- }
-}
-
-int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_spi_call_open_sync(
- spi_proxy,
- bus,
- cs,
- &spi->handle,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_spi_close(peripheral_spi_h spi)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_spi_call_close_sync(
- spi_proxy,
- spi->handle,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_spi_call_set_mode_sync(
- spi_proxy,
- spi->handle,
- (guchar)mode,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_spi_call_set_bit_order_sync(
- spi_proxy,
- spi->handle,
- lsb,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_spi_call_set_bits_per_word_sync(
- spi_proxy,
- spi->handle,
- bits,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_spi_call_set_frequency_sync(
- spi_proxy,
- spi->handle,
- freq_hz,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- GVariant *data_array;
- GVariantIter *iter;
- guint8 str;
- int i = 0;
-
- if (spi_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_spi_call_read_sync(
- spi_proxy,
- spi->handle,
- length,
- &data_array,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", 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);
- g_variant_unref(data_array);
-
- return ret;
-}
-
-int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- GVariantBuilder *builder;
- GVariant *data_array;
- int i = 0;
-
- if (spi_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);
-
- data_array = g_variant_new("a(y)", builder);
- g_variant_builder_unref(builder);
-
- if (peripheral_io_gdbus_spi_call_write_sync(
- spi_proxy,
- spi->handle,
- length,
- data_array,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- GVariantBuilder *builder;
- GVariant *rx_data_array;
- GVariant *tx_data_array;
- GVariantIter *iter;
- guint8 str;
- int i = 0;
-
- if (spi_proxy == NULL || !rx_data || !tx_data) 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)", tx_data[i]);
- g_variant_builder_add(builder, "(y)", 0x00);
-
- tx_data_array = g_variant_new("a(y)", builder);
- g_variant_builder_unref(builder);
-
- if (peripheral_io_gdbus_spi_call_transfer_sync(
- spi_proxy,
- spi->handle,
- length,
- tx_data_array,
- &rx_data_array,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- i = 0;
- g_variant_get(rx_data_array, "a(y)", &iter);
- while (g_variant_iter_loop(iter, "(y)", &str)) {
- rx_data[i] = str;
- if (i++ == length) break;
- }
- g_variant_iter_free(iter);
- g_variant_unref(rx_data_array);
-
- return ret;
-}
+++ /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 "peripheral_io.h"
-#include "peripheral_gdbus.h"
-#include "peripheral_common.h"
-#include "peripheral_internal.h"
-#include "peripheral_io_gdbus.h"
-
-static PeripheralIoGdbusUart *uart_proxy = NULL;
-
-void uart_proxy_init(void)
-{
- GError *error = NULL;
-
- if (uart_proxy != NULL) {
- g_object_ref(uart_proxy);
- return;
- }
-
- uart_proxy = peripheral_io_gdbus_uart_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- PERIPHERAL_GDBUS_NAME,
- PERIPHERAL_GDBUS_UART_PATH,
- NULL,
- &error);
-}
-
-void uart_proxy_deinit()
-{
- if (uart_proxy) {
- g_object_unref(uart_proxy);
- if (!G_IS_OBJECT(uart_proxy))
- uart_proxy = NULL;
- }
-}
-
-int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_uart_call_open_sync(
- uart_proxy,
- port,
- &uart->handle,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_uart_close(peripheral_uart_h uart)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_uart_call_close_sync(
- uart_proxy,
- uart->handle,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud)
-{
- GError *error = NULL;
- gint32 ret = PERIPHERAL_ERROR_NONE;
-
- if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_uart_call_set_baud_rate_sync(
- uart_proxy,
- uart->handle,
- baud,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size)
-{
- GError *error = NULL;
- gint32 ret = PERIPHERAL_ERROR_NONE;
-
- if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_uart_call_set_byte_size_sync(
- uart_proxy,
- uart->handle,
- byte_size,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity)
-{
- GError *error = NULL;
- gint32 ret = PERIPHERAL_ERROR_NONE;
-
- if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_uart_call_set_parity_sync(
- uart_proxy,
- uart->handle,
- parity,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits)
-{
- GError *error = NULL;
- gint32 ret = PERIPHERAL_ERROR_NONE;
-
- if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_uart_call_set_stop_bits_sync(
- uart_proxy,
- uart->handle,
- stop_bits,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts)
-{
- GError *error = NULL;
- gint32 ret = PERIPHERAL_ERROR_NONE;
-
- if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_uart_call_set_flow_control_sync(
- uart_proxy,
- uart->handle,
- xonxoff,
- rtscts,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_uart_read(peripheral_uart_h uart, 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 (uart_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_uart_call_read_sync(
- uart_proxy,
- uart->handle,
- length,
- &data_array,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __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);
- g_variant_unref(data_array);
-
- return ret;
-}
-
-int peripheral_gdbus_uart_write(peripheral_uart_h uart, uint8_t *data, int length)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- GVariantBuilder *builder;
- GVariant *g_data;
- int i = 0;
-
- if (uart_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_uart_call_write_sync(
- uart_proxy,
- uart->handle,
- length,
- g_data,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("Error in %s() : %s", __func__, error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
#include <unistd.h>
#include <assert.h>
#include <system_info.h>
+#include <glib.h>
#include "peripheral_io.h"
#include "peripheral_gdbus_gpio.h"
#include "peripheral_common.h"
#include "peripheral_internal.h"
-#include "peripheral_io_gdbus.h"
#define PERIPHERAL_IO_GPIO_FEATURE "http://tizen.org/feature/peripheral_io.gpio"
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<node>
- <interface name="org.tizen.peripheral_io.gpio">
- <method name="Open">
- <arg type="i" name="pin" 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>
- <method name="SetDirection">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="direction" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SetEdgeMode">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="edge" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SetInterruptedCb">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="UnsetInterruptedCb">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <signal name="InterruptedCb">
- <arg type="i" name="pin"/>
- <arg type="i" name="value"/>
- <arg type="t" name="timestamp"/>
- </signal>
- <method name="Read">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="value" direction="out"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="Write">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="value" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- </interface>
- <interface name="org.tizen.peripheral_io.i2c">
- <method name="Open">
- <arg type="i" name="bus" direction="in"/>
- <arg type="i" name="address" 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>
- <method name="Read">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="length" direction="in"/>
- <arg type="a(y)" name="data" direction="out">
- <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
- </arg>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="Write">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="length" direction="in"/>
- <arg type="a(y)" name="data" direction="in">
- <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
- </arg>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SmbusIoctl">
- <arg type="u" name="handle" direction="in"/>
- <arg type="y" name="read_write" direction="in"/>
- <arg type="y" name="command" direction="in"/>
- <arg type="u" name="size" direction="in"/>
- <arg type="q" name="data_in" direction="in"/>
- <arg type="q" name="data_out" direction="out"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- </interface>
- <interface name="org.tizen.peripheral_io.pwm">
- <method name="Open">
- <arg type="i" name="chip" direction="in"/>
- <arg type="i" name="pin" 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>
- <method name="SetPeriod">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="period" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SetDutyCycle">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="duty_cycle" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SetPolarity">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="polarity" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SetEnable">
- <arg type="u" name="handle" direction="in"/>
- <arg type="b" name="enable" direction="in"/>
- <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"/>
- <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>
- <method name="SetBaudRate">
- <arg type="u" name="handle" direction="in"/>
- <arg type="u" name="baudrate" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SetByteSize">
- <arg type="u" name="handle" direction="in"/>
- <arg type="u" name="byte_size" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SetParity">
- <arg type="u" name="handle" direction="in"/>
- <arg type="u" name="parity" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SetStopBits">
- <arg type="u" name="handle" direction="in"/>
- <arg type="u" name="stop_bits" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SetFlowControl">
- <arg type="u" name="handle" direction="in"/>
- <arg type="b" name="xonxoff" direction="in"/>
- <arg type="b" name="rtscts" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="Read">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="length" direction="in"/>
- <arg type="a(y)" name="data" direction="out">
- <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
- </arg>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="Write">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="length" direction="in"/>
- <arg type="a(y)" name="data" direction="in">
- <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
- </arg>
- <arg type="i" name="result" direction="out"/>
- </method>
- </interface>
- <interface name="org.tizen.peripheral_io.spi">
- <method name="Open">
- <arg type="i" name="bus" direction="in"/>
- <arg type="i" name="cs" 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>
- <method name="SetMode">
- <arg type="u" name="handle" direction="in"/>
- <arg type="y" name="mode" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SetBitOrder">
- <arg type="u" name="handle" direction="in"/>
- <arg type="b" name="lsb" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SetBitsPerWord">
- <arg type="u" name="handle" direction="in"/>
- <arg type="y" name="bits" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="SetFrequency">
- <arg type="u" name="handle" direction="in"/>
- <arg type="u" name="freq" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="Read">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="length" direction="in"/>
- <arg type="a(y)" name="data" direction="out">
- <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
- </arg>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="Write">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="length" direction="in"/>
- <arg type="a(y)" name="data" direction="in">
- <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
- </arg>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="Transfer">
- <arg type="u" name="handle" direction="in"/>
- <arg type="i" name="length" direction="in"/>
- <arg type="a(y)" name="tx_data" direction="in">
- <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
- </arg>
- <arg type="a(y)" name="rx_data" direction="out">
- <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
- </arg>
- <arg type="i" name="result" direction="out"/>
- </method>
- </interface>
-</node>