]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/common/unimap.c
xt_usb: Fix XT soft reset
[max/tmk_keyboard.git] / tmk_core / common / unimap.c
1 #include "keyboard.h"
2 #include "action.h"
3 #include "unimap.h"
4 #include "print.h"
5 #if defined(__AVR__)
6 #   include <avr/pgmspace.h>
7 #endif
8
9
10 /* Keymapping with 16bit action codes */
11 extern const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS];
12
13 // table translates matrix to universal keymap
14 extern const uint8_t unimap_trans[MATRIX_ROWS][MATRIX_COLS];
15
16
17
18 // translates raw matrix to universal map
19 keypos_t unimap_translate(keypos_t key)
20 {
21     uint8_t unimap_pos = 
22 #if defined(__AVR__)
23         pgm_read_byte(&unimap_trans[key.row][key.col]);
24 #else
25         unimap_trans[key.row][key.col];
26 #endif
27     return (keypos_t) {
28         .row = ((unimap_pos >> 4 ) & 0x07),
29         .col = (unimap_pos & 0x0F)
30     };
31 }
32
33 /* Converts key to action */
34 __attribute__ ((weak))
35 action_t action_for_key(uint8_t layer, keypos_t key)
36 {
37     keypos_t uni = unimap_translate(key);
38     if ((uni.row << 4 | uni.col) > 0x7F) {
39         return (action_t)ACTION_NO;
40     }
41 #if defined(__AVR__)
42     return (action_t)pgm_read_word(&actionmaps[(layer)][(uni.row & 0x07)][(uni.col & 0x0F)]);
43 #else
44     return actionmaps[(layer)][(uni.row & 0x07)][(uni.col & 0x0F)];
45 #endif
46 }
47
48 /* Macro */
49 __attribute__ ((weak))
50 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
51 {
52     return MACRO_NONE;
53 }
54
55 /* Function */
56 __attribute__ ((weak))
57 void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
58 {
59 }