mirror of
https://github.com/qmk/qmk_firmware.git
synced 2026-07-12 20:06:00 -04:00
Merge remote-tracking branch 'origin/develop' into xap
This commit is contained in:
@@ -17,10 +17,22 @@ def _gen_led_configs(info_data):
|
||||
lines = []
|
||||
|
||||
if 'layout' in info_data.get('rgb_matrix', {}):
|
||||
lines.append('#ifdef RGB_MATRIX_ENABLE')
|
||||
lines.append('#include "rgb_matrix.h"')
|
||||
lines.append('')
|
||||
lines.extend(_gen_led_config(info_data, 'rgb_matrix'))
|
||||
lines.extend(_gen_led_duplicate_config(info_data, 'rgb_matrix'))
|
||||
lines.append('#endif')
|
||||
lines.append('')
|
||||
|
||||
if 'layout' in info_data.get('led_matrix', {}):
|
||||
lines.append('#ifdef LED_MATRIX_ENABLE')
|
||||
lines.append('#include "led_matrix.h"')
|
||||
lines.append('')
|
||||
lines.extend(_gen_led_config(info_data, 'led_matrix'))
|
||||
lines.extend(_gen_led_duplicate_config(info_data, 'led_matrix'))
|
||||
lines.append('#endif')
|
||||
lines.append('')
|
||||
|
||||
return lines
|
||||
|
||||
@@ -45,13 +57,6 @@ def _gen_led_config(info_data, config_type):
|
||||
pos.append(f'{{{led_data.get("x", 0)}, {led_data.get("y", 0)}}}')
|
||||
flags.append(str(led_data.get('flags', 0)))
|
||||
|
||||
if config_type == 'rgb_matrix':
|
||||
lines.append('#ifdef RGB_MATRIX_ENABLE')
|
||||
lines.append('#include "rgb_matrix.h"')
|
||||
elif config_type == 'led_matrix':
|
||||
lines.append('#ifdef LED_MATRIX_ENABLE')
|
||||
lines.append('#include "led_matrix.h"')
|
||||
|
||||
lines.append('__attribute__ ((weak)) led_config_t g_led_config = {')
|
||||
lines.append(' {')
|
||||
for line in matrix:
|
||||
@@ -60,7 +65,51 @@ def _gen_led_config(info_data, config_type):
|
||||
lines.append(f' {{ {", ".join(pos)} }},')
|
||||
lines.append(f' {{ {", ".join(flags)} }},')
|
||||
lines.append('};')
|
||||
lines.append('#endif')
|
||||
lines.append('')
|
||||
|
||||
return lines
|
||||
|
||||
|
||||
def _gen_led_duplicate_config(info_data, config_type):
|
||||
"""Convert duplicate led mappings to map_row_column_to_led_kb implementations"""
|
||||
|
||||
# precompute our map of matrix[r,c] -> [ids]
|
||||
duplicates = False
|
||||
led_map = {}
|
||||
led_layout = info_data[config_type]['layout']
|
||||
for led_index, led_data in enumerate(led_layout):
|
||||
if 'matrix' in led_data:
|
||||
matrix = tuple(led_data['matrix'])
|
||||
led_map[matrix] = [*led_map.get(matrix, []), led_index]
|
||||
duplicates = True
|
||||
|
||||
if not duplicates:
|
||||
return []
|
||||
|
||||
lines = []
|
||||
lines.append(f'uint8_t {config_type}_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) {{')
|
||||
|
||||
for matrix, indexes in led_map.items():
|
||||
if len(indexes) > 1:
|
||||
# Match last one wins behavior of _gen_led_config w.r.t. g_led_config matrix generation
|
||||
last_index = indexes[-1]
|
||||
other_indexes = indexes[:-1]
|
||||
|
||||
lines.append(f'#if LED_HITS_TO_REMEMBER < {len(indexes)}')
|
||||
lines.append(f'# pragma message("LED_HITS_TO_REMEMBER is not large enough to handle matrix{list(matrix)} indexes{indexes}")')
|
||||
lines.append('#else')
|
||||
lines.append(f' if (row == {matrix[0]} && column == {matrix[1]}) {{')
|
||||
lines.append(f' // {last_index} will be added by the default lookup code that runs after this')
|
||||
|
||||
for index, led_index in enumerate(other_indexes):
|
||||
lines.append(f' led_i[{index}] = {led_index};')
|
||||
|
||||
lines.append(f' return {len(other_indexes)};')
|
||||
lines.append(' }')
|
||||
lines.append('#endif')
|
||||
|
||||
lines.append(' return 0;')
|
||||
lines.append('}')
|
||||
lines.append('')
|
||||
|
||||
return lines
|
||||
|
||||
Reference in New Issue
Block a user