- The pwm methods will pass handle instead of device informations.
- The pwm enable(set/get) functions were modified.
Change-Id: I54aa6444f6d22f1ba9ee1bf30391d2c04ff9a4f7
Signed-off-by: jino.cho <jino.cho@samsung.com>
int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle);
int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle);
int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e enable);
+int peripheral_gdbus_pwm_get_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e *enable);
#endif /* __PERIPHERAL_GDBUS_PWM_H__ */
};
/**
+ * @brief Internal struct for pwm context
+ */
+struct _peripheral_pwm_s {
+ uint handle;
+};
+
+/**
* @brief Internal struct for uart context
*/
struct _peripheral_uart_s {
* @{
*/
-struct _peripheral_pwm_s {
- int device;
- int channel;
- int period;
- int duty_cycle;
- int enabled;
-};
-
/**
* @brief The handle to the pwm device
* @since_tizen 4.0
int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle);
-int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, peripheral_pwm_state_e enable);
+int peripheral_pwm_set_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e enable);
-int peripheral_pwm_is_enabled(peripheral_pwm_h pwm);
+int peripheral_pwm_get_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e *enable);
/**
* @}
pwm_proxy,
device,
channel,
+ &pwm->handle,
&ret,
NULL,
&error) == FALSE) {
/* TODO: Need to reorganize arguments */
if (peripheral_io_gdbus_pwm_call_close_sync(
pwm_proxy,
- pwm->device,
- pwm->channel,
+ pwm->handle,
&ret,
NULL,
&error) == FALSE) {
/* TODO: Need to reorganize arguments */
if (peripheral_io_gdbus_pwm_call_set_period_sync(
pwm_proxy,
- pwm->device,
- pwm->channel,
+ pwm->handle,
period,
&ret,
NULL,
/* TODO: Need to reorganize arguments */
if (peripheral_io_gdbus_pwm_call_get_period_sync(
pwm_proxy,
- pwm->device,
- pwm->channel,
- period,
+ pwm->handle,
+ (gint*)period,
&ret,
NULL,
&error) == FALSE) {
/* TODO: Need to reorganize arguments */
if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync(
pwm_proxy,
- pwm->device,
- pwm->channel,
+ pwm->handle,
duty_cycle,
&ret,
NULL,
/* TODO: Need to reorganize arguments */
if (peripheral_io_gdbus_pwm_call_get_duty_cycle_sync(
pwm_proxy,
- pwm->device,
- pwm->channel,
- duty_cycle,
+ pwm->handle,
+ (gint*)duty_cycle,
&ret,
NULL,
&error) == FALSE) {
/* TODO: Need to reorganize arguments */
if (peripheral_io_gdbus_pwm_call_set_enable_sync(
pwm_proxy,
- pwm->device,
- pwm->channel,
+ pwm->handle,
enable,
&ret,
NULL,
return ret;
}
+
+int peripheral_gdbus_pwm_get_enable(peripheral_pwm_h pwm, bool *enable)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_pwm_call_get_enable_sync(
+ pwm_proxy,
+ pwm->handle,
+ (gint*)enable,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("%s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
+
<method name="Open">
<arg type="i" name="device" direction="in"/>
<arg type="i" name="channel" direction="in"/>
+ <arg type="u" name="handle" direction="out"/>
<arg type="i" name="result" direction="out"/>
</method>
<method name="Close">
- <arg type="i" name="device" direction="in"/>
- <arg type="i" name="channel" direction="in"/>
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="GetDutyCycle">
- <arg type="i" name="device" direction="in"/>
- <arg type="i" name="channel" direction="in"/>
- <arg type="i" name="duty_cycle" direction="out"/>
+ <arg type="u" name="handle" direction="in"/>
<arg type="i" name="result" direction="out"/>
</method>
- <method name="SetDutyCycle">
- <arg type="i" name="device" direction="in"/>
- <arg type="i" name="channel" direction="in"/>
- <arg type="i" name="duty_cycle" direction="in"/>
+ <method name="SetPeriod">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="period" direction="in"/>
<arg type="i" name="result" direction="out"/>
</method>
<method name="GetPeriod">
- <arg type="i" name="device" direction="in"/>
- <arg type="i" name="channel" direction="in"/>
+ <arg type="u" name="handle" direction="in"/>
<arg type="i" name="period" direction="out"/>
<arg type="i" name="result" direction="out"/>
</method>
- <method name="SetPeriod">
- <arg type="i" name="device" direction="in"/>
- <arg type="i" name="channel" direction="in"/>
- <arg type="i" name="period" direction="in"/>
+ <method name="SetDutyCycle">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="duty_cycle" direction="in"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
+ <method name="GetDutyCycle">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="duty_cycle" direction="out"/>
<arg type="i" name="result" direction="out"/>
</method>
<method name="SetEnable">
- <arg type="i" name="device" direction="in"/>
- <arg type="i" name="channel" direction="in"/>
+ <arg type="u" name="handle" direction="in"/>
<arg type="i" name="enable" direction="in"/>
<arg type="i" name="result" direction="out"/>
</method>
+ <method name="GetEnable">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="i" name="enable" direction="out"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
</interface>
<interface name="org.tizen.peripheral_io.uart">
<method name="Open">
#include "peripheral_io.h"
#include "peripheral_gdbus_pwm.h"
#include "peripheral_common.h"
+#include "peripheral_internal.h"
#define PWM_ENABLE 1
#define PWM_DISABLE 0
int peripheral_pwm_open(int device, int channel, peripheral_pwm_h* pwm)
{
- peripheral_pwm_h dev = NULL;
+ peripheral_pwm_h handle;
int ret = PERIPHERAL_ERROR_NONE;
assert(device >= 0);
assert(channel >= 0);
/* Initialize */
- dev = (peripheral_pwm_h)malloc(sizeof(struct _peripheral_pwm_s));
+ handle = (peripheral_pwm_h)calloc(1, sizeof(struct _peripheral_pwm_s));
- if (dev == NULL) {
+ if (handle == NULL) {
_E("Failed to allocate peripheral_pwm_h");
return PERIPHERAL_ERROR_OUT_OF_MEMORY;
}
pwm_proxy_init();
- dev->device = device;
- dev->channel = channel;
-
- ret = peripheral_gdbus_pwm_open(dev, device, channel);
+ ret = peripheral_gdbus_pwm_open(handle, device, channel);
if (ret != PERIPHERAL_ERROR_NONE) {
_E("PWM open error (%d, %d)", device, channel);
- free(dev);
- dev = NULL;
+ free(handle);
+ handle = NULL;
}
- *pwm = dev;
+ *pwm = handle;
return ret;
}
int peripheral_pwm_set_period(peripheral_pwm_h pwm, int period)
{
- int ret = PERIPHERAL_ERROR_NONE;
-
- ret = peripheral_gdbus_pwm_set_period(pwm, period);
+ if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
- if (ret != PERIPHERAL_ERROR_NONE)
- pwm->period = period;
-
- return ret;
+ return peripheral_gdbus_pwm_set_period(pwm, period);
}
int peripheral_pwm_get_period(peripheral_pwm_h pwm, int *period)
{
- int ret = PERIPHERAL_ERROR_NONE;
+ if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
- ret = peripheral_gdbus_pwm_get_period(pwm, period);
-
- if (ret != PERIPHERAL_ERROR_NONE)
- pwm->period = *period;
-
- return ret;
+ return peripheral_gdbus_pwm_get_period(pwm, period);
}
int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle)
{
- int ret = PERIPHERAL_ERROR_NONE;
-
- ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle);
+ if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
- if (ret != PERIPHERAL_ERROR_NONE)
- pwm->duty_cycle = duty_cycle;
-
- return ret;
+ return peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle);
}
int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle)
{
- int ret = PERIPHERAL_ERROR_NONE;
+ if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
- ret = peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle);
-
- if (ret != PERIPHERAL_ERROR_NONE)
- pwm->duty_cycle = *duty_cycle;
-
- return ret;
+ return peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle);
}
-int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, peripheral_pwm_state_e enable)
+int peripheral_pwm_set_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e enable)
{
- int ret = PERIPHERAL_ERROR_NONE;
-
- ret = peripheral_gdbus_pwm_set_enable(pwm, enable);
-
- if (ret != PERIPHERAL_ERROR_NONE)
- pwm->enabled = enable;
+ if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
- return PERIPHERAL_ERROR_NONE;
+ return peripheral_gdbus_pwm_set_enable(pwm, enable);
}
-int peripheral_pwm_is_enabled(peripheral_pwm_h pwm)
+int peripheral_pwm_get_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e *enable)
{
- if (pwm->enabled == PWM_ENABLE)
- return PWM_ENABLE;
- else
- return PWM_DISABLE;
-}
+ if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ return peripheral_gdbus_pwm_get_enable(pwm, enable);
+}
peripheral_pwm_open(device, channel, &dev);
peripheral_pwm_set_period(dev, period); /* period: nanosecond */
peripheral_pwm_set_duty_cycle(dev, duty_cycle); /* duty_cycle: nanosecond */
- peripheral_pwm_set_enabled(dev, 1); /* 0: disable, 1: enable */
+ peripheral_pwm_set_enable(dev, 1); /* 0: disable, 1: enable */
while (cnt < 5) {
for (set_duty_cycle = period; set_duty_cycle > 0; set_duty_cycle -= 50) {
}
cnt++;
}
- peripheral_pwm_set_enabled(dev, 0); /* 0: disable, 1: enable */
+ peripheral_pwm_set_enable(dev, 0); /* 0: disable, 1: enable */
peripheral_pwm_close(dev);
return 0;
printf("set degree: %d\n", degree[idx]);
peripheral_pwm_set_period(dev, period);
peripheral_pwm_set_duty_cycle(dev, duty_cycle);
- peripheral_pwm_set_enabled(dev, 1); /* 0: disable, 1: enable */
+ peripheral_pwm_set_enable(dev, 1); /* 0: disable, 1: enable */
usleep(500000);
}
}
- peripheral_pwm_set_enabled(dev, 0); /* 0: disable, 1: enable */
+ peripheral_pwm_set_enable(dev, 0); /* 0: disable, 1: enable */
peripheral_pwm_close(dev);
return 0;