Skip to content

Commit ddbd7b4

Browse files
committed
core: Add default implemenation of keymap read
1 parent 671cacc commit ddbd7b4

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

common/keymap.c

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2013 Jun Wako <[email protected]>
2+
Copyright 2013,2016 Jun Wako <[email protected]>
33
44
This program is free software: you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -23,6 +23,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2323
#include "wait.h"
2424
#include "debug.h"
2525
#include "bootloader.h"
26+
#if defined(__AVR__)
27+
#include <avr/pgmspace.h>
28+
#endif
2629

2730
#ifdef BOOTMAGIC_ENABLE
2831
extern keymap_config_t keymap_config;
@@ -32,6 +35,7 @@ static action_t keycode_to_action(uint8_t keycode);
3235

3336

3437
/* converts key to action */
38+
__attribute__ ((weak))
3539
action_t action_for_key(uint8_t layer, keypos_t key)
3640
{
3741
uint8_t keycode = keymap_key_to_keycode(layer, key);
@@ -169,6 +173,28 @@ static action_t keycode_to_action(uint8_t keycode)
169173
* Legacy keymap support
170174
* Consider using new keymap API instead.
171175
*/
176+
extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
177+
extern const uint8_t fn_layer[];
178+
extern const uint8_t fn_keycode[];
179+
180+
__attribute__ ((weak))
181+
uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col)
182+
{
183+
return pgm_read_byte(&keymaps[(layer)][(row)][(col)]);
184+
}
185+
186+
__attribute__ ((weak))
187+
uint8_t keymap_fn_layer(uint8_t index)
188+
{
189+
return pgm_read_byte(&fn_layer[index]);
190+
}
191+
192+
__attribute__ ((weak))
193+
uint8_t keymap_fn_keycode(uint8_t index)
194+
{
195+
return pgm_read_byte(&fn_keycode[index]);
196+
}
197+
172198
__attribute__ ((weak))
173199
uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
174200
{
@@ -196,4 +222,31 @@ action_t keymap_fn_to_action(uint8_t keycode)
196222
return (action_t)ACTION_NO;
197223
}
198224
}
225+
226+
#else
227+
228+
/* user keymaps should be defined somewhere */
229+
extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
230+
extern const action_t fn_actions[];
231+
232+
__attribute__ ((weak))
233+
uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
234+
{
235+
#if defined(__AVR__)
236+
return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
237+
#else
238+
return keymaps[(layer)][(key.row)][(key.col)];
239+
#endif
240+
}
241+
242+
__attribute__ ((weak))
243+
action_t keymap_fn_to_action(uint8_t keycode)
244+
{
245+
#if defined(__AVR__)
246+
return (action_t)pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
247+
#else
248+
return fn_actions[FN_INDEX(keycode)];
249+
#endif
250+
}
251+
199252
#endif

0 commit comments

Comments
 (0)