2 * Copyright (c) 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.
22 #include "peripheral_io.h"
23 #include "peripheral_gdbus_pwm.h"
24 #include "peripheral_common.h"
29 peripheral_pwm_h peripheral_pwm_open(int device, int channel)
31 peripheral_pwm_h dev = NULL;
32 int ret = PERIPHERAL_ERROR_NONE;
38 dev = (peripheral_pwm_h)malloc(sizeof(struct _peripheral_pwm_s));
41 _E("Failed to allocate peripheral_pwm_h");
48 dev->channel = channel;
50 ret = peripheral_gdbus_pwm_open(dev, device, channel);
52 if (ret != PERIPHERAL_ERROR_NONE) {
60 int peripheral_pwm_close(peripheral_pwm_h pwm)
62 int ret = PERIPHERAL_ERROR_NONE;
64 ret = peripheral_gdbus_pwm_close(pwm);
67 if (ret == PERIPHERAL_ERROR_NONE) {
76 int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle)
78 int ret = PERIPHERAL_ERROR_NONE;
80 ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle);
82 if (ret != PERIPHERAL_ERROR_NONE)
83 pwm->duty_cycle = duty_cycle;
88 int peripheral_pwm_set_period(peripheral_pwm_h pwm, int period)
90 int ret = PERIPHERAL_ERROR_NONE;
92 ret = peripheral_gdbus_pwm_set_period(pwm, period);
94 if (ret != PERIPHERAL_ERROR_NONE)
100 int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, peripheral_pwm_state_e enable)
102 int ret = PERIPHERAL_ERROR_NONE;
104 ret = peripheral_gdbus_pwm_set_enable(pwm, enable);
106 if (ret != PERIPHERAL_ERROR_NONE)
107 pwm->enabled = enable;
109 return PERIPHERAL_ERROR_NONE;
112 int peripheral_pwm_is_enabled(peripheral_pwm_h pwm)
114 if (pwm->enabled == PWM_ENABLE)
120 int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle)
122 int ret = PERIPHERAL_ERROR_NONE;
124 ret = peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle);
126 if (ret != PERIPHERAL_ERROR_NONE)
127 pwm->duty_cycle = *duty_cycle;
132 int peripheral_pwm_get_period(peripheral_pwm_h pwm, int *period)
134 int ret = PERIPHERAL_ERROR_NONE;
136 ret = peripheral_gdbus_pwm_get_period(pwm, period);
138 if (ret != PERIPHERAL_ERROR_NONE)
139 pwm->period = *period;