mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-02-18 10:36:55 +00:00
Dump lighting maps out of inline gen
This commit is contained in:
parent
124df6e407
commit
edc14b29be
@ -81,6 +81,7 @@ 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',
|
||||
]
|
||||
|
128
lib/python/qmk/cli/xap/generate_lighting.py
Normal file
128
lib/python/qmk/cli/xap/generate_lighting.py
Normal file
@ -0,0 +1,128 @@
|
||||
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.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
|
||||
|
||||
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 _append_lighting_map(lines, feature, spec):
|
||||
"""TODO:
|
||||
"""
|
||||
groups = spec.get('groups', {})
|
||||
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 ''
|
||||
|
||||
line = f'''
|
||||
#ifdef {ifdef_prefix}_{define}
|
||||
{{ {id}, {def_prefix}_{define}{offset}}},
|
||||
#endif'''
|
||||
|
||||
group = groups.get(obj.get('group', None), {}).get('define', None)
|
||||
if group:
|
||||
line = f'''
|
||||
#ifdef {group}
|
||||
{line}
|
||||
#endif'''
|
||||
|
||||
lines.append(line)
|
||||
|
||||
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:
|
||||
"""
|
||||
groups = spec.get('groups', {})
|
||||
ifdef_prefix = PREFIX_MAP[feature]['ifdef']
|
||||
|
||||
lines.append(f'enum {{ ENABLED_{feature.upper()}_EFFECTS = 0')
|
||||
for id, obj in spec.get('effects', {}).items():
|
||||
define = obj['define']
|
||||
|
||||
line = f'''
|
||||
#ifdef {ifdef_prefix}_{define}
|
||||
| (1ULL << {id})
|
||||
#endif'''
|
||||
|
||||
group = groups.get(obj.get('group', None), {}).get('define', None)
|
||||
if group:
|
||||
line = f'''
|
||||
#ifdef {group}
|
||||
{line}
|
||||
#endif'''
|
||||
|
||||
lines.append(line)
|
||||
|
||||
lines.append('};')
|
||||
|
||||
|
||||
def _append_lighting_mapping(lines):
|
||||
"""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 = 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')
|
||||
|
||||
|
||||
@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.subcommand('Generates effect header.')
|
||||
def xap_generate_lighting_map(cli):
|
||||
# Preamble
|
||||
lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '// clang-format off']
|
||||
|
||||
_append_lighting_mapping(lines)
|
||||
|
||||
dump_lines(cli.args.output, lines, cli.args.quiet)
|
@ -3,22 +3,7 @@
|
||||
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, load_lighting_spec
|
||||
|
||||
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',
|
||||
},
|
||||
}
|
||||
from qmk.xap.common import merge_xap_defs, route_conditions
|
||||
|
||||
|
||||
def _get_c_type(xap_type):
|
||||
@ -298,101 +283,6 @@ 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:
|
||||
"""
|
||||
groups = spec.get('groups', {})
|
||||
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 ''
|
||||
|
||||
line = f'''
|
||||
#ifdef {ifdef_prefix}_{define}
|
||||
{{ {id}, {def_prefix}_{define}{offset}}},
|
||||
#endif'''
|
||||
|
||||
group = groups.get(obj.get('group', None), {}).get('define', None)
|
||||
if group:
|
||||
line = f'''
|
||||
#ifdef {group}
|
||||
{line}
|
||||
#endif'''
|
||||
|
||||
lines.append(line)
|
||||
|
||||
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:
|
||||
"""
|
||||
groups = spec.get('groups', {})
|
||||
ifdef_prefix = PREFIX_MAP[feature]['ifdef']
|
||||
|
||||
lines.append(f'enum {{ ENABLED_{feature.upper()}_EFFECTS = 0')
|
||||
for id, obj in spec.get('effects', {}).items():
|
||||
define = obj['define']
|
||||
|
||||
line = f'''
|
||||
#ifdef {ifdef_prefix}_{define}
|
||||
| (1ULL << {id})
|
||||
#endif'''
|
||||
|
||||
group = groups.get(obj.get('group', None), {}).get('define', None)
|
||||
if group:
|
||||
line = f'''
|
||||
#ifdef {group}
|
||||
{line}
|
||||
#endif'''
|
||||
|
||||
lines.append(line)
|
||||
|
||||
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 = 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')
|
||||
|
||||
|
||||
def generate_inline(output_file, keyboard, keymap):
|
||||
"""Generates the XAP protocol header file, generated during normal build.
|
||||
"""
|
||||
@ -401,9 +291,6 @@ 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)
|
||||
|
1092
quantum/xap/lighting_map.h
Normal file
1092
quantum/xap/lighting_map.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,7 @@
|
||||
#include <xap.h>
|
||||
#include "secure.h"
|
||||
|
||||
#include "lighting_map.h"
|
||||
#include "config_blob_gz.h"
|
||||
bool get_config_blob_chunk(uint16_t offset, uint8_t *data, uint8_t data_len) {
|
||||
if (offset + data_len > CONFIG_BLOB_GZ_LEN) {
|
||||
|
Loading…
Reference in New Issue
Block a user