Finish stub for effect mapping

This commit is contained in:
zvecr 2022-09-29 23:44:11 +01:00
parent f81328068e
commit 019d3f4877
7 changed files with 237 additions and 195 deletions

View File

@ -3,76 +3,76 @@
"reactive": {}
},
"effects": {
"0x01": {
"0x00": {
"key": "SOLID"
},
"0x02": {
"0x01": {
"key": "ALPHAS_MODS"
},
"0x03": {
"0x02": {
"key": "BREATHING"
},
"0x04": {
"0x03": {
"key": "BAND"
},
"0x05": {
"0x04": {
"key": "BAND_PINWHEEL"
},
"0x06": {
"0x05": {
"key": "BAND_SPIRAL"
},
"0x07": {
"0x06": {
"key": "CYCLE_LEFT_RIGHT"
},
"0x08": {
"0x07": {
"key": "CYCLE_UP_DOWN"
},
"0x09": {
"0x08": {
"key": "CYCLE_OUT_IN"
},
"0x0A": {
"0x09": {
"key": "DUAL_BEACON"
},
"0x0B": {
"0x0A": {
"key": "WAVE_LEFT_RIGHT"
},
"0x0C": {
"0x0B": {
"key": "WAVE_UP_DOWN"
},
"0x0D": {
"0x0C": {
"key": "SOLID_REACTIVE_SIMPLE",
"group": "reactive"
},
"0x0E": {
"0x0D": {
"key": "SOLID_REACTIVE_WIDE",
"group": "reactive"
},
"0x0F": {
"0x0E": {
"key": "SOLID_REACTIVE_MULTIWIDE",
"group": "reactive"
},
"0x10": {
"0x0F": {
"key": "SOLID_REACTIVE_CROSS",
"group": "reactive"
},
"0x11": {
"0x10": {
"key": "SOLID_REACTIVE_MULTICROSS",
"group": "reactive"
},
"0x12": {
"0x11": {
"key": "SOLID_REACTIVE_NEXUS",
"group": "reactive"
},
"0x13": {
"0x12": {
"key": "SOLID_REACTIVE_MULTINEXUS",
"group": "reactive"
},
"0x14": {
"0x13": {
"key": "SOLID_SPLASH",
"group": "reactive"
},
"0x15": {
"0x14": {
"key": "SOLID_MULTISPLASH",
"group": "reactive"
}

View File

@ -4,151 +4,151 @@
"reactive": {}
},
"effects": {
"0x01": {
"0x00": {
"key": "SOLID_COLOR"
},
"0x02": {
"0x01": {
"key": "ALPHAS_MODS"
},
"0x03": {
"0x02": {
"key": "GRADIENT_UP_DOWN"
},
"0x04": {
"0x03": {
"key": "GRADIENT_LEFT_RIGHT"
},
"0x05": {
"0x04": {
"key": "BREATHING"
},
"0x06": {
"0x05": {
"key": "BAND_SAT"
},
"0x07": {
"0x06": {
"key": "BAND_VAL"
},
"0x08": {
"0x07": {
"key": "BAND_PINWHEEL_SAT"
},
"0x09": {
"0x08": {
"key": "BAND_PINWHEEL_VAL"
},
"0x0A": {
"0x09": {
"key": "BAND_SPIRAL_SAT"
},
"0x0B": {
"0x0A": {
"key": "BAND_SPIRAL_VAL"
},
"0x0C": {
"0x0B": {
"key": "CYCLE_ALL"
},
"0x0D": {
"0x0C": {
"key": "CYCLE_LEFT_RIGHT"
},
"0x0E": {
"0x0D": {
"key": "CYCLE_UP_DOWN"
},
"0x0F": {
"0x0E": {
"key": "CYCLE_OUT_IN"
},
"0x10": {
"0x0F": {
"key": "CYCLE_OUT_IN_DUAL"
},
"0x11": {
"0x10": {
"key": "RAINBOW_MOVING_CHEVRON"
},
"0x12": {
"0x11": {
"key": "CYCLE_PINWHEEL"
},
"0x13": {
"0x12": {
"key": "CYCLE_SPIRAL"
},
"0x14": {
"0x13": {
"key": "DUAL_BEACON"
},
"0x15": {
"0x14": {
"key": "RAINBOW_BEACON"
},
"0x16": {
"0x15": {
"key": "RAINBOW_PINWHEELS"
},
"0x17": {
"0x16": {
"key": "RAINDROPS"
},
"0x18": {
"0x17": {
"key": "JELLYBEAN_RAINDROPS"
},
"0x19": {
"0x18": {
"key": "HUE_BREATHING"
},
"0x1A": {
"0x19": {
"key": "HUE_PENDULUM"
},
"0x1B": {
"0x1A": {
"key": "HUE_WAVE"
},
"0x1C": {
"0x1B": {
"key": "PIXEL_FRACTAL"
},
"0x1D": {
"0x1C": {
"key": "PIXEL_FLOW"
},
"0x1E": {
"0x1D": {
"key": "PIXEL_RAIN"
},
"0x1F": {
"0x1E": {
"key": "TYPING_HEATMAP",
"group": "framebuffer"
},
"0x20": {
"0x1F": {
"key": "DIGITAL_RAIN",
"group": "framebuffer"
},
"0x21": {
"0x20": {
"key": "SOLID_REACTIVE_SIMPLE",
"group": "reactive"
},
"0x22": {
"0x21": {
"key": "RGB_MATRIX_SOLID_REACTIVE",
"group": "reactive"
},
"0x23": {
"0x22": {
"key": "RGB_MATRIX_SOLID_REACTIVE_WIDE",
"group": "reactive"
},
"0x24": {
"0x23": {
"key": "SOLID_REACTIVE_MULTIWIDE",
"group": "reactive"
},
"0x25": {
"0x24": {
"key": "SOLID_REACTIVE_CROSS",
"group": "reactive"
},
"0x26": {
"0x25": {
"key": "SOLID_REACTIVE_MULTICROSS",
"group": "reactive"
},
"0x27": {
"0x26": {
"key": "SOLID_REACTIVE_NEXUS",
"group": "reactive"
},
"0x28": {
"0x27": {
"key": "SOLID_REACTIVE_MULTINEXUS",
"group": "reactive"
},
"0x29": {
"0x28": {
"key": "SPLASH",
"group": "reactive"
},
"0x2A": {
"0x29": {
"key": "MULTISPLASH",
"group": "reactive"
},
"0x2B": {
"0x2A": {
"key": "SOLID_SPLASH",
"group": "reactive"
},
"0x2C": {
"0x2B": {
"key": "SOLID_MULTISPLASH",
"group": "reactive"
}

View File

@ -1,129 +1,129 @@
{
"effects": {
"0x01": {
"0x00": {
"key": "STATIC_LIGHT"
},
"0x02": {
"0x01": {
"key": "BREATHING"
},
"0x03": {
"0x02": {
"key": "BREATHING_2"
},
"0x04": {
"0x03": {
"key": "BREATHING_3"
},
"0x05": {
"0x04": {
"key": "BREATHING_4"
},
"0x06": {
"0x05": {
"key": "RAINBOW_MOOD"
},
"0x07": {
"0x06": {
"key": "RAINBOW_MOOD_2"
},
"0x08": {
"0x07": {
"key": "RAINBOW_MOOD_3"
},
"0x09": {
"0x08": {
"key": "RAINBOW_SWIRL"
},
"0x0A": {
"0x09": {
"key": "RAINBOW_SWIRL_2"
},
"0x0B": {
"0x0A": {
"key": "RAINBOW_SWIRL_3"
},
"0x0C": {
"0x0B": {
"key": "RAINBOW_SWIRL_4"
},
"0x0D": {
"0x0C": {
"key": "RAINBOW_SWIRL_5"
},
"0x0E": {
"0x0D": {
"key": "RAINBOW_SWIRL_6"
},
"0x0F": {
"0x0E": {
"key": "SNAKE"
},
"0x10": {
"0x0F": {
"key": "SNAKE_2"
},
"0x11": {
"0x10": {
"key": "SNAKE_3"
},
"0x12": {
"0x11": {
"key": "SNAKE_4"
},
"0x13": {
"0x12": {
"key": "SNAKE_5"
},
"0x14": {
"0x13": {
"key": "SNAKE_6"
},
"0x15": {
"0x14": {
"key": "KNIGHT"
},
"0x16": {
"0x15": {
"key": "KNIGHT_2"
},
"0x17": {
"0x16": {
"key": "KNIGHT_3"
},
"0x18": {
"0x17": {
"key": "CHRISTMAS"
},
"0x19": {
"0x18": {
"key": "STATIC_GRADIENT"
},
"0x1A": {
"0x19": {
"key": "STATIC_GRADIENT_2"
},
"0x1B": {
"0x1A": {
"key": "STATIC_GRADIENT_3"
},
"0x1C": {
"0x1B": {
"key": "STATIC_GRADIENT_4"
},
"0x1D": {
"0x1C": {
"key": "STATIC_GRADIENT_5"
},
"0x1E": {
"0x1D": {
"key": "STATIC_GRADIENT_6"
},
"0x1F": {
"0x1E": {
"key": "STATIC_GRADIENT_7"
},
"0x20": {
"0x1F": {
"key": "STATIC_GRADIENT_8"
},
"0x21": {
"0x20": {
"key": "STATIC_GRADIENT_9"
},
"0x22": {
"0x21": {
"key": "STATIC_GRADIENT_10"
},
"0x23": {
"key": "TEST"
"0x22": {
"key": "RGB_TEST"
},
"0x24": {
"0x23": {
"key": "ALTERNATING"
},
"0x25": {
"0x24": {
"key": "TWINKLE"
},
"0x26": {
"0x25": {
"key": "TWINKLE_2"
},
"0x27": {
"0x26": {
"key": "TWINKLE_3"
},
"0x28": {
"0x27": {
"key": "TWINKLE_4"
},
"0x29": {
"0x28": {
"key": "TWINKLE_5"
},
"0x2A": {
"0x29": {
"key": "TWINKLE_6"
}
}

View File

@ -19,11 +19,11 @@ def xap_generate_qmk_inc(cli):
# Determine our keyboard/keymap
if not cli.args.keyboard:
cli.log.error('Missing parameter: --keyboard')
cli.subcommands['xap-generate-info-h'].print_help()
cli.subcommands['xap-generate-qmk-inc'].print_help()
return False
if not cli.args.keymap:
cli.log.error('Missing parameter: --keymap')
cli.subcommands['xap-generate-info-h'].print_help()
cli.subcommands['xap-generate-qmk-inc'].print_help()
return False
generate_inline(cli.args.output, cli.args.keyboard, cli.args.keymap)
@ -39,11 +39,11 @@ def xap_generate_qmk_h(cli):
# Determine our keyboard/keymap
if not cli.args.keyboard:
cli.log.error('Missing parameter: --keyboard')
cli.subcommands['xap-generate-info-h'].print_help()
cli.subcommands['xap-generate-qmk-h'].print_help()
return False
if not cli.args.keymap:
cli.log.error('Missing parameter: --keymap')
cli.subcommands['xap-generate-info-h'].print_help()
cli.subcommands['xap-generate-qmk-h'].print_help()
return False
generate_header(cli.args.output, cli.args.keyboard, cli.args.keymap)
@ -59,11 +59,11 @@ def xap_generate_qmk_blob_h(cli):
# Determine our keyboard/keymap
if not cli.args.keyboard:
cli.log.error('Missing parameter: --keyboard')
cli.subcommands['xap-generate-info-h'].print_help()
cli.subcommands['xap-generate-qmk-blob-h'].print_help()
return False
if not cli.args.keymap:
cli.log.error('Missing parameter: --keymap')
cli.subcommands['xap-generate-info-h'].print_help()
cli.subcommands['xap-generate-qmk-blob-h'].print_help()
return False
generate_blob(cli.args.output, cli.args.keyboard, cli.args.keymap)

View File

@ -1,9 +1,46 @@
"""This script generates the XAP protocol generated header to be compiled into QMK.
"""
import re
from pathlib import Path
from qmk.casing import to_snake
from qmk.commands import dump_lines
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
from qmk.xap.common import merge_xap_defs, route_conditions
from qmk.json_schema import json_load
PREFIX_MAP = {
'rgblight': {
'ifdef': 'RGBLIGHT_EFFECT',
'def': 'RGBLIGHT_MODE',
},
'rgb_matrix': {
'ifdef': 'ENABLE_RGB_MATRIX',
'def': 'RGB_MATRIX',
},
'led_matrix': {
'ifdef': 'ENABLE_LED_MATRIX',
'def': 'LED_MATRIX',
},
}
def _get_lighting_spec(xap_defs, feature):
version = xap_defs["uses"][feature]
spec = json_load(Path(f'data/constants/{feature}_{version}.json'))
# preprocess for gross rgblight "mode + n"
for obj in spec.get('effects', {}).values():
define = obj["key"]
offset = 0
found = re.match("(.*)_(\\d+)$", define)
if found:
define = found.group(1)
offset = int(found.group(2)) - 1
obj["define"] = define
obj["offset"] = offset
return spec
def _get_c_type(xap_type):
@ -276,6 +313,82 @@ def _append_broadcast_messages(lines, container):
lines.append(f'void {name}(const void *data, size_t length){{ xap_broadcast({key}, data, length); }}')
def _append_lighting_map(lines, feature, spec):
"""TODO:
"""
ifdef_prefix = PREFIX_MAP[feature]['ifdef']
def_prefix = PREFIX_MAP[feature]['def']
lines.append(f'static uint8_t {feature}_effect_map[][2] = {{')
for id, obj in spec.get('effects', {}).items():
define = obj["define"]
offset = f' + {obj["offset"]}' if obj["offset"] else ''
lines.append(f'''
#ifdef {ifdef_prefix}_{define}
{{ {id}, {def_prefix}_{define}{offset}}},
#endif''')
lines.append('};')
# add helper funcs
lines.append(
f'''
uint8_t {feature}2xap(uint8_t val) {{
for(uint8_t i = 0; i < ARRAY_SIZE({feature}_effect_map); i++) {{
if ({feature}_effect_map[i][1] == val)
return {feature}_effect_map[i][0];
}}
return 0xFF;
}}
uint8_t xap2{feature}(uint8_t val) {{
for(uint8_t i = 0; i < ARRAY_SIZE({feature}_effect_map); i++) {{
if ({feature}_effect_map[i][0] == val)
return {feature}_effect_map[i][1];
}}
return 0xFF;
}}'''
)
def _append_lighting_bitmask(lines, feature, spec):
"""TODO:
"""
ifdef_prefix = PREFIX_MAP[feature]['ifdef']
lines.append(f"static const uint64_t ENABLED_{feature.upper()}_EFFECTS = 0")
for id, obj in spec.get('effects', {}).items():
define = obj["define"]
lines.append(f'''
#ifdef {ifdef_prefix}_{define}
| (1ULL << {id})
#endif''')
lines.append(';')
def _append_lighting_mapping(lines, xap_defs):
"""TODO:
"""
# TODO: remove bodge for always enabled effects
lines.append('''
#define RGBLIGHT_EFFECT_STATIC_LIGHT
#define ENABLE_RGB_MATRIX_SOLID_COLOR
#define ENABLE_LED_MATRIX_SOLID
''')
for feature in PREFIX_MAP.keys():
spec = _get_lighting_spec(xap_defs, feature)
lines.append(f"#ifdef {feature.upper()}_ENABLE")
_append_lighting_map(lines, feature, spec)
lines.append(f"#endif //{feature.upper()}_ENABLE")
# TODO: should be inside ifdef but causes build issues
_append_lighting_bitmask(lines, feature, spec)
def generate_inline(output_file, keyboard, keymap):
"""Generates the XAP protocol header file, generated during normal build.
"""
@ -284,6 +397,9 @@ def generate_inline(output_file, keyboard, keymap):
# Preamble
lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '']
# TODO: gen somewhere else?
_append_lighting_mapping(lines, xap_defs)
# Add all the generated code
_append_broadcast_messages(lines, xap_defs)
_append_routing_tables(lines, xap_defs)

View File

@ -28,9 +28,7 @@ bool get_config_blob_chunk(uint16_t offset, uint8_t *data, uint8_t data_len) {
return true;
}
// TODO: return actual values
#define ENABLED_RGBLIGHT_EFFECTS 0xFFFFFFFF
#define ENABLED_RGB_MATRIX_EFFECTS 0xFFFFFFFF
// TODO: move to better location?
#ifdef BACKLIGHT_BREATHING
# define ENABLED_BACKLIGHT_EFFECTS 0b00000001
#else

View File

@ -182,6 +182,8 @@ bool xap_respond_dynamic_encoder_set_keycode(xap_token_t token, const void *data
}
#endif
#define INVALID_EFFECT 0xFF
#if ((defined(BACKLIGHT_ENABLE)))
# include "backlight.h"
@ -204,66 +206,13 @@ bool xap_respond_get_backlight_config(xap_token_t token, const void *data, size_
extern rgblight_config_t rgblight_config;
// static uint8_t effect_map[][2] = {
// {1, RGBLIGHT_MODE_STATIC_LIGHT},
// # ifdef RGBLIGHT_EFFECT_BREATHING
// {2, RGBLIGHT_MODE_BREATHING},
// {3, RGBLIGHT_MODE_BREATHING + 1},
// {4, RGBLIGHT_MODE_BREATHING + 2},
// {5, RGBLIGHT_MODE_BREATHING + 3},
// # endif
// /*...*/
// };
// static uint8_t xap2rgb(uint8_t val) {
// for(uint8_t i = 0; i < ARRAY_SIZE(effect_map); i++){
// if (effect_map[i][0] == val) {
// return effect_map[i][1];
// }
// }
// return 0;
// }
// static uint8_t rgb2xap(uint8_t val) {
// for(uint8_t i = 0; i < ARRAY_SIZE(effect_map); i++){
// if (effect_map[i][1] == val) {
// return effect_map[i][0];
// }
// }
// return 0;
// }
static uint8_t effect_map[43] = {
0, //
RGBLIGHT_MODE_STATIC_LIGHT, //
# ifdef RGBLIGHT_EFFECT_BREATHING
RGBLIGHT_MODE_BREATHING,
RGBLIGHT_MODE_BREATHING + 1,
RGBLIGHT_MODE_BREATHING + 2,
RGBLIGHT_MODE_BREATHING + 3,
# endif
0,
/*...*/
};
// static uint8_t xap2rgb(uint8_t val) {
// return effect_map[val];
// }
static uint8_t rgb2xap(uint8_t val) {
for (uint8_t i = 0; i < ARRAY_SIZE(effect_map); i++) {
if (effect_map[i] == val) {
return i;
}
}
return 0;
}
uint8_t rgblight2xap(uint8_t val);
bool xap_respond_get_rgblight_config(xap_token_t token, const void *data, size_t length) {
xap_route_lighting_rgblight_get_config_t ret;
ret.enable = rgblight_config.enable;
ret.mode = rgb2xap(rgblight_config.mode);
ret.mode = rgblight2xap(rgblight_config.mode);
ret.hue = rgblight_config.hue;
ret.sat = rgblight_config.sat;
ret.val = rgblight_config.val;
@ -278,34 +227,13 @@ bool xap_respond_get_rgblight_config(xap_token_t token, const void *data, size_t
extern rgb_config_t rgb_matrix_config;
static uint8_t effect_map[43] = {
0, //
RGB_MATRIX_SOLID_COLOR, //
# ifdef ENABLE_RGB_MATRIX_ALPHAS_MODS
RGB_MATRIX_ALPHAS_MODS,
# endif
0,
/*...*/
};
// static uint8_t xap2rgb(uint8_t val) {
// return effect_map[val];
// }
static uint8_t rgb2xap(uint8_t val) {
for (uint8_t i = 0; i < ARRAY_SIZE(effect_map); i++) {
if (effect_map[i] == val) {
return i;
}
}
return 0;
}
uint8_t rgb_matrix2xap(uint8_t val);
bool xap_respond_get_rgb_matrix_config(xap_token_t token, const void *data, size_t length) {
xap_route_lighting_rgb_matrix_get_config_t ret;
ret.enable = rgb_matrix_config.enable;
ret.mode = rgb2xap(rgb_matrix_config.mode);
ret.mode = rgb_matrix2xap(rgb_matrix_config.mode);
ret.hue = rgb_matrix_config.hsv.h;
ret.sat = rgb_matrix_config.hsv.s;
ret.val = rgb_matrix_config.hsv.v;