microbit-dal: added a reset mechanism to uBit
Users can now call uBit.reset() to reset the device.
This commit is contained in:
parent
d7b3ba9dab
commit
3ef5901c5b
3 changed files with 28 additions and 2 deletions
|
@ -21,6 +21,9 @@
|
|||
*/
|
||||
void panic(int statusCode);
|
||||
|
||||
void reset(int statusCode);
|
||||
|
||||
|
||||
#include "MicroBitMalloc.h"
|
||||
#include "MicroBitCompat.h"
|
||||
#include "MicroBitFiber.h"
|
||||
|
@ -187,6 +190,16 @@ class MicroBit
|
|||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Will reset the micro:bit when called.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* uBit.reset();
|
||||
* @endcode
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Delay for the given amount of time.
|
||||
* If the scheduler is running, this will deschedule the current fiber and perform
|
||||
|
|
|
@ -119,6 +119,19 @@ void MicroBit::init()
|
|||
systemTicker.attach(this, &MicroBit::systemTick, MICROBIT_DISPLAY_REFRESH_PERIOD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will reset the micro:bit when called.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* uBit.reset();
|
||||
* @endcode
|
||||
*/
|
||||
void MicroBit::reset()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delay for the given amount of time.
|
||||
* If the scheduler is running, this will deschedule the current fiber and perform
|
||||
|
|
|
@ -8,7 +8,7 @@ MicroBit uBit;
|
|||
InterruptIn resetButton(MICROBIT_PIN_BUTTON_RESET);
|
||||
|
||||
void
|
||||
onResetButtonPressed()
|
||||
reset()
|
||||
{
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ int main()
|
|||
{
|
||||
// Bring up soft reset button.
|
||||
resetButton.mode(PullUp);
|
||||
resetButton.fall(onResetButtonPressed);
|
||||
resetButton.fall(reset);
|
||||
|
||||
#ifdef MICROBIT_DBG
|
||||
pc.baud(115200);
|
||||
|
|
Loading…
Reference in a new issue