#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
*
* @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);
*
* @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__ */
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) {
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) {
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) {
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};