From b90c21de1ced6b7a2729a77e1295c85d21627efc Mon Sep 17 00:00:00 2001 From: James Devine Date: Fri, 24 Feb 2017 10:22:51 +0000 Subject: [PATCH] microbit-dal: DynamicPWM now has a static period member variable Previously DynamicPWM had a per instance member variable that was not shared across all instances of DyanmicPWM which is not true to the hardware, that shares a period across all pwm channels. This commit adds a static member variable, and sets the default to 20000 us - a default set at the mbed layer. --- inc/drivers/DynamicPwm.h | 2 +- source/drivers/DynamicPwm.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/inc/drivers/DynamicPwm.h b/inc/drivers/DynamicPwm.h index 3290eec..441f048 100644 --- a/inc/drivers/DynamicPwm.h +++ b/inc/drivers/DynamicPwm.h @@ -40,7 +40,7 @@ DEALINGS IN THE SOFTWARE. class DynamicPwm : public PwmOut { private: - uint32_t period; + static uint32_t period; float lastValue; public: diff --git a/source/drivers/DynamicPwm.cpp b/source/drivers/DynamicPwm.cpp index 9e67aba..ac9d981 100644 --- a/source/drivers/DynamicPwm.cpp +++ b/source/drivers/DynamicPwm.cpp @@ -35,6 +35,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitPin.h" #include "ErrorNo.h" +uint32_t DynamicPwm::period = MICROBIT_DEFAULT_PWM_PERIOD; + /** * An internal constructor used when allocating a new DynamicPwm instance. * @@ -45,7 +47,6 @@ DEALINGS IN THE SOFTWARE. */ DynamicPwm::DynamicPwm(PinName pin) : PwmOut(pin) { - this->period = 0; } /** @@ -131,7 +132,7 @@ int DynamicPwm::getValue() */ uint32_t DynamicPwm::getPeriodUs() { - return period; + return this->period; } /**