Skip to content

Commit 014b58e

Browse files
committed
PmwOut: Add method to enable/disable PWM
The new method can be called to disable PWM to not block deep sleep
1 parent 7eb8807 commit 014b58e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

drivers/PwmOut.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ class PwmOut {
118118
*/
119119
void pulsewidth_us(int us);
120120

121+
/** Enable or disable PWM
122+
*
123+
* Control enabling of device's PWM. This is primarily intended
124+
* for temporary power-saving; This call can
125+
* allow pwm to be temporarily disabled to permit power saving without
126+
* losing device state.
127+
*
128+
* @param enabled true to enable, false to disable.
129+
*/
130+
void enable_pwm(bool enabled = true);
131+
121132
/** A operator shorthand for write()
122133
* \sa PwmOut::write()
123134
*/

drivers/source/PwmOut.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ void PwmOut::pulsewidth_us(int us)
9898
core_util_critical_section_exit();
9999
}
100100

101+
void PwmOut::enable_pwm(bool enabled)
102+
{
103+
core_util_critical_section_enter();
104+
if (_deep_sleep_locked == enabled) {
105+
if (enabled) {
106+
PwmOut::unlock_deep_sleep();
107+
} else {
108+
PwmOut::lock_deep_sleep();
109+
}
110+
}
111+
core_util_critical_section_exit();
112+
}
113+
101114
void PwmOut::lock_deep_sleep()
102115
{
103116
if (_deep_sleep_locked == false) {

0 commit comments

Comments
 (0)