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).
pull/244/head
Michael Richters 7 years ago
parent de39e20d78
commit 2784d0e9a9

@ -8,6 +8,9 @@ Key Layer_::liveCompositeKeymap[ROWS][COLS];
uint8_t Layer_::activeLayers[ROWS][COLS]; uint8_t Layer_::activeLayers[ROWS][COLS];
Key(*Layer_::getKey)(uint8_t layer, byte row, byte col) = Layer.getKeyFromPROGMEM; 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) { static void handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) {
if (keymapEntry.keyCode >= LAYER_SHIFT_OFFSET) { if (keymapEntry.keyCode >= LAYER_SHIFT_OFFSET) {
uint8_t target = keymapEntry.keyCode - LAYER_SHIFT_OFFSET; uint8_t target = keymapEntry.keyCode - LAYER_SHIFT_OFFSET;

@ -6,10 +6,7 @@
#define CREATE_KEYMAP(layers...) \ #define CREATE_KEYMAP(layers...) \
const Key keymaps[][ROWS][COLS] PROGMEM = { layers }; \ const Key keymaps[][ROWS][COLS] PROGMEM = { layers }; \
const uint8_t LayerCount = sizeof(keymaps) / sizeof(*keymaps); uint8_t LayerCount = sizeof(keymaps) / sizeof(*keymaps);
// The total number of defined layers in the firmware sketch keymaps[] array
extern const uint8_t LayerCount;
class Layer_ { class Layer_ {

Loading…
Cancel
Save