1
0
tmk_keyboard/tmk_core/common/unimap.c

60 lines
1.3 KiB
C
Raw Permalink Normal View History

2016-06-29 10:59:59 +00:00
#include "keyboard.h"
#include "action.h"
#include "unimap.h"
#include "print.h"
#if defined(__AVR__)
# include <avr/pgmspace.h>
#endif
/* Keymapping with 16bit action codes */
extern const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS];
// table translates matrix to universal keymap
extern const uint8_t unimap_trans[MATRIX_ROWS][MATRIX_COLS];
// translates raw matrix to universal map
keypos_t unimap_translate(keypos_t key)
{
uint8_t unimap_pos =
#if defined(__AVR__)
pgm_read_byte(&unimap_trans[key.row][key.col]);
#else
unimap_trans[key.row][key.col];
#endif
return (keypos_t) {
2016-09-08 04:18:05 +00:00
.row = ((unimap_pos & 0xf0) >> 4),
.col = (unimap_pos & 0x0f)
2016-06-29 10:59:59 +00:00
};
}
/* Converts key to action */
__attribute__ ((weak))
action_t action_for_key(uint8_t layer, keypos_t key)
{
keypos_t uni = unimap_translate(key);
2016-09-08 04:18:05 +00:00
if ((uni.row << 4 | uni.col) == UNIMAP_NO) {
return (action_t)ACTION_NO;
}
2016-06-29 10:59:59 +00:00
#if defined(__AVR__)
2016-09-08 04:18:05 +00:00
return (action_t)pgm_read_word(&actionmaps[(layer)][(uni.row & 0x7)][(uni.col)]);
2016-06-29 10:59:59 +00:00
#else
2016-09-08 04:18:05 +00:00
return actionmaps[(layer)][(uni.row & 0x7)][(uni.col)];
2016-06-29 10:59:59 +00:00
#endif
}
/* Macro */
__attribute__ ((weak))
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
{
return MACRO_NONE;
}
/* Function */
__attribute__ ((weak))
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{
}