From 19dca3def8560888c0492072511ff90f8ad17df6 Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 25 Jun 2016 23:10:31 +0900 Subject: [PATCH] core: Add default implemenation of keymap read --- tmk_core/common/keymap.c | 55 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/tmk_core/common/keymap.c b/tmk_core/common/keymap.c index b37bade8..01c6e642 100644 --- a/tmk_core/common/keymap.c +++ b/tmk_core/common/keymap.c @@ -1,5 +1,5 @@ /* -Copyright 2013 Jun Wako +Copyright 2013,2016 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 @@ -23,6 +23,9 @@ along with this program. If not, see . #include "wait.h" #include "debug.h" #include "bootloader.h" +#if defined(__AVR__) +#include +#endif #ifdef BOOTMAGIC_ENABLE extern keymap_config_t keymap_config; @@ -32,6 +35,7 @@ static action_t keycode_to_action(uint8_t keycode); /* converts key to action */ +__attribute__ ((weak)) action_t action_for_key(uint8_t layer, keypos_t key) { uint8_t keycode = keymap_key_to_keycode(layer, key); @@ -169,6 +173,28 @@ static action_t keycode_to_action(uint8_t keycode) * Legacy keymap support * Consider using new keymap API instead. */ +extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; +extern const uint8_t fn_layer[]; +extern const uint8_t fn_keycode[]; + +__attribute__ ((weak)) +uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col) +{ + return pgm_read_byte(&keymaps[(layer)][(row)][(col)]); +} + +__attribute__ ((weak)) +uint8_t keymap_fn_layer(uint8_t index) +{ + return pgm_read_byte(&fn_layer[index]); +} + +__attribute__ ((weak)) +uint8_t keymap_fn_keycode(uint8_t index) +{ + return pgm_read_byte(&fn_keycode[index]); +} + __attribute__ ((weak)) uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key) { @@ -196,4 +222,31 @@ action_t keymap_fn_to_action(uint8_t keycode) return (action_t)ACTION_NO; } } + +#else + +/* user keymaps should be defined somewhere */ +extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; +extern const action_t fn_actions[]; + +__attribute__ ((weak)) +uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key) +{ +#if defined(__AVR__) + return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); +#else + return keymaps[(layer)][(key.row)][(key.col)]; +#endif +} + +__attribute__ ((weak)) +action_t keymap_fn_to_action(uint8_t keycode) +{ +#if defined(__AVR__) + return (action_t)pgm_read_word(&fn_actions[FN_INDEX(keycode)]); +#else + return fn_actions[FN_INDEX(keycode)]; +#endif +} + #endif -- 2.39.3