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"
25 #include "peripheral_internal.h"
27 int peripheral_pwm_open(int device, int channel, peripheral_pwm_h *pwm)
29 peripheral_pwm_h handle;
30 int ret = PERIPHERAL_ERROR_NONE;
32 RETVM_IF(device < 0 || channel < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
35 handle = (peripheral_pwm_h)calloc(1, sizeof(struct _peripheral_pwm_s));
38 _E("Failed to allocate peripheral_pwm_h");
39 return PERIPHERAL_ERROR_OUT_OF_MEMORY;
44 ret = peripheral_gdbus_pwm_open(handle, device, channel);
46 if (ret != PERIPHERAL_ERROR_NONE) {
47 _E("Failed to open PWM device : %d, channel : %d", device, channel);
56 int peripheral_pwm_close(peripheral_pwm_h pwm)
58 int ret = PERIPHERAL_ERROR_NONE;
60 RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
62 if ((ret = peripheral_gdbus_pwm_close(pwm)) < 0)
63 _E("Failed to close PWM device, continuing anyway, ret : %d", ret);
71 int peripheral_pwm_set_period(peripheral_pwm_h pwm, int period)
75 RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
77 ret = peripheral_gdbus_pwm_set_period(pwm, period);
78 if (ret != PERIPHERAL_ERROR_NONE)
79 _E("Failed to set period, ret : %d", ret);
84 int peripheral_pwm_get_period(peripheral_pwm_h pwm, int *period)
88 RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
90 ret = peripheral_gdbus_pwm_get_period(pwm, period);
91 if (ret != PERIPHERAL_ERROR_NONE)
92 _E("Failed to get period, ret : %d", ret);
97 int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle)
101 RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
103 ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle);
104 if (ret != PERIPHERAL_ERROR_NONE)
105 _E("Failed to set duty cycle, ret : %d", ret);
110 int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle)
114 RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
116 ret = peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle);
117 if (ret != PERIPHERAL_ERROR_NONE)
118 _E("Failed to get duty cycle, ret : %d", ret);
123 int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity)
127 RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
128 RETVM_IF(polarity > PERIPHERAL_PWM_POLARITY_INVERSED, PERIPHERAL_ERROR_INVALID_PARAMETER,
129 "Invalid polarity parameter");
131 ret = peripheral_gdbus_pwm_set_polarity(pwm, polarity);
132 if (ret != PERIPHERAL_ERROR_NONE)
133 _E("Failed to set polarity, ret : %d", ret);
138 int peripheral_pwm_get_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e *polarity)
142 RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
144 ret = peripheral_gdbus_pwm_get_polarity(pwm, polarity);
145 if (ret != PERIPHERAL_ERROR_NONE)
146 _E("Failed to get polarity, ret : %d", ret);
151 int peripheral_pwm_set_enable(peripheral_pwm_h pwm, bool enable)
155 RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
157 ret = peripheral_gdbus_pwm_set_enable(pwm, enable);
158 if (ret != PERIPHERAL_ERROR_NONE)
159 _E("Failed to set enable, ret : %d", ret);
164 int peripheral_pwm_get_enable(peripheral_pwm_h pwm, bool *enable)
168 RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
170 ret = peripheral_gdbus_pwm_get_enable(pwm, enable);
171 if (ret != PERIPHERAL_ERROR_NONE)
172 _E("Failed to get enable, ret : %d", ret);