From 1bebaa310abb637cbca146b6d7859f3efe503cfd Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 14 Jan 2024 21:33:58 +1100 Subject: [PATCH] CLI: Allow generation of both LED and RGB Matrix config (#22896) --- lib/python/qmk/cli/generate/keyboard_c.py | 25 ++++++++++------- lib/python/qmk/info.py | 34 ++++++++++------------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/lib/python/qmk/cli/generate/keyboard_c.py b/lib/python/qmk/cli/generate/keyboard_c.py index f010341613..5a6c967486 100755 --- a/lib/python/qmk/cli/generate/keyboard_c.py +++ b/lib/python/qmk/cli/generate/keyboard_c.py @@ -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 diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index b018ba96fd..efe4dac34a 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -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 + for feature in ['rgb_matrix', 'led_matrix']: + if info_data.get('features', {}).get(feature, False) or feature in info_data: - 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}') + # 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']) + 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