summaryrefslogtreecommitdiffstats
path: root/usb_keyboard.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2010-10-24 01:17:26 +0900
committertmk <nobody@nowhere>2010-10-24 01:17:26 +0900
commit06eb50be07ff16e4bfb046e4773185d9bcf048e9 (patch)
tree86a8fb688282004893eedd28641f8300c9d812d1 /usb_keyboard.c
parent9d7979931e0037fc5ddc77a2cb895eb055501f34 (diff)
hhkb: refactored
Diffstat (limited to 'usb_keyboard.c')
-rw-r--r--usb_keyboard.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/usb_keyboard.c b/usb_keyboard.c
index 9d41e8bc59..44365bb857 100644
--- a/usb_keyboard.c
+++ b/usb_keyboard.c
@@ -1,8 +1,11 @@
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "usb_keyboard.h"
+#include "print.h"
+static bool is_sent = false;
+
// which modifier keys are currently pressed
// 1=left ctrl, 2=left shift, 4=left alt, 8=left gui
// 16=right ctrl, 32=right shift, 64=right alt, 128=right gui
@@ -72,5 +75,45 @@ int8_t usb_keyboard_send(void)
UEINTX = 0x3A;
keyboard_idle_count = 0;
SREG = intr_state;
+ is_sent = true;
return 0;
}
+
+void usb_keyboard_init(void) {
+ usb_keyboard_clear();
+ is_sent = false;
+}
+
+void usb_keyboard_clear(void) {
+ usb_keyboard_clear_key();
+ usb_keyboard_clear_mod();
+}
+
+void usb_keyboard_clear_key(void) {
+ for (int i = 0; i < 6; i++) keyboard_keys[i] = 0;
+}
+
+void usb_keyboard_clear_mod(void) {
+ keyboard_modifier_keys = 0;
+}
+
+bool usb_keyboard_is_sent(void) {
+ return is_sent;
+}
+
+bool usb_keyboard_has_key(void) {
+ uint8_t keys = 0;
+ for (int i = 0; i < 6; i++) keys |= keyboard_keys[i];
+ return keys ? true : false;
+}
+
+bool usb_keyboard_has_mod(void) {
+ return keyboard_modifier_keys ? true : false;
+}
+
+void usb_keyboard_print(void) {
+ print("\nkeys: ");
+ for (int i = 0; i < 6; i++) { phex(keyboard_keys[i]); print(" "); }
+ print("\n");
+ print("mods: "); phex(keyboard_modifier_keys); print("\n");
+}