#include "Pwm.h" #include "DevUtil.h" #include "stringex.hpp" #define PWMPATH "%s%d/pwm0/%s" Pwm::Pwm(int port) { path_enable = string_format(PWMPATH, path_base.c_str(), port, path_enable.c_str()); path_duty_cycle = string_format(PWMPATH, path_base.c_str(), port, path_duty_cycle.c_str()); path_period = string_format(PWMPATH, path_base.c_str(), port, path_period.c_str()); } Pwm::~Pwm() { } void Pwm::setFreq(int freq) { int value = PWM_PERIOD / freq; write_dev(path_period, value); write_dev(path_duty_cycle, value / 2); } int Pwm::getFreq() { return PWM_PERIOD / read_dev_i(path_period); } void Pwm::enable(bool bEnable) { write_dev(path_enable, bEnable); } bool Pwm::isEnable() { return (bool)read_dev_i(path_enable); }