summary refs log tree commit diff
path: root/key_process.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2010-11-24 22:17:35 +0900
committertmk <nobody@nowhere>2010-11-24 22:17:35 +0900
commitd6da5546879f9979d043a0b223597af7e8dedbf8 (patch)
tree1bdef24f6cd0a3a6d8d8a1670121b9cdb78b3fbf /key_process.c
parent9019c901dd7b4e37006eb1f0442a57dacc0b3f0c (diff)
support 12KRO
Diffstat (limited to 'key_process.c')
-rw-r--r--key_process.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/key_process.c b/key_process.c
index 0bd2028061..c23d17277b 100644
--- a/key_process.c
+++ b/key_process.c
@@ -32,7 +32,6 @@ void proc_matrix(void) {
     static int mouse_repeat = 0;
 
     bool modified = false;
-    int key_index = 0;
     uint8_t mouse_btn = 0;
     int8_t mouse_x = 0;
     int8_t mouse_y = 0;
@@ -58,6 +57,7 @@ void proc_matrix(void) {
         return;
     }
 
+    usb_keyboard_swap_report();
     usb_keyboard_clear_report();
     for (int row = 0; row < matrix_rows(); row++) {
         for (int col = 0; col < matrix_cols(); col++) {
@@ -111,9 +111,22 @@ void proc_matrix(void) {
 
             // normal keys
             else {
-                if (key_index < 6)
-                    usb_keyboard_keys[key_index] = code;
-                key_index++;
+                // TODO: fix ugly code
+                int8_t i = 0;
+                int8_t empty = -1;
+                for (; i < KEYBOARD_REPORT_MAX; i++) {
+                    if (usb_keyboard_keys_prev[i] == code) {
+                        usb_keyboard_keys[i] = code;
+                        break;
+                    } else if (empty == -1 && usb_keyboard_keys_prev[i] == 0 && usb_keyboard_keys[i] == 0) {
+                        empty = i;
+                    }
+                }
+                if (i == KEYBOARD_REPORT_MAX) {
+                    if (empty != -1) {
+                        usb_keyboard_keys[empty] = code;
+                    }
+                }
             }
         }
     }
@@ -270,9 +283,6 @@ void proc_matrix(void) {
 
     // send key packet to host
     if (modified) {
-        if (key_index > 6) {
-            //Rollover
-        }
         usb_keyboard_send();
     }
 }