]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - keyboard/hhkb/keymap.c
Fix debug code of serial_soft.c
[max/tmk_keyboard.git] / keyboard / hhkb / keymap.c
index 65ef89ad77da326d840ead3db02e1dda88b20d63..ef21282ff150d7103e88fd1fdb179326d0270e13 100644 (file)
@@ -24,6 +24,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "keycode.h"
 #include "action.h"
 #include "action_macro.h"
+#include "report.h"
 #include "host.h"
 #include "debug.h"
 #include "keymap.h"
@@ -48,7 +49,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 }
 
 
-// TODO: use [1] = KEYMAP(...) to prevent from changing index of element?
 static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     /* Layer 0: Default Layer
      * ,-----------------------------------------------------------.
@@ -309,40 +309,34 @@ void keymap_call_function(keyrecord_t *record, uint8_t id, uint8_t opt)
     }
 }
 
-/* convert keycode to action */
-action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) {
-    uint8_t key = (pgm_read_byte(&keymaps[(layer)][(row)][(col)]));
+
+
+/* translates key to keycode */
+uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
+{
+    return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
+}
+
+/* translates Fn index to action */
+action_t keymap_fn_to_action(uint8_t keycode)
+{
     action_t action;
-    switch (key) {
-        case KC_A ... KC_EXSEL:
-            action.code = ACTION_KEY(key);
-            break;
-        case KC_LCTRL ... KC_LGUI:
-            action.code = ACTION_LMOD(key);
-            break;
-        case KC_RCTRL ... KC_RGUI:
-            action.code = ACTION_RMOD(key);
-            break;
-        case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
-            action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(key));
-            break;
-        case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
-            action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(key));
-            break;
-        case KC_MS_UP ... KC_MS_ACCEL2:
-            action.code = ACTION_MOUSEKEY(key);
-            break;
+    if (FN_INDEX(keycode) < sizeof(fn_actions) / sizeof(fn_actions[0])) {
+        action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
+    } else {
+        action.code = ACTION_NO;
+    }
+    return action;
+}
+
+/* convert key to action */
+action_t action_for_key(uint8_t layer, key_t key)
+{
+    uint8_t keycode = keymap_key_to_keycode(layer, key);
+    switch (keycode) {
         case KC_FN0 ... KC_FN31:
-            if (FN_INDEX(key) < sizeof(fn_actions) / sizeof(fn_actions[0])) {
-                action.code = pgm_read_word(&fn_actions[FN_INDEX(key)]);
-            } else {
-                action.code = ACTION_NO;
-            }
-            break;
-        case KC_NO ... KC_UNDEFINED:
+            return keymap_fn_to_action(keycode);
         default:
-            action.code = ACTION_NO;
-            break;
+            return keymap_keycode_to_action(keycode);
     }
-    return action;
 }