]> git.donarmstrong.com Git - tmk_firmware.git/blob - keyboard/lightpad/keymap.c
6d078230bb7f2b78e4cec168eb0171fc9c18804a
[tmk_firmware.git] / keyboard / lightpad / keymap.c
1 /*
2 Copyright 2014 Ralf Schmitt <ralf@bunkertor.net>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <stdint.h>
19 #include <stdbool.h>
20 #include <avr/pgmspace.h>
21 #include "keycode.h"
22 #include "action.h"
23 #include "action_macro.h"
24 #include "report.h"
25 #include "host.h"
26 #include "debug.h"
27 #include "keymap.h"
28
29 /* Map physical keyboard layout to matrix array */
30 #define KEYMAP( \
31             K5A, K5B, K5C, K5D, \
32             K4A, K4B, K4C, K4D, \
33             K3A, K3B, K3C, K3D, \
34             K2A, K2B, K2C,      \
35             K1A, K1B, K1C, K1D, \
36             K0A, K0B, K0C       \
37 ) { \
38 /*             0         1         2         3    */ \
39 /* 5 */   { KC_##K5A, KC_##K5B, KC_##K5C, KC_##K5D}, \
40 /* 4 */   { KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D}, \
41 /* 3 */   { KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D}, \
42 /* 2 */   { KC_##K2A, KC_##K2B, KC_##K2C, KC_NO},    \
43 /* 1 */   { KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D}, \
44 /* 0 */   { KC_##K0A, KC_##K0B, KC_##K0C, KC_NO,  }  \
45 }
46
47 #include "keymap_lightpad.h"
48
49 #define KEYMAPS_SIZE    (sizeof(keymaps) / sizeof(keymaps[0]))
50 #define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
51
52 /* translates key to keycode */
53 uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
54 {
55     if (layer < KEYMAPS_SIZE) {
56         return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
57     } else {
58         // fall back to layer 0
59         return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
60     }
61 }
62
63 /* translates Fn keycode to action */
64 action_t keymap_fn_to_action(uint8_t keycode)
65 {
66     action_t action;
67     if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) {
68         action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
69     } else {
70         action.code = ACTION_NO;
71     }
72     return action;
73 }