summaryrefslogtreecommitdiff
path: root/lib/python/qmk/keymap.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/keymap.py')
-rw-r--r--lib/python/qmk/keymap.py36
1 files changed, 33 insertions, 3 deletions
diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py
index dddf6449a7..11e8d39dad 100644
--- a/lib/python/qmk/keymap.py
+++ b/lib/python/qmk/keymap.py
@@ -25,13 +25,14 @@ __INCLUDES__
* This file was generated by qmk json2c. You may or may not want to
* edit it directly.
*/
+__KEYCODE_OUTPUT_GOES_HERE__
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
__KEYMAP_GOES_HERE__
};
#if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
-const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = {
+const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
__ENCODER_MAP_GOES_HERE__
};
#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
@@ -123,6 +124,29 @@ def _generate_macros_function(keymap_json):
return macro_txt
+def _generate_keycodes_function(keymap_json):
+ """Generates keymap level keycodes.
+ """
+ lines = []
+ lines.append('enum keymap_keycodes {')
+
+ for index, item in enumerate(keymap_json.get('keycodes', [])):
+ key = item["key"]
+ if index == 0:
+ lines.append(f' {key} = QK_USER_0,')
+ else:
+ lines.append(f' {key},')
+
+ lines.append('};')
+
+ for item in keymap_json.get('keycodes', []):
+ key = item["key"]
+ for alias in item.get("aliases", []):
+ lines.append(f'#define {alias} {key}')
+
+ return lines
+
+
def template_json(keyboard):
"""Returns a `keymap.json` template for a keyboard.
@@ -317,6 +341,12 @@ def generate_c(keymap_json):
hostlang = f'#include "keymap_{keymap_json["host_language"]}.h"\n#include "sendstring_{keymap_json["host_language"]}.h"\n'
new_keymap = new_keymap.replace('__INCLUDES__', hostlang)
+ keycodes = ''
+ if 'keycodes' in keymap_json and keymap_json['keycodes'] is not None:
+ keycodes_txt = _generate_keycodes_function(keymap_json)
+ keycodes = '\n'.join(keycodes_txt)
+ new_keymap = new_keymap.replace('__KEYCODE_OUTPUT_GOES_HERE__', keycodes)
+
return new_keymap
@@ -349,7 +379,7 @@ def write_json(keyboard, keymap, layout, layers, macros=None):
"""
keymap_json = generate_json(keyboard, keymap, layout, layers, macros=None)
keymap_content = json.dumps(keymap_json)
- keymap_file = qmk.path.keymap(keyboard) / keymap / 'keymap.json'
+ keymap_file = qmk.path.keymaps(keyboard)[0] / keymap / 'keymap.json'
return write_file(keymap_file, keymap_content)
@@ -376,7 +406,7 @@ def write(keymap_json):
A list of macros for this keymap.
"""
keymap_content = generate_c(keymap_json)
- keymap_file = qmk.path.keymap(keymap_json['keyboard']) / keymap_json['keymap'] / 'keymap.c'
+ keymap_file = qmk.path.keymaps(keymap_json['keyboard'])[0] / keymap_json['keymap'] / 'keymap.c'
return write_file(keymap_file, keymap_content)