]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - common/keyboard.c
Merge branch 'phantom'
[max/tmk_keyboard.git] / common / keyboard.c
index e973c46d5b0c7fe600895aa3d3545ff87fcd1c00..cd1ceb420cfac3b9089f1627b6a5720735852376 100644 (file)
@@ -1,5 +1,5 @@
 /*
-Copyright 2011 Jun Wako <wakojun@gmail.com>
+Copyright 2011,2012 Jun Wako <wakojun@gmail.com>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -25,6 +25,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "debug.h"
 #include "command.h"
 #include "util.h"
+#include "sendchar.h"
 #ifdef MOUSEKEY_ENABLE
 #include "mousekey.h"
 #endif
@@ -543,7 +544,10 @@ static inline void process_key(keyevent_t event)
 
 void keyboard_init(void)
 {
-    debug_keyboard = true;
+    // TODO: to enable debug print magic key bind on boot time
+
+    // TODO: configuration of sendchar impl
+    print_sendchar_func = sendchar;
 
     timer_init();
     matrix_init();
@@ -555,24 +559,25 @@ void keyboard_init(void)
 void keyboard_task(void)
 {
     static matrix_row_t matrix_prev[MATRIX_ROWS];
+    static uint8_t led_status = 0;
     matrix_row_t matrix_row = 0;
     matrix_row_t matrix_change = 0;
 
     matrix_scan();
-    for (int r = 0; r < MATRIX_ROWS; r++) {
+    for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
         matrix_row = matrix_get_row(r);
         matrix_change = matrix_row ^ matrix_prev[r];
         if (matrix_change) {
             if (debug_matrix) matrix_print();
 
-            for (int c = 0; c < MATRIX_COLS; c++) {
-                if (matrix_change & (1<<c)) {
+            for (uint8_t c = 0; c < MATRIX_COLS; c++) {
+                if (matrix_change & ((matrix_row_t)1<<c)) {
                     process_key((keyevent_t){
                         .key = (key_t){ .row = r, .col = c },
-                        .pressed = (matrix_row & (1<<c))
+                        .pressed = (matrix_row & ((matrix_row_t)1<<c))
                     });
                     // record a processed key
-                    matrix_prev[r] ^= (1<<c);
+                    matrix_prev[r] ^= ((matrix_row_t)1<<c);
                     // process a key per task call
                     goto MATRIX_LOOP_END;
                 }
@@ -617,6 +622,12 @@ void keyboard_task(void)
         }
     }
 
+    // update LED
+    if (led_status != host_keyboard_leds()) {
+        led_status = host_keyboard_leds();
+        keyboard_set_leds(led_status);
+    }
+
     return;
 }