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:
- 35:6a7fddfa14cf
- Parent:
- 34:7da766a8aa96
- Child:
- 36:78c211da4eb0
--- a/main.cpp Thu Aug 25 12:57:48 2016 +0000
+++ b/main.cpp Thu Aug 25 15:24:19 2016 +0000
@@ -228,14 +228,21 @@
// Unsed pins. Set to output for power consumption
+
+// Pad pinout
+/*
DigitalIn unused_p0_7(P0_7, PullUp);
DigitalIn unused_p0_6(P0_6, PullUp);
DigitalIn unused_p0_15(P0_15, PullUp);
DigitalIn unused_p0_29(P0_29, PullUp);
DigitalIn unused_p0_28(P0_28, PullUp);
+*/
+
DigitalIn unused_p0_19(P0_19, PullUp); // This is on board LED which connected to VDD
DigitalIn unused_p0_11(P0_11, PullUp); // RXD
+Timeout timeout;
+
// ROWS=8
// COLS=16
// 列ごとに1バイトにパックしてキーの状態を保持する
@@ -261,6 +268,19 @@
statusLed = !statusLed;
}
+static bool updateStatudLedEnabled = false;
+void updateStatusLed() {
+ switch (HIDController::status()) {
+ case TIMEOUT:
+ case DISCONNECTED: timeout.attach(updateStatusLed, statusLed ? 3 : 0.1); break;
+ case ADVERTISING:
+ case CONNECTING: timeout.attach(updateStatusLed, statusLed ? 0.5 : 0.1); break;
+ case CONNECTED: statusLed = 0; updateStatudLedEnabled = false; return;
+ }
+ statusLed = !statusLed;
+ updateStatudLedEnabled = true;
+}
+
static volatile bool timer1_interrupted = false;
extern "C" void TIMER1_IRQHandler(void) {
NRF_TIMER1->EVENTS_COMPARE[0] = 0;
@@ -284,18 +304,17 @@
static void reload() {
NRF_WDT->RR[0] = RELOAD_VALUE;
}
+
};
+
int main(void) {
{
uint32_t reason = NRF_POWER->RESETREAS;
NRF_POWER->RESETREAS = 0xffffffff; // clear reason
printf("init [%x]\r\n", reason);
}
-
-
-
-
+
// Enable Pin-reset on DEBUG mode
// This makes possiable booting without normal mode easily.
NRF_POWER->RESET = 1;
@@ -339,9 +358,10 @@
// Disable TWI by default.
NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
-
+
while (1) {
WatchDog::reload();
+
if (pollCount > 0) {
printf("scan keys\r\n");
@@ -369,7 +389,8 @@
}
}
state = !state;
-
+
+
if (queue) HIDController::queueCurrentReportData();
// wait_ms(5); is busy loop
@@ -388,6 +409,7 @@
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());
// allow printf in some interrupts while connecting