File tree Expand file tree Collapse file tree 2 files changed +6
-1
lines changed
libraries/Servo/src/nrf52 Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ bool HardwarePWM::takeOwnership(uintptr_t token)
58
58
{
59
59
if (this ->_owner_token != 0 ) return false ; // doesn't matter if it's actually a match ... it's not legal to take ownership twice
60
60
if (this ->usedChannelCount () != 0 ) return false ; // at least one channel is already in use
61
+ if (this ->enabled ) return false ; // if it's enabled, do not allow new ownership, even with no pins in use
61
62
// use gcc built-in intrinsic to ensure atomicity
62
63
// See https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html
63
64
return __sync_bool_compare_and_swap (&(this ->_owner_token ), 0 , token);
@@ -67,6 +68,7 @@ bool HardwarePWM::releaseOwnership(uintptr_t token)
67
68
{
68
69
if (!this ->isOwner (token) ) return false ; // don't even look at peripheral
69
70
if ( this ->usedChannelCount () != 0 ) return false ; // fail if any channels still have pins
71
+ if ( this ->enabled ) return false ; // if it's enabled, do not allow ownership to be released, even with no pins in use
70
72
// use gcc built-in intrinsic to ensure atomicity
71
73
// See https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html
72
74
return __sync_bool_compare_and_swap (&(this ->_owner_token ), token, 0 );
Original file line number Diff line number Diff line change @@ -108,7 +108,10 @@ void Servo::detach()
108
108
HardwarePWM * pwm = this ->pwm ;
109
109
this ->pwm = nullptr ;
110
110
pwm->removePin (pin);
111
- pwm->releaseOwnership (_servoToken); // ignore failure ... which happens if a pin is still in use, for example
111
+ if (pwm->usedChannelCount () == 0 ) {
112
+ pwm->stop (); // disables peripheral so can release ownership
113
+ pwm->releaseOwnership (_servoToken);
114
+ }
112
115
}
113
116
114
117
void Servo::write (int value)
You can’t perform that action at this time.
0 commit comments