From 1605365a5a6304d3c78b6e45809c44462f1d28f5 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Mon, 11 Aug 2014 15:08:49 +0900 Subject: [PATCH] Add keymap cache to speedup keycode responding --- keyboard/tentapad/keymap_common.c | 27 ++++++++++++++++++++++----- keyboard/tentapad/keymap_common.h | 14 ++------------ keyboard/tentapad/keymap_default.c | 10 ++++++++-- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/keyboard/tentapad/keymap_common.c b/keyboard/tentapad/keymap_common.c index 53087379..9a016754 100644 --- a/keyboard/tentapad/keymap_common.c +++ b/keyboard/tentapad/keymap_common.c @@ -14,17 +14,34 @@ 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 "keymap.h" +#include "keymap_in_eeprom.h" #include "keymap_common.h" +static uint8_t keymaps_cache[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS]; + +void keymaps_cache_init(void) +{ + for (uint8_t layer = 0; layer < KEYMAPS_COUNT; layer++) { + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { +#ifndef KEYMAP_IN_EEPROM_ENABLE + keymaps_cache[layer][row][col] = pgm_read_byte(&keymaps[layer][row][col]); +#else + keymaps_cache[layer][row][col] = eeconfig_read_keymap_key(layer, row, col); +#endif + } + } + } +} /* translates key to keycode */ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) { -#ifndef KEYMAP_IN_EEPROM_ENABLE - return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); -#else - return eeconfig_read_keymap_key(layer, key.row, key.col); -#endif + return keymaps_cache[layer][key.row][key.col]; } /* translates Fn keycode to action */ diff --git a/keyboard/tentapad/keymap_common.h b/keyboard/tentapad/keymap_common.h index 61c3bb97..bfe7261c 100644 --- a/keyboard/tentapad/keymap_common.h +++ b/keyboard/tentapad/keymap_common.h @@ -19,22 +19,12 @@ along with this program. If not, see . #define KEYMAP_COMMON_H #include -#include -#include -#include "keycode.h" -#include "action.h" -#include "action_macro.h" -#include "report.h" -#include "host.h" -#include "print.h" -#include "debug.h" -#include "keymap.h" -#include "keymap_in_eeprom.h" - extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; extern const uint16_t fn_actions[]; +void keymaps_cache_init(void); + /* TentaPad keymap definition macro */ #define KEYMAP( \ diff --git a/keyboard/tentapad/keymap_default.c b/keyboard/tentapad/keymap_default.c index 866069b0..5f1a291d 100644 --- a/keyboard/tentapad/keymap_default.c +++ b/keyboard/tentapad/keymap_default.c @@ -15,6 +15,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include +#include "keycode.h" +#include "action_layer.h" +#include "eeconfig.h" +#include "backlight.h" #include "keymap_common.h" enum function_id { @@ -24,7 +29,7 @@ enum function_id { }; enum { - CONFIG_LAYER = 31, + CONFIG_LAYER = 8, }; // Default @@ -89,6 +94,7 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) if (record->event.pressed) { if (config_mode) { default_layer_set(1UL<event.pressed) { if (config_mode) { backlight_level(backlight); - backlight = (backlight + 1) % BACKLIGHT_LEVEL; + backlight = (backlight + 1) % (BACKLIGHT_LEVELS + 1); } } break;