From 1a65e4e7bc8a5e739336e29d1958c2adc9dda872 Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Sun, 1 Nov 2015 21:30:16 +0000 Subject: [PATCH] microbit: Added support for soft reset button in panic mode Also recalibrated loop timers in MicroBitDisplay::Error(), as used by panic()... strange these now seem off by several orders of magnitude. TODO: Ensure CPU is running at correct internal frequency with an oscilloscope test... --- source/MicroBitDisplay.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/source/MicroBitDisplay.cpp b/source/MicroBitDisplay.cpp index cbedd7d..1cd3bd3 100644 --- a/source/MicroBitDisplay.cpp +++ b/source/MicroBitDisplay.cpp @@ -976,6 +976,8 @@ void MicroBitDisplay::clear() */ void MicroBitDisplay::error(int statusCode) { + extern InterruptIn resetButton; + __disable_irq(); //stop ALL interrupts if(statusCode < 0 || statusCode > 255) @@ -1001,7 +1003,7 @@ void MicroBitDisplay::error(int statusCode) int outerCount = 0; //display the current character - while( outerCount < 100000) + while(outerCount < 500) { int coldata = 0; @@ -1033,11 +1035,17 @@ void MicroBitDisplay::error(int statusCode) nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, strobeBitMsk | (~coldata>>4 & 0x1F)); //set port 1 8-12 //set i to an obscene number. - i = 100000; + i = 1000; //burn cycles while(i>0) + { + // Check if the reset button has been pressed. Interrupts are disabled, so the normal method can't be relied upon... + if (resetButton == 0) + microbit_reset(); + i--; + } //update the bit mask and row count strobeBitMsk <<= 1;