Browse Source

core: Add default implemenation of keymap read

master
tmk 7 years ago
parent
commit
19dca3def8
1 changed files with 54 additions and 1 deletions
  1. 54
    1
      tmk_core/common/keymap.c

+ 54
- 1
tmk_core/common/keymap.c View File

/* /*
Copyright 2013 Jun Wako <[email protected]>
Copyright 2013,2016 Jun Wako <[email protected]>


This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
#include "wait.h" #include "wait.h"
#include "debug.h" #include "debug.h"
#include "bootloader.h" #include "bootloader.h"
#if defined(__AVR__)
#include <avr/pgmspace.h>
#endif


#ifdef BOOTMAGIC_ENABLE #ifdef BOOTMAGIC_ENABLE
extern keymap_config_t keymap_config; extern keymap_config_t keymap_config;




/* converts key to action */ /* converts key to action */
__attribute__ ((weak))
action_t action_for_key(uint8_t layer, keypos_t key) action_t action_for_key(uint8_t layer, keypos_t key)
{ {
uint8_t keycode = keymap_key_to_keycode(layer, key); uint8_t keycode = keymap_key_to_keycode(layer, key);
* Legacy keymap support * Legacy keymap support
* Consider using new keymap API instead. * Consider using new keymap API instead.
*/ */
extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
extern const uint8_t fn_layer[];
extern const uint8_t fn_keycode[];

__attribute__ ((weak))
uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col)
{
return pgm_read_byte(&keymaps[(layer)][(row)][(col)]);
}

__attribute__ ((weak))
uint8_t keymap_fn_layer(uint8_t index)
{
return pgm_read_byte(&fn_layer[index]);
}

__attribute__ ((weak))
uint8_t keymap_fn_keycode(uint8_t index)
{
return pgm_read_byte(&fn_keycode[index]);
}

__attribute__ ((weak)) __attribute__ ((weak))
uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key) uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
{ {
return (action_t)ACTION_NO; return (action_t)ACTION_NO;
} }
} }

#else

/* user keymaps should be defined somewhere */
extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
extern const action_t fn_actions[];

__attribute__ ((weak))
uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
{
#if defined(__AVR__)
return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
#else
return keymaps[(layer)][(key.row)][(key.col)];
#endif
}

__attribute__ ((weak))
action_t keymap_fn_to_action(uint8_t keycode)
{
#if defined(__AVR__)
return (action_t)pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
#else
return fn_actions[FN_INDEX(keycode)];
#endif
}

#endif #endif

Loading…
Cancel
Save