Decouple lighting_map from XAP
This commit is contained in:
parent
5eed80c66b
commit
42895141de
13 changed files with 1206 additions and 1178 deletions
|
|
@ -58,6 +58,7 @@ subcommands = [
|
|||
'qmk.cli.generate.keyboard_h',
|
||||
'qmk.cli.generate.keycodes',
|
||||
'qmk.cli.generate.keycodes_tests',
|
||||
'qmk.cli.generate.lighting_map',
|
||||
'qmk.cli.generate.rgb_breathe_table',
|
||||
'qmk.cli.generate.rules_mk',
|
||||
'qmk.cli.generate.version_h',
|
||||
|
|
@ -83,7 +84,6 @@ subcommands = [
|
|||
'qmk.cli.xap',
|
||||
'qmk.cli.xap.generate_docs',
|
||||
'qmk.cli.xap.generate_json',
|
||||
'qmk.cli.xap.generate_lighting',
|
||||
'qmk.cli.xap.generate_python',
|
||||
'qmk.cli.xap.generate_qmk',
|
||||
]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from milc import cli
|
|||
|
||||
from qmk.path import normpath
|
||||
from qmk.commands import dump_lines
|
||||
from qmk.xap.common import load_lighting_spec
|
||||
from qmk.lighting import load_lighting_spec
|
||||
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
|
||||
|
||||
PREFIX_MAP = {
|
||||
|
|
@ -21,8 +21,21 @@ PREFIX_MAP = {
|
|||
}
|
||||
|
||||
|
||||
def _always_enabled(id):
|
||||
"""Assumption that first effect is always enabled
|
||||
"""
|
||||
return id == '0x00'
|
||||
|
||||
|
||||
def _wrap_ifdef(line, define):
|
||||
return f'''
|
||||
#ifdef {define}
|
||||
{line}
|
||||
#endif'''
|
||||
|
||||
|
||||
def _append_lighting_map(lines, feature, spec):
|
||||
"""TODO:
|
||||
"""Translate effect to 'constant id'->'firmware id' lookup table
|
||||
"""
|
||||
groups = spec.get('groups', {})
|
||||
ifdef_prefix = PREFIX_MAP[feature]['ifdef']
|
||||
|
|
@ -33,17 +46,14 @@ def _append_lighting_map(lines, feature, spec):
|
|||
define = obj['define']
|
||||
offset = f' + {obj["offset"]}' if obj['offset'] else ''
|
||||
|
||||
line = f'''
|
||||
#ifdef {ifdef_prefix}_{define}
|
||||
{{ {id}, {def_prefix}_{define}{offset}}},
|
||||
#endif'''
|
||||
line = f'{{ {id}, {def_prefix}_{define}{offset}}},'
|
||||
|
||||
if not _always_enabled(id):
|
||||
line = _wrap_ifdef(line, f'{ifdef_prefix}_{define}')
|
||||
|
||||
group = groups.get(obj.get('group', None), {}).get('define', None)
|
||||
if group:
|
||||
line = f'''
|
||||
#ifdef {group}
|
||||
{line}
|
||||
#endif'''
|
||||
line = _wrap_ifdef(line, group)
|
||||
|
||||
lines.append(line)
|
||||
|
||||
|
|
@ -52,7 +62,7 @@ def _append_lighting_map(lines, feature, spec):
|
|||
# add helper funcs
|
||||
lines.append(
|
||||
f'''
|
||||
uint8_t {feature}2xap(uint8_t val) {{
|
||||
uint8_t {feature}_effect_to_id(uint8_t val) {{
|
||||
for(uint8_t i = 0; i < ARRAY_SIZE({feature}_effect_map); i++) {{
|
||||
if (pgm_read_byte(&{feature}_effect_map[i][1]) == val)
|
||||
return pgm_read_byte(&{feature}_effect_map[i][0]);
|
||||
|
|
@ -60,7 +70,7 @@ uint8_t {feature}2xap(uint8_t val) {{
|
|||
return 0xFF;
|
||||
}}
|
||||
|
||||
uint8_t xap2{feature}(uint8_t val) {{
|
||||
uint8_t {feature}_id_to_effect(uint8_t val) {{
|
||||
for(uint8_t i = 0; i < ARRAY_SIZE({feature}_effect_map); i++) {{
|
||||
if (pgm_read_byte(&{feature}_effect_map[i][0]) == val)
|
||||
return pgm_read_byte(&{feature}_effect_map[i][1]);
|
||||
|
|
@ -70,8 +80,8 @@ uint8_t xap2{feature}(uint8_t val) {{
|
|||
)
|
||||
|
||||
|
||||
def _append_lighting_bitmask(lines, feature, spec):
|
||||
"""TODO:
|
||||
def _append_lighting_bit_field(lines, feature, spec):
|
||||
"""Translate effect to bit of bit-field
|
||||
"""
|
||||
groups = spec.get('groups', {})
|
||||
ifdef_prefix = PREFIX_MAP[feature]['ifdef']
|
||||
|
|
@ -80,49 +90,37 @@ def _append_lighting_bitmask(lines, feature, spec):
|
|||
for id, obj in spec.get('effects', {}).items():
|
||||
define = obj['define']
|
||||
|
||||
line = f'''
|
||||
#ifdef {ifdef_prefix}_{define}
|
||||
| (1ULL << {id})
|
||||
#endif'''
|
||||
line = f' | (1ULL << {id})'
|
||||
|
||||
if not _always_enabled(id):
|
||||
line = _wrap_ifdef(line, f'{ifdef_prefix}_{define}')
|
||||
|
||||
group = groups.get(obj.get('group', None), {}).get('define', None)
|
||||
if group:
|
||||
line = f'''
|
||||
#ifdef {group}
|
||||
{line}
|
||||
#endif'''
|
||||
line = _wrap_ifdef(line, group)
|
||||
|
||||
lines.append(line)
|
||||
|
||||
lines.append('};')
|
||||
|
||||
|
||||
def _append_lighting_mapping(lines):
|
||||
"""TODO:
|
||||
def _append_lighting_mapping(lines, feature):
|
||||
"""Generate lookup table and bit-field of effect
|
||||
"""
|
||||
# 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
|
||||
''')
|
||||
spec = load_lighting_spec(feature)
|
||||
|
||||
for feature in PREFIX_MAP.keys():
|
||||
spec = load_lighting_spec(feature)
|
||||
|
||||
lines.append(f'#ifdef {feature.upper()}_ENABLE')
|
||||
_append_lighting_map(lines, feature, spec)
|
||||
_append_lighting_bitmask(lines, feature, spec)
|
||||
lines.append(f'#endif //{feature.upper()}_ENABLE')
|
||||
_append_lighting_bit_field(lines, feature, spec)
|
||||
_append_lighting_map(lines, feature, spec)
|
||||
|
||||
|
||||
@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
|
||||
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
|
||||
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help='Quiet mode, only output error messages')
|
||||
@cli.argument('-f', '--feature', required=True, help='Feature to generate map', choices=PREFIX_MAP.keys())
|
||||
@cli.subcommand('Generates effect header.')
|
||||
def xap_generate_lighting_map(cli):
|
||||
def generate_lighting_map(cli):
|
||||
# Preamble
|
||||
lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '// clang-format off']
|
||||
|
||||
_append_lighting_mapping(lines)
|
||||
_append_lighting_mapping(lines, cli.args.feature)
|
||||
|
||||
dump_lines(cli.args.output, lines, cli.args.quiet)
|
||||
Loading…
Reference in a new issue