Skip to content

Commit

Permalink
PmwOut: Add method to enable/disable PWM
Browse files Browse the repository at this point in the history
The new method can be called to disable PWM to not block deep sleep
  • Loading branch information
hugueskamba committed Oct 7, 2019
1 parent 7eb8807 commit 014b58e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions drivers/PwmOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ class PwmOut {
*/
void pulsewidth_us(int us);

/** Enable or disable PWM
*
* Control enabling of device's PWM. This is primarily intended
* for temporary power-saving; This call can
* allow pwm to be temporarily disabled to permit power saving without
* losing device state.
*
* @param enabled true to enable, false to disable.
*/
void enable_pwm(bool enabled = true);

/** A operator shorthand for write()
* \sa PwmOut::write()
*/
Expand Down
13 changes: 13 additions & 0 deletions drivers/source/PwmOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ void PwmOut::pulsewidth_us(int us)
core_util_critical_section_exit();
}

void PwmOut::enable_pwm(bool enabled)
{
core_util_critical_section_enter();
if (_deep_sleep_locked == enabled) {
if (enabled) {
PwmOut::unlock_deep_sleep();
} else {
PwmOut::lock_deep_sleep();
}
}
core_util_critical_section_exit();
}

void PwmOut::lock_deep_sleep()
{
if (_deep_sleep_locked == false) {
Expand Down

0 comments on commit 014b58e

Please sign in to comment.