mirror of
https://github.com/qmk/qmk_firmware
synced 2024-12-22 08:26:21 +00:00
Allow codegen of keymap.json
=> keymap.c
without requiring layers/layout etc. (#23451)
This commit is contained in:
parent
859dab864a
commit
7d8f193988
@ -186,7 +186,10 @@ endif
|
||||
# Have we found a keymap.json?
|
||||
ifneq ("$(wildcard $(KEYMAP_JSON))", "")
|
||||
ifneq ("$(wildcard $(KEYMAP_C))", "")
|
||||
$(call WARNING_MESSAGE,Keymap is specified as both keymap.json and keymap.c -- keymap.json file wins.)
|
||||
# Allow a separately-found keymap.c next to keymap.json -- the keymap.c
|
||||
# generator will include the other keymap.c in the process, if supplied.
|
||||
OTHER_KEYMAP_C := $(KEYMAP_C)
|
||||
OPT_DEFS += -DOTHER_KEYMAP_C=\"$(OTHER_KEYMAP_C)\"
|
||||
endif
|
||||
|
||||
KEYMAP_PATH := $(KEYMAP_JSON_PATH)
|
||||
|
@ -72,10 +72,5 @@
|
||||
"notes": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"keyboard",
|
||||
"layout",
|
||||
"layers"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,6 @@
|
||||
"pid": "0x6465",
|
||||
"device_version": "0.0.1"
|
||||
},
|
||||
"tapping": {
|
||||
"term": 500
|
||||
},
|
||||
"diode_direction": "COL2ROW",
|
||||
"features": {
|
||||
"bootmagic": false,
|
||||
|
@ -3,9 +3,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#define DEBUG_MATRIX_SCAN_RATE
|
||||
|
||||
#define QMK_WAITING_TEST_BUSY_PIN GP8
|
||||
#define QMK_WAITING_TEST_YIELD_PIN GP9
|
||||
|
||||
@ -18,4 +15,4 @@
|
||||
#define I2C_DRIVER I2CD0
|
||||
#define I2C1_SDA_PIN GP12
|
||||
#define I2C1_SCL_PIN GP13
|
||||
|
||||
|
||||
|
10
keyboards/handwired/onekey/keymaps/adc/keymap.json
Normal file
10
keyboards/handwired/onekey/keymaps/adc/keymap.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"config": {
|
||||
"features": {
|
||||
"console": true
|
||||
},
|
||||
"tapping": {
|
||||
"term": 500
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1 @@
|
||||
CONSOLE_ENABLE = yes
|
||||
|
||||
ANALOG_DRIVER_REQUIRED = yes
|
||||
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define RGBLIGHT_LED_COUNT 40
|
||||
#define APA102_DEFAULT_BRIGHTNESS 5
|
||||
#define RGBLIGHT_EFFECT_BREATHING
|
||||
#define RGBLIGHT_EFFECT_RAINBOW_MOOD
|
||||
#define RGBLIGHT_EFFECT_RAINBOW_SWIRL
|
||||
#define RGBLIGHT_EFFECT_SNAKE
|
||||
#define RGBLIGHT_EFFECT_KNIGHT
|
||||
#define RGBLIGHT_EFFECT_CHRISTMAS
|
||||
#define RGBLIGHT_EFFECT_STATIC_GRADIENT
|
||||
#define RGBLIGHT_EFFECT_RGB_TEST
|
||||
#define RGBLIGHT_EFFECT_ALTERNATING
|
||||
#define RGBLIGHT_EFFECT_TWINKLE
|
29
keyboards/handwired/onekey/keymaps/apa102/keymap.json
Normal file
29
keyboards/handwired/onekey/keymaps/apa102/keymap.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"config": {
|
||||
"features": {
|
||||
"rgblight": true
|
||||
},
|
||||
"tapping": {
|
||||
"term": 500
|
||||
},
|
||||
"rgblight": {
|
||||
"driver": "apa102",
|
||||
"led_count": 40,
|
||||
"default": {
|
||||
"val": 5
|
||||
},
|
||||
"animations": {
|
||||
"breathing": true,
|
||||
"rainbow_mood": true,
|
||||
"rainbow_swirl": true,
|
||||
"snake": true,
|
||||
"knight": true,
|
||||
"christmas": true,
|
||||
"static_gradient": true,
|
||||
"rgb_test": true,
|
||||
"alternating": true,
|
||||
"twinkle": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
RGBLIGHT_ENABLE = yes
|
||||
RGBLIGHT_DRIVER = apa102
|
@ -1,3 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define BACKLIGHT_BREATHING
|
14
keyboards/handwired/onekey/keymaps/backlight/keymap.json
Normal file
14
keyboards/handwired/onekey/keymaps/backlight/keymap.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"config": {
|
||||
"features": {
|
||||
"backlight": true,
|
||||
"tap_dance": true
|
||||
},
|
||||
"tapping": {
|
||||
"term": 500
|
||||
},
|
||||
"backlight": {
|
||||
"breathing": true
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
BACKLIGHT_ENABLE = yes
|
||||
TAP_DANCE_ENABLE = yes
|
8
keyboards/handwired/onekey/keymaps/console/keymap.json
Normal file
8
keyboards/handwired/onekey/keymaps/console/keymap.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"config": {
|
||||
"features": {
|
||||
"console": true,
|
||||
"debug_matrix_scan_rate": true
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
CONSOLE_ENABLE = yes
|
||||
DEBUG_MATRIX_SCAN_RATE_ENABLE = yes
|
7
keyboards/handwired/onekey/keymaps/default/keymap.json
Normal file
7
keyboards/handwired/onekey/keymaps/default/keymap.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"config": {
|
||||
"tapping": {
|
||||
"term": 500
|
||||
}
|
||||
}
|
||||
}
|
@ -3,9 +3,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#define DEBUG_MATRIX_SCAN_RATE
|
||||
|
||||
#define QMK_WAITING_TEST_BUSY_PIN GP8
|
||||
#define QMK_WAITING_TEST_YIELD_PIN GP9
|
||||
|
||||
|
@ -54,7 +54,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
* |------+------+------+------+------+------| |------+------+------+------+------+------|
|
||||
* | | % | ^ | [ | ] | ~ | | & | 1 | 2 | 3 | \ | |
|
||||
* |------+------+------+------+------+------' `------+------+------+------+------+------|
|
||||
* |QK_BOOT | | | | | | | . | 0 | = | |
|
||||
* |BtLdr | | | | | | | . | 0 | = | |
|
||||
* `----------------------------------' `----------------------------------'
|
||||
* ,-------------. ,-------------.
|
||||
* | | | | | |
|
||||
|
@ -1,43 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"notes": "",
|
||||
"author": "Marcus Young",
|
||||
"keyboard": "handwired/pterodactyl",
|
||||
"keymap": "default",
|
||||
"layout": "LAYOUT",
|
||||
"layers": [
|
||||
[
|
||||
"KC_EQL", "KC_1", "KC_2", "KC_3", "KC_4", "KC_5", "KC_6", "KC_7", "KC_8", "KC_9", "KC_0", "KC_MINS",
|
||||
"KC_DEL", "KC_Q", "KC_W", "KC_E", "KC_R", "KC_T", "KC_Y", "KC_U", "KC_I", "KC_O", "KC_P", "KC_BSLS",
|
||||
"KC_BSPC", "KC_A", "KC_S", "KC_D", "KC_F", "KC_G", "KC_H", "KC_J", "KC_K", "KC_L", "LT(2,KC_SCLN)", "LGUI_T(KC_QUOT)",
|
||||
"KC_LSFT", "LCTL_T(KC_Z)", "KC_X", "KC_C", "KC_V", "KC_B", "KC_N", "KC_M", "KC_COMM", "KC_DOT", "LCTL_T(KC_SLSH)", "KC_RSFT",
|
||||
"LT(1,KC_GRV)", "KC_QUOT", "LALT(KC_LSFT)", "KC_LEFT", "KC_RGHT", "KC_UP", "KC_DOWN", "KC_LBRC", "KC_RBRC", "TT(1)",
|
||||
|
||||
"LALT_T(KC_APP)", "KC_LGUI", "KC_RALT", "LCTL_T(KC_ESC)",
|
||||
"KC_HOME", "KC_PGUP",
|
||||
"KC_SPC", "KC_BSPC", "KC_END", "KC_PGDN", "KC_TAB", "KC_ENT"
|
||||
],
|
||||
[
|
||||
"KC_TRNS", "KC_F1", "KC_F2", "KC_F3", "KC_F4", "KC_F5", "KC_F6", "KC_F7", "KC_F8", "KC_F9", "KC_F10", "KC_F11",
|
||||
"KC_TRNS", "KC_EXLM", "KC_AT", "KC_LCBR", "KC_RCBR", "KC_PIPE", "KC_UP", "KC_7", "KC_8", "KC_9", "KC_ASTR", "KC_F12",
|
||||
"KC_TRNS", "KC_HASH", "KC_DLR", "KC_LPRN", "KC_RPRN", "KC_GRV", "KC_DOWN", "KC_4", "KC_5", "KC_6", "KC_PLUS", "KC_TRNS",
|
||||
"KC_TRNS", "KC_PERC", "KC_CIRC", "KC_LBRC", "KC_RBRC", "KC_TILD", "KC_AMPR", "KC_1", "KC_2", "KC_3", "KC_BSLS", "KC_TRNS",
|
||||
"QK_BOOT", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_DOT", "KC_0", "KC_EQL", "KC_TRNS",
|
||||
|
||||
"KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS",
|
||||
"KC_TRNS", "KC_TRNS",
|
||||
"KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS"
|
||||
],
|
||||
[
|
||||
"KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS",
|
||||
"KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_MS_U", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS",
|
||||
"KC_TRNS", "KC_TRNS", "KC_MS_L", "KC_MS_D", "KC_MS_R", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_MPLY",
|
||||
"KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_MPRV", "KC_MNXT", "KC_TRNS", "KC_TRNS",
|
||||
"KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_BTN1", "KC_BTN2", "KC_VOLU", "KC_VOLD", "KC_MUTE", "KC_TRNS", "KC_TRNS",
|
||||
|
||||
"KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS",
|
||||
"KC_TRNS", "KC_TRNS",
|
||||
"KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_WBAK"
|
||||
]
|
||||
]
|
||||
}
|
@ -55,7 +55,7 @@ def parse_configurator_json(configurator_file):
|
||||
cli.log.error(f'Invalid JSON keymap: {configurator_file} : {e.message}')
|
||||
maybe_exit(1)
|
||||
|
||||
keyboard = user_keymap['keyboard']
|
||||
keyboard = user_keymap.get('keyboard', None)
|
||||
aliases = keyboard_alias_definitions()
|
||||
|
||||
while keyboard in aliases:
|
||||
|
@ -29,38 +29,40 @@ __INCLUDES__
|
||||
* This file was generated by qmk json2c. You may or may not want to
|
||||
* edit it directly.
|
||||
*/
|
||||
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][NUM_DIRECTIONS] = {
|
||||
__ENCODER_MAP_GOES_HERE__
|
||||
};
|
||||
#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
||||
|
||||
__MACRO_OUTPUT_GOES_HERE__
|
||||
|
||||
#ifdef OTHER_KEYMAP_C
|
||||
# include OTHER_KEYMAP_C
|
||||
#endif // OTHER_KEYMAP_C
|
||||
"""
|
||||
|
||||
|
||||
def _generate_keymap_table(keymap_json):
|
||||
lines = []
|
||||
lines = ['const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {']
|
||||
for layer_num, layer in enumerate(keymap_json['layers']):
|
||||
if layer_num != 0:
|
||||
lines[-1] = lines[-1] + ','
|
||||
layer = map(_strip_any, layer)
|
||||
layer_keys = ', '.join(layer)
|
||||
lines.append(' [%s] = %s(%s)' % (layer_num, keymap_json['layout'], layer_keys))
|
||||
lines.append('};')
|
||||
return lines
|
||||
|
||||
|
||||
def _generate_encodermap_table(keymap_json):
|
||||
lines = []
|
||||
lines = [
|
||||
'#if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)',
|
||||
'const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {',
|
||||
]
|
||||
for layer_num, layer in enumerate(keymap_json['encoders']):
|
||||
if layer_num != 0:
|
||||
lines[-1] = lines[-1] + ','
|
||||
encoder_keycode_txt = ', '.join([f'ENCODER_CCW_CW({_strip_any(e["ccw"])}, {_strip_any(e["cw"])})' for e in layer])
|
||||
lines.append(' [%s] = {%s}' % (layer_num, encoder_keycode_txt))
|
||||
lines.extend(['};', '#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)'])
|
||||
return lines
|
||||
|
||||
|
||||
@ -271,8 +273,11 @@ def generate_c(keymap_json):
|
||||
A sequence of strings containing macros to implement for this keyboard.
|
||||
"""
|
||||
new_keymap = DEFAULT_KEYMAP_C
|
||||
layer_txt = _generate_keymap_table(keymap_json)
|
||||
keymap = '\n'.join(layer_txt)
|
||||
|
||||
keymap = ''
|
||||
if 'layers' in keymap_json and keymap_json['layers'] is not None:
|
||||
layer_txt = _generate_keymap_table(keymap_json)
|
||||
keymap = '\n'.join(layer_txt)
|
||||
new_keymap = new_keymap.replace('__KEYMAP_GOES_HERE__', keymap)
|
||||
|
||||
encodermap = ''
|
||||
|
@ -152,17 +152,16 @@ def test_json2c():
|
||||
* This file was generated by qmk json2c. You may or may not want to
|
||||
* edit it directly.
|
||||
*/
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
[0] = LAYOUT_ortho_1x1(KC_A)
|
||||
};
|
||||
|
||||
#if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
||||
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
|
||||
|
||||
};
|
||||
#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
||||
|
||||
|
||||
#ifdef OTHER_KEYMAP_C
|
||||
# include OTHER_KEYMAP_C
|
||||
#endif // OTHER_KEYMAP_C
|
||||
|
||||
|
||||
"""
|
||||
@ -190,28 +189,21 @@ def test_json2c_stdin():
|
||||
* This file was generated by qmk json2c. You may or may not want to
|
||||
* edit it directly.
|
||||
*/
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
[0] = LAYOUT_ortho_1x1(KC_A)
|
||||
};
|
||||
|
||||
#if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
||||
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
|
||||
|
||||
};
|
||||
#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
||||
|
||||
|
||||
#ifdef OTHER_KEYMAP_C
|
||||
# include OTHER_KEYMAP_C
|
||||
#endif // OTHER_KEYMAP_C
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def test_json2c_wrong_json():
|
||||
result = check_subcommand('json2c', 'keyboards/handwired/pytest/info.json')
|
||||
check_returncode(result, [1])
|
||||
assert 'Invalid JSON keymap' in result.stdout
|
||||
|
||||
|
||||
def test_json2c_no_json():
|
||||
result = check_subcommand('json2c', 'keyboards/handwired/pytest/basic/keymaps/default/keymap.c')
|
||||
check_returncode(result, [1])
|
||||
|
@ -20,17 +20,16 @@ def test_generate_c_pytest_basic():
|
||||
* This file was generated by qmk json2c. You may or may not want to
|
||||
* edit it directly.
|
||||
*/
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
[0] = LAYOUT(KC_A)
|
||||
};
|
||||
|
||||
#if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
||||
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
|
||||
|
||||
};
|
||||
#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
||||
|
||||
|
||||
#ifdef OTHER_KEYMAP_C
|
||||
# include OTHER_KEYMAP_C
|
||||
#endif // OTHER_KEYMAP_C
|
||||
"""
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user