X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=keyboard%2Fhid_liber%2Fkeymap.c;h=28f59aab6b3ce343dad704904fabae81af1b0013;hb=ff2d276b193632136c785d92ed01df48aea8461f;hp=e35f7245d040a2d2bb917b215acfd429d493c8a7;hpb=8c80deb775ac151001dc1592a2e94e8677b49964;p=max%2Ftmk_keyboard.git diff --git a/keyboard/hid_liber/keymap.c b/keyboard/hid_liber/keymap.c index e35f7245..28f59aab 100644 --- a/keyboard/hid_liber/keymap.c +++ b/keyboard/hid_liber/keymap.c @@ -22,9 +22,12 @@ along with this program. If not, see . #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 "util.h" #include "keymap.h" @@ -59,34 +62,12 @@ along with this program. If not, see . /* R */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_##KR4, KC_NO , KC_NO , KC_NO } \ } -#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) - - -// Assign Fn key(0-7) to a layer to which switch with the Fn key pressed. -static const uint8_t PROGMEM fn_layer[] = { - 0, // Fn0 - 1, // Fn1 - 2, // Fn2 - 3, // Fn3 - 4, // Fn4 - 5, // Fn5 - 6, // Fn6 - 7 // Fn7 -}; - -// Assign Fn key(0-7) to a keycode sent when release Fn key without use of the layer. -// See layer.c for details. -static const uint8_t PROGMEM fn_keycode[] = { - KC_NO, // Fn0 - KC_NO, // Fn1 - KC_NO, // Fn2 - KC_NO, // Fn3 - KC_NO, // Fn4 - KC_NO, // Fn5 - KC_NO, // Fn6 - KC_NO // Fn7 -}; - +/* + * Add custom layouts. If no custom layout is defined the default layout is used. +*/ +#if defined(KEYMAP_CUSTOM) + #include "keymap_custom.h" +#else /* * Tenkeyless keyboard default layout, ISO & ANSI (ISO is between Left Shift * and Z, and the ANSI \ key above Return/Enter is used for the additional ISO @@ -178,18 +159,43 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; +/* + * Fn action definition + */ +static const uint16_t PROGMEM fn_actions[] = { + [0] = ACTION_LAYER_MOMENTARY(0), + [1] = ACTION_LAYER_MOMENTARY(1), + [2] = ACTION_LAYER_MOMENTARY(2), + [3] = ACTION_LAYER_MOMENTARY(3), + [4] = ACTION_LAYER_MOMENTARY(4), + [5] = ACTION_LAYER_MOMENTARY(5), + [6] = ACTION_LAYER_MOMENTARY(6), + [7] = ACTION_LAYER_MOMENTARY(7), + [8] = ACTION_LAYER_MOMENTARY(8), +}; +#endif -uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col) -{ - return KEYCODE(layer, row, col); -} +#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0])) +#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0])) -uint8_t keymap_fn_layer(uint8_t index) +/* translates key to keycode */ +uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) { - return pgm_read_byte(&fn_layer[index]); + if (layer < KEYMAPS_SIZE) { + return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); + } else { + return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]); + } } -uint8_t keymap_fn_keycode(uint8_t index) +/* translates Fn keycode to action */ +action_t keymap_fn_to_action(uint8_t keycode) { - return pgm_read_byte(&fn_keycode[index]); + action_t action; + if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) { + action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]); + } else { + action.code = ACTION_NO; + } + return action; }