From 2784d0e9a9ce94308ba323ea2e1ff218eaaa1285 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Sun, 19 Nov 2017 12:00:07 -0600 Subject: [PATCH] Use weak attribute declaration for LayerCount Declaring LayerCount as a weak symbol in layers.cpp lets us override it if the CREATE_KEYMAP macro is used to define the keymap in the sketch file, but still allows old sketch files to compile without errors. Still some changes necessary to allow old sketches to work properly (Layer.on() will abort before doing anything). --- src/layers.cpp | 3 +++ src/layers.h | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/layers.cpp b/src/layers.cpp index 7bfe05ab..0cf9129d 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -8,6 +8,9 @@ Key Layer_::liveCompositeKeymap[ROWS][COLS]; uint8_t Layer_::activeLayers[ROWS][COLS]; Key(*Layer_::getKey)(uint8_t layer, byte row, byte col) = Layer.getKeyFromPROGMEM; +// The total number of defined layers in the firmware sketch keymaps[] array +uint8_t LayerCount __attribute__((weak)) = 0; + static void handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) { if (keymapEntry.keyCode >= LAYER_SHIFT_OFFSET) { uint8_t target = keymapEntry.keyCode - LAYER_SHIFT_OFFSET; diff --git a/src/layers.h b/src/layers.h index 19512477..f34ce0e4 100644 --- a/src/layers.h +++ b/src/layers.h @@ -6,10 +6,7 @@ #define CREATE_KEYMAP(layers...) \ const Key keymaps[][ROWS][COLS] PROGMEM = { layers }; \ - const uint8_t LayerCount = sizeof(keymaps) / sizeof(*keymaps); - -// The total number of defined layers in the firmware sketch keymaps[] array -extern const uint8_t LayerCount; + uint8_t LayerCount = sizeof(keymaps) / sizeof(*keymaps); class Layer_ {