Return pwm handle through pointer argument 65/129465/2
authorjino.cho <jino.cho@samsung.com>
Tue, 16 May 2017 10:16:42 +0000 (19:16 +0900)
committerjino.cho <jino.cho@samsung.com>
Tue, 16 May 2017 23:33:32 +0000 (08:33 +0900)
Change-Id: I3b62a841edaafe2298592132cb2fdd8ed23a9694
Signed-off-by: jino.cho <jino.cho@samsung.com>
include/peripheral_io.h
src/peripheral_pwm.c
test/peripheral-io-test.c

index a0b7fad..95bc38a 100644 (file)
@@ -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);
 
index ea08352..9c291b0 100644 (file)
@@ -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)
index 21d0a8b..699be4a 100644 (file)
@@ -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]) {