Created
February 11, 2018 16:42
-
-
Save boochow/add9bb8d4723eb0819398ead915a37ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// initialize usb | |
UsbInitialise(); | |
while (1) { | |
unsigned int kbd_addr; | |
unsigned int keys[6]; | |
unsigned int key; | |
if (kbd_addr == 0) { | |
// Is there a keyboard ? | |
while(KeyboardCount() == 0) { | |
UsbCheckForChange(); | |
delay_ms(100); | |
} | |
println("Found: keyboard"); | |
kbd_addr = KeyboardGetAddress(0); | |
} | |
if (kbd_addr != 0) { | |
for(int i = 0; i < 6; i++) { | |
// Read and print each keycode of pressed keys | |
key = KeyboardGetKeyDown(kbd_addr, i); | |
if (key != keys[0] && key != keys[1] && key != keys[2] && \ | |
key != keys[3] && key != keys[4] && key != keys[5] && key) { | |
uart_puthex(key); | |
uart_putchar(' '); | |
} | |
keys[i] = key; | |
} | |
if (KeyboardPoll(kbd_addr) != 0) { | |
kbd_addr = 0; | |
println("Lost: keyboard"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment