From: Segwon Date: Thu, 21 Sep 2017 03:12:41 +0000 (+0900) Subject: api: sync functions name with changed apis name. X-Git-Tag: submit/tizen_4.0/20170926.023348^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca6e6994b7c0be79156d53d0c69e7eb8b97fdb86;p=platform%2Fcore%2Fapi%2Fperipheral-io.git api: sync functions name with changed apis name. Signed-off-by: Segwon Change-Id: I12c8dcc1a850b182b791674d0fe4891f74d3717a --- diff --git a/include/peripheral_gdbus_gpio.h b/include/peripheral_gdbus_gpio.h index 0d23b91..39c67c5 100644 --- a/include/peripheral_gdbus_gpio.h +++ b/include/peripheral_gdbus_gpio.h @@ -22,13 +22,11 @@ void gpio_proxy_deinit(void); int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio); int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio); -int peripheral_gdbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction); int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); +int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); +int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data); +int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio); int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value); int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value); -int peripheral_gdbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge); -int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); -int peripheral_gdbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data); -int peripheral_gdbus_gpio_unregister_cb(peripheral_gpio_h gpio); #endif /* __PERIPHERAL_GDBUS_GPIO_H__ */ diff --git a/include/peripheral_gdbus_pwm.h b/include/peripheral_gdbus_pwm.h index 3fc3cab..f6d4c1c 100644 --- a/include/peripheral_gdbus_pwm.h +++ b/include/peripheral_gdbus_pwm.h @@ -20,15 +20,11 @@ void pwm_proxy_init(void); void pwm_proxy_deinit(void); -int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int device, int channel); +int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin); int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm); int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period); -int peripheral_gdbus_pwm_get_period(peripheral_pwm_h pwm, int *period); -int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle); -int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle); +int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns); int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity); -int peripheral_gdbus_pwm_get_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e *polarity); int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable); -int peripheral_gdbus_pwm_get_enable(peripheral_pwm_h pwm, bool *enable); #endif /* __PERIPHERAL_GDBUS_PWM_H__ */ diff --git a/include/peripheral_gdbus_spi.h b/include/peripheral_gdbus_spi.h index 78e7e97..7ab743a 100644 --- a/include/peripheral_gdbus_spi.h +++ b/include/peripheral_gdbus_spi.h @@ -22,15 +22,11 @@ void spi_proxy_deinit(); int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs); int peripheral_gdbus_spi_close(peripheral_spi_h spi); int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode); -int peripheral_gdbus_spi_get_mode(peripheral_spi_h spi, peripheral_spi_mode_e *mode); -int peripheral_gdbus_spi_set_lsb_first(peripheral_spi_h spi, bool lsb); -int peripheral_gdbus_spi_get_lsb_first(peripheral_spi_h spi, bool *lsb); -int peripheral_gdbus_spi_set_bits(peripheral_spi_h spi, unsigned char bits); -int peripheral_gdbus_spi_get_bits(peripheral_spi_h spi, unsigned char *bits); -int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq); -int peripheral_gdbus_spi_get_frequency(peripheral_spi_h spi, unsigned int *freq); +int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb); +int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits); +int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz); int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length); int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length); -int peripheral_gdbus_spi_read_write(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length); +int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length); #endif /* __PERIPHERAL_GDBUS_SPI_H_ */ diff --git a/include/peripheral_gdbus_uart.h b/include/peripheral_gdbus_uart.h index 7c7f8e7..15b5d06 100644 --- a/include/peripheral_gdbus_uart.h +++ b/include/peripheral_gdbus_uart.h @@ -21,10 +21,11 @@ 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_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud); +int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size); +int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity); +int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits); +int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts); int peripheral_gdbus_uart_read(peripheral_uart_h uart, uint8_t *data, int length); int peripheral_gdbus_uart_write(peripheral_uart_h uart, uint8_t *data, int length); diff --git a/src/peripheral_gdbus_gpio.c b/src/peripheral_gdbus_gpio.c index b476e47..be01654 100644 --- a/src/peripheral_gdbus_gpio.c +++ b/src/peripheral_gdbus_gpio.c @@ -23,17 +23,19 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" -extern int peripheral_gpio_isr_callback(int pin, int value, unsigned long long timestamp); - -void handle_gpio_changed( - PeripheralIoGdbusGpio *gpio, - gint pin, - gint value, - guint64 timestamp, - gpointer user_data); +extern int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int err); PeripheralIoGdbusGpio *gpio_proxy = NULL; +static void __peripheral_gpio_interrupted_cb(PeripheralIoGdbusGpio *gpio, gint pin, gint value, guint64 timestamp, gpointer user_data) +{ + int err = PERIPHERAL_ERROR_NONE; + if (!gpio) + err = PERIPHERAL_ERROR_IO_ERROR; + + peripheral_gpio_interrupted_cb_handler(pin, value, timestamp, err); +} + void gpio_proxy_init(void) { GError *error = NULL; @@ -57,8 +59,8 @@ void gpio_proxy_init(void) } g_signal_connect(gpio_proxy, - "gpio-changed", - G_CALLBACK(handle_gpio_changed), + "interrupted-cb", + G_CALLBACK(__peripheral_gpio_interrupted_cb), NULL); } @@ -71,19 +73,6 @@ void gpio_proxy_deinit() } } -void handle_gpio_changed( - PeripheralIoGdbusGpio *gpio, - gint pin, - gint value, - guint64 timestamp, - gpointer user_data) -{ - if (!gpio) - return; - - peripheral_gpio_isr_callback(pin, value, timestamp); -} - int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) { GError *error = NULL; @@ -127,33 +116,6 @@ int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) return ret; } -int peripheral_gdbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gint value = 0; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_get_direction_sync( - gpio_proxy, - gpio->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - } - - if (value >= PERIPHERAL_GPIO_DIRECTION_IN && value <= PERIPHERAL_GPIO_DIRECTION_OUT_HIGH) - *direction = value; - else - return PERIPHERAL_ERROR_UNKNOWN; - - return ret; -} - int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) { GError *error = NULL; @@ -176,39 +138,17 @@ int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_ return ret; } -int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_read_sync( - gpio_proxy, - gpio->handle, - value, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value) +int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_gpio_call_write_sync( + if (peripheral_io_gdbus_gpio_call_set_edge_mode_sync( gpio_proxy, gpio->handle, - value, + edge, &ret, NULL, &error) == FALSE) { @@ -220,18 +160,16 @@ int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value) return ret; } -int peripheral_gdbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge) +int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gint value = 0; if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_gpio_call_get_edge_mode_sync( + if (peripheral_io_gdbus_gpio_call_set_interrupted_cb_sync( gpio_proxy, gpio->handle, - &value, &ret, NULL, &error) == FALSE) { @@ -240,25 +178,19 @@ int peripheral_gdbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_ return PERIPHERAL_ERROR_UNKNOWN; } - if (value >= PERIPHERAL_GPIO_EDGE_NONE && value <= PERIPHERAL_GPIO_EDGE_BOTH) - *edge = value; - else - return PERIPHERAL_ERROR_UNKNOWN; - return ret; } -int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) +int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_gpio_call_set_edge_mode_sync( + if (peripheral_io_gdbus_gpio_call_unset_interrupted_cb_sync( gpio_proxy, gpio->handle, - edge, &ret, NULL, &error) == FALSE) { @@ -270,16 +202,17 @@ int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_ return ret; } -int peripheral_gdbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data) +int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_gpio_call_register_irq_sync( + if (peripheral_io_gdbus_gpio_call_read_sync( gpio_proxy, gpio->handle, + value, &ret, NULL, &error) == FALSE) { @@ -291,16 +224,17 @@ int peripheral_gdbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callba return ret; } -int peripheral_gdbus_gpio_unregister_cb(peripheral_gpio_h gpio) +int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_gpio_call_unregister_irq_sync( + if (peripheral_io_gdbus_gpio_call_write_sync( gpio_proxy, gpio->handle, + value, &ret, NULL, &error) == FALSE) { @@ -310,4 +244,4 @@ int peripheral_gdbus_gpio_unregister_cb(peripheral_gpio_h gpio) } return ret; -} +} \ No newline at end of file diff --git a/src/peripheral_gdbus_pwm.c b/src/peripheral_gdbus_pwm.c index b32074e..5d83882 100644 --- a/src/peripheral_gdbus_pwm.c +++ b/src/peripheral_gdbus_pwm.c @@ -52,7 +52,7 @@ void pwm_proxy_deinit() } } -int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int device, int channel) +int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; @@ -61,8 +61,8 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int device, int channel) if (peripheral_io_gdbus_pwm_call_open_sync( pwm_proxy, - device, - channel, + chip, + pin, &pwm->handle, &ret, NULL, @@ -118,32 +118,7 @@ int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period) return ret; } -int peripheral_gdbus_pwm_get_period(peripheral_pwm_h pwm, int *period) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gint value = 0; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_get_period_sync( - pwm_proxy, - pwm->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - *period = value; - - return ret; -} - -int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) +int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; @@ -153,7 +128,7 @@ int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync( pwm_proxy, pwm->handle, - duty_cycle, + duty_cycle_ns, &ret, NULL, &error) == FALSE) { @@ -165,31 +140,6 @@ int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) return ret; } -int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gint value = 0; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_get_duty_cycle_sync( - pwm_proxy, - pwm->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - *duty_cycle = value; - - return ret; -} - int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity) { GError *error = NULL; @@ -212,34 +162,6 @@ int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polar return ret; } -int peripheral_gdbus_pwm_get_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e *polarity) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gint value = 0; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_get_polarity_sync( - pwm_proxy, - pwm->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (!value) - *polarity = PERIPHERAL_PWM_POLARITY_NORMAL; - else - *polarity = PERIPHERAL_PWM_POLARITY_INVERSED; - - return ret; -} - int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable) { GError *error = NULL; @@ -261,32 +183,3 @@ int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable) return ret; } - -int peripheral_gdbus_pwm_get_enable(peripheral_pwm_h pwm, bool *enable) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gboolean value = 0; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_get_enable_sync( - pwm_proxy, - pwm->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (!value) - *enable = false; - else - *enable = true; - - return ret; -} - diff --git a/src/peripheral_gdbus_spi.c b/src/peripheral_gdbus_spi.c index b42e926..ae01e87 100644 --- a/src/peripheral_gdbus_spi.c +++ b/src/peripheral_gdbus_spi.c @@ -118,42 +118,14 @@ int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mo return ret; } -int peripheral_gdbus_spi_get_mode(peripheral_spi_h spi, peripheral_spi_mode_e *mode) +int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - guchar value; if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_spi_call_get_mode_sync( - spi_proxy, - spi->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (value <= PERIPHERAL_SPI_MODE_3) - *mode = value; - else - _E("Invalid mode : %d", value); - - return ret; -} - -int peripheral_gdbus_spi_set_lsb_first(peripheral_spi_h spi, bool lsb) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_set_lsb_first_sync( + if (peripheral_io_gdbus_spi_call_set_bit_order_sync( spi_proxy, spi->handle, lsb, @@ -168,39 +140,14 @@ int peripheral_gdbus_spi_set_lsb_first(peripheral_spi_h spi, bool lsb) return ret; } -int peripheral_gdbus_spi_get_lsb_first(peripheral_spi_h spi, bool *lsb) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gboolean value; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_get_lsb_first_sync( - spi_proxy, - spi->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - *lsb = value ? true : false; - - return ret; -} - -int peripheral_gdbus_spi_set_bits(peripheral_spi_h spi, unsigned char bits) +int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_spi_call_set_bits_sync( + if (peripheral_io_gdbus_spi_call_set_bits_per_word_sync( spi_proxy, spi->handle, bits, @@ -215,32 +162,7 @@ int peripheral_gdbus_spi_set_bits(peripheral_spi_h spi, unsigned char bits) return ret; } -int peripheral_gdbus_spi_get_bits(peripheral_spi_h spi, unsigned char *bits) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - guchar value; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_get_bits_sync( - spi_proxy, - spi->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - *bits = (unsigned char)value; - - return ret; -} - -int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq) +int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; @@ -250,7 +172,7 @@ int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq) if (peripheral_io_gdbus_spi_call_set_frequency_sync( spi_proxy, spi->handle, - freq, + freq_hz, &ret, NULL, &error) == FALSE) { @@ -262,31 +184,6 @@ int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq) return ret; } -int peripheral_gdbus_spi_get_frequency(peripheral_spi_h spi, unsigned int *freq) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - guint value; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_get_frequency_sync( - spi_proxy, - spi->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - *freq = (unsigned int)value; - - return ret; -} - int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length) { GError *error = NULL; @@ -357,7 +254,7 @@ int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int le return ret; } -int peripheral_gdbus_spi_read_write(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length) +int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; @@ -379,7 +276,7 @@ int peripheral_gdbus_spi_read_write(peripheral_spi_h spi, unsigned char *tx_data tx_data_array = g_variant_new("a(y)", builder); g_variant_builder_unref(builder); - if (peripheral_io_gdbus_spi_call_read_write_sync( + if (peripheral_io_gdbus_spi_call_transfer_sync( spi_proxy, spi->handle, length, diff --git a/src/peripheral_gdbus_uart.c b/src/peripheral_gdbus_uart.c index 81b77c1..aa3b364 100644 --- a/src/peripheral_gdbus_uart.c +++ b/src/peripheral_gdbus_uart.c @@ -95,16 +95,17 @@ int peripheral_gdbus_uart_close(peripheral_uart_h uart) return ret; } -int peripheral_gdbus_uart_flush(peripheral_uart_h uart) +int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud) { GError *error = NULL; gint32 ret = PERIPHERAL_ERROR_NONE; if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_uart_call_flush_sync( + if (peripheral_io_gdbus_uart_call_set_baud_rate_sync( uart_proxy, uart->handle, + baud, &ret, NULL, &error) == FALSE) { @@ -116,17 +117,17 @@ int peripheral_gdbus_uart_flush(peripheral_uart_h uart) return ret; } -int peripheral_gdbus_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_e baud) +int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size) { GError *error = NULL; gint32 ret = PERIPHERAL_ERROR_NONE; if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_uart_call_set_baudrate_sync( + if (peripheral_io_gdbus_uart_call_set_byte_size_sync( uart_proxy, uart->handle, - baud, + byte_size, &ret, NULL, &error) == FALSE) { @@ -138,19 +139,17 @@ int peripheral_gdbus_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_b 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) +int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity) { GError *error = NULL; gint32 ret = PERIPHERAL_ERROR_NONE; if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_uart_call_set_mode_sync( + if (peripheral_io_gdbus_uart_call_set_parity_sync( uart_proxy, uart->handle, - bytesize, parity, - stopbits, &ret, NULL, &error) == FALSE) { @@ -162,14 +161,36 @@ int peripheral_gdbus_uart_set_mode(peripheral_uart_h uart, peripheral_uart_bytes return ret; } -int peripheral_gdbus_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool rtscts) +int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_uart_call_set_stop_bits_sync( + uart_proxy, + uart->handle, + stop_bits, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts) { GError *error = NULL; gint32 ret = PERIPHERAL_ERROR_NONE; if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_uart_call_set_flowcontrol_sync( + if (peripheral_io_gdbus_uart_call_set_flow_control_sync( uart_proxy, uart->handle, xonxoff, diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 8a7ccdf..f7b68ee 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -26,29 +26,24 @@ #include "peripheral_io_gdbus.h" typedef struct { - int pin; - gpio_isr_cb callback; + peripheral_gpio_h handle; + peripheral_gpio_interrupted_cb callback; void *user_data; -} gpio_isr_data_s; +} interrupted_cb_info_s; -static GList *gpio_isr_list = NULL; +static GList *interrupted_cb_info_list = NULL; -int peripheral_gpio_isr_callback(int pin, int value, unsigned long long timestamp) +int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int error) { GList *link; - gpio_isr_data_s *isr_data; - gpio_isr_cb_s cb_data; + interrupted_cb_info_s *cb_info; - link = gpio_isr_list; + link = interrupted_cb_info_list; while (link) { - isr_data = (gpio_isr_data_s*)link->data; - - if (isr_data->pin == pin) { - cb_data.pin = pin; - cb_data.value = value; - cb_data.timestamp = timestamp; - if (isr_data->callback) - isr_data->callback(&cb_data, isr_data->user_data); + cb_info = (interrupted_cb_info_s*)link->data; + if (cb_info->handle->pin == pin) { + if (cb_info->callback) + cb_info->callback(cb_info->handle, error, cb_info->user_data); return PERIPHERAL_ERROR_NONE; } link = g_list_next(link); @@ -57,50 +52,50 @@ int peripheral_gpio_isr_callback(int pin, int value, unsigned long long timestam return PERIPHERAL_ERROR_NONE; } -int peripheral_gpio_isr_set(int pin, gpio_isr_cb callback, void *user_data) +static int __interrupted_cb_info_list_append(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data) { GList *link; - gpio_isr_data_s *isr_data = NULL; + interrupted_cb_info_s *cb_info = NULL; - link = gpio_isr_list; + link = interrupted_cb_info_list; while (link) { - gpio_isr_data_s *tmp; - tmp = (gpio_isr_data_s*)link->data; - if (tmp->pin == pin) { - isr_data = tmp; + interrupted_cb_info_s *tmp; + tmp = (interrupted_cb_info_s*)link->data; + if (tmp->handle == gpio) { + cb_info = tmp; break; } link = g_list_next(link); } - if (isr_data == NULL) { - isr_data = (gpio_isr_data_s*)calloc(1, sizeof(gpio_isr_data_s)); - if (isr_data == NULL) { - _E("failed to allocate gpio_isr_data_s"); + if (cb_info == NULL) { + cb_info = (interrupted_cb_info_s*)calloc(1, sizeof(interrupted_cb_info_s)); + if (cb_info == NULL) { + _E("failed to allocate interrupted_cb_info_s"); return PERIPHERAL_ERROR_OUT_OF_MEMORY; } - gpio_isr_list = g_list_append(gpio_isr_list, isr_data); + link = g_list_append(link, cb_info); } - isr_data->pin = pin; - isr_data->callback = callback; - isr_data->user_data = user_data; + cb_info->handle = gpio; + cb_info->callback = callback; + cb_info->user_data = user_data; return PERIPHERAL_ERROR_NONE; } -int peripheral_gpio_isr_unset(int pin) +static int __interrupted_cb_info_list_remove(peripheral_gpio_h gpio) { GList *link; - gpio_isr_data_s *isr_data; + interrupted_cb_info_s *cb_info; - link = gpio_isr_list; + link = interrupted_cb_info_list; while (link) { - isr_data = (gpio_isr_data_s*)link->data; + cb_info = (interrupted_cb_info_s*)link->data; - if (isr_data->pin == pin) { - gpio_isr_list = g_list_remove_link(gpio_isr_list, link); + if (cb_info->handle == gpio) { + interrupted_cb_info_list = g_list_remove_link(interrupted_cb_info_list, link); free(link->data); g_list_free(link); break; @@ -167,23 +162,6 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) return ret; } -/** - * @brief Gets direction of the gpio. - */ -int peripheral_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction) -{ - int ret = PERIPHERAL_ERROR_NONE; - - RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - - ret = peripheral_gdbus_gpio_get_direction(gpio, direction); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get direction of the gpio pin, ret : %d", ret); - - return ret; -} - - /** * @brief Sets direction of the gpio pin. */ @@ -192,8 +170,6 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct int ret = PERIPHERAL_ERROR_NONE; RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - RETVM_IF(direction > PERIPHERAL_GPIO_DIRECTION_OUT_HIGH, PERIPHERAL_ERROR_INVALID_PARAMETER, - "Invalid direction input"); /* call gpio_set_direction */ ret = peripheral_gdbus_gpio_set_direction(gpio, direction); @@ -203,55 +179,6 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct return ret; } -/** - * @brief Reads value of the gpio. - */ -int peripheral_gpio_read(peripheral_gpio_h gpio, int *value) -{ - int ret = PERIPHERAL_ERROR_NONE; - - RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - - /* call gpio_read */ - ret = peripheral_gdbus_gpio_read(gpio, value); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to read value of the gpio pin, ret : %d", ret); - - return ret; -} - -/** - * @brief Writes value to the gpio. - */ -int peripheral_gpio_write(peripheral_gpio_h gpio, int value) -{ - int ret = PERIPHERAL_ERROR_NONE; - - RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - - /* call gpio_write */ - ret = peripheral_gdbus_gpio_write(gpio, value); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to write to the gpio pin, ret : %d", ret); - - return ret; -} - -/** - * @brief Gets the edge mode of the gpio. - */ -int peripheral_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge) -{ - int ret = PERIPHERAL_ERROR_NONE; - - RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - - ret = peripheral_gdbus_gpio_get_edge_mode(gpio, edge); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get edge mode of the gpio pin, ret : %d", ret); - - return ret; -} /** * @brief Sets the edge mode of the gpio pin. @@ -275,22 +202,22 @@ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e /** * @brief Registers a callback function to be invoked when the gpio interrupt is triggered. */ -int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data) +int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data) { int ret = PERIPHERAL_ERROR_NONE; RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - ret = peripheral_gdbus_gpio_register_cb(gpio, callback, user_data); + ret = peripheral_gdbus_gpio_set_interrupted_cb(gpio, callback, user_data); if (ret != PERIPHERAL_ERROR_NONE) { - _E("Failed to register cb, ret : %d", ret); + _E("Failed to set gpio interrupted cb, ret : %d", ret); return ret; } /* set isr */ - ret = peripheral_gpio_isr_set(gpio->pin, callback, user_data); + ret = __interrupted_cb_info_list_append(gpio, callback, user_data); if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to register gpio isr, ret : %d", ret); + _E("Failed to append gpio interrupt callback info, ret : %d", ret); return ret; } @@ -298,32 +225,55 @@ int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, vo /** * @brief Unregisters the callback function for the gpio handler. */ -int peripheral_gpio_unregister_cb(peripheral_gpio_h gpio) +int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) { int ret = PERIPHERAL_ERROR_NONE; RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - ret = peripheral_gdbus_gpio_unregister_cb(gpio); + ret = peripheral_gdbus_gpio_unset_interrupted_cb(gpio); if (ret != PERIPHERAL_ERROR_NONE) { - _E("Failed to unregister gpio isr, ret : %d", ret); + _E("Failed to unset gpio interrupt callback, ret : %d", ret); return ret; } - /* clean up isr */ - ret = peripheral_gpio_isr_unset(gpio->pin); + ret = __interrupted_cb_info_list_remove(gpio); + if (ret != PERIPHERAL_ERROR_NONE) + _E("Failed to remove gpio interrupt callback info, ret : %d", ret); return ret; } /** - * @brief Gets pin number of the gpio handle. + * @brief Reads value of the gpio. */ -int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin) +int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value) { + int ret = PERIPHERAL_ERROR_NONE; + RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - *gpio_pin = gpio->pin; + /* call gpio_read */ + ret = peripheral_gdbus_gpio_read(gpio, (int *)value); + if (ret != PERIPHERAL_ERROR_NONE) + _E("Failed to read value of the gpio pin, ret : %d", ret); - return PERIPHERAL_ERROR_NONE; + return ret; +} + +/** + * @brief Writes value to the gpio. + */ +int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value) +{ + int ret = PERIPHERAL_ERROR_NONE; + + RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); + + /* call gpio_write */ + ret = peripheral_gdbus_gpio_write(gpio, (int)value); + if (ret != PERIPHERAL_ERROR_NONE) + _E("Failed to write to the gpio pin, ret : %d", ret); + + return ret; } diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index 4035eb6..f52b9b4 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -79,72 +79,42 @@ int peripheral_i2c_close(peripheral_i2c_h i2c) return ret; } -int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length) +int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { int ret; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - ret = peripheral_gdbus_i2c_read(i2c, data, length); + ret = peripheral_gdbus_i2c_read(i2c, data, (int)length); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to read data from device, ret : %d", ret); return ret; } -int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length) +int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { int ret; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - ret = peripheral_gdbus_i2c_write(i2c, data, length); + ret = peripheral_gdbus_i2c_write(i2c, data, (int)length); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to write data to device, ret : %d", ret); return ret; } -int peripheral_i2c_read_byte(peripheral_i2c_h i2c, uint8_t *data) +int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data) { int ret; uint16_t w_data, dummy = 0; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, 0x0, I2C_SMBUS_BYTE, dummy, &w_data); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to read, ret : %d", ret); - - *data = (uint8_t)w_data; - - return ret; -} - -int peripheral_i2c_write_byte(peripheral_i2c_h i2c, uint8_t data) -{ - int ret = PERIPHERAL_ERROR_NONE; - uint16_t dummy = 0; - - RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, dummy, I2C_SMBUS_BYTE, (uint16_t)data, &dummy); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to write, ret : %d", ret); - - return ret; -} - -int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t *data) -{ - int ret; - uint16_t w_data, dummy = 0; - - RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, address, I2C_SMBUS_BYTE_DATA, dummy, &w_data); + ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, reg, I2C_SMBUS_BYTE_DATA, dummy, &w_data); if (ret != PERIPHERAL_ERROR_NONE) _E("Smbus transaction failed, ret : %d", ret); @@ -153,28 +123,28 @@ int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t address, uin return ret; } -int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t data) +int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data) { int ret; uint16_t dummy = 0; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, address, I2C_SMBUS_BYTE_DATA, (uint16_t)data, &dummy); + ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE_DATA, (uint16_t)data, &dummy); if (ret != PERIPHERAL_ERROR_NONE) _E("Smbus transaction failed, ret : %d", ret); return ret; } -int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t *data) +int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data) { int ret; uint16_t dummy = 0, data_out; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, address, I2C_SMBUS_WORD_DATA, dummy, &data_out); + ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, reg, I2C_SMBUS_WORD_DATA, dummy, &data_out); if (ret != PERIPHERAL_ERROR_NONE) _E("Smbus transaction failed, ret : %d", ret); @@ -183,14 +153,14 @@ int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t address, uin return ret; } -int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t data) +int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data) { int ret; uint16_t dummy = 0; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, address, I2C_SMBUS_WORD_DATA, data, &dummy); + ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, reg, I2C_SMBUS_WORD_DATA, data, &dummy); if (ret != PERIPHERAL_ERROR_NONE) _E("Smbus transaction failed, ret : %d", ret); diff --git a/src/peripheral_io.xml b/src/peripheral_io.xml index ad80f04..9b556d6 100644 --- a/src/peripheral_io.xml +++ b/src/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/peripheral_pwm.c b/src/peripheral_pwm.c index e3718ee..be18d45 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -24,12 +24,12 @@ #include "peripheral_common.h" #include "peripheral_internal.h" -int peripheral_pwm_open(int device, int channel, peripheral_pwm_h *pwm) +int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm) { peripheral_pwm_h handle; int ret = PERIPHERAL_ERROR_NONE; - RETVM_IF(device < 0 || channel < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + RETVM_IF(chip < 0 || pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); /* Initialize */ handle = (peripheral_pwm_h)calloc(1, sizeof(struct _peripheral_pwm_s)); @@ -41,10 +41,10 @@ int peripheral_pwm_open(int device, int channel, peripheral_pwm_h *pwm) pwm_proxy_init(); - ret = peripheral_gdbus_pwm_open(handle, device, channel); + ret = peripheral_gdbus_pwm_open(handle, chip, pin); if (ret != PERIPHERAL_ERROR_NONE) { - _E("Failed to open PWM device : %d, channel : %d", device, channel); + _E("Failed to open PWM chip : %d, pin : %d", chip, pin); free(handle); handle = NULL; } @@ -60,7 +60,7 @@ int peripheral_pwm_close(peripheral_pwm_h pwm) RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); if ((ret = peripheral_gdbus_pwm_close(pwm)) < 0) - _E("Failed to close PWM device, continuing anyway, ret : %d", ret); + _E("Failed to close PWM chip, continuing anyway, ret : %d", ret); pwm_proxy_deinit(); free(pwm); @@ -68,65 +68,37 @@ int peripheral_pwm_close(peripheral_pwm_h pwm) return ret; } -int peripheral_pwm_set_period(peripheral_pwm_h pwm, int period) +int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns) { int ret; RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - ret = peripheral_gdbus_pwm_set_period(pwm, period); + ret = peripheral_gdbus_pwm_set_period(pwm, (int)period_ns); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set period, ret : %d", ret); return ret; } -int peripheral_pwm_get_period(peripheral_pwm_h pwm, int *period) +int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns) { int ret; RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - ret = peripheral_gdbus_pwm_get_period(pwm, period); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get period, ret : %d", ret); - - return ret; -} - -int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) -{ - int ret; - - RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - - ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle); + ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, (int)duty_cycle_ns); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set duty cycle, ret : %d", ret); return ret; } -int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle) -{ - int ret; - - RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - - ret = peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get duty cycle, ret : %d", ret); - - return ret; -} - int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity) { int ret; RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - RETVM_IF(polarity > PERIPHERAL_PWM_POLARITY_INVERSED, PERIPHERAL_ERROR_INVALID_PARAMETER, - "Invalid polarity parameter"); ret = peripheral_gdbus_pwm_set_polarity(pwm, polarity); if (ret != PERIPHERAL_ERROR_NONE) @@ -135,20 +107,7 @@ int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e return ret; } -int peripheral_pwm_get_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e *polarity) -{ - int ret; - - RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - - ret = peripheral_gdbus_pwm_get_polarity(pwm, polarity); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get polarity, ret : %d", ret); - - return ret; -} - -int peripheral_pwm_set_enable(peripheral_pwm_h pwm, bool enable) +int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enable) { int ret; @@ -160,16 +119,3 @@ int peripheral_pwm_set_enable(peripheral_pwm_h pwm, bool enable) return ret; } - -int peripheral_pwm_get_enable(peripheral_pwm_h pwm, bool *enable) -{ - int ret; - - RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - - ret = peripheral_gdbus_pwm_get_enable(pwm, enable); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get enable, ret : %d", ret); - - return ret; -} diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index eff8f23..7b2baf7 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -85,130 +85,79 @@ int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) return ret; } -int peripheral_spi_get_mode(peripheral_spi_h spi, peripheral_spi_mode_e *mode) +int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order) { int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - ret = peripheral_gdbus_spi_get_mode(spi, mode); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get spi mode, ret : %d", ret); - - return ret; -} - -int peripheral_spi_set_lsb_first(peripheral_spi_h spi, bool lsb) -{ - int ret; - - RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - - ret = peripheral_gdbus_spi_set_lsb_first(spi, lsb); + bool lsb = (bit_order == PERIPHERAL_SPI_BIT_ORDER_LSB) ? true : false; + ret = peripheral_gdbus_spi_set_bit_order(spi, lsb); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set lsb first, ret : %d", ret); return ret; } -int peripheral_spi_get_lsb_first(peripheral_spi_h spi, bool *lsb) -{ - int ret; - - RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - - ret = peripheral_gdbus_spi_get_lsb_first(spi, lsb); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get lsb first, ret : %d", ret); - - return ret; -} - -int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits) +int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits) { int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - ret = peripheral_gdbus_spi_set_bits(spi, bits); + ret = peripheral_gdbus_spi_set_bits_per_word(spi, (unsigned char)bits); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set bits per word, ret : %d", ret); return ret; } -int peripheral_spi_get_bits_per_word(peripheral_spi_h spi, unsigned char *bits) +int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz) { int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - ret = peripheral_gdbus_spi_get_bits(spi, bits); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get bits per word, ret : %d", ret); - - return ret; -} - -int peripheral_spi_set_frequency(peripheral_spi_h spi, unsigned int freq) -{ - int ret; - - RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - - ret = peripheral_gdbus_spi_set_frequency(spi, freq); + ret = peripheral_gdbus_spi_set_frequency(spi, (unsigned int)freq_hz); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set frequency, ret : %d", ret); return ret; } -int peripheral_spi_get_frequency(peripheral_spi_h spi, unsigned int *freq) -{ - int ret; - - RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - - ret = peripheral_gdbus_spi_get_frequency(spi, freq); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get spi frequency, ret : %d", ret); - - return ret; -} - -int peripheral_spi_read(peripheral_spi_h spi, unsigned char *data, int length) +int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length) { int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - ret = peripheral_gdbus_spi_read(spi, data, length); + ret = peripheral_gdbus_spi_read(spi, data, (int)length); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to read from spi device, ret : %d", ret); return ret; } -int peripheral_spi_write(peripheral_spi_h spi, unsigned char *data, int length) +int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length) { int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - ret = peripheral_gdbus_spi_write(spi, data, length); + ret = peripheral_gdbus_spi_write(spi, data, (int)length); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to write to spi device, ret : %d", ret); return ret; } -int peripheral_spi_read_write(peripheral_spi_h spi, unsigned char *txdata, unsigned char *rxdata, int length) +int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxdata, uint32_t length) { int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - ret = peripheral_gdbus_spi_read_write(spi, txdata, rxdata, length); + ret = peripheral_gdbus_spi_transfer(spi, txdata, rxdata, (int)length); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to read and write, ret : %d", ret); diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index 1b18c17..cb62b52 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -76,70 +76,79 @@ int peripheral_uart_close(peripheral_uart_h uart) } /** - * @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. + * @brief Sets baudrate of the uart device. */ -int peripheral_uart_flush(peripheral_uart_h uart) +int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud) { int ret; RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); + RETVM_IF(baud > PERIPHERAL_UART_BAUD_RATE_230400, PERIPHERAL_ERROR_INVALID_PARAMETER, + "Invalid baud input"); - ret = peripheral_gdbus_uart_flush(uart); + ret = peripheral_gdbus_uart_set_baud_rate(uart, baud); if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to flush, ret : %d", ret); + _E("Failed to set baudrate, ret : %d", ret); return ret; } -/** - * @brief Sets baudrate of the uart device. - */ -int peripheral_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_e baud) +int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size) { int ret; RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); - RETVM_IF(baud > PERIPHERAL_UART_BAUDRATE_230400, PERIPHERAL_ERROR_INVALID_PARAMETER, - "Invalid baud input"); + RETVM_IF((byte_size < PERIPHERAL_UART_BYTE_SIZE_5BIT) || (byte_size > PERIPHERAL_UART_BYTE_SIZE_8BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - ret = peripheral_gdbus_uart_set_baudrate(uart, baud); + ret = peripheral_gdbus_uart_set_byte_size(uart, byte_size); if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set baudrate, ret : %d", ret); + _E("Failed to set uart mode, ret : %d", ret); return ret; } -/** - * @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) +int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity) { int ret; RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); - RETVM_IF(bytesize > PERIPHERAL_UART_BYTESIZE_8BIT - || parity > PERIPHERAL_UART_PARITY_ODD - || stopbits > PERIPHERAL_UART_STOPBITS_2BIT, - PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + RETVM_IF((parity < PERIPHERAL_UART_PARITY_NONE) || (parity > PERIPHERAL_UART_PARITY_ODD), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - ret = peripheral_gdbus_uart_set_mode(uart, bytesize, parity, stopbits); + ret = peripheral_gdbus_uart_set_parity(uart, parity); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set uart mode, ret : %d", ret); return ret; } +int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits) +{ + int ret; + + RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); + RETVM_IF((stop_bits < PERIPHERAL_UART_STOP_BITS_1BIT) || (stop_bits > PERIPHERAL_UART_STOP_BITS_2BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + + ret = peripheral_gdbus_uart_set_stop_bits(uart, stop_bits); + if (ret != PERIPHERAL_ERROR_NONE) + _E("Failed to set uart mode, ret : %d", ret); + + return ret; +} + + /** * @brief Sets baudrate of the uart device. */ -int peripheral_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool rtscts) +int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_software_flow_control_e sw_flow_control, peripheral_uart_hardware_flow_control_e hw_flow_control) { int ret; RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); - ret = peripheral_gdbus_uart_set_flowcontrol(uart, xonxoff, rtscts); + bool xonxoff = (sw_flow_control == PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF) ? true : false; + bool rtscts = (hw_flow_control == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS) ? true : false; + + ret = peripheral_gdbus_uart_set_flow_control(uart, xonxoff, rtscts); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set flocontrol, ret : %d", ret); @@ -149,14 +158,14 @@ int peripheral_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool r /** * @brief Reads data from the uart device. */ -int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, int length) +int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length) { int ret; RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - ret = peripheral_gdbus_uart_read(uart, data, length); + ret = peripheral_gdbus_uart_read(uart, data, (int)length); if (ret < PERIPHERAL_ERROR_NONE) _E("Failed to read from uart device, ret : %d", ret); @@ -166,14 +175,14 @@ int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, int length) /** * @brief Write data to the uart device. */ -int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, int length) +int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length) { int ret; RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - ret = peripheral_gdbus_uart_write(uart, data, length); + ret = peripheral_gdbus_uart_write(uart, data, (int)length); if (ret < PERIPHERAL_ERROR_NONE) _E("Failed to write to uart device, ret : %d", ret);