Rearrange the order of pwm interface functions 18/129518/1
authorjino.cho <jino.cho@samsung.com>
Tue, 16 May 2017 08:17:20 +0000 (17:17 +0900)
committerjino.cho <jino.cho@samsung.com>
Wed, 17 May 2017 00:23:56 +0000 (09:23 +0900)
Change-Id: I2eb373f5764b39eeda0d37718e794863e1dda649
Signed-off-by: jino.cho <jino.cho@samsung.com>
src/interface/include/pwm.h
src/interface/pwm.c

index 7591697..49342b1 100644 (file)
@@ -46,53 +46,53 @@ int pwm_close(int device, int channel);
 int pwm_set_period(int device, int channel, int period);
 
 /**
-* @brief pwm_set_duty_cycle() sets the pwm duty cycle.
+* @brief pwm_get_period() gets the pwm period.
 *
 * @param[in] device pwm chip number
 * @param[in] channel pwm channel number
-* @param[in] duty_cycle pwm duty cycle
-* @return On success, 0 is returned. On failure, a negative value is returned.
+* @param[in] period pwm period
+* @return On success, current pwm period is returned. On failure, a negative value is returned.
 */
-int pwm_set_duty_cycle(int device, int channel, int duty_cycle);
+int pwm_get_period(int device, int channel, int *period);
 
 /**
-* @brief pwm_set_enabled() sets the pwm state.
+* @brief pwm_set_duty_cycle() sets the pwm duty cycle.
 *
 * @param[in] device pwm chip number
 * @param[in] channel pwm channel number
-* @param[in] enable pwm enable/disabled state value
+* @param[in] duty_cycle pwm duty cycle
 * @return On success, 0 is returned. On failure, a negative value is returned.
 */
-int pwm_set_enabled(int device, int channel, int enable);
+int pwm_set_duty_cycle(int device, int channel, int duty_cycle);
 
 /**
-* @brief pwm_is_enabled() checks if pwm state is enabled.
+* @brief pwm_get_duty_cycle() gets the pwm duty cycle.
 *
 * @param[in] device pwm chip number
 * @param[in] channel pwm channel number
-* @param[in] enable pwm enable/disabled state value
-* @return On success, current pwm state value is returned. On failure, a negative value is returned.
+* @param[in] duty_cycle pwm duty cycle
+* @return On success, current pwm duty cycle is returned. On failure, a negative value is returned.
 */
-int pwm_get_enabled(int device, int channel, int *enable);
+int pwm_get_duty_cycle(int device, int channel, int *duty_cycle);
 
 /**
-* @brief pwm_get_period() gets the pwm period.
+* @brief pwm_set_enabled() sets the pwm state.
 *
 * @param[in] device pwm chip number
 * @param[in] channel pwm channel number
-* @param[in] period pwm period
-* @return On success, current pwm period is returned. On failure, a negative value is returned.
+* @param[in] enable pwm enable/disabled state value
+* @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_set_enabled(int device, int channel, int enable);
 
 /**
-* @brief pwm_get_duty_cycle() gets the pwm duty cycle.
+* @brief pwm_is_enabled() checks if pwm state is enabled.
 *
 * @param[in] device pwm chip number
 * @param[in] channel pwm channel number
-* @param[in] duty_cycle pwm duty cycle
-* @return On success, current pwm duty cycle is returned. On failure, a negative value is returned.
+* @param[in] enable pwm enable/disabled state value
+* @return On success, current pwm state value is returned. On failure, a negative value is returned.
 */
-int pwm_get_duty_cycle(int device, int channel, int *duty_cycle);
+int pwm_get_enabled(int device, int channel, int *enable);
 
 #endif /* __PWM_H__ */
index 32994eb..11879c4 100644 (file)
@@ -101,120 +101,120 @@ int pwm_set_period(int device, int channel, int period)
        return 0;
 }
 
-int pwm_set_duty_cycle(int device, int channel, int duty_cycle)
+int pwm_get_period(int device, int channel, int *period)
 {
-       int fd, len, ret;
+       int fd, result, ret;
        char buff[PWM_BUF_MAX] = {0};
        char fName[PATH_BUF_MAX] = {0};
 
-       snprintf(fName, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", device, channel);
-       if ((fd = open(fName, O_WRONLY)) < 0) {
+       snprintf(fName, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/period", device, channel);
+       if ((fd = open(fName, O_RDONLY)) < 0) {
                _E("Error[%d]: can't open %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
                return -ENOENT;
        }
-       _D("[PWM] duty_cycle = %d\n", duty_cycle);
 
-       len = snprintf(buff, sizeof(buff), "%d", duty_cycle);
-       if ((ret = write(fd, buff, len)) < 0) {
-               _E("Error[%d]: can't write %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
+       if ((ret = read(fd, buff, PWM_BUF_MAX)) < 0) {
+               _E("Error[%d]: can't read %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
                close(fd);
                return -EIO;
        }
+       result = atoi(buff);
+       *period = result;
        close(fd);
 
        return 0;
 }
 
-int pwm_set_enabled(int device, int channel, int enable)
+int pwm_set_duty_cycle(int device, int channel, int duty_cycle)
 {
        int fd, len, ret;
        char buff[PWM_BUF_MAX] = {0};
        char fName[PATH_BUF_MAX] = {0};
 
-       _D("[PWM] set enable = %d!!\n", enable);
-       snprintf(fName, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", device, channel);
+       snprintf(fName, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", device, channel);
        if ((fd = open(fName, O_WRONLY)) < 0) {
                _E("Error[%d]: can't open %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
                return -ENOENT;
        }
+       _D("[PWM] duty_cycle = %d\n", duty_cycle);
 
-       len = snprintf(buff, sizeof(buff), "%d", enable);
+       len = snprintf(buff, sizeof(buff), "%d", duty_cycle);
        if ((ret = write(fd, buff, len)) < 0) {
                _E("Error[%d]: can't write %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
                close(fd);
                return -EIO;
        }
        close(fd);
+
        return 0;
 }
 
-int pwm_get_enabled(int device, int channel, int *enable)
+int pwm_get_duty_cycle(int device, int channel, int *duty_cycle)
 {
        int fd, result, ret;
        char buff[PWM_BUF_MAX] = {0};
        char fName[PATH_BUF_MAX] = {0};
 
-       snprintf(fName, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", device, channel);
+       snprintf(fName, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", device, channel);
        if ((fd = open(fName, O_RDONLY)) < 0) {
                _E("Error[%d]: can't open %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
                return -ENOENT;
        }
 
        if ((ret = read(fd, buff, PWM_BUF_MAX)) < 0) {
-               _E("Error[%d]: can't read %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
+               _E("Error[%d]: can't open %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
                close(fd);
                return -EIO;
        }
        result = atoi(buff);
-       enable = &result;
+       *duty_cycle = result;
        close(fd);
 
        return 0;
 }
 
-int pwm_get_period(int device, int channel, int *period)
+int pwm_set_enabled(int device, int channel, int enable)
 {
-       int fd, result, ret;
+       int fd, len, ret;
        char buff[PWM_BUF_MAX] = {0};
        char fName[PATH_BUF_MAX] = {0};
 
-       snprintf(fName, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/period", device, channel);
-       if ((fd = open(fName, O_RDONLY)) < 0) {
+       _D("[PWM] set enable = %d!!\n", enable);
+       snprintf(fName, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", device, channel);
+       if ((fd = open(fName, O_WRONLY)) < 0) {
                _E("Error[%d]: can't open %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
                return -ENOENT;
        }
 
-       if ((ret = read(fd, buff, PWM_BUF_MAX)) < 0) {
-               _E("Error[%d]: can't read %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
+       len = snprintf(buff, sizeof(buff), "%d", enable);
+       if ((ret = write(fd, buff, len)) < 0) {
+               _E("Error[%d]: can't write %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
                close(fd);
                return -EIO;
        }
-       result = atoi(buff);
-       *period = result;
        close(fd);
-
        return 0;
 }
 
-int pwm_get_duty_cycle(int device, int channel, int *duty_cycle)
+int pwm_get_enabled(int device, int channel, int *enable)
 {
        int fd, result, ret;
        char buff[PWM_BUF_MAX] = {0};
        char fName[PATH_BUF_MAX] = {0};
 
-       snprintf(fName, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", device, channel);
+       snprintf(fName, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", device, channel);
        if ((fd = open(fName, O_RDONLY)) < 0) {
                _E("Error[%d]: can't open %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
                return -ENOENT;
        }
 
        if ((ret = read(fd, buff, PWM_BUF_MAX)) < 0) {
-               _E("Error[%d]: can't open %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
+               _E("Error[%d]: can't read %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__);
                close(fd);
                return -EIO;
        }
        result = atoi(buff);
-       *duty_cycle = result;
+       enable = &result;
        close(fd);
 
        return 0;