Add check for PWM being ENABLED
This commit is contained in:
1 parent
3efce16900
commit
c58c01df68
2 files changed
+6
-1
No files matched your search
@@ -58,6 +58,7 @@ bool HardwarePWM::takeOwnership(uintptr_t token)
|
||||
{
|
||||
if (this->_owner_token != 0) return false; // doesn't matter if it's actually a match ... it's not legal to take ownership twice
|
||||
if (this->usedChannelCount() != 0) return false; // at least one channel is already in use
|
||||
if (this->enabled ) return false; // if it's enabled, do not allow new ownership, even with no pins in use
|
||||
// use gcc built-in intrinsic to ensure atomicity
|
||||
// See https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html
|
||||
return __sync_bool_compare_and_swap(&(this->_owner_token), 0, token);
|
||||
@@ -67,6 +68,7 @@ bool HardwarePWM::releaseOwnership(uintptr_t token)
|
||||
{
|
||||
if (!this->isOwner(token) ) return false; // don't even look at peripheral
|
||||
if ( this->usedChannelCount() != 0) return false; // fail if any channels still have pins
|
||||
if ( this->enabled ) return false; // if it's enabled, do not allow ownership to be released, even with no pins in use
|
||||
// use gcc built-in intrinsic to ensure atomicity
|
||||
// See https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html
|
||||
return __sync_bool_compare_and_swap(&(this->_owner_token), token, 0);
|
||||
|
||||
@@ -108,7 +108,10 @@ void Servo::detach()
|
||||
HardwarePWM * pwm = this->pwm;
|
||||
this->pwm = nullptr;
|
||||
pwm->removePin(pin);
|
||||
pwm->releaseOwnership(_servoToken); // ignore failure ... which happens if a pin is still in use, for example
|
||||
if (pwm->usedChannelCount() == 0) {
|
||||
pwm->stop(); // disables peripheral so can release ownership
|
||||
pwm->releaseOwnership(_servoToken);
|
||||
}
|
||||
}
|
||||
|
||||
void Servo::write(int value)
|
||||
|
||||
Reference in new issue
Block a user