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.
20 #include "peripheral_io.h"
21 #include "peripheral_gdbus.h"
22 #include "peripheral_common.h"
23 #include "peripheral_internal.h"
24 #include "peripheral_io_gdbus.h"
26 static PeripheralIoGdbusPwm *pwm_proxy = NULL;
28 void pwm_proxy_init(void)
32 if (pwm_proxy != NULL) {
33 g_object_ref(pwm_proxy);
37 pwm_proxy = peripheral_io_gdbus_pwm_proxy_new_for_bus_sync(
39 G_DBUS_PROXY_FLAGS_NONE,
40 PERIPHERAL_GDBUS_NAME,
41 PERIPHERAL_GDBUS_PWM_PATH,
46 void pwm_proxy_deinit()
49 g_object_unref(pwm_proxy);
50 if (!G_IS_OBJECT(pwm_proxy))
55 int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin)
58 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
60 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
62 if (peripheral_io_gdbus_pwm_call_open_sync(
70 _E("%s", error->message);
72 return PERIPHERAL_ERROR_UNKNOWN;
78 int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm)
81 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
83 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
85 if (peripheral_io_gdbus_pwm_call_close_sync(
91 _E("%s", error->message);
93 return PERIPHERAL_ERROR_UNKNOWN;
99 int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period)
101 GError *error = NULL;
102 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
104 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
106 if (peripheral_io_gdbus_pwm_call_set_period_sync(
113 _E("%s", error->message);
115 return PERIPHERAL_ERROR_UNKNOWN;
121 int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns)
123 GError *error = NULL;
124 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
126 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
128 if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync(
135 _E("%s", error->message);
137 return PERIPHERAL_ERROR_UNKNOWN;
143 int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity)
145 GError *error = NULL;
146 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
148 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
150 if (peripheral_io_gdbus_pwm_call_set_polarity_sync(
157 _E("%s", error->message);
159 return PERIPHERAL_ERROR_UNKNOWN;
165 int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable)
167 GError *error = NULL;
168 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
170 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
172 if (peripheral_io_gdbus_pwm_call_set_enable_sync(
179 _E("%s", error->message);
181 return PERIPHERAL_ERROR_UNKNOWN;