2015-08-12 10:53:41 +00:00
|
|
|
#include "MicroBit.h"
|
|
|
|
|
|
|
|
MicroBit uBit;
|
|
|
|
InterruptIn resetButton(MICROBIT_PIN_BUTTON_RESET);
|
|
|
|
|
2015-10-18 13:46:42 +00:00
|
|
|
extern char* MICROBIT_BLE_DEVICE_NAME;
|
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// Bring up soft reset button.
|
|
|
|
resetButton.mode(PullUp);
|
2015-09-17 22:32:40 +00:00
|
|
|
resetButton.fall(microbit_reset);
|
2016-01-05 01:25:52 +00:00
|
|
|
|
2015-09-02 11:42:24 +00:00
|
|
|
#if CONFIG_ENABLED(MICROBIT_DBG)
|
2015-10-08 13:37:35 +00:00
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
// For diagnostics. Gives time to open the console window. :-)
|
2015-08-31 22:25:10 +00:00
|
|
|
for (int i=3; i>0; i--)
|
2015-08-12 10:53:41 +00:00
|
|
|
{
|
2015-11-01 23:42:53 +00:00
|
|
|
uBit.serial.printf("=== SUPERMAIN: Starting in %d ===\n", i);
|
2015-08-12 10:53:41 +00:00
|
|
|
wait(1.0);
|
|
|
|
}
|
2015-10-08 13:37:35 +00:00
|
|
|
|
2015-11-01 23:42:53 +00:00
|
|
|
uBit.serial.printf("micro:bit runtime DAL version %s\n", MICROBIT_DAL_VERSION);
|
2015-10-08 13:37:35 +00:00
|
|
|
|
2015-08-31 22:25:10 +00:00
|
|
|
#endif
|
2015-08-12 10:53:41 +00:00
|
|
|
|
2015-08-31 22:25:10 +00:00
|
|
|
// Bring up our nested heap allocator.
|
|
|
|
microbit_heap_init();
|
2015-08-12 10:53:41 +00:00
|
|
|
|
|
|
|
// Bring up fiber scheduler
|
|
|
|
scheduler_init();
|
2016-01-05 01:25:52 +00:00
|
|
|
|
2015-08-31 22:25:10 +00:00
|
|
|
// Bring up random number generator, BLE, display and system timers.
|
2015-08-12 10:53:41 +00:00
|
|
|
uBit.init();
|
2015-08-31 22:25:10 +00:00
|
|
|
|
|
|
|
// Provide time for all threaded initialisers to complete.
|
2015-08-12 10:53:41 +00:00
|
|
|
uBit.sleep(100);
|
2015-08-12 23:49:48 +00:00
|
|
|
|
2015-12-11 03:43:18 +00:00
|
|
|
#if CONFIG_ENABLED(MICROBIT_BLE_PAIRING_MODE)
|
2015-08-12 10:53:41 +00:00
|
|
|
// Test if we need to enter BLE pairing mode...
|
|
|
|
int i=0;
|
|
|
|
while (uBit.buttonA.isPressed() && uBit.buttonB.isPressed() && i<10)
|
|
|
|
{
|
|
|
|
uBit.sleep(100);
|
|
|
|
i++;
|
2016-01-05 01:25:52 +00:00
|
|
|
|
2015-08-31 22:25:10 +00:00
|
|
|
if (i == 10)
|
|
|
|
{
|
2016-01-25 20:41:16 +00:00
|
|
|
// Start the BLE stack, if it isn't already running.
|
2015-08-31 22:25:10 +00:00
|
|
|
if (!uBit.ble)
|
2016-01-25 20:41:16 +00:00
|
|
|
{
|
|
|
|
uBit.bleManager.init(uBit.getName(), uBit.getSerial(), true);
|
|
|
|
uBit.ble = uBit.bleManager.ble;
|
|
|
|
}
|
2015-10-19 13:42:13 +00:00
|
|
|
|
2015-12-11 03:43:18 +00:00
|
|
|
// Enter pairing mode, using the LED matrix for any necessary pairing operations
|
2016-01-05 01:25:52 +00:00
|
|
|
uBit.bleManager.pairingMode(uBit.display);
|
2015-08-31 22:25:10 +00:00
|
|
|
}
|
2015-08-12 10:53:41 +00:00
|
|
|
}
|
2015-08-12 23:49:48 +00:00
|
|
|
#endif
|
2016-01-05 01:25:52 +00:00
|
|
|
|
2016-01-25 20:41:16 +00:00
|
|
|
#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED)
|
|
|
|
// Start the BLE stack, if it isn't already running.
|
|
|
|
if (!uBit.ble)
|
|
|
|
{
|
|
|
|
uBit.bleManager.init(uBit.getName(), uBit.getSerial(), false);
|
|
|
|
uBit.ble = uBit.bleManager.ble;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-08-12 10:53:41 +00:00
|
|
|
app_main();
|
|
|
|
|
2015-08-31 22:25:10 +00:00
|
|
|
// If app_main exits, there may still be other fibers running, registered event handlers etc.
|
|
|
|
// Simply release this fiber, which will mean we enter the scheduler. Worse case, we then
|
|
|
|
// sit in the idle task forever, in a power efficient sleep.
|
|
|
|
release_fiber();
|
2016-01-05 01:25:52 +00:00
|
|
|
|
2015-08-31 22:25:10 +00:00
|
|
|
// We should never get here, but just in case.
|
|
|
|
while(1);
|
2015-08-12 10:53:41 +00:00
|
|
|
}
|