Skip to content

Instantly share code, notes, and snippets.

@boochow
Created February 11, 2018 16:42
Show Gist options
  • Save boochow/add9bb8d4723eb0819398ead915a37ba to your computer and use it in GitHub Desktop.
Save boochow/add9bb8d4723eb0819398ead915a37ba to your computer and use it in GitHub Desktop.
// 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