2 * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 #include "peripheral_common.h"
27 #include "peripheral_internal.h"
29 #define SYSFS_PWM_PATH "/sys/class/pwm"
31 #define PATH_BUF_MAX 64
32 #define PWM_BUF_MAX 16
33 #define MAX_ERR_LEN 255
35 int pwm_close(peripheral_pwm_h pwm)
39 status = close(pwm->fd_period);
41 _E("Error: pwm period fd close error \n");
45 status = close(pwm->fd_duty_cycle);
47 _E("Error: pwm duty cycle fd close error \n");
51 status = close(pwm->fd_polarity);
53 _E("Error: pwm polarity fd close error \n");
57 status = close(pwm->fd_enable);
59 _E("Error: pwm enable fd close error \n");
66 int pwm_set_period(peripheral_pwm_h pwm, int period)
69 char pwm_buf[PWM_BUF_MAX] = {0};
71 len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", period);
72 status = write(pwm->fd_period, pwm_buf, len);
74 _E("Failed to set period");
81 int pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle)
84 char pwm_buf[PWM_BUF_MAX] = {0};
86 len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", duty_cycle);
87 status = write(pwm->fd_duty_cycle, pwm_buf, len);
89 _E("Failed to set duty cycle");
96 int pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity)
100 if (polarity == PWM_POLARITY_NORMAL)
101 status = write(pwm->fd_polarity, "normal", strlen("normal")+1);
102 else if (polarity == PWM_POLARITY_INVERSED)
103 status = write(pwm->fd_polarity, "inversed", strlen("inversed")+1);
105 _E("Invalid pwm polarity : %d", polarity);
110 _E("Failed to set polarity");
117 int pwm_set_enable(peripheral_pwm_h pwm, bool enable)
120 char pwm_buf[PWM_BUF_MAX] = {0};
122 len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", enable);
123 status = write(pwm->fd_enable, pwm_buf, len);
125 _E("Failed to set enable");