/* 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 the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include "keyboard.h" #include "matrix.h" #include "keymap.h" #include "host.h" #include "led.h" #include "keycode.h" #include "timer.h" #include "print.h" #include "debug.h" #include "command.h" #include "util.h" #include "sendchar.h" #include "bootmagic.h" #include "eeconfig.h" #include "backlight.h" #ifdef SOFTPWM_LED_ENABLE #include "softpwm_led.h" #else #include "breathing_led.h" #endif #include "ledmap.h" #include "ledmap_in_eeprom.h" #include "keymap_in_eeprom.h" #ifdef MOUSEKEY_ENABLE # include "mousekey.h" #endif #ifdef PS2_MOUSE_ENABLE # include "ps2_mouse.h" #endif #ifdef MATRIX_HAS_GHOST static bool has_ghost_in_row(uint8_t row) { matrix_row_t matrix_row = matrix_get_row(row); // No ghost exists when less than 2 keys are down on the row if (((matrix_row - 1) & matrix_row) == 0) return false; // Ghost occurs when the row shares column line with other row for (uint8_t i=0; i < MATRIX_ROWS; i++) { if (i != row && (matrix_get_row(i) & matrix_row)) return true; } return false; } #endif extern uint8_t ps2_mouse_enabled; void keyboard_init(void) { timer_init(); matrix_init(); #ifdef LED_MATRIX_ENABLE led_matrix_init(); #endif #ifdef PS2_MOUSE_ENABLE if (ps2_mouse_enabled) { ps2_mouse_init(); } #endif #ifdef BOOTMAGIC_ENABLE bootmagic(); #endif #ifdef LEDMAP_ENABLE #ifdef LEDMAP_IN_EEPROM_ENABLE ledmap_in_eeprom_init(); #endif ledmap_init(); #endif #ifdef SOFTPWM_LED_ENABLE softpwm_init(); #endif #ifdef BREATHING_LED_ENABLE breathing_led_init(); #endif #ifdef BACKLIGHT_ENABLE backlight_init(); #endif #ifdef KEYMAP_IN_EEPROM_ENABLE keymap_in_eeprom_init(); #endif } /* * Do keyboard routine jobs: scan mantrix, light LEDs, ... * This is repeatedly called as fast as possible. */ 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 (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(); #ifdef MATRIX_HAS_GHOST if (has_ghost_in_row(r)) { matrix_prev[r] = matrix_row; continue; } #endif for (uint8_t c = 0; c < MATRIX_COLS; c++) { if (matrix_change & ((matrix_row_t)1<