New setAnalogPeriodUs function.

Fixes bbc/microbit-extras#1389.
This commit is contained in:
Jonathan Protzenko 2015-09-16 11:46:39 -07:00
parent a17830030e
commit 3158445208
2 changed files with 17 additions and 5 deletions

View file

@ -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

View file

@ -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);
}