From 771c0de2475d7adeb418ee85fc6d21e46be9390d Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Wed, 9 Nov 2016 12:47:05 -0800 Subject: [PATCH] move keymaps to progmem. This is a fairly large memory win --- key_defs.h | 10 +++++++--- key_events.cpp | 12 +++++++----- key_events.h | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/key_defs.h b/key_defs.h index e132e766..2ca01f91 100644 --- a/key_defs.h +++ b/key_defs.h @@ -2,9 +2,13 @@ #include "HIDTables.h" -typedef struct { - uint8_t flags; - uint8_t rawKey; +typedef union { + + struct { + uint8_t flags; + uint8_t rawKey; + }; + uint16_t raw; } Key; diff --git a/key_events.cpp b/key_events.cpp index 741c9df5..7ebeb7d3 100644 --- a/key_events.cpp +++ b/key_events.cpp @@ -1,6 +1,6 @@ #include "key_events.h" -const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_LIST }; +static const Key keymaps[KEYMAPS][ROWS][COLS] PROGMEM = { KEYMAP_LIST }; void handle_synthetic_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState) { if (mappedKey.flags & IS_MOUSE_KEY && !( mappedKey.rawKey & KEY_MOUSE_WARP) ) { @@ -50,10 +50,12 @@ void handle_key_event(byte row, byte col, uint8_t currentState, uint8_t previous //for every newly pressed button, figure out what logical key it is and send a key down event // for every newly released button, figure out what logical key it is and send a key up event - Key mappedKey = keymaps[temporary_keymap][row][col]; - - if (keymaps[primary_keymap][row][col].flags & SWITCH_TO_KEYMAP) { - handle_keymap_key_event(keymaps[primary_keymap][row][col], currentState, previousState); + Key mappedKey; + mappedKey.raw= pgm_read_word(&(keymaps[temporary_keymap][row][col])); + Key baseKey; + baseKey.raw= pgm_read_word(&(keymaps[primary_keymap][row][col])); + if (baseKey.flags & SWITCH_TO_KEYMAP) { + handle_keymap_key_event(baseKey, currentState, previousState); } else if (mappedKey.flags & SYNTHETIC_KEY) { handle_synthetic_key_event( mappedKey, currentState, previousState); } else if (key_is_pressed(currentState, previousState)) { diff --git a/key_events.h b/key_events.h index 844798bd..20661ab9 100644 --- a/key_events.h +++ b/key_events.h @@ -9,7 +9,7 @@ #include "keymap_metadata.h" #include "generated/keymaps.h" -extern const Key keymaps[KEYMAPS][ROWS][COLS]; +//static const Key keymaps[KEYMAPS][ROWS][COLS]; extern uint8_t primary_keymap; extern uint8_t temporary_keymap;