Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed-dev nRF51822
Diff: main.cpp
- Revision:
- 36:78c211da4eb0
- Parent:
- 35:6a7fddfa14cf
- Child:
- 37:4ce71fa47fc3
--- a/main.cpp Thu Aug 25 15:24:19 2016 +0000
+++ b/main.cpp Thu Aug 25 15:33:42 2016 +0000
@@ -281,11 +281,9 @@
updateStatudLedEnabled = true;
}
-static volatile bool timer1_interrupted = false;
-extern "C" void TIMER1_IRQHandler(void) {
- NRF_TIMER1->EVENTS_COMPARE[0] = 0;
- NRF_TIMER1->TASKS_CLEAR = 1;
- timer1_interrupted = true;
+static volatile bool keyIntervalInterrupt = false;
+void wakeupKeyIntervalSleep() {
+ keyIntervalInterrupt = true;
}
class WatchDog {
@@ -330,20 +328,10 @@
NRF_UART0->PSELRTS = 0xFFFFFFFFUL;
NRF_UART0->PSELCTS = 0xFFFFFFFFUL;
- // Setup timer for just wakeup from sleep
- NRF_TIMER1->TASKS_STOP = 1;
- NRF_TIMER1->PRESCALER = 4; // f = HFCLK / 2^N => 1MHz timer
- // TIMER1 is 16bit timer
- NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos;
- NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer << TIMER_MODE_MODE_Pos;
- NVIC_SetPriority(TIMER1_IRQn, 3);
- NVIC_ClearPendingIRQ(TIMER1_IRQn);
- NVIC_EnableIRQ(TIMER1_IRQn);
-
WatchDog::init();
// 100kHz
- i2c.frequency(100000);
+ i2c.frequency(250000);
buttonInt.mode(PullUp);
buttonInt.fall(buttonIntCallback);
@@ -395,19 +383,12 @@
// wait_ms(5); is busy loop
// use timer1 to use wait 5ms
- NRF_TIMER1->CC[0] = 1e6 / 200; // 5ms
- NRF_TIMER1->EVENTS_COMPARE[0] = 0;
- NRF_TIMER1->TASKS_CLEAR = 1;
- NRF_TIMER1->INTENSET = TIMER_INTENSET_COMPARE0_Set << TIMER_INTENSET_COMPARE0_Pos;
- NRF_TIMER1->TASKS_START = 1;
- while (!timer1_interrupted) sleep();
- timer1_interrupted = false;
- NRF_TIMER1->INTENCLR = TIMER_INTENCLR_COMPARE0_Clear << TIMER_INTENCLR_COMPARE0_Pos;
- NRF_TIMER1->TASKS_STOP = 1;
+ timeout.attach_us(wakeupKeyIntervalSleep, 5000);
+ keyIntervalInterrupt = false;
+ while (!keyIntervalInterrupt) sleep();
}
printf("disable int\r\n");
- NRF_TIMER1->TASKS_SHUTDOWN = 1;
} else {
if (!updateStatudLedEnabled) updateStatusLed();
printf("[%d:%s] wait for events...\r\n", HIDController::status(), HIDController::statusString());