diff --git a/cores/arduino/pwm.cpp b/cores/arduino/pwm.cpp index 96e2ea29f..c68b70d29 100644 --- a/cores/arduino/pwm.cpp +++ b/cores/arduino/pwm.cpp @@ -90,6 +90,28 @@ bool PwmOut::begin(uint32_t period_width, uint32_t pulse_width, bool raw /*= fal return _enabled; } +/* -------------------------------------------------------------------------- */ +bool PwmOut::begin(float freq_hz, float duty_perc) { +/* -------------------------------------------------------------------------- */ + _enabled = true; + int max_index = PINS_COUNT; + _enabled &= cfg_pin(max_index); + + if(_enabled) { + _enabled &= timer.begin(TIMER_MODE_PWM, (_is_agt) ? AGT_TIMER : GPT_TIMER, timer_channel, freq_hz, duty_perc); + } + + if(_enabled) { + timer.add_pwm_extended_cfg(); + timer.enable_pwm_channel(_pwm_channel); + + _enabled &= timer.open(); + _enabled &= timer.start(); + } + + return _enabled; +} + bool PwmOut::period(int ms) { return timer.set_period_ms((double)ms); } diff --git a/cores/arduino/pwm.h b/cores/arduino/pwm.h index 29c90b9d3..94fac4f11 100644 --- a/cores/arduino/pwm.h +++ b/cores/arduino/pwm.h @@ -22,6 +22,7 @@ class PwmOut { TIMER_SOURCE_DIV_256 TIMER_SOURCE_DIV_1024 */ bool begin(uint32_t period_usec, uint32_t pulse_usec, bool raw = false, timer_source_div_t sd = TIMER_SOURCE_DIV_1); + bool begin(float freq_hz, float duty_perc); void end(); bool period(int ms); bool pulseWidth(int ms);