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:
- 7:b9270a37345b
- Parent:
- 6:f1c3ea8bc850
- Child:
- 8:d684faf04c9a
--- a/main.cpp Thu Jul 21 01:25:31 2016 +0900
+++ b/main.cpp Thu Jul 21 07:56:04 2016 +0900
@@ -106,12 +106,6 @@
void scanKeyboard(uint8_t* keys) {
int ok;
- // Disable interrupt
- ok = gpio1.write8(
- MCP23017::GPINTENB,
- 0b00000000
- );
-
for (int i = 0; i < 8; i++) {
ok = gpio1.write8(
MCP23017::GPIOA,
@@ -126,6 +120,20 @@
0b00000000
);
+ // TODO gpio2
+ }
+
+ void disableInterrupt() {
+ int ok;
+ // Disable interrupt
+ ok = gpio1.write8(
+ MCP23017::GPINTENB,
+ 0b00000000
+ );
+ }
+
+ void enableInterrupt() {
+ int ok;
// Enable interrupt
ok = gpio1.write8(
MCP23017::GPINTENB,
@@ -134,8 +142,6 @@
// Clear interrupt
gpio1.read8(MCP23017::GPIOB, ok);
-
- // TODO gpio2
}
};
@@ -153,25 +159,7 @@
static bool state = 0;
void buttonIntCallback() {
- printf("pinChanged!!!\r\n");
- uint8_t (&keysCurr)[COLS] = state ? keysA : keysB;
- uint8_t (&keysPrev)[COLS] = state ? keysB : keysA;
-
- printf("scanKeyboard\r\n");
- keyboardMatrixController.scanKeyboard(keysCurr);
-
- for (int col = 0; col < COLS; col++) {
- uint8_t changed = keysPrev[col] ^ keysCurr[col];
- if (changed) printf("changed: %x\r\n", changed);
- 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;
+ printf("int!\r\n");
}
int main(void) {
@@ -194,5 +182,29 @@
HIDController::init();
while (1) {
HIDController::process();
+
+ if (!buttonIntIn.read()) {
+ uint8_t (&keysCurr)[COLS] = state ? keysA : keysB;
+ uint8_t (&keysPrev)[COLS] = state ? keysB : keysA;
+
+ keyboardMatrixController.disableInterrupt();
+ keyboardMatrixController.scanKeyboard(keysCurr);
+
+ for (int col = 0; col < COLS; col++) {
+ uint8_t changed = keysPrev[col] ^ keysCurr[col];
+ 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;
+
+ // XXX
+ keyboardMatrixController.enableInterrupt();
+ wait_ms(5);
+ }
}
}