Add dynamic key overrides support

This commit is contained in:
Ilya Zhuravlev
2021-09-30 13:16:41 -04:00
parent 0f73a109c6
commit 53a41dcfab
5 changed files with 165 additions and 2 deletions

View File

@ -101,9 +101,18 @@ static pin_t encoders_pad_a[] = ENCODERS_PAD_A;
#define VIAL_COMBO_SIZE 0
#endif
// Key overrides
#define VIAL_KEY_OVERRIDE_EEPROM_ADDR (VIAL_COMBO_EEPROM_ADDR + VIAL_COMBO_SIZE)
#ifdef VIAL_KEY_OVERRIDE_ENABLE
#define VIAL_KEY_OVERRIDE_SIZE (sizeof(vial_key_override_entry_t) * VIAL_KEY_OVERRIDE_ENTRIES)
#else
#define VIAL_KEY_OVERRIDE_SIZE 0
#endif
// Dynamic macro
#ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR
# define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (VIAL_COMBO_EEPROM_ADDR + VIAL_COMBO_SIZE)
# define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (VIAL_KEY_OVERRIDE_EEPROM_ADDR + VIAL_KEY_OVERRIDE_SIZE)
#endif
// Sanity check that dynamic keymaps fit in available EEPROM
@ -246,6 +255,28 @@ int dynamic_keymap_set_combo(uint8_t index, const vial_combo_entry_t *entry) {
}
#endif
#ifdef VIAL_KEY_OVERRIDE_ENABLE
int dynamic_keymap_get_key_override(uint8_t index, vial_key_override_entry_t *entry) {
if (index >= VIAL_KEY_OVERRIDE_ENTRIES)
return -1;
void *address = (void*)(VIAL_KEY_OVERRIDE_EEPROM_ADDR + index * sizeof(vial_key_override_entry_t));
eeprom_read_block(entry, address, sizeof(vial_key_override_entry_t));
return 0;
}
int dynamic_keymap_set_key_override(uint8_t index, const vial_key_override_entry_t *entry) {
if (index >= VIAL_KEY_OVERRIDE_ENTRIES)
return -1;
void *address = (void*)(VIAL_KEY_OVERRIDE_EEPROM_ADDR + index * sizeof(vial_key_override_entry_t));
eeprom_write_block(entry, address, sizeof(vial_key_override_entry_t));
return 0;
}
#endif
#if defined(VIAL_ENCODERS_ENABLE) && defined(VIAL_ENCODER_DEFAULT)
static const uint16_t PROGMEM vial_encoder_default[] = VIAL_ENCODER_DEFAULT;
_Static_assert(sizeof(vial_encoder_default)/sizeof(*vial_encoder_default) == 2 * DYNAMIC_KEYMAP_LAYER_COUNT * NUMBER_OF_ENCODERS,
@ -299,6 +330,14 @@ void dynamic_keymap_reset(void) {
dynamic_keymap_set_combo(i, &combo);
#endif
#ifdef VIAL_KEY_OVERRIDE_ENABLE
vial_key_override_entry_t ko = { 0 };
ko.layers = ~0;
ko.options = vial_ko_option_activation_negative_mod_up | vial_ko_option_activation_required_mod_down | vial_ko_option_activation_trigger_down;
for (size_t i = 0; i < VIAL_KEY_OVERRIDE_ENTRIES; ++i)
dynamic_keymap_set_key_override(i, &ko);
#endif
#ifdef VIAL_ENABLE
/* re-lock the keyboard */
vial_unlocked = vial_unlocked_prev;