From ddb0f39ebf317c7a23c69ed45efb1882746a01b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Mon, 11 Feb 2019 23:21:41 +0100 Subject: [PATCH] Generate UNICODE and UNICODEMAP constants using macros --- users/konstantin/konstantin.h | 2 +- users/konstantin/rules.mk | 3 +++ users/konstantin/unicode.c | 7 +++++++ users/konstantin/unicode.h | 37 ++++++++++++++++++++++++++++------- 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 users/konstantin/unicode.c diff --git a/users/konstantin/konstantin.h b/users/konstantin/konstantin.h index d8b00c4c89..c32d674e8c 100644 --- a/users/konstantin/konstantin.h +++ b/users/konstantin/konstantin.h @@ -7,7 +7,7 @@ #ifdef TAP_DANCE_ENABLE #include "tap_dance.h" #endif -#ifdef UNICODE_ENABLE +#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) #include "unicode.h" #endif diff --git a/users/konstantin/rules.mk b/users/konstantin/rules.mk index 8913e57558..6bda030fb0 100644 --- a/users/konstantin/rules.mk +++ b/users/konstantin/rules.mk @@ -5,5 +5,8 @@ endif ifeq ($(strip $(TAP_DANCE_ENABLE)), yes) SRC += tap_dance.c endif +ifneq (,$(filter yes,$(UNICODE_ENABLE) $(UNICODEMAP_ENABLE))) # if either is yes + SRC += unicode.c +endif EXTRAFLAGS += -flto diff --git a/users/konstantin/unicode.c b/users/konstantin/unicode.c new file mode 100644 index 0000000000..3b6164bc51 --- /dev/null +++ b/users/konstantin/unicode.c @@ -0,0 +1,7 @@ +#include "unicode.h" + +#ifdef UNICODEMAP_ENABLE + const uint32_t PROGMEM unicode_map[] = { + FOREACH_UNICODE(X_ENTRY) + }; +#endif diff --git a/users/konstantin/unicode.h b/users/konstantin/unicode.h index 09af7e1c7f..d76f2a1700 100644 --- a/users/konstantin/unicode.h +++ b/users/konstantin/unicode.h @@ -2,10 +2,33 @@ #include "quantum.h" -#define COMMA UC(0x002C) -#define L_PAREN UC(0x0028) -#define R_PAREN UC(0x0029) -#define EQUALS UC(0x003D) -#define TIMES UC(0x00D7) -#define DIVIDE UC(0x00F7) -#define MINUS UC(0x2212) +#define FOREACH_UNICODE(M) \ + M(COMMA, 0x002C) \ + M(L_PAREN, 0x0028) \ + M(R_PAREN, 0x0029) \ + M(EQUALS, 0x003D) \ + M(TIMES, 0x00D7) \ + M(DIVIDE, 0x00F7) \ + M(MINUS, 0x2212) + +#define UC_KEYCODE(name, code) name = UC(code), + +#define X_NAME(name, code) X_ ## name, +#define X_ENTRY(name, code) [X_ ## name] = code, +#define X_KEYCODE(name, code) name = X(X_ ## name), + +#if defined(UNICODE_ENABLE) + enum unicode_keycodes { + FOREACH_UNICODE(UC_KEYCODE) + }; +#elif defined(UNICODEMAP_ENABLE) + enum unicode_names { + FOREACH_UNICODE(X_NAME) + }; + + extern const uint32_t PROGMEM unicode_map[]; + + enum unicode_keycodes { + FOREACH_UNICODE(X_KEYCODE) + }; +#endif