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:
- 31:010a44d53627
- Parent:
- 30:f9ebc769118d
- Child:
- 32:6c0f43fda460
--- a/main.cpp Wed Aug 24 12:31:15 2016 +0000
+++ b/main.cpp Wed Aug 24 13:11:10 2016 +0000
@@ -258,11 +258,11 @@
statusLed = !statusLed;
}
-static volatile bool timer2_interrupted = false;
-void TIMER2_IRQHandler(void) {
- NRF_TIMER2->TASKS_CLEAR = 1;
- NRF_TIMER2->EVENTS_COMPARE[0] = 0;
- timer2_interrupted = 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;
}
@@ -284,6 +284,17 @@
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);
+
+
// 100kHz
i2c.frequency(100000);
@@ -304,23 +315,7 @@
while (1) {
if (pollCount > 0) {
printf("scan keys\r\n");
-
- /*
- // Setup timer for just wakeup from sleep
- NRF_TIMER2->TASKS_STOP = 1;
- NRF_TIMER2->PRESCALER = 4; // f = HFCLK / 2^N => 1MHz timer
- // TIMER2 is 16bit timer
- NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos;
- NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer << TIMER_MODE_MODE_Pos;
- NRF_TIMER2->CC[0] = 1e6 / 200; // 5ms
- NRF_TIMER2->EVENTS_COMPARE[0] = 0;
- NRF_TIMER2->TASKS_CLEAR = 1;
- NRF_TIMER2->INTENSET = 1;
- NVIC_SetPriority(TIMER2_IRQn, 3);
- NVIC_ClearPendingIRQ(TIMER2_IRQn);
- NVIC_EnableIRQ(TIMER2_IRQn);
- */
-
+
while (pollCount -- > 0) {
uint8_t (&keysCurr)[COLS] = state ? keysA : keysB;
uint8_t (&keysPrev)[COLS] = state ? keysB : keysA;
@@ -347,19 +342,21 @@
if (queue) HIDController::queueCurrentReportData();
- wait_ms(5);
-
- /*
- while (!timer2_interrupted) sleep();
- timer2_interrupted = false;
- */
+ // 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;
}
- /*
- NVIC_DisableIRQ(TIMER2_IRQn);
- NRF_TIMER2->TASKS_STOP = 1;
- NRF_TIMER2->TASKS_SHUTDOWN = 1;
- */
+ printf("disable int\r\n");
+ NRF_TIMER1->TASKS_SHUTDOWN = 1;
} else {
printf("[%s] wait for events...\r\n", HIDController::connected() ? "connected" : "disconnected");
@@ -389,4 +386,4 @@
}
}
}
-}
+}
\ No newline at end of file