From 872d1500364bd2b3adb07e22a0098b54aaf750a4 Mon Sep 17 00:00:00 2001 From: "jino.cho" Date: Tue, 16 May 2017 20:49:28 +0900 Subject: [PATCH] Change argument of pwm gdbus method - The pwm methods will pass handle instead of device informations. - The pwm enable(set/get) functions were modified. Change-Id: I54aa6444f6d22f1ba9ee1bf30391d2c04ff9a4f7 Signed-off-by: jino.cho --- include/peripheral_gdbus_pwm.h | 1 + include/peripheral_internal.h | 7 ++++ include/peripheral_io.h | 12 ++----- src/peripheral_gdbus_pwm.c | 46 ++++++++++++++++++-------- src/peripheral_io.xml | 40 +++++++++++----------- src/peripheral_pwm.c | 75 +++++++++++++----------------------------- test/peripheral-io-test.c | 8 ++--- 7 files changed, 89 insertions(+), 100 deletions(-) diff --git a/include/peripheral_gdbus_pwm.h b/include/peripheral_gdbus_pwm.h index 9b6dc02..7096af2 100644 --- a/include/peripheral_gdbus_pwm.h +++ b/include/peripheral_gdbus_pwm.h @@ -27,5 +27,6 @@ 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_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e enable); +int peripheral_gdbus_pwm_get_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e *enable); #endif /* __PERIPHERAL_GDBUS_PWM_H__ */ diff --git a/include/peripheral_internal.h b/include/peripheral_internal.h index 290fb28..85263aa 100644 --- a/include/peripheral_internal.h +++ b/include/peripheral_internal.h @@ -34,6 +34,13 @@ struct _peripheral_i2c_s { }; /** + * @brief Internal struct for pwm context + */ +struct _peripheral_pwm_s { + uint handle; +}; + +/** * @brief Internal struct for uart context */ struct _peripheral_uart_s { diff --git a/include/peripheral_io.h b/include/peripheral_io.h index e9ee0ea..c6838e7 100644 --- a/include/peripheral_io.h +++ b/include/peripheral_io.h @@ -369,14 +369,6 @@ int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length); * @{ */ -struct _peripheral_pwm_s { - int device; - int channel; - int period; - int duty_cycle; - int enabled; -}; - /** * @brief The handle to the pwm device * @since_tizen 4.0 @@ -401,9 +393,9 @@ int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle); int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle); -int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, peripheral_pwm_state_e enable); +int peripheral_pwm_set_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e enable); -int peripheral_pwm_is_enabled(peripheral_pwm_h pwm); +int peripheral_pwm_get_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e *enable); /** * @} diff --git a/src/peripheral_gdbus_pwm.c b/src/peripheral_gdbus_pwm.c index 76cc7a9..76f4a5b 100644 --- a/src/peripheral_gdbus_pwm.c +++ b/src/peripheral_gdbus_pwm.c @@ -61,6 +61,7 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int device, int channel) pwm_proxy, device, channel, + &pwm->handle, &ret, NULL, &error) == FALSE) { @@ -82,8 +83,7 @@ int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm) /* TODO: Need to reorganize arguments */ if (peripheral_io_gdbus_pwm_call_close_sync( pwm_proxy, - pwm->device, - pwm->channel, + pwm->handle, &ret, NULL, &error) == FALSE) { @@ -105,8 +105,7 @@ int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period) /* TODO: Need to reorganize arguments */ if (peripheral_io_gdbus_pwm_call_set_period_sync( pwm_proxy, - pwm->device, - pwm->channel, + pwm->handle, period, &ret, NULL, @@ -129,9 +128,8 @@ int peripheral_gdbus_pwm_get_period(peripheral_pwm_h pwm, int *period) /* TODO: Need to reorganize arguments */ if (peripheral_io_gdbus_pwm_call_get_period_sync( pwm_proxy, - pwm->device, - pwm->channel, - period, + pwm->handle, + (gint*)period, &ret, NULL, &error) == FALSE) { @@ -153,8 +151,7 @@ int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) /* TODO: Need to reorganize arguments */ if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync( pwm_proxy, - pwm->device, - pwm->channel, + pwm->handle, duty_cycle, &ret, NULL, @@ -177,9 +174,8 @@ int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle) /* TODO: Need to reorganize arguments */ if (peripheral_io_gdbus_pwm_call_get_duty_cycle_sync( pwm_proxy, - pwm->device, - pwm->channel, - duty_cycle, + pwm->handle, + (gint*)duty_cycle, &ret, NULL, &error) == FALSE) { @@ -201,8 +197,7 @@ int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e /* TODO: Need to reorganize arguments */ if (peripheral_io_gdbus_pwm_call_set_enable_sync( pwm_proxy, - pwm->device, - pwm->channel, + pwm->handle, enable, &ret, NULL, @@ -214,3 +209,26 @@ int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e return ret; } + +int peripheral_gdbus_pwm_get_enable(peripheral_pwm_h pwm, bool *enable) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_pwm_call_get_enable_sync( + pwm_proxy, + pwm->handle, + (gint*)enable, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + diff --git a/src/peripheral_io.xml b/src/peripheral_io.xml index c6343c4..285c6f5 100644 --- a/src/peripheral_io.xml +++ b/src/peripheral_io.xml @@ -86,43 +86,43 @@ + - - - - - - - - + - - - - + + + - - + - - - - + + + + + + + + - - + + + + + + diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index a7c4206..45f29fc 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -22,39 +22,37 @@ #include "peripheral_io.h" #include "peripheral_gdbus_pwm.h" #include "peripheral_common.h" +#include "peripheral_internal.h" #define PWM_ENABLE 1 #define PWM_DISABLE 0 int peripheral_pwm_open(int device, int channel, peripheral_pwm_h* pwm) { - peripheral_pwm_h dev = NULL; + peripheral_pwm_h handle; int ret = PERIPHERAL_ERROR_NONE; assert(device >= 0); assert(channel >= 0); /* Initialize */ - dev = (peripheral_pwm_h)malloc(sizeof(struct _peripheral_pwm_s)); + handle = (peripheral_pwm_h)calloc(1, sizeof(struct _peripheral_pwm_s)); - if (dev == NULL) { + if (handle == NULL) { _E("Failed to allocate peripheral_pwm_h"); return PERIPHERAL_ERROR_OUT_OF_MEMORY; } pwm_proxy_init(); - dev->device = device; - dev->channel = channel; - - ret = peripheral_gdbus_pwm_open(dev, device, channel); + ret = peripheral_gdbus_pwm_open(handle, device, channel); if (ret != PERIPHERAL_ERROR_NONE) { _E("PWM open error (%d, %d)", device, channel); - free(dev); - dev = NULL; + free(handle); + handle = NULL; } - *pwm = dev; + *pwm = handle; return ret; } @@ -76,69 +74,42 @@ int peripheral_pwm_close(peripheral_pwm_h pwm) int peripheral_pwm_set_period(peripheral_pwm_h pwm, int period) { - int ret = PERIPHERAL_ERROR_NONE; - - ret = peripheral_gdbus_pwm_set_period(pwm, period); + if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - if (ret != PERIPHERAL_ERROR_NONE) - pwm->period = period; - - return ret; + return peripheral_gdbus_pwm_set_period(pwm, period); } int peripheral_pwm_get_period(peripheral_pwm_h pwm, int *period) { - int ret = PERIPHERAL_ERROR_NONE; + if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - ret = peripheral_gdbus_pwm_get_period(pwm, period); - - if (ret != PERIPHERAL_ERROR_NONE) - pwm->period = *period; - - return ret; + return peripheral_gdbus_pwm_get_period(pwm, period); } int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) { - int ret = PERIPHERAL_ERROR_NONE; - - ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle); + if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - if (ret != PERIPHERAL_ERROR_NONE) - pwm->duty_cycle = duty_cycle; - - return ret; + return peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle); } int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle) { - int ret = PERIPHERAL_ERROR_NONE; + if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - ret = peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle); - - if (ret != PERIPHERAL_ERROR_NONE) - pwm->duty_cycle = *duty_cycle; - - return ret; + return peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle); } -int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, peripheral_pwm_state_e enable) +int peripheral_pwm_set_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e enable) { - int ret = PERIPHERAL_ERROR_NONE; - - ret = peripheral_gdbus_pwm_set_enable(pwm, enable); - - if (ret != PERIPHERAL_ERROR_NONE) - pwm->enabled = enable; + if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - return PERIPHERAL_ERROR_NONE; + return peripheral_gdbus_pwm_set_enable(pwm, enable); } -int peripheral_pwm_is_enabled(peripheral_pwm_h pwm) +int peripheral_pwm_get_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e *enable) { - if (pwm->enabled == PWM_ENABLE) - return PWM_ENABLE; - else - return PWM_DISABLE; -} + if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; + return peripheral_gdbus_pwm_get_enable(pwm, enable); +} diff --git a/test/peripheral-io-test.c b/test/peripheral-io-test.c index 699be4a..dae9170 100644 --- a/test/peripheral-io-test.c +++ b/test/peripheral-io-test.c @@ -227,7 +227,7 @@ int pwm_test_led(void) peripheral_pwm_open(device, channel, &dev); peripheral_pwm_set_period(dev, period); /* period: nanosecond */ peripheral_pwm_set_duty_cycle(dev, duty_cycle); /* duty_cycle: nanosecond */ - peripheral_pwm_set_enabled(dev, 1); /* 0: disable, 1: enable */ + peripheral_pwm_set_enable(dev, 1); /* 0: disable, 1: enable */ while (cnt < 5) { for (set_duty_cycle = period; set_duty_cycle > 0; set_duty_cycle -= 50) { @@ -248,7 +248,7 @@ int pwm_test_led(void) } cnt++; } - peripheral_pwm_set_enabled(dev, 0); /* 0: disable, 1: enable */ + peripheral_pwm_set_enable(dev, 0); /* 0: disable, 1: enable */ peripheral_pwm_close(dev); return 0; @@ -285,12 +285,12 @@ int pwm_test_motor(void) printf("set degree: %d\n", degree[idx]); peripheral_pwm_set_period(dev, period); peripheral_pwm_set_duty_cycle(dev, duty_cycle); - peripheral_pwm_set_enabled(dev, 1); /* 0: disable, 1: enable */ + peripheral_pwm_set_enable(dev, 1); /* 0: disable, 1: enable */ usleep(500000); } } - peripheral_pwm_set_enabled(dev, 0); /* 0: disable, 1: enable */ + peripheral_pwm_set_enable(dev, 0); /* 0: disable, 1: enable */ peripheral_pwm_close(dev); return 0; -- 2.7.4