X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Fpwm.c;h=3062802032c0730d3f4ea22533fdcc7d12b0935d;hb=62c64455f33dd53639f04d35014ef5e50f9acd50;hp=3946188262263c0f406062adef2fac522a19d77b;hpb=791e167e053bdd9250d34a9a5ccae6ccde4d6679;p=bertos.git diff --git a/bertos/drv/pwm.c b/bertos/drv/pwm.c index 39461882..30628020 100644 --- a/bertos/drv/pwm.c +++ b/bertos/drv/pwm.c @@ -38,15 +38,25 @@ * \author Daniele Basile */ -#include -#include - -#include -#include +#include "cfg/cfg_pwm.h" #include +#include + +// Define logging setting (for cfg/log.h module). +#define LOG_LEVEL PWM_LOG_LEVEL +#define LOG_VERBOSITY PWM_LOG_FORMAT + +#include #include +#include + +#include CPU_HEADER(pwm) + +#include +#include + /** * Set duty of pwm channel \p dev. @@ -56,13 +66,13 @@ void pwm_setDuty(PwmDev dev, pwm_duty_t duty) pwm_period_t period = 0; pwm_duty_t real_duty = 0; - duty = MIN(duty, (pwm_duty_t)PWM_MAX_DUTY); + duty = MIN(duty, PWM_MAX_DUTY); period = pwm_hw_getPeriod(dev); real_duty = (uint64_t)(duty * period) >> (uint64_t)PWM_MAX_PERIOD_LOG2; -// kprintf("real_duty[%d] duty[%d], period[%d]\n", real_duty, duty, period); + LOG_INFO("real_duty[%d] duty[%d], period[%d]", real_duty, duty, period); pwm_hw_setDutyUnlock(dev, real_duty); } @@ -85,23 +95,26 @@ void pwm_enable(PwmDev dev, bool state) pwm_hw_disable(dev); } +MOD_DEFINE(pwm); + /** * Initialize PWM hw. */ void pwm_init(void) { - cpuflags_t flags; + cpu_flags_t flags; PwmDev dev; IRQ_SAVE_DISABLE(flags); + pwm_hw_init(); + /* set all pwm to 0 */ for (dev = 0; dev < PWM_CNT; dev++) pwm_setDuty(dev, 0); - pwm_hw_init(); - IRQ_RESTORE(flags); + MOD_INIT(pwm); }