Some fix for reading keymap from eeprom
This commit is contained in:
parent
ba3220faa7
commit
6919d47744
@ -22,22 +22,48 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "keymap_common.h"
|
||||
|
||||
static uint8_t keymaps_cache[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS];
|
||||
static uint8_t last_layer_number = 1;
|
||||
|
||||
void keymaps_cache_init(void)
|
||||
{
|
||||
for (uint8_t layer = 0; layer < KEYMAPS_COUNT; layer++) {
|
||||
uint8_t non_empty_key = 0;
|
||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
|
||||
if (col == 3) {
|
||||
keymaps_cache[layer][row][col] = KC_FN28;
|
||||
}
|
||||
else if (col == 4) {
|
||||
keymaps_cache[layer][row][col] = KC_FN29;
|
||||
}
|
||||
else {
|
||||
if (layer < CONFIG_LAYER) {
|
||||
#ifndef KEYMAP_IN_EEPROM_ENABLE
|
||||
keymaps_cache[layer][row][col] = pgm_read_byte(&keymaps[layer][row][col]);
|
||||
keymaps_cache[layer][row][col] = pgm_read_byte(&keymaps[layer][row][col]);
|
||||
#else
|
||||
keymaps_cache[layer][row][col] = eeconfig_read_keymap_key(layer, row, col);
|
||||
keymaps_cache[layer][row][col] = eeconfig_read_keymap_key(layer, row, col);
|
||||
#endif
|
||||
if (keymaps_cache[layer][row][col] > KC_TRANSPARENT) {
|
||||
non_empty_key++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
keymaps_cache[layer][row][col] = pgm_read_byte(&keymaps[layer][row][col]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (non_empty_key) {
|
||||
last_layer_number = layer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t last_layer(void)
|
||||
{
|
||||
return last_layer_number;
|
||||
}
|
||||
|
||||
/* translates key to keycode */
|
||||
uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
|
||||
{
|
||||
@ -47,13 +73,23 @@ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
|
||||
/* translates Fn keycode to action */
|
||||
action_t keymap_fn_to_action(uint8_t keycode)
|
||||
{
|
||||
return (action_t) {
|
||||
#ifndef KEYMAP_IN_EEPROM_ENABLE
|
||||
return (action_t) {
|
||||
.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)])
|
||||
#else
|
||||
.code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode))
|
||||
#endif
|
||||
};
|
||||
#else
|
||||
uint8_t index = FN_INDEX(keycode);
|
||||
if (index < RESERVED_FN) {
|
||||
return (action_t) {
|
||||
.code = eeconfig_read_keymap_fn_action(index)
|
||||
};
|
||||
}
|
||||
else {
|
||||
return (action_t) {
|
||||
.code = pgm_read_word(&fn_actions[index])
|
||||
};
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef KEYMAP_IN_EEPROM_ENABLE
|
||||
|
@ -23,14 +23,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
|
||||
extern const uint16_t fn_actions[];
|
||||
|
||||
#define CONFIG_LAYER (KEYMAPS_COUNT - 1)
|
||||
#define RESERVED_FN (FN_ACTIONS_COUNT - 4)
|
||||
|
||||
void keymaps_cache_init(void);
|
||||
uint8_t last_layer(void);
|
||||
|
||||
/* TentaPad keymap definition macro
|
||||
*/
|
||||
#define KEYMAP( \
|
||||
K1, K2, TT, TP, FN \
|
||||
K1, K2, TT \
|
||||
) { \
|
||||
{ KC_##K1, KC_##K2, KC_##TT, KC_##TP, KC_##FN } \
|
||||
{ KC_##K1, KC_##K2, KC_##TT } \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -23,28 +23,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "keymap_common.h"
|
||||
|
||||
enum function_id {
|
||||
CONFIG_MODE = 0,
|
||||
TOUCH_PROXIMITY = 0,
|
||||
CONFIG_MODE,
|
||||
SWITCH_LAYOUT,
|
||||
SWITCH_BACKLIGHT
|
||||
};
|
||||
|
||||
enum {
|
||||
CONFIG_LAYER = 8,
|
||||
};
|
||||
|
||||
// Default
|
||||
#ifdef KEYMAP_SECTION_ENABLE
|
||||
const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
|
||||
#else
|
||||
const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
|
||||
#endif
|
||||
[0] = KEYMAP( Z, X, ESC, NO, FN0 ),
|
||||
[1] = KEYMAP( BTN1,BTN2,ESC, NO, FN0 ),
|
||||
[2] = KEYMAP( LEFT,RGHT,ESC, NO, FN0 ),
|
||||
[3] = KEYMAP( UP, DOWN,ESC, NO, FN0 ),
|
||||
[4] = KEYMAP( PGUP,PGDN,ESC, NO, FN0 ),
|
||||
[5] = KEYMAP( SPC, ESC, ESC, NO, FN0 ),
|
||||
[CONFIG_LAYER] = KEYMAP( FN1, FN2, NO, NO, FN0 ),
|
||||
[0] = KEYMAP( Z, X, ESC ),
|
||||
[1] = KEYMAP( BTN1,BTN2,ESC ),
|
||||
[2] = KEYMAP( LEFT,RGHT,ESC ),
|
||||
[3] = KEYMAP( UP, DOWN,ESC ),
|
||||
[4] = KEYMAP( PGUP,PGDN,ESC ),
|
||||
[5] = KEYMAP( SPC, ESC, ESC ),
|
||||
[CONFIG_LAYER] = KEYMAP( FN30, FN31, NO )
|
||||
};
|
||||
|
||||
/*
|
||||
@ -55,9 +52,10 @@ const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn
|
||||
#else
|
||||
const uint16_t fn_actions[] PROGMEM = {
|
||||
#endif
|
||||
[0] = ACTION_FUNCTION(CONFIG_MODE),
|
||||
[1] = ACTION_FUNCTION(SWITCH_LAYOUT),
|
||||
[2] = ACTION_FUNCTION(SWITCH_BACKLIGHT)
|
||||
[28] = ACTION_FUNCTION(TOUCH_PROXIMITY),
|
||||
[29] = ACTION_FUNCTION(CONFIG_MODE),
|
||||
[30] = ACTION_FUNCTION(SWITCH_LAYOUT),
|
||||
[31] = ACTION_FUNCTION(SWITCH_BACKLIGHT)
|
||||
};
|
||||
|
||||
#ifdef KEYMAP_IN_EEPROM_ENABLE
|
||||
@ -95,7 +93,7 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||
if (config_mode) {
|
||||
default_layer_set(1UL<<layer);
|
||||
eeconfig_write_default_layer(1UL<<layer);
|
||||
layer = (layer + 1) % 6;
|
||||
layer = (layer + 1) % (last_layer() + 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Reference in New Issue
Block a user