]> git.friedersdorff.com Git - max/tmk_keyboard.git/commitdiff
core: Add default implemenation of keymap read
authortmk <hasu@tmk-kbd.com>
Sat, 25 Jun 2016 14:10:31 +0000 (23:10 +0900)
committertmk <hasu@tmk-kbd.com>
Mon, 29 Aug 2016 04:54:44 +0000 (13:54 +0900)
tmk_core/common/keymap.c

index b37bade8e581a9e481e53e03c2b28c05978562b3..01c6e64290a25cf6c6cf4666d953194a00d4bb9d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-Copyright 2013 Jun Wako <wakojun@gmail.com>
+Copyright 2013,2016 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
@@ -23,6 +23,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "wait.h"
 #include "debug.h"
 #include "bootloader.h"
+#if defined(__AVR__)
+#include <avr/pgmspace.h>
+#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