~ruther/qmk_firmware

1bebaa310abb637cbca146b6d7859f3efe503cfd — Ryan 1 year, 5 months ago e2517ff
CLI: Allow generation of both LED and RGB Matrix config (#22896)

2 files changed, 32 insertions(+), 31 deletions(-)

M lib/python/qmk/cli/generate/keyboard_c.py
M lib/python/qmk/info.py
M lib/python/qmk/cli/generate/keyboard_c.py => lib/python/qmk/cli/generate/keyboard_c.py +15 -10
@@ 9,21 9,25 @@ from qmk.path import normpath
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE


def _gen_led_config(info_data):
def _gen_led_configs(info_data):
    lines = []

    if 'layout' in info_data.get('rgb_matrix', {}):
        lines.extend(_gen_led_config(info_data, 'rgb_matrix'))

    if 'layout' in info_data.get('led_matrix', {}):
        lines.extend(_gen_led_config(info_data, 'led_matrix'))

    return lines


def _gen_led_config(info_data, config_type):
    """Convert info.json content to g_led_config
    """
    cols = info_data['matrix_size']['cols']
    rows = info_data['matrix_size']['rows']

    config_type = None
    if 'layout' in info_data.get('rgb_matrix', {}):
        config_type = 'rgb_matrix'
    elif 'layout' in info_data.get('led_matrix', {}):
        config_type = 'led_matrix'

    lines = []
    if not config_type:
        return lines

    matrix = [['NO_LED'] * cols for _ in range(rows)]
    pos = []


@@ 53,6 57,7 @@ def _gen_led_config(info_data):
    lines.append(f'  {{ {", ".join(flags)} }},')
    lines.append('};')
    lines.append('#endif')
    lines.append('')

    return lines



@@ 98,7 103,7 @@ def generate_keyboard_c(cli):
    # Build the layouts.h file.
    keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#include QMK_KEYBOARD_H', '']

    keyboard_h_lines.extend(_gen_led_config(kb_info_json))
    keyboard_h_lines.extend(_gen_led_configs(kb_info_json))
    keyboard_h_lines.extend(_gen_matrix_mask(kb_info_json))

    # Show the results

M lib/python/qmk/info.py => lib/python/qmk/info.py +17 -21
@@ 686,27 686,23 @@ def _extract_led_config(info_data, keyboard):
    cols = info_data['matrix_size']['cols']
    rows = info_data['matrix_size']['rows']

    # Determine what feature owns g_led_config
    feature = None
    for feat in ['rgb_matrix', 'led_matrix']:
        if info_data.get('features', {}).get(feat, False) or feat in info_data:
            feature = feat

    if feature:
        # Only attempt search if dd led config is missing
        if 'layout' not in info_data.get(feature, {}):
            # Process
            for file in find_keyboard_c(keyboard):
                try:
                    ret = find_led_config(file, cols, rows)
                    if ret:
                        info_data[feature] = info_data.get(feature, {})
                        info_data[feature]['layout'] = ret
                except Exception as e:
                    _log_warning(info_data, f'led_config: {file.name}: {e}')

        if info_data[feature].get('layout', None) and not info_data[feature].get('led_count', None):
            info_data[feature]['led_count'] = len(info_data[feature]['layout'])
    for feature in ['rgb_matrix', 'led_matrix']:
        if info_data.get('features', {}).get(feature, False) or feature in info_data:

            # Only attempt search if dd led config is missing
            if 'layout' not in info_data.get(feature, {}):
                # Process
                for file in find_keyboard_c(keyboard):
                    try:
                        ret = find_led_config(file, cols, rows)
                        if ret:
                            info_data[feature] = info_data.get(feature, {})
                            info_data[feature]['layout'] = ret
                    except Exception as e:
                        _log_warning(info_data, f'led_config: {file.name}: {e}')

            if info_data[feature].get('layout', None) and not info_data[feature].get('led_count', None):
                info_data[feature]['led_count'] = len(info_data[feature]['layout'])

    return info_data


Do not follow this link