Skip to content

Commit 4e98fb4

Browse files
committed
Expose API for count of used/free channels
1 parent a4afbc9 commit 4e98fb4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

cores/nRF5/HardwarePWM.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,21 @@ uint16_t HardwarePWM::readChannel(uint8_t ch)
218218
return (_seq0[ch] & 0x7FFF);
219219
}
220220

221+
uint8_t HardwarePWM::usedChannelCount(void)
222+
{
223+
uint8_t usedChannels = 0;
224+
for(int i=0; i<MAX_CHANNELS; i++)
225+
{
226+
if ( _pwm->PSEL.OUT[i] & PWM_PSEL_OUT_CONNECT_Msk )
227+
{
228+
usedChannels++;
229+
}
230+
}
231+
return usedChannels;
232+
}
233+
234+
uint8_t HardwarePWM::freeChannelCount(void)
235+
{
236+
return MAX_CHANNELS - usedChannelCount();
237+
}
238+

cores/nRF5/HardwarePWM.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ class HardwarePWM
9696
// Read current set value
9797
uint16_t readPin (uint8_t pin);
9898
uint16_t readChannel (uint8_t ch);
99+
100+
// Get count of used / free channels
101+
uint8_t usedChannelCount();
102+
uint8_t freeChannelCount();
99103
};
100104

101105
extern HardwarePWM HwPWM0;

0 commit comments

Comments
 (0)