/*
 * pwm.c
 *
 *  Created on: Aug 9, 2016
 *      Author: tkl
 */

#include <stddef.h>
#include <pwm.h>

int pwm_open(const struct pwm *device)
{
	if(NULL == device)
		return -1;
	pwm_fp_open_t open = device->fp->open;
	return open(device->arch_dep_device);
}

int pwm_close(const struct pwm *device)
{
	if(NULL == device)
		return -1;
	pwm_fp_close_t close = device->fp->close;
	return close(device->arch_dep_device);
}

int pwm_set_duty_cycle(const struct pwm *device, unsigned int duty_cycle_percent)
{
	if(NULL == device)
		return -1;
	pwm_fp_set_duty_cycle_t set = device->fp->set_duty_cycle;
	return set(device->arch_dep_device, duty_cycle_percent);
}

int pwm_get_period_ns(const struct pwm *device)
{
	if(NULL == device)
		return -1;
	pwm_fp_get_period_ns_t get = device->fp->get_period;
	return get(device->arch_dep_device);
}

int pwm_get_pulse_width_ns(const struct pwm *device)
{
	if(NULL == device)
		return -1;
	pwm_fp_get_pulse_width_ns_t get = device->fp->get_pulse_width;
	return get(device->arch_dep_device);
}
