From 315844520811268cda7f7acca645ded410837141 Mon Sep 17 00:00:00 2001 From: Jonathan Protzenko Date: Wed, 16 Sep 2015 11:46:39 -0700 Subject: [PATCH] New setAnalogPeriodUs function. Fixes bbc/microbit-extras#1389. --- inc/MicroBitPin.h | 5 +++++ source/MicroBitPin.cpp | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/inc/MicroBitPin.h b/inc/MicroBitPin.h index e4ba2fd..a6381e1 100644 --- a/inc/MicroBitPin.h +++ b/inc/MicroBitPin.h @@ -154,6 +154,11 @@ class MicroBitPin : public MicroBitComponent * @param period The new period for the analog output in milliseconds. */ void setAnalogPeriod(int period); + + /** + * Same thing as setAnalogPeriodUs, but with microseconds. + */ + void setAnalogPeriodUs(int period); }; #endif diff --git a/source/MicroBitPin.cpp b/source/MicroBitPin.cpp index 9d03e8c..17302a5 100644 --- a/source/MicroBitPin.cpp +++ b/source/MicroBitPin.cpp @@ -205,11 +205,18 @@ int MicroBitPin::isTouched() * If this pin is not configured as an analog output, the operation * has no effect. * - * @param period The new period for the analog output in milliseconds. - */ -void MicroBitPin::setAnalogPeriod(int period) + * @param period The new period for the analog output in microseconds. + */ +void MicroBitPin::setAnalogPeriodUs(int period) { if (status & IO_STATUS_ANALOG_OUT) - ((DynamicPwm *)pin)->setPeriodUs(period*1000); - + ((DynamicPwm *)pin)->setPeriodUs(period); +} + +/** + * Same thing as setAnalogPeriodUs, but with milliseconds. + */ +void MicroBitPin::setAnalogPeriod(int period) +{ + setAnalogPeriodUs(period*1000); }