Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
Diff: drivers/PwmOut.h
- Revision:
- 187:0387e8f68319
- Parent:
- 184:08ed48f1de7f
--- a/drivers/PwmOut.h Fri Jun 22 16:45:37 2018 +0100 +++ b/drivers/PwmOut.h Thu Sep 06 13:40:20 2018 +0100 @@ -57,13 +57,15 @@ * * @param pin PwmOut pin to connect to */ - PwmOut(PinName pin) : _deep_sleep_locked(false) { + PwmOut(PinName pin) : _deep_sleep_locked(false) + { core_util_critical_section_enter(); pwmout_init(&_pwm, pin); core_util_critical_section_exit(); } - ~PwmOut() { + ~PwmOut() + { core_util_critical_section_enter(); unlock_deep_sleep(); core_util_critical_section_exit(); @@ -76,7 +78,8 @@ * 0.0f (representing on 0%) and 1.0f (representing on 100%). * Values outside this range will be saturated to 0.0f or 1.0f. */ - void write(float value) { + void write(float value) + { core_util_critical_section_enter(); lock_deep_sleep(); pwmout_write(&_pwm, value); @@ -93,7 +96,8 @@ * @note * This value may not match exactly the value set by a previous write(). */ - float read() { + float read() + { core_util_critical_section_enter(); float val = pwmout_read(&_pwm); core_util_critical_section_exit(); @@ -107,7 +111,8 @@ * The resolution is currently in microseconds; periods smaller than this * will be set to zero. */ - void period(float seconds) { + void period(float seconds) + { core_util_critical_section_enter(); pwmout_period(&_pwm, seconds); core_util_critical_section_exit(); @@ -116,7 +121,8 @@ /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same. * @param ms Change the period of a PWM signal in milli-seconds without modifying the duty cycle */ - void period_ms(int ms) { + void period_ms(int ms) + { core_util_critical_section_enter(); pwmout_period_ms(&_pwm, ms); core_util_critical_section_exit(); @@ -125,7 +131,8 @@ /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same. * @param us Change the period of a PWM signal in micro-seconds without modifying the duty cycle */ - void period_us(int us) { + void period_us(int us) + { core_util_critical_section_enter(); pwmout_period_us(&_pwm, us); core_util_critical_section_exit(); @@ -134,7 +141,8 @@ /** 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) */ - void pulsewidth(float seconds) { + void pulsewidth(float seconds) + { core_util_critical_section_enter(); pwmout_pulsewidth(&_pwm, seconds); core_util_critical_section_exit(); @@ -143,16 +151,18 @@ /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same. * @param ms Change the pulse width of a PWM signal specified in milli-seconds */ - void pulsewidth_ms(int ms) { + void pulsewidth_ms(int ms) + { core_util_critical_section_enter(); pwmout_pulsewidth_ms(&_pwm, ms); core_util_critical_section_exit(); } /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same. - * @param us Change the pulse width of a PWM signal specified in micro-seconds + * @param us Change the pulse width of a PWM signal specified in micro-seconds */ - void pulsewidth_us(int us) { + void pulsewidth_us(int us) + { core_util_critical_section_enter(); pwmout_pulsewidth_us(&_pwm, us); core_util_critical_section_exit(); @@ -161,7 +171,8 @@ /** A operator shorthand for write() * \sa PwmOut::write() */ - PwmOut& operator= (float value) { + PwmOut &operator= (float value) + { // Underlying call is thread safe write(value); return *this; @@ -169,8 +180,9 @@ /** A operator shorthand for write() * \sa PwmOut::write() - */ - PwmOut& operator= (PwmOut& rhs) { + */ + PwmOut &operator= (PwmOut &rhs) + { // Underlying call is thread safe write(rhs.read()); return *this; @@ -179,14 +191,16 @@ /** An operator shorthand for read() * \sa PwmOut::read() */ - operator float() { + operator float() + { // Underlying call is thread safe return read(); } protected: /** Lock deep sleep only if it is not yet locked */ - void lock_deep_sleep() { + void lock_deep_sleep() + { if (_deep_sleep_locked == false) { sleep_manager_lock_deep_sleep(); _deep_sleep_locked = true; @@ -194,7 +208,8 @@ } /** Unlock deep sleep in case it is locked */ - void unlock_deep_sleep() { + void unlock_deep_sleep() + { if (_deep_sleep_locked == true) { sleep_manager_unlock_deep_sleep(); _deep_sleep_locked = false;