Skip to content

Commit 6625bdb

Browse files
committed
fixed resets after suspend
1 parent 191ec42 commit 6625bdb

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

drivers/include/drivers/PwmOut.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ class PwmOut {
110110
*/
111111
void period_us(int us);
112112

113+
/** Read the PWM period
114+
* @returns
115+
* The PWM period, specified in microseconds (int)
116+
*/
117+
int read_period_us();
118+
113119
/** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
114120
* @param seconds Change the pulse width of a PWM signal specified in seconds (float)
115121
*/
@@ -125,6 +131,12 @@ class PwmOut {
125131
*/
126132
void pulsewidth_us(int us);
127133

134+
/** Read the PWM pulsewidth
135+
* @returns
136+
* The PWM pulsewith, specified in microseconds (int)
137+
*/
138+
int read_pulsewitdth_us();
139+
128140
/** Suspend PWM operation
129141
*
130142
* Control the PWM state. This is primarily intended
@@ -191,6 +203,7 @@ class PwmOut {
191203
bool _deep_sleep_locked;
192204
bool _initialized;
193205
float _duty_cycle;
206+
int _period_us;
194207
#endif
195208
};
196209

drivers/source/PwmOut.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ PwmOut::PwmOut(PinName pin) :
3030
_pin(pin),
3131
_deep_sleep_locked(false),
3232
_initialized(false),
33-
_duty_cycle(0)
33+
_duty_cycle(0),
34+
_period_us(0)
3435
{
3536
PwmOut::init();
3637
}
@@ -83,6 +84,14 @@ void PwmOut::period_us(int us)
8384
core_util_critical_section_exit();
8485
}
8586

87+
int PwmOut::read_period_us()
88+
{
89+
core_util_critical_section_enter();
90+
auto val = pwmout_read_period_us(&_pwm);
91+
core_util_critical_section_exit();
92+
return val;
93+
}
94+
8695
void PwmOut::pulsewidth(float seconds)
8796
{
8897
core_util_critical_section_enter();
@@ -104,11 +113,20 @@ void PwmOut::pulsewidth_us(int us)
104113
core_util_critical_section_exit();
105114
}
106115

116+
int PwmOut::read_pulsewitdth_us()
117+
{
118+
core_util_critical_section_enter();
119+
auto val = pwmout_read_pulsewidth_us(&_pwm);
120+
core_util_critical_section_exit();
121+
return val;
122+
}
123+
107124
void PwmOut::suspend()
108125
{
109126
core_util_critical_section_enter();
110127
if (_initialized) {
111128
_duty_cycle = PwmOut::read();
129+
_period_us = PwmOut::read_period_us();
112130
PwmOut::deinit();
113131
}
114132
core_util_critical_section_exit();
@@ -120,6 +138,7 @@ void PwmOut::resume()
120138
if (!_initialized) {
121139
PwmOut::init();
122140
PwmOut::write(_duty_cycle);
141+
PwmOut::period_us(_period_us);
123142
}
124143
core_util_critical_section_exit();
125144
}

0 commit comments

Comments
 (0)