2015-08-12 10:53:41 +00:00
|
|
|
#include "MicroBit.h"
|
2015-08-31 22:25:10 +00:00
|
|
|
#include "MicroBitPin.h"
|
2015-08-12 10:53:41 +00:00
|
|
|
|
|
|
|
/**
|
2016-01-09 18:46:52 +00:00
|
|
|
* Constructor.
|
2015-08-12 10:53:41 +00:00
|
|
|
* Create a Button representation with the given ID.
|
|
|
|
* @param id the ID of the new Pin object.
|
|
|
|
* @param name the pin name for this MicroBitPin instance to represent
|
|
|
|
* @param capability the capability of this pin, can it only be digital? can it only be analog? can it be both?
|
2016-01-09 18:46:52 +00:00
|
|
|
*
|
2015-08-12 10:53:41 +00:00
|
|
|
* Example:
|
2016-01-09 18:46:52 +00:00
|
|
|
* @code
|
2015-08-12 10:53:41 +00:00
|
|
|
* MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH);
|
|
|
|
* @endcode
|
|
|
|
*/
|
2016-01-09 18:46:52 +00:00
|
|
|
MicroBitPin::MicroBitPin(int id, PinName name, PinCapability capability)
|
|
|
|
{
|
|
|
|
//set mandatory attributes
|
2015-08-12 10:53:41 +00:00
|
|
|
this->id = id;
|
|
|
|
this->name = name;
|
|
|
|
this->capability = capability;
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
// Power up in a disconnected, low power state.
|
|
|
|
// If we're unused, this is how it will stay...
|
|
|
|
this->status = 0x00;
|
|
|
|
this->pin = NULL;
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnect any attached mbed IO from this pin.
|
|
|
|
* Used only when pin changes mode (i.e. Input/Output/Analog/Digital)
|
|
|
|
*/
|
|
|
|
void MicroBitPin::disconnect()
|
|
|
|
{
|
|
|
|
// This is a bit ugly, but rarely used code.
|
|
|
|
// It would be much better to use some polymorphism here, but the mBed I/O classes aren't arranged in an inheritance hierarchy... yet. :-)
|
|
|
|
if (status & IO_STATUS_DIGITAL_IN)
|
|
|
|
delete ((DigitalIn *)pin);
|
|
|
|
|
|
|
|
if (status & IO_STATUS_DIGITAL_OUT)
|
|
|
|
delete ((DigitalOut *)pin);
|
|
|
|
|
|
|
|
if (status & IO_STATUS_ANALOG_IN){
|
|
|
|
NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Disabled; // forcibly disable the ADC - BUG in mbed....
|
|
|
|
delete ((AnalogIn *)pin);
|
|
|
|
}
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
if (status & IO_STATUS_ANALOG_OUT)
|
|
|
|
{
|
|
|
|
if(((DynamicPwm *)pin)->getPinName() == name)
|
2016-01-09 18:46:52 +00:00
|
|
|
((DynamicPwm *)pin)->release();
|
|
|
|
}
|
2015-08-12 10:53:41 +00:00
|
|
|
|
|
|
|
if (status & IO_STATUS_TOUCH_IN)
|
|
|
|
delete ((MicroBitButton *)pin);
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
this->pin = NULL;
|
|
|
|
this->status = status & IO_STATUS_EVENTBUS_ENABLED; //retain event bus status
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configures this IO pin as a digital output (if necessary) and sets the pin to 'value'.
|
|
|
|
* @param value 0 (LO) or 1 (HI)
|
2016-01-09 18:46:52 +00:00
|
|
|
*
|
2015-08-12 10:53:41 +00:00
|
|
|
* Example:
|
2016-01-09 18:46:52 +00:00
|
|
|
* @code
|
2015-08-12 10:53:41 +00:00
|
|
|
* MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH);
|
2015-10-25 21:51:33 +00:00
|
|
|
* P0.setDigitalValue(1); // P0 is now HI
|
|
|
|
* @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range, or MICROBIT_NOT_SUPPORTED
|
|
|
|
* if the given pin does not have digital capability.
|
2015-08-12 10:53:41 +00:00
|
|
|
* @endcode
|
|
|
|
*/
|
2015-10-25 21:51:33 +00:00
|
|
|
int MicroBitPin::setDigitalValue(int value)
|
2015-08-12 10:53:41 +00:00
|
|
|
{
|
2015-10-25 21:51:33 +00:00
|
|
|
// Check if this pin has a digital mode...
|
|
|
|
if(!(PIN_CAPABILITY_DIGITAL & capability))
|
|
|
|
return MICROBIT_NOT_SUPPORTED;
|
|
|
|
|
|
|
|
// Ensure we have a valid value.
|
|
|
|
if (value < 0 || value > 1)
|
|
|
|
return MICROBIT_INVALID_PARAMETER;
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
// Move into a Digital input state if necessary.
|
|
|
|
if (!(status & IO_STATUS_DIGITAL_OUT)){
|
2016-01-09 18:46:52 +00:00
|
|
|
disconnect();
|
2015-08-12 10:53:41 +00:00
|
|
|
pin = new DigitalOut(name);
|
|
|
|
status |= IO_STATUS_DIGITAL_OUT;
|
|
|
|
}
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-10-25 21:51:33 +00:00
|
|
|
// Write the value.
|
2015-08-12 10:53:41 +00:00
|
|
|
((DigitalOut *)pin)->write(value);
|
2015-10-25 21:51:33 +00:00
|
|
|
|
|
|
|
return MICROBIT_OK;
|
2015-08-12 10:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configures this IO pin as a digital input (if necessary) and tests its current value.
|
2015-10-25 21:51:33 +00:00
|
|
|
* @return 1 if this input is high, 0 if input is LO, or MICROBIT_NOT_SUPPORTED if the given pin does not have analog capability.
|
2016-01-09 18:46:52 +00:00
|
|
|
*
|
2015-08-12 10:53:41 +00:00
|
|
|
* Example:
|
2016-01-09 18:46:52 +00:00
|
|
|
* @code
|
2015-08-12 10:53:41 +00:00
|
|
|
* MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH);
|
|
|
|
* P0.getDigitalValue(); // P0 is either 0 or 1;
|
|
|
|
* @endcode
|
|
|
|
*/
|
|
|
|
int MicroBitPin::getDigitalValue()
|
|
|
|
{
|
|
|
|
//check if this pin has a digital mode...
|
|
|
|
if(!(PIN_CAPABILITY_DIGITAL & capability))
|
2015-10-25 21:51:33 +00:00
|
|
|
return MICROBIT_NOT_SUPPORTED;
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
// Move into a Digital input state if necessary.
|
|
|
|
if (!(status & IO_STATUS_DIGITAL_IN)){
|
2016-01-09 18:46:52 +00:00
|
|
|
disconnect();
|
|
|
|
pin = new DigitalIn(name,PullDown);
|
2015-08-12 10:53:41 +00:00
|
|
|
status |= IO_STATUS_DIGITAL_IN;
|
|
|
|
}
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
return ((DigitalIn *)pin)->read();
|
|
|
|
}
|
|
|
|
|
2016-01-12 20:30:53 +00:00
|
|
|
int MicroBitPin::obtainAnalogChannel()
|
|
|
|
{
|
|
|
|
// Move into an analogue input state if necessary, if we are no longer the focus of a DynamicPWM instance, allocate ourselves again!
|
|
|
|
if (!(status & IO_STATUS_ANALOG_OUT) || !(((DynamicPwm *)pin)->getPinName() == name)){
|
|
|
|
disconnect();
|
|
|
|
pin = (void *)DynamicPwm::allocate(name);
|
|
|
|
status |= IO_STATUS_ANALOG_OUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MICROBIT_OK;
|
|
|
|
}
|
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
/**
|
2015-10-25 21:51:33 +00:00
|
|
|
* Configures this IO pin as an analog/pwm output, and change the output value to the given level.
|
2016-01-12 20:30:53 +00:00
|
|
|
* @param value the level to set on the output pin, in the range 0 - 1023
|
2015-10-25 21:51:33 +00:00
|
|
|
* @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range, or MICROBIT_NOT_SUPPORTED
|
|
|
|
* if the given pin does not have analog capability.
|
|
|
|
*/
|
|
|
|
int MicroBitPin::setAnalogValue(int value)
|
2015-08-12 10:53:41 +00:00
|
|
|
{
|
|
|
|
//check if this pin has an analogue mode...
|
|
|
|
if(!(PIN_CAPABILITY_ANALOG & capability))
|
2015-10-25 21:51:33 +00:00
|
|
|
return MICROBIT_NOT_SUPPORTED;
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2016-01-12 20:30:53 +00:00
|
|
|
//sanitise the level value
|
2015-08-12 10:53:41 +00:00
|
|
|
if(value < 0 || value > MICROBIT_PIN_MAX_OUTPUT)
|
2015-10-25 21:51:33 +00:00
|
|
|
return MICROBIT_INVALID_PARAMETER;
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
float level = (float)value / float(MICROBIT_PIN_MAX_OUTPUT);
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2016-01-12 20:30:53 +00:00
|
|
|
//obtain use of the DynamicPwm instance, if it has changed / configure if we do not have one
|
|
|
|
if(obtainAnalogChannel() == MICROBIT_OK)
|
2016-01-09 19:52:46 +00:00
|
|
|
return ((DynamicPwm *)pin)->write(level);
|
2015-10-25 21:51:33 +00:00
|
|
|
|
|
|
|
return MICROBIT_OK;
|
2015-08-12 10:53:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 20:30:53 +00:00
|
|
|
/**
|
|
|
|
* Configures this IO pin as an analog/pwm output if it isn't already, configures the period to be 20ms,
|
2016-03-07 13:59:24 +00:00
|
|
|
* and sets the duty cycle between 500 us and 2500 us.
|
2016-01-12 20:30:53 +00:00
|
|
|
*
|
2016-03-07 13:59:24 +00:00
|
|
|
* A value of 180 sets the duty cycle to be 2500us, and a value of 0 sets the duty cycle to be 500us by default.
|
2016-01-12 20:30:53 +00:00
|
|
|
*
|
|
|
|
* This range can be modified to fine tune, and also tolerate different servos.
|
|
|
|
*
|
|
|
|
* @param value the level to set on the output pin, in the range 0 - 180
|
2016-03-07 13:59:24 +00:00
|
|
|
* @param range which gives the span of possible values the i.e. lower and upper bounds center +/- range/2 (Defaults to: MICROBIT_PIN_DEFAULT_SERVO_RANGE)
|
2016-01-12 20:30:53 +00:00
|
|
|
* @param center the center point from which to calculate the lower and upper bounds (Defaults to: MICROBIT_PIN_DEFAULT_SERVO_CENTER)
|
|
|
|
* @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range, or MICROBIT_NOT_SUPPORTED
|
|
|
|
* if the given pin does not have analog capability.
|
|
|
|
*/
|
|
|
|
int MicroBitPin::setServoValue(int value, int range, int center)
|
|
|
|
{
|
|
|
|
//check if this pin has an analogue mode...
|
|
|
|
if(!(PIN_CAPABILITY_ANALOG & capability))
|
|
|
|
return MICROBIT_NOT_SUPPORTED;
|
|
|
|
|
|
|
|
//sanitise the servo level
|
|
|
|
if(value < 0 || range < 1 || center < 1)
|
|
|
|
return MICROBIT_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
//clip - just in case
|
|
|
|
if(value > MICROBIT_PIN_MAX_SERVO_RANGE)
|
|
|
|
value = MICROBIT_PIN_MAX_SERVO_RANGE;
|
|
|
|
|
|
|
|
//calculate the lower bound based on the midpoint
|
|
|
|
int lower = (center - (range / 2)) * 1000;
|
|
|
|
|
|
|
|
value = value * 1000;
|
|
|
|
|
|
|
|
//add the percentage of the range based on the value between 0 and 180
|
|
|
|
int scaled = lower + (range * (value / MICROBIT_PIN_MAX_SERVO_RANGE));
|
|
|
|
|
|
|
|
return setServoPulseUs(scaled / 1000);
|
|
|
|
}
|
2015-08-12 10:53:41 +00:00
|
|
|
|
|
|
|
/**
|
2015-10-25 21:51:33 +00:00
|
|
|
* Configures this IO pin as an analogue input (if necessary and possible).
|
|
|
|
* @return the current analogue level on the pin, in the range 0 - 1024, or MICROBIT_NOT_SUPPORTED if the given pin does not have analog capability.
|
2016-01-09 18:46:52 +00:00
|
|
|
*
|
2015-10-25 21:51:33 +00:00
|
|
|
* Example:
|
2016-01-09 18:46:52 +00:00
|
|
|
* @code
|
2015-10-25 21:51:33 +00:00
|
|
|
* MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH);
|
|
|
|
* P0.getAnalogValue(); // P0 is a value in the range of 0 - 1024
|
|
|
|
* @endcode
|
|
|
|
*/
|
2015-08-12 10:53:41 +00:00
|
|
|
int MicroBitPin::getAnalogValue()
|
|
|
|
{
|
|
|
|
//check if this pin has an analogue mode...
|
|
|
|
if(!(PIN_CAPABILITY_ANALOG & capability))
|
2015-10-25 21:51:33 +00:00
|
|
|
return MICROBIT_NOT_SUPPORTED;
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
// Move into an analogue input state if necessary.
|
|
|
|
if (!(status & IO_STATUS_ANALOG_IN)){
|
2016-01-09 18:46:52 +00:00
|
|
|
disconnect();
|
2015-08-12 10:53:41 +00:00
|
|
|
pin = new AnalogIn(name);
|
|
|
|
status |= IO_STATUS_ANALOG_IN;
|
|
|
|
}
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
//perform a read!
|
|
|
|
return ((AnalogIn *)pin)->read_u16();
|
|
|
|
}
|
|
|
|
|
2015-09-22 15:13:08 +00:00
|
|
|
/**
|
|
|
|
* Determines if this IO pin is currently configured as an input.
|
|
|
|
* @return 1 if pin is an analog or digital input, 0 otherwise.
|
|
|
|
*/
|
|
|
|
int MicroBitPin::isInput()
|
|
|
|
{
|
|
|
|
return (status & (IO_STATUS_DIGITAL_IN | IO_STATUS_ANALOG_IN)) == 0 ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if this IO pin is currently configured as an output.
|
|
|
|
* @return 1 if pin is an analog or digital output, 0 otherwise.
|
|
|
|
*/
|
|
|
|
int MicroBitPin::isOutput()
|
|
|
|
{
|
|
|
|
return (status & (IO_STATUS_DIGITAL_OUT | IO_STATUS_ANALOG_OUT)) == 0 ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if this IO pin is currently configured for digital use.
|
|
|
|
* @return 1 if pin is digital, 0 otherwise.
|
|
|
|
*/
|
|
|
|
int MicroBitPin::isDigital()
|
|
|
|
{
|
|
|
|
return (status & (IO_STATUS_DIGITAL_IN | IO_STATUS_DIGITAL_OUT)) == 0 ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if this IO pin is currently configured for analog use.
|
|
|
|
* @return 1 if pin is analog, 0 otherwise.
|
|
|
|
*/
|
|
|
|
int MicroBitPin::isAnalog()
|
|
|
|
{
|
|
|
|
return (status & (IO_STATUS_ANALOG_IN | IO_STATUS_ANALOG_OUT)) == 0 ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
/**
|
|
|
|
* Configures this IO pin as a makey makey style touch sensor (if necessary) and tests its current debounced state.
|
2015-10-25 21:51:33 +00:00
|
|
|
* @return 1 if pin is touched, 0 if not, or MICROBIT_NOT_SUPPORTED if this pin does not support touch capability.
|
2016-01-09 18:46:52 +00:00
|
|
|
*
|
2015-08-12 10:53:41 +00:00
|
|
|
* Example:
|
2016-01-09 18:46:52 +00:00
|
|
|
* @code
|
2015-08-12 10:53:41 +00:00
|
|
|
* MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_ALL);
|
|
|
|
* if(P0.isTouched())
|
|
|
|
* {
|
|
|
|
* uBit.display.clear();
|
2016-01-09 18:46:52 +00:00
|
|
|
* }
|
2015-08-12 10:53:41 +00:00
|
|
|
* @endcode
|
|
|
|
*/
|
|
|
|
int MicroBitPin::isTouched()
|
|
|
|
{
|
|
|
|
//check if this pin has a touch mode...
|
|
|
|
if(!(PIN_CAPABILITY_TOUCH & capability))
|
2015-10-25 21:51:33 +00:00
|
|
|
return MICROBIT_NOT_SUPPORTED;
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
// Move into a touch input state if necessary.
|
|
|
|
if (!(status & IO_STATUS_TOUCH_IN)){
|
2016-01-09 18:46:52 +00:00
|
|
|
disconnect();
|
|
|
|
pin = new MicroBitButton(id, name);
|
2015-08-12 10:53:41 +00:00
|
|
|
status |= IO_STATUS_TOUCH_IN;
|
|
|
|
}
|
2016-01-09 18:46:52 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
return ((MicroBitButton *)pin)->isPressed();
|
|
|
|
}
|
|
|
|
|
2016-01-12 20:30:53 +00:00
|
|
|
/**
|
|
|
|
* Configures this IO pin as an analog/pwm output if it isn't already, configures the period to be 20ms,
|
|
|
|
* and sets the pulse width, based on the value it is given
|
|
|
|
*
|
|
|
|
* @param pulseWidth the desired pulse width in microseconds.
|
|
|
|
* @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range, or MICROBIT_NOT_SUPPORTED
|
|
|
|
* if the given pin does not have analog capability.
|
|
|
|
*/
|
|
|
|
int MicroBitPin::setServoPulseUs(int pulseWidth)
|
|
|
|
{
|
|
|
|
//check if this pin has an analogue mode...
|
|
|
|
if(!(PIN_CAPABILITY_ANALOG & capability))
|
|
|
|
return MICROBIT_NOT_SUPPORTED;
|
|
|
|
|
|
|
|
//sanitise the pulse width
|
|
|
|
if(pulseWidth < 0)
|
|
|
|
return MICROBIT_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
//Check we still have the control over the DynamicPwm instance
|
|
|
|
if(obtainAnalogChannel() == MICROBIT_OK)
|
|
|
|
{
|
|
|
|
//check if the period is set to 20ms
|
|
|
|
if(((DynamicPwm *)pin)->getPeriodUs() != MICROBIT_DEFAULT_PWM_PERIOD)
|
|
|
|
((DynamicPwm *)pin)->setPeriodUs(MICROBIT_DEFAULT_PWM_PERIOD);
|
|
|
|
|
|
|
|
((DynamicPwm *)pin)->pulsewidth_us(pulseWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
return MICROBIT_OK;
|
|
|
|
}
|
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
/**
|
|
|
|
* Configures the PWM period of the analog output to the given value.
|
|
|
|
*
|
2015-09-16 18:46:39 +00:00
|
|
|
* @param period The new period for the analog output in microseconds.
|
2016-01-09 18:46:52 +00:00
|
|
|
* @return MICROBIT_OK on success, or MICROBIT_NOT_SUPPORTED if the
|
2015-10-25 21:51:33 +00:00
|
|
|
* given pin is not configured as an analog output.
|
2015-09-16 18:46:39 +00:00
|
|
|
*/
|
2015-10-25 21:51:33 +00:00
|
|
|
int MicroBitPin::setAnalogPeriodUs(int period)
|
2015-08-12 10:53:41 +00:00
|
|
|
{
|
2015-10-25 21:51:33 +00:00
|
|
|
if (!(status & IO_STATUS_ANALOG_OUT))
|
|
|
|
return MICROBIT_NOT_SUPPORTED;
|
|
|
|
|
2016-01-09 19:52:46 +00:00
|
|
|
return ((DynamicPwm *)pin)->setPeriodUs(period);
|
2015-09-16 18:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-25 21:51:33 +00:00
|
|
|
* Configures the PWM period of the analog output to the given value.
|
|
|
|
*
|
|
|
|
* @param period The new period for the analog output in microseconds.
|
2016-01-09 18:46:52 +00:00
|
|
|
* @return MICROBIT_OK on success, or MICROBIT_NOT_SUPPORTED if the
|
2015-10-25 21:51:33 +00:00
|
|
|
* given pin is not configured as an analog output.
|
2016-01-09 18:46:52 +00:00
|
|
|
*/
|
2015-10-25 21:51:33 +00:00
|
|
|
int MicroBitPin::setAnalogPeriod(int period)
|
2015-09-16 18:46:39 +00:00
|
|
|
{
|
2015-10-25 21:51:33 +00:00
|
|
|
return setAnalogPeriodUs(period*1000);
|
2015-08-12 10:53:41 +00:00
|
|
|
}
|
2016-01-09 19:52:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the PWM period of the analog output.
|
|
|
|
*
|
|
|
|
* @return the period on success, or MICROBIT_NOT_SUPPORTED if the
|
|
|
|
* given pin is not configured as an analog output.
|
|
|
|
*/
|
|
|
|
int MicroBitPin::getAnalogPeriodUs()
|
|
|
|
{
|
|
|
|
if (!(status & IO_STATUS_ANALOG_OUT))
|
|
|
|
return MICROBIT_NOT_SUPPORTED;
|
|
|
|
|
|
|
|
return ((DynamicPwm *)pin)->getPeriodUs();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the PWM period of the analog output.
|
|
|
|
*
|
|
|
|
* @return the period on success, or MICROBIT_NOT_SUPPORTED if the
|
|
|
|
* given pin is not configured as an analog output.
|
|
|
|
*/
|
|
|
|
int MicroBitPin::getAnalogPeriod()
|
|
|
|
{
|
|
|
|
return getAnalogPeriodUs()/1000;
|
|
|
|
}
|