Skip to content

Commit e61fbe9

Browse files
committed
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.
1 parent 49568c0 commit e61fbe9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cores/nRF5/HardwarePWM.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,20 @@ void HardwarePWM::setClockDiv(uint8_t div)
7878
*/
7979
bool HardwarePWM::addPin(uint8_t pin)
8080
{
81-
VERIFY( isPinValid(pin) && (_count < MAX_CHANNELS) );
81+
VERIFY( isPinValid(pin) && (_count <= MAX_CHANNELS) );
8282

8383
// Check if pin is already configured
8484
for(uint8_t i=0; i<_count; i++)
8585
{
8686
if (_pwm->PSEL.OUT[i] == pin) return true;
8787
}
8888

89+
if ((_count >= MAX_CHANNELS))
90+
{
91+
//Pin not already configured, but this HardwarePWM is full
92+
return false;
93+
}
94+
8995
pinMode(pin, OUTPUT);
9096
digitalWrite(pin, LOW);
9197

0 commit comments

Comments
 (0)