mirror of https://github.com/ARMmbed/mbed-os.git
fixed resets after suspend
parent
191ec42dd6
commit
6625bdb9f3
|
@ -110,6 +110,12 @@ public:
|
|||
*/
|
||||
void period_us(int us);
|
||||
|
||||
/** Read the PWM period
|
||||
* @returns
|
||||
* The PWM period, specified in microseconds (int)
|
||||
*/
|
||||
int read_period_us();
|
||||
|
||||
/** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
|
||||
* @param seconds Change the pulse width of a PWM signal specified in seconds (float)
|
||||
*/
|
||||
|
@ -125,6 +131,12 @@ public:
|
|||
*/
|
||||
void pulsewidth_us(int us);
|
||||
|
||||
/** Read the PWM pulsewidth
|
||||
* @returns
|
||||
* The PWM pulsewith, specified in microseconds (int)
|
||||
*/
|
||||
int read_pulsewitdth_us();
|
||||
|
||||
/** Suspend PWM operation
|
||||
*
|
||||
* Control the PWM state. This is primarily intended
|
||||
|
@ -191,6 +203,7 @@ protected:
|
|||
bool _deep_sleep_locked;
|
||||
bool _initialized;
|
||||
float _duty_cycle;
|
||||
int _period_us;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -30,7 +30,8 @@ PwmOut::PwmOut(PinName pin) :
|
|||
_pin(pin),
|
||||
_deep_sleep_locked(false),
|
||||
_initialized(false),
|
||||
_duty_cycle(0)
|
||||
_duty_cycle(0),
|
||||
_period_us(0)
|
||||
{
|
||||
PwmOut::init();
|
||||
}
|
||||
|
@ -83,6 +84,14 @@ void PwmOut::period_us(int us)
|
|||
core_util_critical_section_exit();
|
||||
}
|
||||
|
||||
int PwmOut::read_period_us()
|
||||
{
|
||||
core_util_critical_section_enter();
|
||||
auto val = pwmout_read_period_us(&_pwm);
|
||||
core_util_critical_section_exit();
|
||||
return val;
|
||||
}
|
||||
|
||||
void PwmOut::pulsewidth(float seconds)
|
||||
{
|
||||
core_util_critical_section_enter();
|
||||
|
@ -104,11 +113,20 @@ void PwmOut::pulsewidth_us(int us)
|
|||
core_util_critical_section_exit();
|
||||
}
|
||||
|
||||
int PwmOut::read_pulsewitdth_us()
|
||||
{
|
||||
core_util_critical_section_enter();
|
||||
auto val = pwmout_read_pulsewidth_us(&_pwm);
|
||||
core_util_critical_section_exit();
|
||||
return val;
|
||||
}
|
||||
|
||||
void PwmOut::suspend()
|
||||
{
|
||||
core_util_critical_section_enter();
|
||||
if (_initialized) {
|
||||
_duty_cycle = PwmOut::read();
|
||||
_period_us = PwmOut::read_period_us();
|
||||
PwmOut::deinit();
|
||||
}
|
||||
core_util_critical_section_exit();
|
||||
|
@ -120,6 +138,7 @@ void PwmOut::resume()
|
|||
if (!_initialized) {
|
||||
PwmOut::init();
|
||||
PwmOut::write(_duty_cycle);
|
||||
PwmOut::period_us(_period_us);
|
||||
}
|
||||
core_util_critical_section_exit();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue