Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 9d4f1a3

Browse files
committed
Merge pull request #54 from ARMmbed/portability-improvements
Make some portability improvements
2 parents 55b112f + 6fd6d8b commit 9d4f1a3

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

source/btn.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
* limitations under the License.
1616
*/
1717
#include "mbed-drivers/mbed.h"
18+
#include "minar/minar.h"
1819
#include "uvisor-lib/uvisor-lib.h"
1920
#include "btn.h"
2021
#include "main-hw.h"
2122
#include "box-challenge.h"
2223

24+
using mbed::util::FunctionPointer0;
25+
2326
InterruptIn btn(MAIN_BTN);
2427
extern Serial pc;
2528

@@ -33,10 +36,26 @@ static void btn_onpress(void)
3336
pc.printf(" done\n\r");
3437
}
3538

39+
static void btn_set_fall(void)
40+
{
41+
btn.fall(&btn_onpress);
42+
}
43+
3644
void btn_init(void)
3745
{
3846
/* configure pushbutton */
3947
btn.mode(MAIN_BTN_PUPD);
40-
wait(.01);
41-
btn.fall(&btn_onpress);
48+
49+
/* Register the button fall handler after a short delay. */
50+
minar::Scheduler::postCallback(FunctionPointer0<void>(btn_set_fall).bind())
51+
.delay(minar::milliseconds(10))
52+
.tolerance(minar::milliseconds(1));
53+
54+
/* Set a callback to do the equivalent of pushing the button for us. Every
55+
* period, press the button automatically. Pressing the button
56+
* automatically after a certain period of time allows us to trigger button
57+
* presses even for platforms without physically pressable buttons. */
58+
minar::Scheduler::postCallback(FunctionPointer0<void>(btn_onpress).bind())
59+
.period(minar::milliseconds(10000))
60+
.tolerance(minar::milliseconds(100));
4261
}

source/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ MAIN_ACL(g_main_acl);
3131
UVISOR_SET_MODE_ACL(UVISOR_ENABLED, g_main_acl);
3232

3333
DigitalOut led(MAIN_LED);
34-
Serial pc(USBTX, USBRX);
34+
Serial pc(STDIO_UART_TX, STDIO_UART_RX);
3535

3636
uint8_t g_challenge[CHALLENGE_SIZE];
3737
minar::Scheduler *g_scheduler;

0 commit comments

Comments
 (0)