This commit is contained in:
tkl
2016-08-09 12:28:01 +02:00
parent d14354e47c
commit b80a44a4d9
5 changed files with 128 additions and 34 deletions

View File

@@ -0,0 +1,35 @@
/*
* pwm.h
*
* Created on: Aug 9, 2016
* Author: tkl
*/
#ifndef SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_PWM_H_
#define SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_PWM_H_
//! \brief Function pointer to the open function.
typedef int (*pwm_fp_open_t)(const void*);
//! \brief Function pointer to the close function.
typedef int (*pwm_fp_close_t)(const void*);
//! \brief Function pointer to the read function.
typedef int (*pwm_fp_set_duty_cycle_t)(const void*, unsigned int duty_cycle_percent);
struct pwm_fp {
const pwm_fp_open_t open;
const pwm_fp_close_t close;
const pwm_fp_set_duty_cycle_t set_duty_cycle;
};
struct pwm {
const void *arch_dep_device; //!< Architecture depended pwm device (i.e. stm32f10x_pwm_t).
const struct pwm_fp *fp; //!< Function pointer for the pwm driver access.
};
int pwm_open(const struct pwm *device);
int pwm_close(const struct pwm *device);
int pwm_set_duty_cycle(const struct pwm *device, unsigned int duty_cycle_percent);
#endif /* SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_PWM_H_ */

View File

@@ -0,0 +1,33 @@
/*
* 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);
}