Skip to content

Commit 2609ee9

Browse files
author
Florian Fleissner
committed
Refactor KEYMAPS(...) macro
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 <[email protected]>
1 parent 552770f commit 2609ee9

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/kaleidoscope/layers.h

+17-9
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,26 @@
2222
#include KALEIDOSCOPE_HARDWARE_H
2323
#include "kaleidoscope_internal/device.h"
2424

25+
#define START_KEYMAPS __NL__ \
26+
const Key keymaps_linear[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] PROGMEM = {
27+
28+
#define END_KEYMAPS __NL__ \
29+
}; __NL__ \
30+
uint8_t layer_count __NL__ \
31+
= sizeof(keymaps_linear) / sizeof(*keymaps_linear); __NL__ \
32+
__NL__ \
33+
/* This deprecated compatibility wrapper is removed by the linker if __NL__ \
34+
it is not accessed nowhere. __NL__ \
35+
*/ __NL__ \
36+
kaleidoscope::internal::Keymaps2DInterface keymaps;
37+
2538
// Macro for defining the keymap. This should be used in the sketch
2639
// file (*.ino) to define the keymap[] array that holds the user's
2740
// layers. It also computes the number of layers in that keymap.
28-
#define KEYMAPS(layers...) __NL__ \
29-
const Key keymaps_linear[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] PROGMEM = { layers }; __NL__ \
30-
uint8_t layer_count __NL__ \
31-
= sizeof(keymaps_linear) / sizeof(*keymaps_linear); __NL__ \
32-
__NL__ \
33-
/* This deprecated compatibility wrapper is removed by the linker if __NL__ \
34-
it is not accessed nowhere. __NL__ \
35-
*/ __NL__ \
36-
kaleidoscope::internal::Keymaps2DInterface keymaps;
41+
#define KEYMAPS(layers...) __NL__ \
42+
START_KEYMAPS __NL__ \
43+
layers __NL__ \
44+
END_KEYMAPS
3745

3846
extern uint8_t layer_count;
3947

0 commit comments

Comments
 (0)