Add and rename pwm interface functions 20/129520/5
authorjino.cho <jino.cho@samsung.com>
Tue, 16 May 2017 08:31:55 +0000 (17:31 +0900)
committerjino.cho <jino.cho@samsung.com>
Thu, 18 May 2017 06:12:14 +0000 (15:12 +0900)
- add pwm_set_polarity() and pwm_get_polarity()
- rename pwm_set_enabled() to pwm_set_enable()
- rename pwm_get_enabled() to pwm_get_enable()
- modify descriptions
- fix log message level

Change-Id: I4520599bc86b6111f1e55c05e73714b1d5fac1e7
Signed-off-by: jino.cho <jino.cho@samsung.com>
src/daemon/peripheral_bus_pwm.c
src/interface/include/pwm.h
src/interface/pwm.c

index 4551cd9..3d5e61c 100644 (file)
@@ -45,7 +45,7 @@ int peripheral_bus_pwm_set_period(peripheral_pwm_context_h pwm, int period)
 
 int peripheral_bus_pwm_set_enable(peripheral_pwm_context_h pwm, int enable)
 {
-       return pwm_set_enabled(pwm->device, pwm->channel, enable);
+       return pwm_set_enable(pwm->device, pwm->channel, enable);
 }
 
 int peripheral_bus_pwm_get_duty_cycle(peripheral_pwm_context_h pwm, int *duty_cycle)
index 49342b1..d53496f 100644 (file)
 #define __PWM_H__
 
 /**
+ * @brief Enumeration for Polarity
+ */
+typedef enum {
+       PWM_POLARITY_NORMAL = 0,
+       PWM_POLARITY_INVERSED,
+} pwm_polarity_e;
+
+/**
 * @brief pwm_open() init pwm channel.
 *
 * @param[in] device pwm chip number
@@ -50,8 +58,8 @@ int pwm_set_period(int device, int channel, int period);
 *
 * @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[out] period pwm period
+* @return On success, 0 is returned. On failure, a negative value is returned.
 */
 int pwm_get_period(int device, int channel, int *period);
 
@@ -70,29 +78,48 @@ int pwm_set_duty_cycle(int device, int channel, int duty_cycle);
 *
 * @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[out] duty_cycle pwm duty cycle
+* @return On success, 0 is returned. On failure, a negative value is returned.
 */
 int pwm_get_duty_cycle(int device, int channel, int *duty_cycle);
 
 /**
-* @brief pwm_set_enabled() sets the pwm state.
+* @brief pwm_set_polarity() sets the pwm polarity.
 *
 * @param[in] device pwm chip number
 * @param[in] channel pwm channel number
-* @param[in] enable pwm enable/disabled state value
+* @param[in] polarity pwm polarity
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int pwm_set_polarity(int device, int channel, pwm_polarity_e polarity);
+/**
+* @brief pwm_get_polarity() gets the pwm polarity.
+*
+* @param[in] device pwm chip number
+* @param[in] channel pwm channel number
+* @param[out] polarity pwm polarity
 * @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_get_polarity(int device, int channel, pwm_polarity_e *polarity);
 
 /**
-* @brief pwm_is_enabled() checks if pwm state is enabled.
+* @brief pwm_set_enable() sets the pwm state.
 *
 * @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.
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int pwm_set_enable(int device, int channel, int enable);
+
+/**
+* @brief pwm_get_enable() checks if pwm state is enabled.
+*
+* @param[in] device pwm chip number
+* @param[in] channel pwm channel number
+* @param[out] enable pwm enable/disabled state value
+* @return On success, 0 is returned. On failure, a negative value is returned.
 */
-int pwm_get_enabled(int device, int channel, int *enable);
+int pwm_get_enable(int device, int channel, int *enable);
 
 #endif /* __PWM_H__ */
index 9315333..f3929cb 100644 (file)
@@ -90,7 +90,7 @@ int pwm_set_period(int device, int channel, int period)
        char pwm_buf[PWM_BUF_MAX] = {0};
        char pwm_dev[PATH_BUF_MAX] = {0};
 
-       _E("Set period : %d, device : %d, channel : %d", period, device, channel);
+       _D("Set period : %d, device : %d, channel : %d", period, device, channel);
        snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/period", device, channel);
        fd = open(pwm_dev, O_WRONLY);
        if (fd < 0) {
@@ -146,7 +146,7 @@ int pwm_set_duty_cycle(int device, int channel, int duty_cycle)
        char pwm_buf[PWM_BUF_MAX] = {0};
        char pwm_dev[PATH_BUF_MAX] = {0};
 
-       _E("Set duty_cycle : %d, device : %d, channel : %d", duty_cycle, device, channel);
+       _D("Set duty_cycle : %d, device : %d, channel : %d", duty_cycle, device, channel);
        snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", device, channel);
        fd = open(pwm_dev, O_WRONLY);
        if (fd < 0) {
@@ -196,13 +196,84 @@ int pwm_get_duty_cycle(int device, int channel, int *duty_cycle)
        return 0;
 }
 
-int pwm_set_enabled(int device, int channel, int enable)
+int pwm_set_polarity(int device, int channel, pwm_polarity_e polarity)
+{
+       int fd, status;
+       char pwm_dev[PATH_BUF_MAX] = {0};
+
+       _D("Set polarity : %d, device : %d, channel : %d", polarity, device, channel);
+       snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/polarity", device, channel);
+       fd = open(pwm_dev, O_WRONLY);
+       if (fd < 0) {
+               char errmsg[MAX_ERR_LEN];
+               strerror_r(errno, errmsg, MAX_ERR_LEN);
+               _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg);
+               return -ENODEV;
+       }
+
+       if (polarity == PWM_POLARITY_NORMAL)
+               status = write(fd, "normal", strlen("normal")+1);
+       else if (polarity == PWM_POLARITY_INVERSED)
+               status = write(fd, "inversed", strlen("inversed")+1);
+       else {
+               _E("Invalid pwm polarity : %d", polarity);
+               close(fd);
+               return -EINVAL;
+       }
+
+       if (status <= 0) {
+               close(fd);
+               _E("Failed to set polarity, path : %s", pwm_dev);
+               return -EIO;
+       }
+       close(fd);
+
+       return 0;
+}
+
+int pwm_get_polarity(int device, int channel, pwm_polarity_e *polarity)
+{
+       int fd, status;
+       char pwm_buf[PWM_BUF_MAX] = {0};
+       char pwm_dev[PATH_BUF_MAX] = {0};
+
+       snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/polarity", device, channel);
+       fd = open(pwm_dev, O_RDONLY);
+       if (fd < 0) {
+               char errmsg[MAX_ERR_LEN];
+               strerror_r(errno, errmsg, MAX_ERR_LEN);
+               _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg);
+               return -ENODEV;
+       }
+
+       status = read(fd, pwm_buf, PWM_BUF_MAX);
+       if (status < 0) {
+               _E("Failed to get polarity, path : %s", pwm_dev);
+               close(fd);
+               return -EIO;
+       }
+
+       if (0 == strncmp(pwm_buf, "normal", strlen("normal")))
+               *polarity = PWM_POLARITY_NORMAL;
+       else if (0 == strncmp(pwm_buf, "inversed", strlen("inversed")))
+               *polarity = PWM_POLARITY_INVERSED;
+       else {
+               close(fd);
+               _E("Invalid pwm polarity : %d", pwm_buf);
+               return -EIO;
+       }
+       close(fd);
+
+       return 0;
+}
+
+int pwm_set_enable(int device, int channel, int enable)
 {
        int fd, len, status;
        char pwm_buf[PWM_BUF_MAX] = {0};
        char pwm_dev[PATH_BUF_MAX] = {0};
 
-       _E("Set enable : %d, device : %d, channel : %d", enable, device, channel);
+       _D("Set enable : %d, device : %d, channel : %d", enable, device, channel);
        snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", device, channel);
        fd = open(pwm_dev, O_WRONLY);
        if (fd < 0) {
@@ -224,7 +295,7 @@ int pwm_set_enabled(int device, int channel, int enable)
        return 0;
 }
 
-int pwm_get_enabled(int device, int channel, int *enable)
+int pwm_get_enable(int device, int channel, int *enable)
 {
        int fd, result, status;
        char pwm_buf[PWM_BUF_MAX] = {0};