diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c index c9a5cc793c..fb2338b69e 100644 --- a/quantum/dynamic_keymap.c +++ b/quantum/dynamic_keymap.c @@ -21,10 +21,7 @@ #include "quantum.h" // for send_string() #include "dynamic_keymap.h" #include "via.h" // for default VIA_EEPROM_ADDR_END - -#ifdef STM32_EEPROM_ENABLE -# include "eeprom_stm32.h" -#endif +#include "dynamic_keymap_eeprom.h" #ifdef VIAL_ENABLE #include "vial.h" @@ -34,24 +31,6 @@ # define DYNAMIC_KEYMAP_MACRO_COUNT 16 #endif -// This is the default EEPROM max address to use for dynamic keymaps. -// The default is the ATmega32u4 EEPROM max address. -// Explicitly override it if the keyboard uses a microcontroller with -// more EEPROM *and* it makes sense to increase it. -#ifndef DYNAMIC_KEYMAP_EEPROM_MAX_ADDR -# if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) -# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 2047 -# elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) -# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 4095 -# elif defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATtiny85__) -# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 511 -# elif defined(FEE_DENSITY_BYTES) -# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR FEE_DENSITY_BYTES-1 -# else -# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 1023 -# endif -#endif - // Due to usage of uint16_t check for max 65535 #if DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > 65535 # error DYNAMIC_KEYMAP_EEPROM_MAX_ADDR must be less than 65536 diff --git a/quantum/dynamic_keymap.h b/quantum/dynamic_keymap.h index 5114cbe46a..023af87ea7 100644 --- a/quantum/dynamic_keymap.h +++ b/quantum/dynamic_keymap.h @@ -18,6 +18,10 @@ #include #include +#ifdef VIAL_ENABLE +#include "vial.h" +#endif + #ifndef DYNAMIC_KEYMAP_LAYER_COUNT # define DYNAMIC_KEYMAP_LAYER_COUNT 4 #endif diff --git a/quantum/dynamic_keymap_eeprom.h b/quantum/dynamic_keymap_eeprom.h new file mode 100644 index 0000000000..4ce8d4baeb --- /dev/null +++ b/quantum/dynamic_keymap_eeprom.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#pragma once + +#ifdef STM32_EEPROM_ENABLE +# include "eeprom_stm32.h" +#endif + +// This is the default EEPROM max address to use for dynamic keymaps. +// The default is the ATmega32u4 EEPROM max address. +// Explicitly override it if the keyboard uses a microcontroller with +// more EEPROM *and* it makes sense to increase it. +#ifndef DYNAMIC_KEYMAP_EEPROM_MAX_ADDR +# if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) +# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 2047 +# elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) +# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 4095 +# elif defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATtiny85__) +# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 511 +# elif defined(FEE_DENSITY_BYTES) +# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR FEE_DENSITY_BYTES-1 +# else +# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 1023 +# endif +#endif diff --git a/quantum/vial.h b/quantum/vial.h index 74e648fa23..3ace285444 100644 --- a/quantum/vial.h +++ b/quantum/vial.h @@ -19,6 +19,8 @@ #include #include +#include "dynamic_keymap_eeprom.h" + #define VIAL_PROTOCOL_VERSION ((uint32_t)0x00000004) #define VIAL_RAW_EPSIZE 32 @@ -66,7 +68,15 @@ enum { #define VIAL_TAP_DANCE_ENABLE #ifndef VIAL_TAP_DANCE_ENTRIES -#define VIAL_TAP_DANCE_ENTRIES 16 + #if DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > 4000 + #define VIAL_TAP_DANCE_ENTRIES 32 + #elif DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > 2000 + #define VIAL_TAP_DANCE_ENTRIES 16 + #elif DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > 1000 + #define VIAL_TAP_DANCE_ENTRIES 8 + #else + #define VIAL_TAP_DANCE_ENTRIES 4 + #endif #endif typedef struct { @@ -87,7 +97,15 @@ _Static_assert(sizeof(vial_tap_dance_entry_t) == 10, "Unexpected size of the via #define VIAL_COMBO_ENABLE #ifndef VIAL_COMBO_ENTRIES -#define VIAL_COMBO_ENTRIES 16 + #if DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > 4000 + #define VIAL_COMBO_ENTRIES 32 + #elif DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > 2000 + #define VIAL_COMBO_ENTRIES 16 + #elif DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > 1000 + #define VIAL_COMBO_ENTRIES 8 + #else + #define VIAL_COMBO_ENTRIES 4 + #endif #endif typedef struct { @@ -104,5 +122,6 @@ _Static_assert(sizeof(vial_combo_entry_t) == 10, "Unexpected size of the vial_co #define COMBO_COUNT VIAL_COMBO_ENTRIES #else +#undef VIAL_COMBO_ENTRIES #define VIAL_COMBO_ENTRIES 0 #endif