From e61fbe9a68de2ace7ba8b69554c56c5b1381300a Mon Sep 17 00:00:00 2001 From: Brandyn Burbank Date: Sun, 5 Nov 2017 18:58:41 -0700 Subject: [PATCH] Allow HardwarePWM::addPin method to return true if _count == MAX_CHANNELS, but pin passed was already configured. Return false if trying to add a new pin more than MAX_CHANNELS. --- cores/nRF5/HardwarePWM.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cores/nRF5/HardwarePWM.cpp b/cores/nRF5/HardwarePWM.cpp index 89d05887..5cf601ce 100644 --- a/cores/nRF5/HardwarePWM.cpp +++ b/cores/nRF5/HardwarePWM.cpp @@ -78,7 +78,7 @@ void HardwarePWM::setClockDiv(uint8_t div) */ bool HardwarePWM::addPin(uint8_t pin) { - VERIFY( isPinValid(pin) && (_count < MAX_CHANNELS) ); + VERIFY( isPinValid(pin) && (_count <= MAX_CHANNELS) ); // Check if pin is already configured for(uint8_t i=0; i<_count; i++) @@ -86,6 +86,12 @@ bool HardwarePWM::addPin(uint8_t pin) if (_pwm->PSEL.OUT[i] == pin) return true; } + if ((_count >= MAX_CHANNELS)) + { + //Pin not already configured, but this HardwarePWM is full + return false; + } + pinMode(pin, OUTPUT); digitalWrite(pin, LOW);