From db307fc5c408647d0760e3f5320fe894c74c23e5 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 21 Sep 2017 17:38:17 +0900 Subject: [PATCH] name: sync functions name with changed apis name. Signed-off-by: Segwon Change-Id: I093f4eb46c396d91de3caab7a97571f34dd0d79a --- src/daemon/include/peripheral_bus.h | 4 +- src/daemon/include/peripheral_bus_gdbus_gpio.h | 34 ++---- src/daemon/include/peripheral_bus_gdbus_pwm.h | 28 +---- src/daemon/include/peripheral_bus_gdbus_spi.h | 30 +---- src/daemon/include/peripheral_bus_gdbus_uart.h | 18 ++- src/daemon/include/peripheral_bus_gpio.h | 11 +- src/daemon/include/peripheral_bus_pwm.h | 6 +- src/daemon/include/peripheral_bus_spi.h | 10 +- src/daemon/include/peripheral_bus_uart.h | 9 +- src/daemon/peripheral_bus.c | 96 +++++---------- src/daemon/peripheral_bus_gdbus_gpio.c | 92 ++++---------- src/daemon/peripheral_bus_gdbus_pwm.c | 96 +-------------- src/daemon/peripheral_bus_gdbus_spi.c | 106 ++--------------- src/daemon/peripheral_bus_gdbus_uart.c | 49 +++++--- src/daemon/peripheral_bus_gpio.c | 124 +++++++------------ src/daemon/peripheral_bus_pwm.c | 61 +++------- src/daemon/peripheral_bus_spi.c | 52 ++------ src/daemon/peripheral_bus_uart.c | 26 ++-- src/daemon/peripheral_io.xml | 102 +++++----------- src/interface/gpio.c | 8 +- src/interface/include/gpio.h | 4 +- src/interface/include/pwm.h | 64 +++++----- src/interface/include/spi.h | 10 +- src/interface/include/uart.h | 97 +++++++++------ src/interface/pwm.c | 60 +++++----- src/interface/spi.c | 86 +------------- src/interface/uart.c | 158 +++++++++++++++++++++++-- 27 files changed, 541 insertions(+), 900 deletions(-) diff --git a/src/daemon/include/peripheral_bus.h b/src/daemon/include/peripheral_bus.h index 5ce24e1..7c2f661 100644 --- a/src/daemon/include/peripheral_bus.h +++ b/src/daemon/include/peripheral_bus.h @@ -79,8 +79,8 @@ typedef struct { } peripheral_bus_i2c_s; typedef struct { - int device; - int channel; + int chip; + int pin; } peripheral_bus_pwm_s; typedef struct { diff --git a/src/daemon/include/peripheral_bus_gdbus_gpio.h b/src/daemon/include/peripheral_bus_gdbus_gpio.h index 5c75924..68c655c 100644 --- a/src/daemon/include/peripheral_bus_gdbus_gpio.h +++ b/src/daemon/include/peripheral_bus_gdbus_gpio.h @@ -31,12 +31,6 @@ gboolean handle_gpio_close( gint handle, gpointer user_data); -gboolean handle_gpio_get_direction( - PeripheralIoGdbusGpio *gpio, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data); - gboolean handle_gpio_set_direction( PeripheralIoGdbusGpio *gpio, GDBusMethodInvocation *invocation, @@ -44,48 +38,42 @@ gboolean handle_gpio_set_direction( gint direction, gpointer user_data); -gboolean handle_gpio_read( +gboolean handle_gpio_set_edge_mode( PeripheralIoGdbusGpio *gpio, GDBusMethodInvocation *invocation, gint handle, + gint edge, gpointer user_data); -gboolean handle_gpio_write( +gboolean handle_gpio_set_interrupted_cb( PeripheralIoGdbusGpio *gpio, GDBusMethodInvocation *invocation, gint handle, - gint value, gpointer user_data); -gboolean handle_gpio_get_edge_mode( +gboolean handle_gpio_unset_interrupted_cb( PeripheralIoGdbusGpio *gpio, GDBusMethodInvocation *invocation, gint handle, gpointer user_data); -gboolean handle_gpio_set_edge_mode( +void peripheral_bus_emit_interrupted_cb( PeripheralIoGdbusGpio *gpio, - GDBusMethodInvocation *invocation, - gint handle, - gint edge, - gpointer user_data); + gint pin, + gint value, + guint64 timestamp); -gboolean handle_gpio_register_irq( +gboolean handle_gpio_read( PeripheralIoGdbusGpio *gpio, GDBusMethodInvocation *invocation, gint handle, gpointer user_data); -gboolean handle_gpio_unregister_irq( +gboolean handle_gpio_write( PeripheralIoGdbusGpio *gpio, GDBusMethodInvocation *invocation, gint handle, - gpointer user_data); - -void peripheral_bus_emit_gpio_changed( - PeripheralIoGdbusGpio *gpio, - gint pin, gint value, - guint64 timestamp); + gpointer user_data); #endif /* __PERIPHERAL_BUS_GDBUS_GPIO_H__ */ diff --git a/src/daemon/include/peripheral_bus_gdbus_pwm.h b/src/daemon/include/peripheral_bus_gdbus_pwm.h index 817d243..aa159dd 100644 --- a/src/daemon/include/peripheral_bus_gdbus_pwm.h +++ b/src/daemon/include/peripheral_bus_gdbus_pwm.h @@ -22,8 +22,8 @@ gboolean handle_pwm_open( PeripheralIoGdbusPwm *pwm, GDBusMethodInvocation *invocation, - gint device, - gint channel, + gint chip, + gint pin, gpointer user_data); gboolean handle_pwm_close( @@ -39,12 +39,6 @@ gboolean handle_pwm_set_period( gint period, gpointer user_data); -gboolean handle_pwm_get_period( - PeripheralIoGdbusPwm *pwm, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data); - gboolean handle_pwm_set_duty_cycle( PeripheralIoGdbusPwm *pwm, GDBusMethodInvocation *invocation, @@ -52,12 +46,6 @@ gboolean handle_pwm_set_duty_cycle( gint duty_cycle, gpointer user_data); -gboolean handle_pwm_get_duty_cycle( - PeripheralIoGdbusPwm *pwm, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data); - gboolean handle_pwm_set_polarity( PeripheralIoGdbusPwm *pwm, GDBusMethodInvocation *invocation, @@ -65,12 +53,6 @@ gboolean handle_pwm_set_polarity( gint polarity, gpointer user_data); -gboolean handle_pwm_get_polarity( - PeripheralIoGdbusPwm *pwm, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data); - gboolean handle_pwm_set_enable( PeripheralIoGdbusPwm *pwm, GDBusMethodInvocation *invocation, @@ -78,10 +60,4 @@ gboolean handle_pwm_set_enable( gint enable, gpointer user_data); -gboolean handle_pwm_get_enable( - PeripheralIoGdbusPwm *pwm, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data); - #endif /* __PERIPHERAL_BUS_GDBUS_PWM_H__ */ diff --git a/src/daemon/include/peripheral_bus_gdbus_spi.h b/src/daemon/include/peripheral_bus_gdbus_spi.h index 7032806..ac70aba 100644 --- a/src/daemon/include/peripheral_bus_gdbus_spi.h +++ b/src/daemon/include/peripheral_bus_gdbus_spi.h @@ -39,38 +39,20 @@ gboolean handle_spi_set_mode( guchar mode, gpointer user_data); -gboolean handle_spi_get_mode( - PeripheralIoGdbusSpi *spi, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data); - -gboolean handle_spi_set_lsb_first( +gboolean handle_spi_set_bit_order( PeripheralIoGdbusSpi *spi, GDBusMethodInvocation *invocation, gint handle, gboolean lsb, gpointer user_data); -gboolean handle_spi_get_lsb_first( - PeripheralIoGdbusSpi *spi, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data); - -gboolean handle_spi_set_bits( +gboolean handle_spi_set_bits_per_word( PeripheralIoGdbusSpi *spi, GDBusMethodInvocation *invocation, gint handle, guchar bits, gpointer user_data); -gboolean handle_spi_get_bits( - PeripheralIoGdbusSpi *spi, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data); - gboolean handle_spi_set_frequency( PeripheralIoGdbusSpi *spi, GDBusMethodInvocation *invocation, @@ -78,12 +60,6 @@ gboolean handle_spi_set_frequency( guint freq, gpointer user_data); -gboolean handle_spi_get_frequency( - PeripheralIoGdbusSpi *spi, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data); - gboolean handle_spi_read( PeripheralIoGdbusSpi *spi, GDBusMethodInvocation *invocation, @@ -99,7 +75,7 @@ gboolean handle_spi_write( GVariant *data_array, gpointer user_data); -gboolean handle_spi_read_write( +gboolean handle_spi_transfer( PeripheralIoGdbusSpi *spi, GDBusMethodInvocation *invocation, gint handle, diff --git a/src/daemon/include/peripheral_bus_gdbus_uart.h b/src/daemon/include/peripheral_bus_gdbus_uart.h index 68eef7f..5ada2e0 100644 --- a/src/daemon/include/peripheral_bus_gdbus_uart.h +++ b/src/daemon/include/peripheral_bus_gdbus_uart.h @@ -31,29 +31,35 @@ gboolean handle_uart_close( gint handle, gpointer user_data); -gboolean handle_uart_flush( +gboolean handle_uart_set_baud_rate( PeripheralIoGdbusUart *uart, GDBusMethodInvocation *invocation, gint handle, + guint baudrate, gpointer user_data); -gboolean handle_uart_set_baudrate( +gboolean handle_uart_set_byte_size( PeripheralIoGdbusUart *uart, GDBusMethodInvocation *invocation, gint handle, - guint baudrate, + guint byte_size, gpointer user_data); -gboolean handle_uart_set_mode( +gboolean handle_uart_set_parity( PeripheralIoGdbusUart *uart, GDBusMethodInvocation *invocation, gint handle, - guint byte_size, guint parity, + gpointer user_data); + +gboolean handle_uart_set_stop_bits( + PeripheralIoGdbusUart *uart, + GDBusMethodInvocation *invocation, + gint handle, guint stop_bits, gpointer user_data); -gboolean handle_uart_set_flowcontrol( +gboolean handle_uart_set_flow_control( PeripheralIoGdbusUart *uart, GDBusMethodInvocation *invocation, gint handle, diff --git a/src/daemon/include/peripheral_bus_gpio.h b/src/daemon/include/peripheral_bus_gpio.h index 3a63530..e59af40 100644 --- a/src/daemon/include/peripheral_bus_gpio.h +++ b/src/daemon/include/peripheral_bus_gpio.h @@ -18,14 +18,11 @@ #define __PERIPHERAL_BUS_GPIO_H__ int peripheral_bus_gpio_open(gint pin, pb_data_h *handle, gpointer user_data); +int peripheral_bus_gpio_close(pb_data_h handle); int peripheral_bus_gpio_set_direction(pb_data_h handle, gint direction); -int peripheral_bus_gpio_get_direction(pb_data_h handle, gint *direction); int peripheral_bus_gpio_set_edge(pb_data_h handle, gint edge); -int peripheral_bus_gpio_get_edge(pb_data_h handle, gint *edge); -int peripheral_bus_gpio_write(pb_data_h handle, gint value); +int peripheral_bus_gpio_set_interrupted_cb(pb_data_h handle); +int peripheral_bus_gpio_unset_interrupted_cb(pb_data_h handle); int peripheral_bus_gpio_read(pb_data_h handle, gint *value); -int peripheral_bus_gpio_register_irq(pb_data_h handle); -int peripheral_bus_gpio_unregister_irq(pb_data_h handle); -int peripheral_bus_gpio_close(pb_data_h handle); - +int peripheral_bus_gpio_write(pb_data_h handle, gint value); #endif /* __PERIPHERAL_BUS_GPIO_H__ */ diff --git a/src/daemon/include/peripheral_bus_pwm.h b/src/daemon/include/peripheral_bus_pwm.h index fbcc6e3..0072b2b 100644 --- a/src/daemon/include/peripheral_bus_pwm.h +++ b/src/daemon/include/peripheral_bus_pwm.h @@ -17,15 +17,11 @@ #ifndef __PERIPHERAL_BUS_PWM_H__ #define __PERIPHERAL_BUS_PWM_H__ -int peripheral_bus_pwm_open(int device, int channel, pb_data_h *handle, gpointer user_data); +int peripheral_bus_pwm_open(int chip, int pin, pb_data_h *handle, gpointer user_data); int peripheral_bus_pwm_close(pb_data_h handle); int peripheral_bus_pwm_set_period(pb_data_h handle, int period); -int peripheral_bus_pwm_get_period(pb_data_h handle, int *period); int peripheral_bus_pwm_set_duty_cycle(pb_data_h handle, int duty_cycle); -int peripheral_bus_pwm_get_duty_cycle(pb_data_h handle, int *duty_cycle); int peripheral_bus_pwm_set_polarity(pb_data_h handle, int polarity); -int peripheral_bus_pwm_get_polarity(pb_data_h handle, int *polarity); int peripheral_bus_pwm_set_enable(pb_data_h handle, bool enable); -int peripheral_bus_pwm_get_enable(pb_data_h handle, bool *enable); #endif /* __PERIPHERAL_BUS_PWM_H__ */ diff --git a/src/daemon/include/peripheral_bus_spi.h b/src/daemon/include/peripheral_bus_spi.h index 1140600..63e5df7 100644 --- a/src/daemon/include/peripheral_bus_spi.h +++ b/src/daemon/include/peripheral_bus_spi.h @@ -20,15 +20,11 @@ int peripheral_bus_spi_open(int bus, int cs, pb_data_h *handle, gpointer user_data); int peripheral_bus_spi_close(pb_data_h handle); int peripheral_bus_spi_set_mode(pb_data_h handle, unsigned char mode); -int peripheral_bus_spi_get_mode(pb_data_h handle, unsigned char *mode); -int peripheral_bus_spi_set_lsb_first(pb_data_h handle, gboolean lsb); -int peripheral_bus_spi_get_lsb_first(pb_data_h handle, gboolean *lsb); -int peripheral_bus_spi_set_bits(pb_data_h handle, unsigned char bits); -int peripheral_bus_spi_get_bits(pb_data_h handle, unsigned char *bits); +int peripheral_bus_spi_set_bit_order(pb_data_h handle, gboolean lsb); +int peripheral_bus_spi_set_bits_per_word(pb_data_h handle, unsigned char bits); int peripheral_bus_spi_set_frequency(pb_data_h handle, unsigned int freq); -int peripheral_bus_spi_get_frequency(pb_data_h handle, unsigned int *freq); int peripheral_bus_spi_read(pb_data_h handle, GVariant **data_array, int length); int peripheral_bus_spi_write(pb_data_h handle, GVariant *data_array, int length); -int peripheral_bus_spi_read_write(pb_data_h handle, GVariant *tx_data_array, GVariant **rx_data_array, int length); +int peripheral_bus_spi_transfer(pb_data_h handle, GVariant *tx_data_array, GVariant **rx_data_array, int length); #endif /* __PERIPHERAL_BUS_SPI_H__ */ diff --git a/src/daemon/include/peripheral_bus_uart.h b/src/daemon/include/peripheral_bus_uart.h index 680d72a..d6da3b9 100644 --- a/src/daemon/include/peripheral_bus_uart.h +++ b/src/daemon/include/peripheral_bus_uart.h @@ -19,10 +19,11 @@ int peripheral_bus_uart_open(int port, pb_data_h *handle, gpointer user_data); int peripheral_bus_uart_close(pb_data_h handle); -int peripheral_bus_uart_flush(pb_data_h handle); -int peripheral_bus_uart_set_baudrate(pb_data_h handle, int baudrate); -int peripheral_bus_uart_set_mode(pb_data_h handle, int byte_size, int parity, int stop_bits); -int peripheral_bus_uart_set_flowcontrol(pb_data_h handle, int xonxoff, int rtscts); +int peripheral_bus_uart_set_baud_rate(pb_data_h handle, int baud_rate); +int peripheral_bus_uart_set_byte_size(pb_data_h handle, int byte_size); +int peripheral_bus_uart_set_parity(pb_data_h handle, int parity); +int peripheral_bus_uart_set_stop_bits(pb_data_h handle, int stop_bits); +int peripheral_bus_uart_set_flow_control(pb_data_h handle, int xonxoff, int rtscts); int peripheral_bus_uart_read(pb_data_h handle, GVariant **data_array, int length); int peripheral_bus_uart_write(pb_data_h handle, GVariant *data_array, int length); diff --git a/src/daemon/peripheral_bus.c b/src/daemon/peripheral_bus.c index bc346a0..4822915 100644 --- a/src/daemon/peripheral_bus.c +++ b/src/daemon/peripheral_bus.c @@ -50,36 +50,28 @@ static gboolean __gpio_init(peripheral_bus_s *pb_data) G_CALLBACK(handle_gpio_close), pb_data); g_signal_connect(pb_data->gpio_skeleton, - "handle-get-direction", - G_CALLBACK(handle_gpio_get_direction), - pb_data); - g_signal_connect(pb_data->gpio_skeleton, "handle-set-direction", G_CALLBACK(handle_gpio_set_direction), pb_data); g_signal_connect(pb_data->gpio_skeleton, - "handle-read", - G_CALLBACK(handle_gpio_read), - pb_data); - g_signal_connect(pb_data->gpio_skeleton, - "handle-write", - G_CALLBACK(handle_gpio_write), + "handle-set-edge-mode", + G_CALLBACK(handle_gpio_set_edge_mode), pb_data); g_signal_connect(pb_data->gpio_skeleton, - "handle-get-edge-mode", - G_CALLBACK(handle_gpio_get_edge_mode), + "handle-set-interrupted-cb", + G_CALLBACK(handle_gpio_set_interrupted_cb), pb_data); g_signal_connect(pb_data->gpio_skeleton, - "handle-set-edge-mode", - G_CALLBACK(handle_gpio_set_edge_mode), + "handle-unset-interrupted-cb", + G_CALLBACK(handle_gpio_unset_interrupted_cb), pb_data); g_signal_connect(pb_data->gpio_skeleton, - "handle-register-irq", - G_CALLBACK(handle_gpio_register_irq), + "handle-read", + G_CALLBACK(handle_gpio_read), pb_data); g_signal_connect(pb_data->gpio_skeleton, - "handle-unregister-irq", - G_CALLBACK(handle_gpio_unregister_irq), + "handle-write", + G_CALLBACK(handle_gpio_write), pb_data); manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_GPIO_PATH); @@ -168,33 +160,17 @@ static gboolean __pwm_init(peripheral_bus_s *pb_data) G_CALLBACK(handle_pwm_set_period), pb_data); g_signal_connect(pb_data->pwm_skeleton, - "handle-get-period", - G_CALLBACK(handle_pwm_get_period), - pb_data); - g_signal_connect(pb_data->pwm_skeleton, "handle-set-duty-cycle", G_CALLBACK(handle_pwm_set_duty_cycle), pb_data); g_signal_connect(pb_data->pwm_skeleton, - "handle-get-duty-cycle", - G_CALLBACK(handle_pwm_get_duty_cycle), - pb_data); - g_signal_connect(pb_data->pwm_skeleton, "handle-set-polarity", G_CALLBACK(handle_pwm_set_polarity), pb_data); g_signal_connect(pb_data->pwm_skeleton, - "handle-get-polarity", - G_CALLBACK(handle_pwm_get_polarity), - pb_data); - g_signal_connect(pb_data->pwm_skeleton, "handle-set-enable", G_CALLBACK(handle_pwm_set_enable), pb_data); - g_signal_connect(pb_data->pwm_skeleton, - "handle-get-enable", - G_CALLBACK(handle_pwm_get_enable), - pb_data); manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_PWM_PATH); @@ -231,20 +207,24 @@ static gboolean __uart_init(peripheral_bus_s *pb_data) G_CALLBACK(handle_uart_close), pb_data); g_signal_connect(pb_data->uart_skeleton, - "handle-flush", - G_CALLBACK(handle_uart_flush), + "handle-set-baud-rate", + G_CALLBACK(handle_uart_set_baud_rate), pb_data); g_signal_connect(pb_data->uart_skeleton, - "handle-set-baudrate", - G_CALLBACK(handle_uart_set_baudrate), + "handle-set-byte-size", + G_CALLBACK(handle_uart_set_byte_size), pb_data); g_signal_connect(pb_data->uart_skeleton, - "handle-set-mode", - G_CALLBACK(handle_uart_set_mode), + "handle-set-parity", + G_CALLBACK(handle_uart_set_parity), pb_data); g_signal_connect(pb_data->uart_skeleton, - "handle-set-flowcontrol", - G_CALLBACK(handle_uart_set_flowcontrol), + "handle-set-stop-bits", + G_CALLBACK(handle_uart_set_stop_bits), + pb_data); + g_signal_connect(pb_data->uart_skeleton, + "handle-set-flow-control", + G_CALLBACK(handle_uart_set_flow_control), pb_data); g_signal_connect(pb_data->uart_skeleton, "handle-read", @@ -294,44 +274,28 @@ static gboolean __spi_init(peripheral_bus_s *pb_data) G_CALLBACK(handle_spi_set_mode), pb_data); g_signal_connect(pb_data->spi_skeleton, - "handle-get-mode", - G_CALLBACK(handle_spi_get_mode), + "handle-set-bit-order", + G_CALLBACK(handle_spi_set_bit_order), pb_data); g_signal_connect(pb_data->spi_skeleton, - "handle-set-lsb-first", - G_CALLBACK(handle_spi_set_lsb_first), - pb_data); - g_signal_connect(pb_data->spi_skeleton, - "handle-get-lsb-first", - G_CALLBACK(handle_spi_get_lsb_first), - pb_data); - g_signal_connect(pb_data->spi_skeleton, - "handle-set-bits", - G_CALLBACK(handle_spi_set_bits), - pb_data); - g_signal_connect(pb_data->spi_skeleton, - "handle-get-bits", - G_CALLBACK(handle_spi_get_bits), + "handle-set-bits-per-word", + G_CALLBACK(handle_spi_set_bits_per_word), pb_data); g_signal_connect(pb_data->spi_skeleton, "handle-set-frequency", G_CALLBACK(handle_spi_set_frequency), pb_data); g_signal_connect(pb_data->spi_skeleton, - "handle-get-frequency", - G_CALLBACK(handle_spi_get_frequency), + "handle-read", + G_CALLBACK(handle_spi_read), pb_data); g_signal_connect(pb_data->spi_skeleton, "handle-write", G_CALLBACK(handle_spi_write), pb_data); g_signal_connect(pb_data->spi_skeleton, - "handle-read", - G_CALLBACK(handle_spi_read), - pb_data); - g_signal_connect(pb_data->spi_skeleton, - "handle-read-write", - G_CALLBACK(handle_spi_read_write), + "handle-transfer", + G_CALLBACK(handle_spi_transfer), pb_data); manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_SPI_PATH); diff --git a/src/daemon/peripheral_bus_gdbus_gpio.c b/src/daemon/peripheral_bus_gdbus_gpio.c index d4ee8ee..fde3696 100644 --- a/src/daemon/peripheral_bus_gdbus_gpio.c +++ b/src/daemon/peripheral_bus_gdbus_gpio.c @@ -91,28 +91,6 @@ gboolean handle_gpio_close( return true; } -gboolean handle_gpio_get_direction( - PeripheralIoGdbusGpio *gpio, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data) -{ - peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - pb_data_h gpio_handle = GUINT_TO_POINTER(handle); - gint direction = 0; - - if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) { - _E("gpio handle is not valid"); - ret = PERIPHERAL_ERROR_INVALID_PARAMETER; - } else - ret = peripheral_bus_gpio_get_direction(gpio_handle, &direction); - - peripheral_io_gdbus_gpio_complete_get_direction(gpio, invocation, direction, ret); - - return true; -} - gboolean handle_gpio_set_direction( PeripheralIoGdbusGpio *gpio, GDBusMethodInvocation *invocation, @@ -135,33 +113,32 @@ gboolean handle_gpio_set_direction( return true; } -gboolean handle_gpio_read( +gboolean handle_gpio_set_edge_mode( PeripheralIoGdbusGpio *gpio, GDBusMethodInvocation *invocation, gint handle, + gint edge, gpointer user_data) { peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; pb_data_h gpio_handle = GUINT_TO_POINTER(handle); - gint read_value = 0; if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) { _E("gpio handle is not valid"); ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else - ret = peripheral_bus_gpio_read(gpio_handle, &read_value); + ret = peripheral_bus_gpio_set_edge(gpio_handle, edge); - peripheral_io_gdbus_gpio_complete_read(gpio, invocation, read_value, ret); + peripheral_io_gdbus_gpio_complete_set_edge_mode(gpio, invocation, ret); return true; } -gboolean handle_gpio_write( +gboolean handle_gpio_set_interrupted_cb( PeripheralIoGdbusGpio *gpio, GDBusMethodInvocation *invocation, gint handle, - gint value, gpointer user_data) { peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; @@ -172,14 +149,14 @@ gboolean handle_gpio_write( _E("gpio handle is not valid"); ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else - ret = peripheral_bus_gpio_write(gpio_handle, value); + ret = peripheral_bus_gpio_set_interrupted_cb(gpio_handle); - peripheral_io_gdbus_gpio_complete_write(gpio, invocation, ret); + peripheral_io_gdbus_gpio_complete_set_interrupted_cb(gpio, invocation, ret); return true; } -gboolean handle_gpio_get_edge_mode( +gboolean handle_gpio_unset_interrupted_cb( PeripheralIoGdbusGpio *gpio, GDBusMethodInvocation *invocation, gint handle, @@ -188,42 +165,30 @@ gboolean handle_gpio_get_edge_mode( peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; pb_data_h gpio_handle = GUINT_TO_POINTER(handle); - gint edge = 0; if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) { _E("gpio handle is not valid"); ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else - ret = peripheral_bus_gpio_get_edge(gpio_handle, &edge); + ret = peripheral_bus_gpio_unset_interrupted_cb(gpio_handle); - peripheral_io_gdbus_gpio_complete_get_edge_mode(gpio, invocation, edge, ret); + peripheral_io_gdbus_gpio_complete_unset_interrupted_cb(gpio, invocation, ret); return true; } -gboolean handle_gpio_set_edge_mode( +void peripheral_bus_emit_interrupted_cb( PeripheralIoGdbusGpio *gpio, - GDBusMethodInvocation *invocation, - gint handle, - gint edge, - gpointer user_data) + gint pin, + gint value, + guint64 timestamp) { - peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - pb_data_h gpio_handle = GUINT_TO_POINTER(handle); - - if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) { - _E("gpio handle is not valid"); - ret = PERIPHERAL_ERROR_INVALID_PARAMETER; - } else - ret = peripheral_bus_gpio_set_edge(gpio_handle, edge); - - peripheral_io_gdbus_gpio_complete_set_edge_mode(gpio, invocation, ret); + g_assert(gpio != NULL); - return true; + peripheral_io_gdbus_gpio_emit_interrupted_cb(gpio, pin, value, timestamp); } -gboolean handle_gpio_register_irq( +gboolean handle_gpio_read( PeripheralIoGdbusGpio *gpio, GDBusMethodInvocation *invocation, gint handle, @@ -232,22 +197,24 @@ gboolean handle_gpio_register_irq( peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; pb_data_h gpio_handle = GUINT_TO_POINTER(handle); + gint read_value = 0; if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) { _E("gpio handle is not valid"); ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else - ret = peripheral_bus_gpio_register_irq(gpio_handle); + ret = peripheral_bus_gpio_read(gpio_handle, &read_value); - peripheral_io_gdbus_gpio_complete_register_irq(gpio, invocation, ret); + peripheral_io_gdbus_gpio_complete_read(gpio, invocation, read_value, ret); return true; } -gboolean handle_gpio_unregister_irq( +gboolean handle_gpio_write( PeripheralIoGdbusGpio *gpio, GDBusMethodInvocation *invocation, gint handle, + gint value, gpointer user_data) { peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; @@ -258,20 +225,9 @@ gboolean handle_gpio_unregister_irq( _E("gpio handle is not valid"); ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else - ret = peripheral_bus_gpio_unregister_irq(gpio_handle); + ret = peripheral_bus_gpio_write(gpio_handle, value); - peripheral_io_gdbus_gpio_complete_unregister_irq(gpio, invocation, ret); + peripheral_io_gdbus_gpio_complete_write(gpio, invocation, ret); return true; } - -void peripheral_bus_emit_gpio_changed( - PeripheralIoGdbusGpio *gpio, - gint pin, - gint value, - guint64 timestamp) -{ - g_assert(gpio != NULL); - - peripheral_io_gdbus_gpio_emit_gpio_changed(gpio, pin, value, timestamp); -} diff --git a/src/daemon/peripheral_bus_gdbus_pwm.c b/src/daemon/peripheral_bus_gdbus_pwm.c index 33d5123..acb8e21 100644 --- a/src/daemon/peripheral_bus_gdbus_pwm.c +++ b/src/daemon/peripheral_bus_gdbus_pwm.c @@ -37,15 +37,15 @@ static void __pwm_on_name_vanished(GDBusConnection *connection, gboolean handle_pwm_open( PeripheralIoGdbusPwm *pwm, GDBusMethodInvocation *invocation, - gint device, - gint channel, + gint chip, + gint pin, gpointer user_data) { peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; pb_data_h pwm_handle; - if ((ret = peripheral_bus_pwm_open(device, channel, &pwm_handle, user_data)) < PERIPHERAL_ERROR_NONE) + if ((ret = peripheral_bus_pwm_open(chip, pin, &pwm_handle, user_data)) < PERIPHERAL_ERROR_NONE) goto out; if (peripheral_bus_get_client_info(invocation, pb_data, &pwm_handle->client_info) < 0) { @@ -61,7 +61,7 @@ gboolean handle_pwm_open( __pwm_on_name_vanished, pwm_handle, NULL); - _D("device : %d, channel : %d, id = %s", device, channel, pwm_handle->client_info.id); + _D("chip : %d, pin : %d, id = %s", chip, pin, pwm_handle->client_info.id); out: peripheral_io_gdbus_pwm_complete_open(pwm, invocation, GPOINTER_TO_UINT(pwm_handle), ret); @@ -114,28 +114,6 @@ gboolean handle_pwm_set_period( return true; } -gboolean handle_pwm_get_period( - PeripheralIoGdbusPwm *pwm, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data) -{ - peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - pb_data_h pwm_handle = GUINT_TO_POINTER(handle); - int period = 0; - - if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) { - _E("pwm handle is not valid"); - ret = PERIPHERAL_ERROR_INVALID_PARAMETER; - } else - ret = peripheral_bus_pwm_get_period(pwm_handle, &period); - - peripheral_io_gdbus_pwm_complete_get_period(pwm, invocation, period, ret); - - return true; -} - gboolean handle_pwm_set_duty_cycle( PeripheralIoGdbusPwm *pwm, GDBusMethodInvocation *invocation, @@ -158,28 +136,6 @@ gboolean handle_pwm_set_duty_cycle( return true; } -gboolean handle_pwm_get_duty_cycle( - PeripheralIoGdbusPwm *pwm, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data) -{ - peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - pb_data_h pwm_handle = GUINT_TO_POINTER(handle); - int duty_cycle = 0; - - if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) { - _E("pwm handle is not valid"); - ret = PERIPHERAL_ERROR_INVALID_PARAMETER; - } else - ret = peripheral_bus_pwm_get_duty_cycle(pwm_handle, &duty_cycle); - - peripheral_io_gdbus_pwm_complete_get_duty_cycle(pwm, invocation, duty_cycle, ret); - - return true; -} - gboolean handle_pwm_set_polarity( PeripheralIoGdbusPwm *pwm, GDBusMethodInvocation *invocation, @@ -202,28 +158,6 @@ gboolean handle_pwm_set_polarity( return true; } -gboolean handle_pwm_get_polarity( - PeripheralIoGdbusPwm *pwm, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data) -{ - peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - pb_data_h pwm_handle = GUINT_TO_POINTER(handle); - int polarity = 0; - - if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) { - _E("pwm handle is not valid"); - ret = PERIPHERAL_ERROR_INVALID_PARAMETER; - } else - ret = peripheral_bus_pwm_get_polarity(pwm_handle, &polarity); - - peripheral_io_gdbus_pwm_complete_get_polarity(pwm, invocation, polarity, ret); - - return true; -} - gboolean handle_pwm_set_enable( PeripheralIoGdbusPwm *pwm, GDBusMethodInvocation *invocation, @@ -245,25 +179,3 @@ gboolean handle_pwm_set_enable( return true; } - -gboolean handle_pwm_get_enable( - PeripheralIoGdbusPwm *pwm, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data) -{ - peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - pb_data_h pwm_handle = GUINT_TO_POINTER(handle); - bool enable = false; - - if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) { - _E("pwm handle is not valid"); - ret = PERIPHERAL_ERROR_INVALID_PARAMETER; - } else - ret = peripheral_bus_pwm_get_enable(pwm_handle, &enable); - - peripheral_io_gdbus_pwm_complete_get_enable(pwm, invocation, enable, ret); - - return true; -} diff --git a/src/daemon/peripheral_bus_gdbus_spi.c b/src/daemon/peripheral_bus_gdbus_spi.c index 36ff6d1..f0f9010 100644 --- a/src/daemon/peripheral_bus_gdbus_spi.c +++ b/src/daemon/peripheral_bus_gdbus_spi.c @@ -114,29 +114,7 @@ gboolean handle_spi_set_mode( return true; } -gboolean handle_spi_get_mode( - PeripheralIoGdbusSpi *spi, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data) -{ - peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - pb_data_h spi_handle = GUINT_TO_POINTER(handle); - uint8_t mode = 0; - - if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) { - _E("spi handle is not valid"); - ret = PERIPHERAL_ERROR_INVALID_PARAMETER; - } else - ret = peripheral_bus_spi_get_mode(spi_handle, &mode); - - peripheral_io_gdbus_spi_complete_get_mode(spi, invocation, mode, ret); - - return true; -} - -gboolean handle_spi_set_lsb_first( +gboolean handle_spi_set_bit_order( PeripheralIoGdbusSpi *spi, GDBusMethodInvocation *invocation, gint handle, @@ -151,36 +129,14 @@ gboolean handle_spi_set_lsb_first( _E("spi handle is not valid"); ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else - ret = peripheral_bus_spi_set_lsb_first(spi_handle, lsb); - - peripheral_io_gdbus_spi_complete_set_lsb_first(spi, invocation, ret); - - return true; -} - -gboolean handle_spi_get_lsb_first( - PeripheralIoGdbusSpi *spi, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data) -{ - peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - pb_data_h spi_handle = GUINT_TO_POINTER(handle); - gboolean lsb = 0; - - if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) { - _E("spi handle is not valid"); - ret = PERIPHERAL_ERROR_INVALID_PARAMETER; - } else - ret = peripheral_bus_spi_get_lsb_first(spi_handle, &lsb); + ret = peripheral_bus_spi_set_bit_order(spi_handle, lsb); - peripheral_io_gdbus_spi_complete_get_lsb_first(spi, invocation, lsb, ret); + peripheral_io_gdbus_spi_complete_set_bit_order(spi, invocation, ret); return true; } -gboolean handle_spi_set_bits( +gboolean handle_spi_set_bits_per_word( PeripheralIoGdbusSpi *spi, GDBusMethodInvocation *invocation, gint handle, @@ -195,31 +151,9 @@ gboolean handle_spi_set_bits( _E("spi handle is not valid"); ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else - ret = peripheral_bus_spi_set_bits(spi_handle, bits); + ret = peripheral_bus_spi_set_bits_per_word(spi_handle, bits); - peripheral_io_gdbus_spi_complete_set_bits(spi, invocation, ret); - - return true; -} - -gboolean handle_spi_get_bits( - PeripheralIoGdbusSpi *spi, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data) -{ - peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - pb_data_h spi_handle = GUINT_TO_POINTER(handle); - uint8_t bits = 0; - - if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) { - _E("spi handle is not valid"); - ret = PERIPHERAL_ERROR_INVALID_PARAMETER; - } else - ret = peripheral_bus_spi_get_bits(spi_handle, &bits); - - peripheral_io_gdbus_spi_complete_get_bits(spi, invocation, bits, ret); + peripheral_io_gdbus_spi_complete_set_bits_per_word(spi, invocation, ret); return true; } @@ -246,28 +180,6 @@ gboolean handle_spi_set_frequency( return true; } -gboolean handle_spi_get_frequency( - PeripheralIoGdbusSpi *spi, - GDBusMethodInvocation *invocation, - gint handle, - gpointer user_data) -{ - peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - pb_data_h spi_handle = GUINT_TO_POINTER(handle); - unsigned int freq = 0; - - if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) { - _E("spi handle is not valid"); - ret = PERIPHERAL_ERROR_INVALID_PARAMETER; - } else - ret = peripheral_bus_spi_get_frequency(spi_handle, &freq); - - peripheral_io_gdbus_spi_complete_get_frequency(spi, invocation, freq, ret); - - return true; -} - gboolean handle_spi_read( PeripheralIoGdbusSpi *spi, GDBusMethodInvocation *invocation, @@ -316,7 +228,7 @@ gboolean handle_spi_write( return true; } -gboolean handle_spi_read_write( +gboolean handle_spi_transfer( PeripheralIoGdbusSpi *spi, GDBusMethodInvocation *invocation, gint handle, @@ -335,9 +247,9 @@ gboolean handle_spi_read_write( rx_data_array = peripheral_bus_build_variant_ay(err_buf, sizeof(err_buf)); ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else - ret = peripheral_bus_spi_read_write(spi_handle, tx_data_array, &rx_data_array, length); + ret = peripheral_bus_spi_transfer(spi_handle, tx_data_array, &rx_data_array, length); - peripheral_io_gdbus_spi_complete_read_write(spi, invocation, rx_data_array, ret); + peripheral_io_gdbus_spi_complete_transfer(spi, invocation, rx_data_array, ret); return true; } diff --git a/src/daemon/peripheral_bus_gdbus_uart.c b/src/daemon/peripheral_bus_gdbus_uart.c index 136fb45..b927ee6 100644 --- a/src/daemon/peripheral_bus_gdbus_uart.c +++ b/src/daemon/peripheral_bus_gdbus_uart.c @@ -91,10 +91,11 @@ gboolean handle_uart_close( return true; } -gboolean handle_uart_flush( +gboolean handle_uart_set_baud_rate( PeripheralIoGdbusUart *uart, GDBusMethodInvocation *invocation, gint handle, + guint baud_rate, gpointer user_data) { peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; @@ -105,18 +106,18 @@ gboolean handle_uart_flush( _E("uart handle is not valid"); ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else - ret = peripheral_bus_uart_flush(uart_handle); + ret = peripheral_bus_uart_set_baud_rate(uart_handle, baud_rate); - peripheral_io_gdbus_uart_complete_flush(uart, invocation, ret); + peripheral_io_gdbus_uart_complete_set_baud_rate(uart, invocation, ret); return true; } -gboolean handle_uart_set_baudrate( +gboolean handle_uart_set_byte_size( PeripheralIoGdbusUart *uart, GDBusMethodInvocation *invocation, gint handle, - guint baudrate, + guint byte_size, gpointer user_data) { peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; @@ -127,19 +128,39 @@ gboolean handle_uart_set_baudrate( _E("uart handle is not valid"); ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else - ret = peripheral_bus_uart_set_baudrate(uart_handle, baudrate); + ret = peripheral_bus_uart_set_byte_size(uart_handle, byte_size); - peripheral_io_gdbus_uart_complete_set_baudrate(uart, invocation, ret); + peripheral_io_gdbus_uart_complete_set_byte_size(uart, invocation, ret); return true; } -gboolean handle_uart_set_mode( +gboolean handle_uart_set_parity( PeripheralIoGdbusUart *uart, GDBusMethodInvocation *invocation, gint handle, - guint byte_size, guint parity, + gpointer user_data) +{ + peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + pb_data_h uart_handle = GUINT_TO_POINTER(handle); + + if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) { + _E("uart handle is not valid"); + ret = PERIPHERAL_ERROR_INVALID_PARAMETER; + } else + ret = peripheral_bus_uart_set_parity(uart_handle, parity); + + peripheral_io_gdbus_uart_complete_set_parity(uart, invocation, ret); + + return true; +} + +gboolean handle_uart_set_stop_bits( + PeripheralIoGdbusUart *uart, + GDBusMethodInvocation *invocation, + gint handle, guint stop_bits, gpointer user_data) { @@ -151,14 +172,14 @@ gboolean handle_uart_set_mode( _E("uart handle is not valid"); ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else - ret = peripheral_bus_uart_set_mode(uart_handle, byte_size, parity, stop_bits); + ret = peripheral_bus_uart_set_stop_bits(uart_handle, stop_bits); - peripheral_io_gdbus_uart_complete_set_mode(uart, invocation, ret); + peripheral_io_gdbus_uart_complete_set_stop_bits(uart, invocation, ret); return true; } -gboolean handle_uart_set_flowcontrol( +gboolean handle_uart_set_flow_control( PeripheralIoGdbusUart *uart, GDBusMethodInvocation *invocation, gint handle, @@ -174,9 +195,9 @@ gboolean handle_uart_set_flowcontrol( _E("uart handle is not valid"); ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else - ret = peripheral_bus_uart_set_flowcontrol(uart_handle, xonxoff, rtscts); + ret = peripheral_bus_uart_set_flow_control(uart_handle, xonxoff, rtscts); - peripheral_io_gdbus_uart_complete_set_flowcontrol(uart, invocation, ret); + peripheral_io_gdbus_uart_complete_set_flow_control(uart, invocation, ret); return true; } diff --git a/src/daemon/peripheral_bus_gpio.c b/src/daemon/peripheral_bus_gpio.c index c1011e9..2715210 100644 --- a/src/daemon/peripheral_bus_gpio.c +++ b/src/daemon/peripheral_bus_gpio.c @@ -180,41 +180,34 @@ open_err: return ret; } -int peripheral_bus_gpio_set_direction(pb_data_h handle, gint direction) +int peripheral_bus_gpio_close(pb_data_h handle) { peripheral_bus_gpio_s *gpio = &handle->dev.gpio; - int ret; - - gpio->direction = direction; + int ret = PERIPHERAL_ERROR_NONE; - if ((ret = gpio_set_direction(gpio->pin, (gpio_direction_e)direction)) < 0) { - _E("gpio_set_direction error (%d)", ret); + if ((ret = gpio_close(gpio->pin)) < 0) return ret; + + if (peripheral_bus_data_free(handle) < 0) { + _E("Failed to free gpio data"); + ret = PERIPHERAL_ERROR_UNKNOWN; } - return PERIPHERAL_ERROR_NONE; + return ret;; } -int peripheral_bus_gpio_get_direction(pb_data_h handle, gint *direction) +int peripheral_bus_gpio_set_direction(pb_data_h handle, gint direction) { peripheral_bus_gpio_s *gpio = &handle->dev.gpio; int ret; - gint value; - if ((ret = gpio_get_direction(gpio->pin, (gpio_direction_e*)direction)) < 0) { - _E("gpio_get_direction error (%d)", ret); - return ret; - } + gpio->direction = direction; - if (*direction == GPIO_DIRECTION_OUT) { - if ((ret = gpio_read(gpio->pin, &value)) < 0) - return ret; - /* Update direction state with the current value */ - *direction = GPIO_DIRECTION_OUT + value; + if ((ret = gpio_set_direction(gpio->pin, (gpio_direction_e)direction)) < 0) { + _E("gpio_set_direction error (%d)", ret); + return ret; } - gpio->direction = *direction; - return PERIPHERAL_ERROR_NONE; } @@ -233,56 +226,7 @@ int peripheral_bus_gpio_set_edge(pb_data_h handle, gint edge) return PERIPHERAL_ERROR_NONE; } -int peripheral_bus_gpio_get_edge(pb_data_h handle, gint *edge) -{ - peripheral_bus_gpio_s *gpio = &handle->dev.gpio; - int ret; - - if ((ret = gpio_get_edge_mode(gpio->pin, (gpio_edge_e*)edge)) < 0) { - _E("gpio_get_edge_mode error (%d)", ret); - return ret; - } - - gpio->edge = *edge; - - return PERIPHERAL_ERROR_NONE; -} - -int peripheral_bus_gpio_write(pb_data_h handle, gint value) -{ - peripheral_bus_gpio_s *gpio = &handle->dev.gpio; - int ret; - - /* Return error if direction of the pin is input mode */ - if (gpio->direction == GPIO_DIRECTION_IN) { - _E("The direction of the pin is INPUT mode, Cannot write"); - return PERIPHERAL_ERROR_INVALID_OPERATION; - } - - if ((ret = gpio_write(gpio->pin, value)) < 0) { - _E("gpio_write error (%d)", ret); - return ret; - } - /* Update direction state along with the value */ - gpio->direction = GPIO_DIRECTION_OUT + ((value > 0) ? 1 : 0); - - return PERIPHERAL_ERROR_NONE; -} - -int peripheral_bus_gpio_read(pb_data_h handle, gint *value) -{ - peripheral_bus_gpio_s *gpio = &handle->dev.gpio; - int ret; - - if ((ret = gpio_read(gpio->pin, value)) < 0) { - _E("gpio_read error (%d)", ret); - return ret; - } - - return PERIPHERAL_ERROR_NONE; -} - -static gboolean peripheral_bus_gpio_cb(GIOChannel *io, GIOCondition condition, gpointer data) +static gboolean peripheral_bus_interrupted_cb(GIOChannel *io, GIOCondition condition, gpointer data) { peripheral_bus_gpio_s *gpio_data = (peripheral_bus_gpio_s *)data; struct timeval time; @@ -327,12 +271,12 @@ static gboolean peripheral_bus_gpio_cb(GIOChannel *io, GIOCondition condition, return TRUE; timestamp = (unsigned long long)time.tv_sec * 1000000 + time.tv_usec; - peripheral_bus_emit_gpio_changed(gpio_data->gpio_skeleton, gpio_data->pin, value, timestamp); + peripheral_bus_emit_interrupted_cb(gpio_data->gpio_skeleton, gpio_data->pin, value, timestamp); return TRUE; } -int peripheral_bus_gpio_register_irq(pb_data_h handle) +int peripheral_bus_gpio_set_interrupted_cb(pb_data_h handle) { peripheral_bus_gpio_s *gpio = &handle->dev.gpio; GIOStatus status; @@ -355,7 +299,7 @@ int peripheral_bus_gpio_register_irq(pb_data_h handle) } g_free(strval); - gpio->io_id = g_io_add_watch(gpio->io, G_IO_PRI, peripheral_bus_gpio_cb, gpio); + gpio->io_id = g_io_add_watch(gpio->io, G_IO_PRI, peripheral_bus_interrupted_cb, gpio); if (gpio->io_id == 0) { _E("g_io_add_watch error (%d)", gpio->io); goto err_io_add_watch; @@ -378,7 +322,7 @@ err_open_isr: return PERIPHERAL_ERROR_UNKNOWN; } -int peripheral_bus_gpio_unregister_irq(pb_data_h handle) +int peripheral_bus_gpio_unset_interrupted_cb(pb_data_h handle) { peripheral_bus_gpio_s *gpio = &handle->dev.gpio; @@ -395,18 +339,36 @@ int peripheral_bus_gpio_unregister_irq(pb_data_h handle) return PERIPHERAL_ERROR_NONE; } -int peripheral_bus_gpio_close(pb_data_h handle) +int peripheral_bus_gpio_read(pb_data_h handle, gint *value) { peripheral_bus_gpio_s *gpio = &handle->dev.gpio; - int ret = PERIPHERAL_ERROR_NONE; + int ret; - if ((ret = gpio_close(gpio->pin)) < 0) + if ((ret = gpio_read(gpio->pin, value)) < 0) { + _E("gpio_read error (%d)", ret); return ret; + } - if (peripheral_bus_data_free(handle) < 0) { - _E("Failed to free gpio data"); - ret = PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_NONE; +} + +int peripheral_bus_gpio_write(pb_data_h handle, gint value) +{ + peripheral_bus_gpio_s *gpio = &handle->dev.gpio; + int ret; + + /* Return error if direction of the pin is input mode */ + if (gpio->direction == GPIO_DIRECTION_IN) { + _E("The direction of the pin is INPUT mode, Cannot write"); + return PERIPHERAL_ERROR_IO_ERROR; } - return ret;; + if ((ret = gpio_write(gpio->pin, value)) < 0) { + _E("gpio_write error (%d)", ret); + return ret; + } + /* Update direction state along with the value */ + gpio->direction = GPIO_DIRECTION_OUT_LOW + ((value > 0) ? 1 : 0); + + return PERIPHERAL_ERROR_NONE; } diff --git a/src/daemon/peripheral_bus_pwm.c b/src/daemon/peripheral_bus_pwm.c index 021dfed..a9a9f77 100644 --- a/src/daemon/peripheral_bus_pwm.c +++ b/src/daemon/peripheral_bus_pwm.c @@ -25,7 +25,7 @@ #include "peripheral_common.h" #include "peripheral_bus_util.h" -static bool peripheral_bus_pwm_is_available(int device, int channel, peripheral_bus_s *pb_data) +static bool peripheral_bus_pwm_is_available(int chip, int pin, peripheral_bus_s *pb_data) { pb_board_dev_s *pwm = NULL; pb_data_h handle; @@ -34,17 +34,17 @@ static bool peripheral_bus_pwm_is_available(int device, int channel, peripheral_ RETV_IF(pb_data == NULL, false); RETV_IF(pb_data->board == NULL, false); - pwm = peripheral_bus_board_find_device(PB_BOARD_DEV_PWM, pb_data->board, device, channel); + pwm = peripheral_bus_board_find_device(PB_BOARD_DEV_PWM, pb_data->board, chip, pin); if (pwm == NULL) { - _E("Not supported PWM device : %d, channel : %d", device, channel); + _E("Not supported PWM chip : %d, pin : %d", chip, pin); return false; } link = pb_data->pwm_list; while (link) { handle = (pb_data_h)link->data; - if (handle->dev.pwm.device == device && handle->dev.pwm.channel == channel) { - _E("Resource is in use, device : %d, channel : %d", device, channel); + if (handle->dev.pwm.chip == chip && handle->dev.pwm.pin == pin) { + _E("Resource is in use, chip : %d, pin : %d", chip, pin); return false; } link = g_list_next(link); @@ -53,18 +53,18 @@ static bool peripheral_bus_pwm_is_available(int device, int channel, peripheral_ return true; } -int peripheral_bus_pwm_open(int device, int channel, pb_data_h *handle, gpointer user_data) +int peripheral_bus_pwm_open(int chip, int pin, pb_data_h *handle, gpointer user_data) { peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data; pb_data_h pwm_handle; int ret; - if (!peripheral_bus_pwm_is_available(device, channel, pb_data)) { - _E("pwm %d.%d is not available", device, channel); + if (!peripheral_bus_pwm_is_available(chip, pin, pb_data)) { + _E("pwm %d.%d is not available", chip, pin); return PERIPHERAL_ERROR_RESOURCE_BUSY; } - if ((ret = pwm_open(device, channel)) < 0) + if ((ret = pwm_open(chip, pin)) < 0) goto open_err; pwm_handle = peripheral_bus_data_new(&pb_data->pwm_list); @@ -76,14 +76,14 @@ int peripheral_bus_pwm_open(int device, int channel, pb_data_h *handle, gpointer pwm_handle->type = PERIPHERAL_BUS_TYPE_PWM; pwm_handle->list = &pb_data->pwm_list; - pwm_handle->dev.pwm.device = device; - pwm_handle->dev.pwm.channel = channel; + pwm_handle->dev.pwm.chip = chip; + pwm_handle->dev.pwm.pin = pin; *handle = pwm_handle; return PERIPHERAL_ERROR_NONE; err: - pwm_close(device, channel); + pwm_close(chip, pin); open_err: return ret; @@ -94,7 +94,7 @@ int peripheral_bus_pwm_close(pb_data_h handle) peripheral_bus_pwm_s *pwm = &handle->dev.pwm; int ret = PERIPHERAL_ERROR_NONE; - if ((ret = pwm_close(pwm->device, pwm->channel)) < 0) + if ((ret = pwm_close(pwm->chip, pwm->pin)) < 0) return ret; if (peripheral_bus_data_free(handle) < 0) { @@ -109,54 +109,29 @@ int peripheral_bus_pwm_set_period(pb_data_h handle, int period) { peripheral_bus_pwm_s *pwm = &handle->dev.pwm; - return pwm_set_period(pwm->device, pwm->channel, period); + return pwm_set_period(pwm->chip, pwm->pin, period); } -int peripheral_bus_pwm_get_period(pb_data_h handle, int *period) -{ - peripheral_bus_pwm_s *pwm = &handle->dev.pwm; - - return pwm_get_period(pwm->device, pwm->channel, period); -} int peripheral_bus_pwm_set_duty_cycle(pb_data_h handle, int duty_cycle) { peripheral_bus_pwm_s *pwm = &handle->dev.pwm; - return pwm_set_duty_cycle(pwm->device, pwm->channel, duty_cycle); + return pwm_set_duty_cycle(pwm->chip, pwm->pin, duty_cycle); } -int peripheral_bus_pwm_get_duty_cycle(pb_data_h handle, int *duty_cycle) -{ - peripheral_bus_pwm_s *pwm = &handle->dev.pwm; - - return pwm_get_duty_cycle(pwm->device, pwm->channel, duty_cycle); -} int peripheral_bus_pwm_set_polarity(pb_data_h handle, int polarity) { peripheral_bus_pwm_s *pwm = &handle->dev.pwm; - return pwm_set_polarity(pwm->device, pwm->channel, (pwm_polarity_e)polarity); + return pwm_set_polarity(pwm->chip, pwm->pin, (pwm_polarity_e)polarity); } -int peripheral_bus_pwm_get_polarity(pb_data_h handle, int *polarity) -{ - peripheral_bus_pwm_s *pwm = &handle->dev.pwm; - - return pwm_get_polarity(pwm->device, pwm->channel, (pwm_polarity_e*)polarity); -} int peripheral_bus_pwm_set_enable(pb_data_h handle, bool enable) { peripheral_bus_pwm_s *pwm = &handle->dev.pwm; - return pwm_set_enable(pwm->device, pwm->channel, enable); -} - -int peripheral_bus_pwm_get_enable(pb_data_h handle, bool *enable) -{ - peripheral_bus_pwm_s *pwm = &handle->dev.pwm; - - return pwm_get_enable(pwm->device, pwm->channel, enable); -} + return pwm_set_enable(pwm->chip, pwm->pin, enable); +} \ No newline at end of file diff --git a/src/daemon/peripheral_bus_spi.c b/src/daemon/peripheral_bus_spi.c index a02bee1..c336e2a 100644 --- a/src/daemon/peripheral_bus_spi.c +++ b/src/daemon/peripheral_bus_spi.c @@ -28,7 +28,7 @@ static int initial_buffer_size = 128; static int max_buffer_size = 4096; -static bool peripheral_bus_spi_is_available(int bus, int cs, peripheral_bus_s *pb_data) +static bool __peripheral_bus_spi_is_available(int bus, int cs, peripheral_bus_s *pb_data) { pb_board_dev_s *spi = NULL; pb_data_h handle; @@ -63,7 +63,7 @@ int peripheral_bus_spi_open(int bus, int cs, pb_data_h *handle, gpointer user_da int ret = PERIPHERAL_ERROR_NONE; int fd, bufsiz; - if (!peripheral_bus_spi_is_available(bus, cs, pb_data)) { + if (!__peripheral_bus_spi_is_available(bus, cs, pb_data)) { _E("spi %d.%d is not available", bus, cs); return PERIPHERAL_ERROR_RESOURCE_BUSY; } @@ -146,47 +146,18 @@ int peripheral_bus_spi_set_mode(pb_data_h handle, unsigned char mode) return spi_set_mode(spi->fd, mode); } -int peripheral_bus_spi_get_mode(pb_data_h handle, unsigned char *mode) +int peripheral_bus_spi_set_bit_order(pb_data_h handle, gboolean lsb) { peripheral_bus_spi_s *spi = &handle->dev.spi; - return spi_get_mode(spi->fd, mode); + return spi_set_bit_order(spi->fd, (unsigned char)lsb); } -int peripheral_bus_spi_set_lsb_first(pb_data_h handle, gboolean lsb) +int peripheral_bus_spi_set_bits_per_word(pb_data_h handle, unsigned char bits) { peripheral_bus_spi_s *spi = &handle->dev.spi; - return spi_set_lsb_first(spi->fd, (unsigned char)lsb); -} - -int peripheral_bus_spi_get_lsb_first(pb_data_h handle, gboolean *lsb) -{ - peripheral_bus_spi_s *spi = &handle->dev.spi; - int ret; - unsigned char value; - - if ((ret = spi_get_lsb_first(spi->fd, &value)) < 0) { - _E("spi_get_lsb_first error (%d)", ret); - return ret; - } - *lsb = value ? true : false; - - return PERIPHERAL_ERROR_NONE; -} - -int peripheral_bus_spi_set_bits(pb_data_h handle, unsigned char bits) -{ - peripheral_bus_spi_s *spi = &handle->dev.spi; - - return spi_set_bits(spi->fd, bits); -} - -int peripheral_bus_spi_get_bits(pb_data_h handle, unsigned char *bits) -{ - peripheral_bus_spi_s *spi = &handle->dev.spi; - - return spi_get_bits(spi->fd, bits); + return spi_set_bits_per_word(spi->fd, bits); } int peripheral_bus_spi_set_frequency(pb_data_h handle, unsigned int freq) @@ -196,13 +167,6 @@ int peripheral_bus_spi_set_frequency(pb_data_h handle, unsigned int freq) return spi_set_frequency(spi->fd, freq); } -int peripheral_bus_spi_get_frequency(pb_data_h handle, unsigned int *freq) -{ - peripheral_bus_spi_s *spi = &handle->dev.spi; - - return spi_get_frequency(spi->fd, freq); -} - int peripheral_bus_spi_read(pb_data_h handle, GVariant **data_array, int length) { peripheral_bus_spi_s *spi = &handle->dev.spi; @@ -266,7 +230,7 @@ int peripheral_bus_spi_write(pb_data_h handle, GVariant *data_array, int length) return spi_write(spi->fd, spi->tx_buf, length); } -int peripheral_bus_spi_read_write(pb_data_h handle, GVariant *tx_data_array, GVariant **rx_data_array, int length) +int peripheral_bus_spi_transfer(pb_data_h handle, GVariant *tx_data_array, GVariant **rx_data_array, int length) { peripheral_bus_spi_s *spi = &handle->dev.spi; uint8_t err_buf[2] = {0, }; @@ -311,7 +275,7 @@ int peripheral_bus_spi_read_write(pb_data_h handle, GVariant *tx_data_array, GVa spi->tx_buf[i++] = str; g_variant_iter_free(iter); - ret = spi_read_write(spi->fd, spi->tx_buf, spi->rx_buf, length); + ret = spi_transfer(spi->fd, spi->tx_buf, spi->rx_buf, length); *rx_data_array = peripheral_bus_build_variant_ay(spi->rx_buf, length); return ret; diff --git a/src/daemon/peripheral_bus_uart.c b/src/daemon/peripheral_bus_uart.c index bce1a2c..015be63 100644 --- a/src/daemon/peripheral_bus_uart.c +++ b/src/daemon/peripheral_bus_uart.c @@ -29,7 +29,7 @@ #define INITIAL_BUFFER_SIZE 128 #define MAX_BUFFER_SIZE 8192 -static bool peripheral_bus_uart_is_available(int port, peripheral_bus_s *pb_data) +static bool __peripheral_bus_uart_is_available(int port, peripheral_bus_s *pb_data) { pb_board_dev_s *uart = NULL; pb_data_h handle; @@ -64,7 +64,7 @@ int peripheral_bus_uart_open(int port, pb_data_h *handle, gpointer user_data) int ret = PERIPHERAL_ERROR_NONE; int fd; - if (!peripheral_bus_uart_is_available(port, pb_data)) { + if (!__peripheral_bus_uart_is_available(port, pb_data)) { _E("uart %d is not available", port); return PERIPHERAL_ERROR_RESOURCE_BUSY; } @@ -116,32 +116,38 @@ int peripheral_bus_uart_close(pb_data_h handle) return ret; } -int peripheral_bus_uart_flush(pb_data_h handle) +int peripheral_bus_uart_set_baud_rate(pb_data_h handle, int baud_rate) { peripheral_bus_uart_s *uart = &handle->dev.uart; - return uart_flush(uart->fd); + return uart_set_baud_rate(uart->fd, baud_rate); } -int peripheral_bus_uart_set_baudrate(pb_data_h handle, int baudrate) +int peripheral_bus_uart_set_byte_size(pb_data_h handle, int byte_size) { peripheral_bus_uart_s *uart = &handle->dev.uart; - return uart_set_baudrate(uart->fd, baudrate); + return uart_set_byte_size(uart->fd, byte_size); } -int peripheral_bus_uart_set_mode(pb_data_h handle, int byte_size, int parity, int stop_bits) +int peripheral_bus_uart_set_parity(pb_data_h handle, int parity) { peripheral_bus_uart_s *uart = &handle->dev.uart; - return uart_set_mode(uart->fd, byte_size, parity, stop_bits); + return uart_set_parity(uart->fd, parity); +} +int peripheral_bus_uart_set_stop_bits(pb_data_h handle, int stop_bits) +{ + peripheral_bus_uart_s *uart = &handle->dev.uart; + + return uart_set_stop_bits(uart->fd, stop_bits); } -int peripheral_bus_uart_set_flowcontrol(pb_data_h handle, bool xonxoff, bool rtscts) +int peripheral_bus_uart_set_flow_control(pb_data_h handle, bool xonxoff, bool rtscts) { peripheral_bus_uart_s *uart = &handle->dev.uart; - return uart_set_flowcontrol(uart->fd, xonxoff, rtscts); + return uart_set_flow_control(uart->fd, xonxoff, rtscts); } int peripheral_bus_uart_read(pb_data_h handle, GVariant **data_array, int length) diff --git a/src/daemon/peripheral_io.xml b/src/daemon/peripheral_io.xml index ad80f04..281c551 100644 --- a/src/daemon/peripheral_io.xml +++ b/src/daemon/peripheral_io.xml @@ -10,49 +10,39 @@ - - - - - - - - - - - - - - - - - - - - - + - + - + + + + + + + + + + + @@ -93,8 +83,8 @@ - - + + @@ -107,41 +97,21 @@ - - - - - - - - - - - - - - - - - - - - @@ -153,23 +123,27 @@ - + + - + - + - + - + + + + - + @@ -208,41 +182,21 @@ - - - - - - + - - - - - - + - - - - - - - - - - @@ -259,7 +213,7 @@ - + diff --git a/src/interface/gpio.c b/src/interface/gpio.c index 8934b04..77c73c8 100644 --- a/src/interface/gpio.c +++ b/src/interface/gpio.c @@ -72,12 +72,12 @@ int gpio_set_direction(int gpiopin, gpio_direction_e dir) return -ENXIO; } - if (dir == GPIO_DIRECTION_OUT) - status = write(fd, "low", strlen("low")+1); - else if (dir == GPIO_DIRECTION_IN) + if (dir == GPIO_DIRECTION_IN) status = write(fd, "in", strlen("in")+1); else if (dir == GPIO_DIRECTION_OUT_HIGH) status = write(fd, "high", strlen("high")+1); + else if (dir == GPIO_DIRECTION_OUT_LOW) + status = write(fd, "low", strlen("low")+1); else { close(fd); _E("Error: gpio direction is wrong\n"); @@ -121,7 +121,7 @@ int gpio_get_direction(int gpiopin, gpio_direction_e *dir) if (0 == strncmp(gpio_buf, "in", strlen("in"))) *dir = GPIO_DIRECTION_IN; else if (0 == strncmp(gpio_buf, "out", strlen("out"))) - *dir = GPIO_DIRECTION_OUT; + *dir = GPIO_DIRECTION_OUT_LOW; else { close(fd); _E("Error: gpio direction is wrong\n"); diff --git a/src/interface/include/gpio.h b/src/interface/include/gpio.h index 9d7743b..b0b7c5b 100644 --- a/src/interface/include/gpio.h +++ b/src/interface/include/gpio.h @@ -22,8 +22,8 @@ typedef enum { GPIO_DIRECTION_IN = 0, - GPIO_DIRECTION_OUT = 1, - GPIO_DIRECTION_OUT_HIGH = 2, + GPIO_DIRECTION_OUT_HIGH = 1, + GPIO_DIRECTION_OUT_LOW = 2, } gpio_direction_e; typedef enum { diff --git a/src/interface/include/pwm.h b/src/interface/include/pwm.h index 524bfa1..26243d3 100644 --- a/src/interface/include/pwm.h +++ b/src/interface/include/pwm.h @@ -26,100 +26,100 @@ typedef enum { } pwm_polarity_e; /** -* @brief pwm_open() init pwm channel. +* @brief pwm_open() init pwm pin. * -* @param[in] device pwm chip number -* @param[in] channel pwm channel number +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_open(int device, int channel); +int pwm_open(int chip, int pin); /** -* @brief pwm_close() deinit pwm channel. +* @brief pwm_close() deinit pwm pin. * -* @param[in] device pwm chip number -* @param[in] channel pwm channel number +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_close(int device, int channel); +int pwm_close(int chip, int pin); /** * @brief pwm_set_period() sets the pwm period. * -* @param[in] device pwm chip number -* @param[in] channel pwm channel number +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number * @param[in] period pwm period * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_set_period(int device, int channel, int period); +int pwm_set_period(int chip, int pin, int period); /** * @brief pwm_get_period() gets the pwm period. * -* @param[in] device pwm chip number -* @param[in] channel pwm channel number +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number * @param[out] period pwm period * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_get_period(int device, int channel, int *period); +int pwm_get_period(int chip, int pin, int *period); /** * @brief pwm_set_duty_cycle() sets the pwm duty cycle. * -* @param[in] device pwm chip number -* @param[in] channel pwm channel number +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number * @param[in] duty_cycle pwm duty cycle * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_set_duty_cycle(int device, int channel, int duty_cycle); +int pwm_set_duty_cycle(int chip, int pin, int duty_cycle); /** * @brief pwm_get_duty_cycle() gets the pwm duty cycle. * -* @param[in] device pwm chip number -* @param[in] channel pwm channel number +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number * @param[out] duty_cycle pwm duty cycle * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_get_duty_cycle(int device, int channel, int *duty_cycle); +int pwm_get_duty_cycle(int chip, int pin, int *duty_cycle); /** * @brief pwm_set_polarity() sets the pwm polarity. * -* @param[in] device pwm chip number -* @param[in] channel pwm channel number +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number * @param[in] polarity pwm polarity * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_set_polarity(int device, int channel, pwm_polarity_e polarity); +int pwm_set_polarity(int chip, int pin, pwm_polarity_e polarity); /** * @brief pwm_get_polarity() gets the pwm polarity. * -* @param[in] device pwm chip number -* @param[in] channel pwm channel number +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number * @param[out] polarity pwm polarity * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_get_polarity(int device, int channel, pwm_polarity_e *polarity); +int pwm_get_polarity(int chip, int pin, pwm_polarity_e *polarity); /** * @brief pwm_set_enable() sets the pwm state. * -* @param[in] device pwm chip number -* @param[in] channel pwm channel number +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number * @param[in] enable pwm enable/disabled state value * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_set_enable(int device, int channel, bool enable); +int pwm_set_enable(int chip, int pin, bool enable); /** * @brief pwm_get_enable() checks if pwm state is enabled. * -* @param[in] device pwm chip number -* @param[in] channel pwm channel number +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number * @param[out] enable pwm enable/disabled state value * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_get_enable(int device, int channel, bool *enable); +int pwm_get_enable(int chip, int pin, bool *enable); #endif /* __PWM_H__ */ diff --git a/src/interface/include/spi.h b/src/interface/include/spi.h index ee637a0..9937c41 100644 --- a/src/interface/include/spi.h +++ b/src/interface/include/spi.h @@ -20,16 +20,12 @@ int spi_open(int bus, int cs, int *fd); int spi_close(int fd); int spi_set_mode(int fd, unsigned char mode); -int spi_get_mode(int fd, unsigned char *mode); -int spi_set_lsb_first(int fd, unsigned char lsb); -int spi_get_lsb_first(int fd, unsigned char *lsb); -int spi_set_bits(int fd, unsigned char bits); -int spi_get_bits(int fd, unsigned char *bits); +int spi_set_bit_order(int fd, unsigned char lsb); +int spi_set_bits_per_word(int fd, unsigned char bits); int spi_set_frequency(int fd, unsigned int freq); -int spi_get_frequency(int fd, unsigned int *freq); int spi_get_buffer_size(int *bufsiz); int spi_read(int fd, unsigned char *rxbuf, int length); int spi_write(int fd, unsigned char *txbuf, int length); -int spi_read_write(int fd, unsigned char *txbuf, unsigned char *rxbuf, int length); +int spi_transfer(int fd, unsigned char *txbuf, unsigned char *rxbuf, int length); #endif /* __SPI_H__ */ diff --git a/src/interface/include/uart.h b/src/interface/include/uart.h index b9fb082..413b23e 100644 --- a/src/interface/include/uart.h +++ b/src/interface/include/uart.h @@ -23,36 +23,36 @@ * @brief Enumeration for Baud Rate */ typedef enum { - UART_BAUDRATE_0 = 0, - UART_BAUDRATE_50, - UART_BAUDRATE_75, - UART_BAUDRATE_110, - UART_BAUDRATE_134, - UART_BAUDRATE_150, - UART_BAUDRATE_200, - UART_BAUDRATE_300, - UART_BAUDRATE_600, - UART_BAUDRATE_1200, - UART_BAUDRATE_1800, - UART_BAUDRATE_2400, - UART_BAUDRATE_4800, - UART_BAUDRATE_9600, - UART_BAUDRATE_19200, - UART_BAUDRATE_38400, - UART_BAUDRATE_57600, - UART_BAUDRATE_115200, - UART_BAUDRATE_230400 -} uart_baudrate_e; + UART_BAUD_RATE_0 = 0, + UART_BAUD_RATE_50, + UART_BAUD_RATE_75, + UART_BAUD_RATE_110, + UART_BAUD_RATE_134, + UART_BAUD_RATE_150, + UART_BAUD_RATE_200, + UART_BAUD_RATE_300, + UART_BAUD_RATE_600, + UART_BAUD_RATE_1200, + UART_BAUD_RATE_1800, + UART_BAUD_RATE_2400, + UART_BAUD_RATE_4800, + UART_BAUD_RATE_9600, + UART_BAUD_RATE_19200, + UART_BAUD_RATE_38400, + UART_BAUD_RATE_57600, + UART_BAUD_RATE_115200, + UART_BAUD_RATE_230400 +} uart_baud_rate_e; /** * @brief Enumeration for Byte Size */ typedef enum { - UART_BYTESIZE_5BIT = 0, - UART_BYTESIZE_6BIT, - UART_BYTESIZE_7BIT, - UART_BYTESIZE_8BIT -} uart_bytesize_e; + UART_BYTE_SIZE_5BIT = 0, + UART_BYTE_SIZE_6BIT, + UART_BYTE_SIZE_7BIT, + UART_BYTE_SIZE_8BIT +} uart_byte_size_e; /** * @brief Enumeration of Parity Bit @@ -67,9 +67,9 @@ typedef enum { * @brief Enumeration for Stop Bits */ typedef enum { - UART_STOPBITS_1BIT = 0, - UART_STOPBITS_2BIT -} uart_stopbits_e; + UART_STOP_BITS_1BIT = 0, + UART_STOP_BITS_2BIT +} uart_stop_bits_e; /** * @brief uart_valid_baudrate() validation check of input baudrate @@ -77,7 +77,7 @@ typedef enum { * @param[in] baudrate baudrate for uart * @return On success, valid input. On failure, NULL is returned. */ -int uart_valid_baudrate(unsigned int baudrate); +int uart_valid_baud_rate(unsigned int baud_rate); /** * @brief uart_open() initializes uart port. @@ -111,28 +111,55 @@ int uart_flush(int file_hndl); * @param[in] baud uart baud rate * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_baudrate(int file_hndl, uart_baudrate_e baud); +int uart_set_baud_rate(int file_hndl, uart_baud_rate_e baud); /** * @brief uart_set_mode() sets byte size, parity bit and stop bits. * * @param[in] file_hndl handle of uart_context -* @param[in] bytesize uart byte size +* @param[in] byte_size uart byte size * @param[in] parity uart parity type (even/odd/none) -* @param[in] stopbits uart stop bits +* @param[in] stop_bits uart stop bits * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_mode(int file_hndl, uart_bytesize_e bytesize, uart_parity_e parity, uart_stopbits_e stopbits); +int uart_set_mode(int file_hndl, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits); /** -* @brief uart_set_flowcontrol() set flow control settings. +* @brief peripheral_bus_uart_set_byte_size() set byte size. +* +* @param[in] file_hndl handle of uart_context +* @param[in] byte_size uart byte size +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int uart_set_byte_size(int file_hndl, uart_byte_size_e byte_size); + +/** +* @brief peripheral_bus_uart_set_parity() set parity bit. +* +* @param[in] file_hndl handle of uart_context +* @param[in] parity uart parity type (even/odd/none) +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int uart_set_parity(int file_hndl, uart_parity_e parity); + +/** +* @brief peripheral_bus_uart_set_stop_bits() set stop bits. +* +* @param[in] file_hndl handle of uart_context +* @param[in] stop_bits uart stop bits +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int uart_set_stop_bits(int file_hndl, uart_stop_bits_e stop_bits); + +/** +* @brief uart_set_flow_control() set flow control settings. * * @param[in] file_hndl handle of uart_context * @param[in] xonxoff ixon/ixoff * @param[in] rtscts rts/cts * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_flowcontrol(int file_hndl, bool xonxoff, bool rtscts); +int uart_set_flow_control(int file_hndl, bool xonxoff, bool rtscts); /** * @brief uart_read() reads data over uart bus. diff --git a/src/interface/pwm.c b/src/interface/pwm.c index f899b6b..2b6ebd8 100644 --- a/src/interface/pwm.c +++ b/src/interface/pwm.c @@ -31,15 +31,15 @@ #define PWM_BUF_MAX 16 #define MAX_ERR_LEN 255 -int pwm_open(int device, int channel) +int pwm_open(int chip, int pin) { int fd, len, status; char pwm_dev[PATH_BUF_MAX] = {0}; char pwm_buf[PWM_BUF_MAX] = {0}; - _D("device : %d, channel : %d", device, channel); + _D("chip : %d, pin : %d", chip, pin); - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/export", device); + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/export", chip); fd = open(pwm_dev, O_WRONLY); if (fd < 0) { char errmsg[MAX_ERR_LEN]; @@ -48,10 +48,10 @@ int pwm_open(int device, int channel) return -ENXIO; } - len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", channel); + len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", pin); status = write(fd, pwm_buf, len); if (status < 0) { - _E("Failed to export pwmchip%d, pwm%", device, channel); + _E("Failed to export pwmchip%d, pwm%d", chip, pin); close(fd); return -EIO; } @@ -60,15 +60,15 @@ int pwm_open(int device, int channel) return 0; } -int pwm_close(int device, int channel) +int pwm_close(int chip, int pin) { int fd, len, status; char pwm_dev[PATH_BUF_MAX] = {0}; char pwm_buf[PWM_BUF_MAX] = {0}; - _D("device : %d, channel : %d", device, channel); + _D("chip : %d, pin : %d", chip, pin); - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/unexport", device); + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/unexport", chip); fd = open(pwm_dev, O_WRONLY); if (fd < 0) { char errmsg[MAX_ERR_LEN]; @@ -77,10 +77,10 @@ int pwm_close(int device, int channel) return -ENXIO; } - len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", channel); + len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", pin); status = write(fd, pwm_buf, len); if (status < 0) { - _E("Failed to unexport pwmchip%d, pwm%", device, channel); + _E("Failed to unexport pwmchip%d, pwm%", chip, pin); close(fd); return -EIO; } @@ -89,15 +89,15 @@ int pwm_close(int device, int channel) return 0; } -int pwm_set_period(int device, int channel, int period) +int pwm_set_period(int chip, int pin, int period) { int fd, len, status; char pwm_buf[PWM_BUF_MAX] = {0}; char pwm_dev[PATH_BUF_MAX] = {0}; - _D("device : %d, channel : %d, period : %d", device, channel, period); + _D("chip : %d, pin : %d, period : %d", chip, pin, period); - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/period", device, channel); + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/period", chip, pin); fd = open(pwm_dev, O_WRONLY); if (fd < 0) { char errmsg[MAX_ERR_LEN]; @@ -118,13 +118,13 @@ int pwm_set_period(int device, int channel, int period) return 0; } -int pwm_get_period(int device, int channel, int *period) +int pwm_get_period(int chip, int pin, int *period) { int fd, result, status; char pwm_buf[PWM_BUF_MAX] = {0}; char pwm_dev[PATH_BUF_MAX] = {0}; - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/period", device, channel); + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/period", chip, pin); fd = open(pwm_dev, O_RDONLY); if (fd < 0) { char errmsg[MAX_ERR_LEN]; @@ -146,15 +146,15 @@ int pwm_get_period(int device, int channel, int *period) return 0; } -int pwm_set_duty_cycle(int device, int channel, int duty_cycle) +int pwm_set_duty_cycle(int chip, int pin, int duty_cycle) { int fd, len, status; char pwm_buf[PWM_BUF_MAX] = {0}; char pwm_dev[PATH_BUF_MAX] = {0}; - _D("device : %d, channel : %d, duty_cycle : %d", device, channel, duty_cycle); + _D("chip : %d, pin : %d, duty_cycle : %d", chip, pin, duty_cycle); - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", device, channel); + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", chip, pin); fd = open(pwm_dev, O_WRONLY); if (fd < 0) { char errmsg[MAX_ERR_LEN]; @@ -175,13 +175,13 @@ int pwm_set_duty_cycle(int device, int channel, int duty_cycle) return 0; } -int pwm_get_duty_cycle(int device, int channel, int *duty_cycle) +int pwm_get_duty_cycle(int chip, int pin, int *duty_cycle) { int fd, result, status; char pwm_buf[PWM_BUF_MAX] = {0}; char pwm_dev[PATH_BUF_MAX] = {0}; - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", device, channel); + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", chip, pin); fd = open(pwm_dev, O_RDONLY); if (fd < 0) { char errmsg[MAX_ERR_LEN]; @@ -203,14 +203,14 @@ int pwm_get_duty_cycle(int device, int channel, int *duty_cycle) return 0; } -int pwm_set_polarity(int device, int channel, pwm_polarity_e polarity) +int pwm_set_polarity(int chip, int pin, pwm_polarity_e polarity) { int fd, status; char pwm_dev[PATH_BUF_MAX] = {0}; - _D("device : %d, channel : %d, polarity : %d", device, channel, polarity); + _D("chip : %d, pin : %d, polarity : %d", chip, pin, polarity); - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/polarity", device, channel); + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/polarity", chip, pin); fd = open(pwm_dev, O_WRONLY); if (fd < 0) { char errmsg[MAX_ERR_LEN]; @@ -239,13 +239,13 @@ int pwm_set_polarity(int device, int channel, pwm_polarity_e polarity) return 0; } -int pwm_get_polarity(int device, int channel, pwm_polarity_e *polarity) +int pwm_get_polarity(int chip, int pin, pwm_polarity_e *polarity) { int fd, status; char pwm_buf[PWM_BUF_MAX] = {0}; char pwm_dev[PATH_BUF_MAX] = {0}; - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/polarity", device, channel); + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/polarity", chip, pin); fd = open(pwm_dev, O_RDONLY); if (fd < 0) { char errmsg[MAX_ERR_LEN]; @@ -275,15 +275,15 @@ int pwm_get_polarity(int device, int channel, pwm_polarity_e *polarity) return 0; } -int pwm_set_enable(int device, int channel, bool enable) +int pwm_set_enable(int chip, int pin, bool enable) { int fd, len, status; char pwm_buf[PWM_BUF_MAX] = {0}; char pwm_dev[PATH_BUF_MAX] = {0}; - _D("device : %d, channel : %d, enable : %d", device, channel, enable); + _D("chip : %d, pin : %d, enable : %d", chip, pin, enable); - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", device, channel); + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", chip, pin); fd = open(pwm_dev, O_WRONLY); if (fd < 0) { char errmsg[MAX_ERR_LEN]; @@ -304,13 +304,13 @@ int pwm_set_enable(int device, int channel, bool enable) return 0; } -int pwm_get_enable(int device, int channel, bool *enable) +int pwm_get_enable(int chip, int pin, bool *enable) { int fd, result, status; char pwm_buf[PWM_BUF_MAX] = {0}; char pwm_dev[PATH_BUF_MAX] = {0}; - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", device, channel); + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", chip, pin); fd = open(pwm_dev, O_RDONLY); if (fd < 0) { char errmsg[MAX_ERR_LEN]; diff --git a/src/interface/spi.c b/src/interface/spi.c index e0cefc0..1016a9e 100644 --- a/src/interface/spi.c +++ b/src/interface/spi.c @@ -89,27 +89,7 @@ int spi_set_mode(int fd, unsigned char mode) return 0; } -int spi_get_mode(int fd, unsigned char *mode) -{ - unsigned char value = 0; - int status; - - _D("fd : %d", fd); - RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(fd, SPI_IOC_RD_MODE, &value); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to get mode, fd : %d, errmsg : %s", fd, errmsg); - return -EIO; - } - *mode = value; - - return 0; -} - -int spi_set_lsb_first(int fd, unsigned char lsb) +int spi_set_bit_order(int fd, unsigned char lsb) { int status; @@ -127,27 +107,7 @@ int spi_set_lsb_first(int fd, unsigned char lsb) return 0; } -int spi_get_lsb_first(int fd, unsigned char *lsb) -{ - unsigned char value = 0; - int status; - - _D("fd : %d", fd); - RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(fd, SPI_IOC_RD_LSB_FIRST, &value); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to get lsb first, fd : %d, errmsg : %s", fd, errmsg); - return -EIO; - } - *lsb = value ? 1 : 0; - - return 0; -} - -int spi_set_bits(int fd, unsigned char bits) +int spi_set_bits_per_word(int fd, unsigned char bits) { int status; @@ -165,26 +125,6 @@ int spi_set_bits(int fd, unsigned char bits) return 0; } -int spi_get_bits(int fd, unsigned char *bits) -{ - unsigned char value = 0; - int status; - - _D("fd : %d", fd); - RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &value); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to get bits, fd : %d, errmsg : %s", fd, errmsg); - return -EIO; - } - *bits = value; - - return 0; -} - int spi_set_frequency(int fd, unsigned int freq) { int status; @@ -203,26 +143,6 @@ int spi_set_frequency(int fd, unsigned int freq) return 0; } -int spi_get_frequency(int fd, unsigned int *freq) -{ - unsigned int value = 0; - int status; - - _D("fd : %d", fd); - RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &value); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to get frequency, fd : %d, errmsg : %s", fd, errmsg); - return -EIO; - } - *freq = value; - - return 0; -} - int spi_get_buffer_size(int *bufsiz) { int fd, result, status; @@ -293,7 +213,7 @@ int spi_write(int fd, unsigned char *txbuf, int length) return 0; } -int spi_read_write(int fd, unsigned char *txbuf, unsigned char *rxbuf, int length) +int spi_transfer(int fd, unsigned char *txbuf, unsigned char *rxbuf, int length) { int status; struct spi_ioc_transfer xfer; diff --git a/src/interface/uart.c b/src/interface/uart.c index 310d273..fd15ca5 100644 --- a/src/interface/uart.c +++ b/src/interface/uart.c @@ -107,7 +107,7 @@ int uart_flush(int file_hndl) return 0; } -int uart_set_baudrate(int file_hndl, uart_baudrate_e baud) +int uart_set_baud_rate(int file_hndl, uart_baud_rate_e baud) { int ret; struct termios tio; @@ -120,7 +120,7 @@ int uart_set_baudrate(int file_hndl, uart_baudrate_e baud) return -EINVAL; } - if (baud > UART_BAUDRATE_230400) { + if (baud > UART_BAUD_RATE_230400) { _E("Invalid parameter"); return -EINVAL; } @@ -151,19 +151,19 @@ int uart_set_baudrate(int file_hndl, uart_baudrate_e baud) return 0; } -int uart_set_mode(int file_hndl, uart_bytesize_e bytesize, uart_parity_e parity, uart_stopbits_e stopbits) +int uart_set_mode(int file_hndl, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits) { int ret; struct termios tio; - _D("file_hndl : %d, bytesize : %d, parity : %d, stopbits : %d", file_hndl, bytesize, parity, stopbits); + _D("file_hndl : %d, bytesize : %d, parity : %d, stopbits : %d", file_hndl, byte_size, parity, stop_bits); if (!file_hndl) { _E("Invalid NULL parameter"); return -EINVAL; } - if (bytesize > UART_BYTESIZE_8BIT) { + if (byte_size > UART_BYTE_SIZE_8BIT) { _E("Invalid bytesize parameter"); return -EINVAL; } @@ -178,7 +178,7 @@ int uart_set_mode(int file_hndl, uart_bytesize_e bytesize, uart_parity_e parity, /* set byte size */ tio.c_cflag &= ~CSIZE; - tio.c_cflag |= byteinfo[bytesize]; + tio.c_cflag |= byteinfo[byte_size]; tio.c_cflag |= (CLOCAL | CREAD); /* set parity info */ @@ -199,15 +199,15 @@ int uart_set_mode(int file_hndl, uart_bytesize_e bytesize, uart_parity_e parity, } /* set stop bit */ - switch (stopbits) { - case UART_STOPBITS_1BIT: + switch (stop_bits) { + case UART_STOP_BITS_1BIT: tio.c_cflag &= ~CSTOPB; break; - case UART_STOPBITS_2BIT: + case UART_STOP_BITS_2BIT: tio.c_cflag |= CSTOPB; break; default: - _E("Invalid parameter stopbits"); + _E("Invalid parameter stop_bits"); return -EINVAL; } @@ -223,7 +223,143 @@ int uart_set_mode(int file_hndl, uart_bytesize_e bytesize, uart_parity_e parity, return 0; } -int uart_set_flowcontrol(int file_hndl, bool xonxoff, bool rtscts) +int uart_set_byte_size(int file_hndl, uart_byte_size_e byte_size) +{ + int ret; + struct termios tio; + + _D("file_hndl : %d, bytesize : %d", file_hndl, byte_size); + + if (!file_hndl) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + if (byte_size > UART_BYTE_SIZE_8BIT) { + _E("Invalid bytesize parameter"); + return -EINVAL; + } + + ret = tcgetattr(file_hndl, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcgetattr failed, errmsg: %s", errmsg); + return -1; + } + + /* set byte size */ + tio.c_cflag &= ~CSIZE; + tio.c_cflag |= byteinfo[byte_size]; + tio.c_cflag |= (CLOCAL | CREAD); + + uart_flush(file_hndl); + ret = tcsetattr(file_hndl, TCSANOW, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcsetattr failed, errmsg : %s", errmsg); + return -1; + } + + return 0; +} + +int uart_set_parity(int file_hndl, uart_parity_e parity) +{ + int ret; + struct termios tio; + + _D("file_hndl : %d, parity : %d", file_hndl, parity); + + if (!file_hndl) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + ret = tcgetattr(file_hndl, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcgetattr failed, errmsg: %s", errmsg); + return -1; + } + + /* set parity info */ + switch (parity) { + case UART_PARITY_EVEN: + tio.c_cflag |= PARENB; + tio.c_cflag &= ~PARODD; + break; + case UART_PARITY_ODD: + tio.c_cflag |= PARENB; + tio.c_cflag |= PARODD; + break; + case UART_PARITY_NONE: + default: + tio.c_cflag &= ~PARENB; + tio.c_cflag &= ~PARODD; + break; + } + + uart_flush(file_hndl); + ret = tcsetattr(file_hndl, TCSANOW, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcsetattr failed, errmsg : %s", errmsg); + return -1; + } + + return 0; +} + +int uart_set_stop_bits(int file_hndl, uart_stop_bits_e stop_bits) +{ + int ret; + struct termios tio; + + _D("file_hndl : %d, stopbits : %d", file_hndl, stop_bits); + + if (!file_hndl) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + ret = tcgetattr(file_hndl, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcgetattr failed, errmsg: %s", errmsg); + return -1; + } + + /* set stop bit */ + switch (stop_bits) { + case UART_STOP_BITS_1BIT: + tio.c_cflag &= ~CSTOPB; + break; + case UART_STOP_BITS_2BIT: + tio.c_cflag |= CSTOPB; + break; + default: + _E("Invalid parameter stop_bits"); + return -EINVAL; + } + + uart_flush(file_hndl); + ret = tcsetattr(file_hndl, TCSANOW, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcsetattr failed, errmsg : %s", errmsg); + return -1; + } + + return 0; +} + +int uart_set_flow_control(int file_hndl, bool xonxoff, bool rtscts) { int ret; struct termios tio; -- 2.7.4