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.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c
index 8c2d2f5dce..fd1cd2507f 100644
--- a/quantum/dynamic_keymap.c
+++ b/quantum/dynamic_keymap.c
@@ -14,12 +14,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-#include "keymap.h" // to get keymaps[][][]
+#include "keymap.h" // to get keymaps[][][]
#include "eeprom.h"
#include "progmem.h" // to read default from flash
#include "quantum.h" // for send_string()
#include "eeconfig.h"
+#include "dynamic_keymap.h"
#ifndef DYNAMIC_KEYMAP_LAYER_COUNT
# define DYNAMIC_KEYMAP_LAYER_COUNT 4
@@ -29,24 +29,22 @@
# 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 TOTAL_EEPROM_BYTE_COUNT
+# error Unknown total EEPROM size. Cannot derive maximum for dynamic keymaps.
+#endif
+
#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
-# else
-# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 1023
-# endif
+# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR (TOTAL_EEPROM_BYTE_COUNT - 1)
+#endif
+
+#if DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > (TOTAL_EEPROM_BYTE_COUNT - 1)
+# pragma message STR(DYNAMIC_KEYMAP_EEPROM_MAX_ADDR) " > " STR((TOTAL_EEPROM_BYTE_COUNT - 1))
+# error DYNAMIC_KEYMAP_EEPROM_MAX_ADDR is configured to use more space than what is available for the selected EEPROM driver
#endif
// Due to usage of uint16_t check for max 65535
#if DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > 65535
+# pragma message STR(DYNAMIC_KEYMAP_EEPROM_MAX_ADDR) " > 65535"
# error DYNAMIC_KEYMAP_EEPROM_MAX_ADDR must be less than 65536
#endif
@@ -75,6 +73,7 @@
// or DYNAMIC_KEYMAP_EEPROM_MAX_ADDR to increase it, *only if* the microcontroller has
// more than the default.
#if DYNAMIC_KEYMAP_EEPROM_MAX_ADDR - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR < 100
+# pragma message STR(DYNAMIC_KEYMAP_EEPROM_MAX_ADDR - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR) " < 100"
# error Dynamic keymaps are configured to use more EEPROM than is available.
#endif
@@ -84,7 +83,9 @@
# define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE (DYNAMIC_KEYMAP_EEPROM_MAX_ADDR - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + 1)
#endif
-uint8_t dynamic_keymap_get_layer_count(void) { return DYNAMIC_KEYMAP_LAYER_COUNT; }
+uint8_t dynamic_keymap_get_layer_count(void) {
+ return DYNAMIC_KEYMAP_LAYER_COUNT;
+}
void *dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column) {
// TODO: optimize this with some left shifts
@@ -156,9 +157,13 @@ uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) {
}
}
-uint8_t dynamic_keymap_macro_get_count(void) { return DYNAMIC_KEYMAP_MACRO_COUNT; }
+uint8_t dynamic_keymap_macro_get_count(void) {
+ return DYNAMIC_KEYMAP_MACRO_COUNT;
+}
-uint16_t dynamic_keymap_macro_get_buffer_size(void) { return DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE; }
+uint16_t dynamic_keymap_macro_get_buffer_size(void) {
+ return DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE;
+}
void dynamic_keymap_macro_get_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
void * source = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + offset);