Skip to content

Commit

Permalink
Refactor KEYMAPS(...) macro
Browse files Browse the repository at this point in the history
This refactors the KEYMAPS(...) macro and factors out
a header and footer portion that are now define as individual
macros START_KEYMAPS and END_KEYMAPS. The original
KEYMAPS(...) macro now relies on the newly defined macros.

The newly introduced macros enable keymap definitions that
allow for macro definitions between the start and end part
which is not possible inside the KEYMAPS(...) macro invocation.

Signed-off-by: Florian Fleissner <florian.fleissner@inpartik.de>
  • Loading branch information
Florian Fleissner committed Nov 15, 2019
1 parent befceaf commit ca8be53
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/kaleidoscope/layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,26 @@
#include KALEIDOSCOPE_HARDWARE_H
#include "kaleidoscope_internal/device.h"

#define START_KEYMAPS __NL__ \
const Key keymaps_linear[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] PROGMEM = {

#define END_KEYMAPS __NL__ \
}; __NL__ \
uint8_t layer_count __NL__ \
= sizeof(keymaps_linear) / sizeof(*keymaps_linear); __NL__ \
__NL__ \
/* This deprecated compatibility wrapper is removed by the linker if __NL__ \
it is not accessed nowhere. __NL__ \
*/ __NL__ \
kaleidoscope::internal::Keymaps2DInterface keymaps;

// 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 KEYMAPS(layers...) __NL__ \
const Key keymaps_linear[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] PROGMEM = { layers }; __NL__ \
uint8_t layer_count __NL__ \
= sizeof(keymaps_linear) / sizeof(*keymaps_linear); __NL__ \
__NL__ \
/* This deprecated compatibility wrapper is removed by the linker if __NL__ \
it is not accessed nowhere. __NL__ \
*/ __NL__ \
kaleidoscope::internal::Keymaps2DInterface keymaps;
#define KEYMAPS(layers...) __NL__ \
START_KEYMAPS __NL__ \
layers __NL__ \
END_KEYMAPS

extern uint8_t layer_count;

Expand Down

0 comments on commit ca8be53

Please sign in to comment.