summaryrefslogtreecommitdiff
path: root/quantum/dynamic_keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/dynamic_keymap.c')
-rw-r--r--quantum/dynamic_keymap.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c
index fc1c55784d..01be9806e4 100644
--- a/quantum/dynamic_keymap.c
+++ b/quantum/dynamic_keymap.c
@@ -19,7 +19,13 @@
#include "progmem.h" // to read default from flash
#include "quantum.h" // for send_string()
#include "dynamic_keymap.h"
-#include "via.h" // for default VIA_EEPROM_ADDR_END
+
+#ifdef VIA_ENABLE
+# include "via.h" // for VIA_EEPROM_CONFIG_END
+# define DYNAMIC_KEYMAP_EEPROM_START (VIA_EEPROM_CONFIG_END)
+#else
+# define DYNAMIC_KEYMAP_EEPROM_START (EECONFIG_SIZE)
+#endif
#ifdef ENCODER_ENABLE
# include "encoder.h"
@@ -55,13 +61,8 @@
#endif
// If DYNAMIC_KEYMAP_EEPROM_ADDR not explicitly defined in config.h,
-// default it start after VIA_EEPROM_CUSTOM_ADDR+VIA_EEPROM_CUSTOM_SIZE
#ifndef DYNAMIC_KEYMAP_EEPROM_ADDR
-# ifdef VIA_EEPROM_CUSTOM_CONFIG_ADDR
-# define DYNAMIC_KEYMAP_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR + VIA_EEPROM_CUSTOM_CONFIG_SIZE)
-# else
-# error DYNAMIC_KEYMAP_EEPROM_ADDR not defined
-# endif
+# define DYNAMIC_KEYMAP_EEPROM_ADDR DYNAMIC_KEYMAP_EEPROM_START
#endif
// Dynamic encoders starts after dynamic keymaps
@@ -93,6 +94,10 @@ _Static_assert((DYNAMIC_KEYMAP_EEPROM_MAX_ADDR) - (DYNAMIC_KEYMAP_MACRO_EEPROM_A
# define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE (DYNAMIC_KEYMAP_EEPROM_MAX_ADDR - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + 1)
#endif
+#ifndef DYNAMIC_KEYMAP_MACRO_DELAY
+# define DYNAMIC_KEYMAP_MACRO_DELAY TAP_CODE_DELAY
+#endif
+
uint8_t dynamic_keymap_get_layer_count(void) {
return DYNAMIC_KEYMAP_LAYER_COUNT;
}
@@ -144,18 +149,25 @@ void dynamic_keymap_set_encoder(uint8_t layer, uint8_t encoder_id, bool clockwis
void dynamic_keymap_reset(void) {
// Reset the keymaps in EEPROM to what is in flash.
- // All keyboards using dynamic keymaps should define a layout
- // for the same number of layers as DYNAMIC_KEYMAP_LAYER_COUNT.
for (int layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) {
for (int row = 0; row < MATRIX_ROWS; row++) {
for (int column = 0; column < MATRIX_COLS; column++) {
- dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column]));
+ if (layer < keymap_layer_count()) {
+ dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column]));
+ } else {
+ dynamic_keymap_set_keycode(layer, row, column, KC_TRANSPARENT);
+ }
}
}
#ifdef ENCODER_MAP_ENABLE
for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) {
- dynamic_keymap_set_encoder(layer, encoder, true, pgm_read_word(&encoder_map[layer][encoder][0]));
- dynamic_keymap_set_encoder(layer, encoder, false, pgm_read_word(&encoder_map[layer][encoder][1]));
+ if (layer < encodermap_layer_count()) {
+ dynamic_keymap_set_encoder(layer, encoder, true, pgm_read_word(&encoder_map[layer][encoder][0]));
+ dynamic_keymap_set_encoder(layer, encoder, false, pgm_read_word(&encoder_map[layer][encoder][1]));
+ } else {
+ dynamic_keymap_set_encoder(layer, encoder, true, KC_TRANSPARENT);
+ dynamic_keymap_set_encoder(layer, encoder, false, KC_TRANSPARENT);
+ }
}
#endif // ENCODER_MAP_ENABLE
}
@@ -300,6 +312,6 @@ void dynamic_keymap_macro_send(uint8_t id) {
break;
}
}
- send_string(data);
+ send_string_with_delay(data, DYNAMIC_KEYMAP_MACRO_DELAY);
}
}