From: jino.cho Date: Tue, 16 May 2017 10:16:42 +0000 (+0900) Subject: Return pwm handle through pointer argument X-Git-Tag: submit/tizen/20170602.034029~26 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f4670f9a86498e01e5a88701b03f3798334bd3a6;p=platform%2Fcore%2Fapi%2Fperipheral-io.git Return pwm handle through pointer argument Change-Id: I3b62a841edaafe2298592132cb2fdd8ed23a9694 Signed-off-by: jino.cho --- diff --git a/include/peripheral_io.h b/include/peripheral_io.h index a0b7fad..95bc38a 100644 --- a/include/peripheral_io.h +++ b/include/peripheral_io.h @@ -388,7 +388,7 @@ typedef enum { PERIPHERAL_PWM_ENABLE, } peripheral_pwm_state_e; -peripheral_pwm_h peripheral_pwm_open(int device, int channel); +int peripheral_pwm_open(int device, int channel, peripheral_pwm_h *pwm); int peripheral_pwm_close(peripheral_pwm_h pwm); diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index ea08352..9c291b0 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -26,7 +26,7 @@ #define PWM_ENABLE 1 #define PWM_DISABLE 0 -peripheral_pwm_h peripheral_pwm_open(int device, int channel) +int peripheral_pwm_open(int device, int channel, peripheral_pwm_h* pwm) { peripheral_pwm_h dev = NULL; int ret = PERIPHERAL_ERROR_NONE; @@ -39,7 +39,7 @@ peripheral_pwm_h peripheral_pwm_open(int device, int channel) if (dev == NULL) { _E("Failed to allocate peripheral_pwm_h"); - return NULL; + return PERIPHERAL_ERROR_OUT_OF_MEMORY; } pwm_proxy_init(); @@ -50,11 +50,13 @@ peripheral_pwm_h peripheral_pwm_open(int device, int channel) ret = peripheral_gdbus_pwm_open(dev, device, channel); if (ret != PERIPHERAL_ERROR_NONE) { + _E("PWM open error (%d, %d)", device, channel); free(dev); dev = NULL; } + *pwm = dev; - return dev; + return ret; } int peripheral_pwm_close(peripheral_pwm_h pwm) diff --git a/test/peripheral-io-test.c b/test/peripheral-io-test.c index 21d0a8b..699be4a 100644 --- a/test/peripheral-io-test.c +++ b/test/peripheral-io-test.c @@ -224,7 +224,7 @@ int pwm_test_led(void) printf("<<< pwm_test >>>\n"); - dev = peripheral_pwm_open(device, channel); + 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 */ @@ -265,7 +265,7 @@ int pwm_test_motor(void) printf("<<< pwm_test_motor >>>\n"); - dev = peripheral_pwm_open(device, channel); + peripheral_pwm_open(device, channel, &dev); for (cnt = 0; cnt < 5; cnt++) { for (idx = 0; idx < 3; idx++) { switch (degree[idx]) {