From b4d777f7f329ac5d8c65e42bc21702f15ed8a8f7 Mon Sep 17 00:00:00 2001 From: Henry Gabryjelski Date: Sun, 12 Apr 2020 17:20:03 -0700 Subject: [PATCH] Expose API for count of used/free channels --- cores/nRF5/HardwarePWM.cpp | 18 ++++++++++++++++++ cores/nRF5/HardwarePWM.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/cores/nRF5/HardwarePWM.cpp b/cores/nRF5/HardwarePWM.cpp index 881c054d..9caaa860 100644 --- a/cores/nRF5/HardwarePWM.cpp +++ b/cores/nRF5/HardwarePWM.cpp @@ -218,3 +218,21 @@ uint16_t HardwarePWM::readChannel(uint8_t ch) return (_seq0[ch] & 0x7FFF); } +uint8_t HardwarePWM::usedChannelCount(void) +{ + uint8_t usedChannels = 0; + for(int i=0; iPSEL.OUT[i] & PWM_PSEL_OUT_CONNECT_Msk ) + { + usedChannels++; + } + } + return usedChannels; +} + +uint8_t HardwarePWM::freeChannelCount(void) +{ + return MAX_CHANNELS - usedChannelCount(); +} + diff --git a/cores/nRF5/HardwarePWM.h b/cores/nRF5/HardwarePWM.h index bf2691e3..eaccff1f 100644 --- a/cores/nRF5/HardwarePWM.h +++ b/cores/nRF5/HardwarePWM.h @@ -96,6 +96,10 @@ class HardwarePWM // Read current set value uint16_t readPin (uint8_t pin); uint16_t readChannel (uint8_t ch); + + // Get count of used / free channels + uint8_t usedChannelCount(); + uint8_t freeChannelCount(); }; extern HardwarePWM HwPWM0;