X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=common%2Fkeyboard.c;h=5e9945baf450eb1f8ca66441c1800da1de35b7d6;hb=b2aa142ee0a88ae6c38798f33cf5d833b0ae3864;hp=5c2643c951e53ee3a5869b50d792b8878091fc5f;hpb=62d1ebb91c7b381ce3d88aad9ee0b03bea9fce26;p=max%2Ftmk_keyboard.git diff --git a/common/keyboard.c b/common/keyboard.c index 5c2643c9..5e9945ba 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -1,5 +1,5 @@ /* -Copyright 2011 Jun Wako +Copyright 2011,2012,2013 Jun Wako 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 @@ -15,185 +15,91 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "keyboard.h" -#include "host.h" -#include "layer.h" #include "matrix.h" +#include "keymap.h" +#include "host.h" #include "led.h" -#include "usb_keycodes.h" +#include "keycode.h" #include "timer.h" #include "print.h" #include "debug.h" #include "command.h" +#include "util.h" +#include "sendchar.h" +#include "bootloader.h" #ifdef MOUSEKEY_ENABLE #include "mousekey.h" #endif -#ifdef EXTRAKEY_ENABLE -#include -#endif - - -static uint8_t last_leds = 0; void keyboard_init(void) { + // TODO: configuration of sendchar impl + print_sendchar_func = sendchar; + timer_init(); matrix_init(); + + /* boot magic keys goes here */ + matrix_scan(); +#ifdef IS_BOOTMAGIC_BOOTLOADER + /* kick up bootloader */ + if (IS_BOOTMAGIC_BOOTLOADER()) bootloader_jump(); +#endif +#ifdef IS_BOOTMAGIC_DEBUG + if (IS_BOOTMAGIC_DEBUG()) debug_enable = true; +#endif + #ifdef PS2_MOUSE_ENABLE ps2_mouse_init(); #endif } -void keyboard_proc(void) +/* + * Do keyboard routine jobs: scan mantrix, light LEDs, ... + * This is repeatedly called as fast as possible. + */ +void keyboard_task(void) { - uint8_t fn_bits = 0; -#ifdef EXTRAKEY_ENABLE - uint16_t consumer_code = 0; -#endif + 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(); - - if (matrix_is_modified()) { - if (debug_matrix) matrix_print(); -#ifdef DEBUG_LED - // LED flash for debug - DEBUG_LED_CONFIG; - DEBUG_LED_ON; -#endif - } - - if (matrix_has_ghost()) { - // should send error? - debug("matrix has ghost!!\n"); - return; - } - - host_swap_keyboard_report(); - host_clear_keyboard_report(); - for (int row = 0; row < matrix_rows(); row++) { - for (int col = 0; col < matrix_cols(); col++) { - if (!matrix_is_on(row, col)) continue; - - uint8_t code = layer_get_keycode(row, col); - if (code == KB_NO) { - // do nothing - } else if (IS_MOD(code)) { - host_add_mod_bit(MOD_BIT(code)); - } else if (IS_FN(code)) { - fn_bits |= FN_BIT(code); - } -// TODO: use table or something -#ifdef EXTRAKEY_ENABLE - // System Control - else if (code == KB_SYSTEM_POWER) { -#ifdef HOST_PJRC - if (suspend && remote_wakeup) { - usb_remote_wakeup(); - } else { - host_system_send(SYSTEM_POWER_DOWN); + 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 (uint8_t c = 0; c < MATRIX_COLS; c++) { + if (matrix_change & ((matrix_row_t)1<