From 0a33ce06599a292185d4e55f5ee7ecf262afe37d Mon Sep 17 00:00:00 2001 From: Zach White Date: Wed, 8 Sep 2021 23:15:54 -0700 Subject: [PATCH] wip: support for custom keycodes in json --- data/schemas/definitions.jsonschema | 6 ++++++ data/schemas/keyboard.jsonschema | 4 ++++ data/schemas/keymap.jsonschema | 10 +++++++--- lib/python/qmk/cli/generate/layouts.py | 15 +++++++++++++++ tmk_core/rules.mk | 2 +- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/data/schemas/definitions.jsonschema b/data/schemas/definitions.jsonschema index 822f237073c..fc9a1b1f514 100644 --- a/data/schemas/definitions.jsonschema +++ b/data/schemas/definitions.jsonschema @@ -12,6 +12,12 @@ "minLength": 1, "pattern": "^[0-9a-z_]*$" }, + "keycode": { + "type": "string", + "minLength": 1, + "maxLength": 250, + "pattern": "^[A-Z_][0-9A-Z_()]*$" + }, "hex_number_2d": { "type": "string", "pattern": "^0x[0-9A-F]{2}$" diff --git a/data/schemas/keyboard.jsonschema b/data/schemas/keyboard.jsonschema index 78c9a8d36ba..28faa31ffb7 100644 --- a/data/schemas/keyboard.jsonschema +++ b/data/schemas/keyboard.jsonschema @@ -77,6 +77,10 @@ "lto": {"type": "boolean"}, } }, + "custom_keycodes": { + "type": "array", + "items": {"$ref": "qmk.definitions.v1#/keycode"} + }, "diode_direction": { "type": "string", "enum": ["COL2ROW", "ROW2COL"] diff --git a/data/schemas/keymap.jsonschema b/data/schemas/keymap.jsonschema index a4bdab966b6..024b021a259 100644 --- a/data/schemas/keymap.jsonschema +++ b/data/schemas/keymap.jsonschema @@ -5,6 +5,11 @@ "type": "object", "properties": { "author": {"type": "string"}, + "config": {"$ref": "qmk.keyboard.v1"}, + "custom_keycodes": { + "type": "array", + "items": {"$ref": "qmk.definitions.v1#/keycode"} + }, "keyboard": {"$ref": "qmk.definitions.v1#/text_identifier"}, "keymap": {"$ref": "qmk.definitions.v1#/text_identifier"}, "layout": {"$ref": "qmk.definitions.v1#/layout_macro"}, @@ -12,13 +17,12 @@ "type": "array", "items": { "type": "array", - "items": {"type": "string"} + "items": {"$ref": "qmk.definitions.v1#/keycode"} } }, - "config": {"$ref": "qmk.keyboard.v1"}, "notes": { "type": "string", "description": "asdf" } } -} \ No newline at end of file +} diff --git a/lib/python/qmk/cli/generate/layouts.py b/lib/python/qmk/cli/generate/layouts.py index 4de982f822f..f8c25f20f29 100755 --- a/lib/python/qmk/cli/generate/layouts.py +++ b/lib/python/qmk/cli/generate/layouts.py @@ -51,6 +51,21 @@ def generate_layouts(cli): cli.log.error('%s: Invalid matrix config.', cli.config.generate_layouts.keyboard) return False + if 'custom_keycodes' in kb_info_json: + layouts_h_lines.append('\n#include "quantum_keycodes.h"') + #layouts_h_lines.append('\nenum custom_keycodes {') + first = True + #for keycode in kb_info_json['custom_keycodes']: + # if first: + # first = False + # layouts_h_lines.append(f'\t{keycode} = SAFE_RANGE,') + # else: + # layouts_h_lines.append(f'\t{keycode},') + #layouts_h_lines.append('\tNEW_SAFE_RANGE') + #layouts_h_lines.append('}\n') + #layouts_h_lines.append('#undef SAFE_RANGE') + #layouts_h_lines.append('#define SAFE_RANGE NEW_SAFE_RANGE') + for layout_name in kb_info_json['layouts']: if kb_info_json['layouts'][layout_name]['c_macro']: continue diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index 5a7f299102e..1dfcf75a1f6 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk @@ -358,7 +358,7 @@ $1_CONFIG_FLAGS += $$(patsubst %,-include %,$$($1_CONFIG)) endif $1_CFLAGS = $$(ALL_CFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $$(NOLTO_CFLAGS) $1_CXXFLAGS = $$(ALL_CXXFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $$(NOLTO_CFLAGS) -$1_ASFLAGS = $$(ALL_ASFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) +$1_ASFLAGS = $$(ALL_ASFLAGS) $$($1_DEFS) $$($1_INCFLAGS) # Compile: create object files from C source files. $1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt | $(BEGIN)