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:
- 23:b31957ce64e9
- Parent:
- 22:a78f0a91280a
- Child:
- 25:094df0d9e95b
diff -r a78f0a91280a -r b31957ce64e9 main.cpp
--- a/main.cpp Mon Aug 22 15:24:34 2016 +0000
+++ b/main.cpp Mon Aug 22 17:34:10 2016 +0000
@@ -15,6 +15,7 @@
*/
#include "mbed.h"
+#include "Timeout.h"
#include "HIDController_BLE.h"
@@ -229,7 +230,6 @@
DigitalIn unused_p0_19(P0_19, PullUp); // This is on board LED which connected to VDD
DigitalIn unused_p0_11(P0_11, PullUp); // RXD
-
// ROWS=8
// COLS=16
// 列ごとに1バイトにパックしてキーの状態を保持する
@@ -237,13 +237,18 @@
static uint8_t keysB[COLS];
static bool state = 0;
// delay for interrupt
-static volatile int8_t pollCount = 0;
+static volatile int8_t pollCount = 50;
void buttonIntCallback() {
// just for wakeup
pollCount = 100;
}
+void powerOff() {
+ printf("power off\r\n");
+ NRF_POWER->SYSTEMOFF = 1;
+}
+
int main(void) {
printf("init\r\n");
@@ -268,34 +273,38 @@
NRF_UART0->TASKS_STOPRX = 1;
NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
-
+
+
while (1) {
- if (pollCount-- > 0) {
- uint8_t (&keysCurr)[COLS] = state ? keysA : keysB;
- uint8_t (&keysPrev)[COLS] = state ? keysB : keysA;
-
- NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
- keyboardMatrixController.scanKeyboard(keysCurr);
- NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
-
- bool queue = false;
-
- for (int col = 0; col < COLS; col++) {
- uint8_t changed = keysPrev[col] ^ keysCurr[col];
- if (changed) queue = true;
- for (int row = 0; row < ROWS; row++) {
- if (changed & (1<<row)) {
- bool pressed = keysCurr[col] & (1<<row);
- // printf("changed: col=%d, row=%d / pressed=%d\r\n", col, row, pressed);
- keymap.execute(col, row, pressed);
+ if (pollCount > 0) {
+ printf("scan keys\r\n");
+ while (pollCount -- > 0) {
+ uint8_t (&keysCurr)[COLS] = state ? keysA : keysB;
+ uint8_t (&keysPrev)[COLS] = state ? keysB : keysA;
+
+ NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
+ keyboardMatrixController.scanKeyboard(keysCurr);
+ NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
+
+ bool queue = false;
+
+ for (int col = 0; col < COLS; col++) {
+ uint8_t changed = keysPrev[col] ^ keysCurr[col];
+ if (changed) queue = true;
+ for (int row = 0; row < ROWS; row++) {
+ if (changed & (1<<row)) {
+ bool pressed = keysCurr[col] & (1<<row);
+ // printf("changed: col=%d, row=%d / pressed=%d\r\n", col, row, pressed);
+ keymap.execute(col, row, pressed);
+ }
}
}
+ state = !state;
+
+
+ if (queue) HIDController::queueCurrentReportData();
+ wait_ms(5);
}
- state = !state;
-
-
- if (queue) HIDController::queueCurrentReportData();
- wait_ms(5);
} else {
printf("wait for events...\r\n");
@@ -307,9 +316,11 @@
NRF_UART0->TASKS_STOPTX = 1;
NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos);
/**/
-
+
+
HIDController::waitForEvent();
+
/*/
NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
NRF_UART0->TASKS_STARTTX = 1;