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:
- 16:345eebc4f259
- Parent:
- 15:70bf079d3ee1
- Child:
- 17:3233ee19f716
--- a/main.cpp Mon Aug 22 02:29:37 2016 +0000
+++ b/main.cpp Mon Aug 22 12:28:47 2016 +0000
@@ -211,6 +211,7 @@
};
I2C i2c(I2C_SDA0, I2C_SCL0);
+// Serial serial(USBTX, USBRX);
KeyboardMatrixController keyboardMatrixController(i2c);
Keymap keymap;
@@ -251,6 +252,7 @@
NRF_UART0->PSELRTS = 0xFFFFFFFFUL;
NRF_UART0->PSELCTS = 0xFFFFFFFFUL;
+
// 100kHz
i2c.frequency(100000);
@@ -261,12 +263,20 @@
buttonIntCallback();
HIDController::init();
+
+ // STOP UART RX for power consumption
+ 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;
@@ -282,22 +292,32 @@
}
}
state = !state;
+
if (queue) HIDController::queueCurrentReportData();
wait_ms(5);
} else {
printf("wait for events...\r\n");
- /*
+
+ while (NRF_UART0->EVENTS_TXDRDY != 1);
+
+ uint32_t tx = NRF_UART0->PSELTXD;
+
NRF_UART0->TASKS_STOPTX = 1;
NRF_UART0->TASKS_STOPRX = 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;
- NRF_UART0->TASKS_STARTRX = 1;
- */
+ NRF_UART0->PSELTXD = 0xFFFFFFFF;
+ NRF_UART0->EVENTS_TXDRDY = 0;
+ NRF_UART0->TXD = 0;
+ while (NRF_UART0->EVENTS_TXDRDY != 1);
+ NRF_UART0->PSELTXD = tx;
+
}
}
}