src/peripheral_gdbus_gpio.c
src/peripheral_gdbus_i2c.c
src/peripheral_gdbus_pwm.c
+ src/peripheral_gdbus_uart.c
src/peripheral_io_gdbus.c
src/peripheral_spi.c)
#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_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_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_flush(peripheral_uart_h uart);
+int peripheral_gdbus_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_e baud);
+int peripheral_gdbus_uart_set_mode(peripheral_uart_h uart, peripheral_uart_bytesize_e bytesize, peripheral_uart_parity_e parity, peripheral_uart_stopbits_e stopbits);
+int peripheral_gdbus_uart_set_flowcontrol(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_ */
* @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
*/
-int peripheral_uart_read(peripheral_uart_h uart, char *data, int length);
+int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, int length);
/**
* @brief Write data to the uart device.
* @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
*/
-int peripheral_uart_write(peripheral_uart_h uart, const char *data, int length);
+int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, int length);
/**
* @}
--- /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"
+
+PeripheralIoGdbusUart *uart_proxy = NULL;
+
+void uart_proxy_init(void)
+{
+ GError *error = NULL;
+
+ if (uart_proxy != NULL)
+ 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);
+ 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\n", __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\n", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
+int peripheral_gdbus_uart_flush(peripheral_uart_h uart)
+{
+ GError *error = NULL;
+ gint32 ret = PERIPHERAL_ERROR_NONE;
+
+ if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_uart_call_flush_sync(
+ uart_proxy,
+ uart->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_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_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_baudrate_sync(
+ uart_proxy,
+ uart->handle,
+ baud,
+ &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_uart_set_mode(peripheral_uart_h uart, peripheral_uart_bytesize_e bytesize, peripheral_uart_parity_e parity, peripheral_uart_stopbits_e stopbits)
+{
+ GError *error = NULL;
+ gint32 ret = PERIPHERAL_ERROR_NONE;
+
+ if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_uart_call_set_mode_sync(
+ uart_proxy,
+ uart->handle,
+ bytesize,
+ parity,
+ stopbits,
+ &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_uart_set_flowcontrol(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_flowcontrol_sync(
+ uart_proxy,
+ uart->handle,
+ xonxoff,
+ rtscts,
+ &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_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\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_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\n", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
<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="Flush">
+ <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="SetMode">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="u" name="byte_size" direction="in"/>
+ <arg type="u" name="parity" 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>
</node>
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <assert.h>
+
+#include "peripheral_io.h"
+#include "peripheral_gdbus_uart.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+
+/**
+ * @brief Initializes uart communication and creates uart handle.
+ */
+int peripheral_uart_open(int port, peripheral_uart_h *uart)
+{
+ peripheral_uart_h handle;
+ int ret = PERIPHERAL_ERROR_NONE;
+
+ if (port < 0)
+ return PERIPHERAL_ERROR_INVALID_PARAMETER;
+
+ handle = (peripheral_uart_h)calloc(1, sizeof(struct _peripheral_uart_s));
+
+ if (handle == NULL) {
+ _E("Failed to allocate peripheral_uart_h");
+ return PERIPHERAL_ERROR_OUT_OF_MEMORY;
+ }
+
+ uart_proxy_init();
+
+ ret = peripheral_gdbus_uart_open(handle, port);
+
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("[PERIPHERAL] UART open error\n");
+ free(handle);
+ handle = NULL;
+ }
+ *uart = handle;
+
+ return ret;
+}
+
+/**
+ * @brief Destory the uart handle and release the communication.
+ */
+int peripheral_uart_close(peripheral_uart_h uart)
+{
+ int ret = PERIPHERAL_ERROR_NONE;
+
+ if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+
+ ret = peripheral_gdbus_uart_close(uart);
+ uart_proxy_deinit();
+
+ free(uart);
+ uart = NULL;
+
+ return ret;
+}
+
+/**
+ * @brief Flush all input that has received but not yet been read by the uart
+ * device, or all output written but not transmitted to the uart device.
+ */
+int peripheral_uart_flush(peripheral_uart_h uart)
+{
+ if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+
+ return peripheral_gdbus_uart_flush(uart);
+}
+
+/**
+ * @brief Sets baudrate of the uart device.
+ */
+int peripheral_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_e baud)
+{
+ if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+
+ return peripheral_gdbus_uart_set_baudrate(uart, baud);
+}
+
+/**
+ * @brief Sets baudrate of the uart device.
+ */
+int peripheral_uart_set_mode(peripheral_uart_h uart, peripheral_uart_bytesize_e bytesize, peripheral_uart_parity_e parity, peripheral_uart_stopbits_e stopbits)
+{
+ if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+
+ return peripheral_gdbus_uart_set_mode(uart, bytesize, parity, stopbits);
+}
+
+/**
+ * @brief Sets baudrate of the uart device.
+ */
+int peripheral_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool rtscts)
+{
+ if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+
+ return peripheral_gdbus_uart_set_flowcontrol(uart, xonxoff, rtscts);
+}
+
+/**
+ * @brief Reads data from the uart device.
+ */
+int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, int length)
+{
+ if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+
+ return peripheral_gdbus_uart_read(uart, data, length);
+}
+
+/**
+ * @brief Write data to the uart device.
+ */
+int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, int length)
+{
+ if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+
+ return peripheral_gdbus_uart_write(uart, data, length);
+}