diff --git a/src/layers.cpp b/src/layers.cpp index 125ca4a4..b3263d42 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -8,7 +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 +// The total number of defined layers in the firmware sketch keymaps[] +// array. If the keymap wasn't defined using CREATE_KEYMAP() in the +// sketch file, LayerCount gets the default value of zero. uint8_t LayerCount __attribute__((weak)) = 0; static void handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) { @@ -128,7 +130,8 @@ void Layer_::move(uint8_t layer) { } void Layer_::on(uint8_t layer) { - // If we're trying to turn on a layer that doesn't exist; abort + // If we're trying to turn on a layer that doesn't exist, abort (but + // if the keymap wasn't defined using CREATE_KEYMAP(), proceed anyway if (LayerCount != 0 && layer >= LayerCount) return; diff --git a/src/layers.h b/src/layers.h index f34ce0e4..09a2c6dc 100644 --- a/src/layers.h +++ b/src/layers.h @@ -4,6 +4,9 @@ #include "key_defs.h" #include KALEIDOSCOPE_HARDWARE_H +// Macro for defining the keymap. This should be used in the sketch +// file (*.ino) to define the keymap[] array that holds the user's +// layers. It also computes the number of layers in that keymap. #define CREATE_KEYMAP(layers...) \ const Key keymaps[][ROWS][COLS] PROGMEM = { layers }; \ uint8_t LayerCount = sizeof(keymaps) / sizeof(*keymaps);