Skip to content

Commit

Permalink
Add ifdefs to generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr committed May 15, 2022
1 parent 0857c30 commit 440c40e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/python/qmk/cli/generate/keyboard_c.py
Expand Up @@ -15,27 +15,35 @@ def _gen_led_config(info_data):
cols = info_data['matrix_size']['cols']
rows = info_data['matrix_size']['rows']

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

lines = []
if not led_config:
if not config_type:
return lines

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

led_config = info_data[config_type]['layout']
for index, item in enumerate(led_config, start=0):
if 'matrix' in item:
(x, y) = item['matrix']
matrix[x][y] = str(index)
pos.append(f'{{ {item.get("x", 0)},{item.get("y", 0)} }}')
flags.append(str(item.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:
Expand All @@ -44,6 +52,7 @@ def _gen_led_config(info_data):
lines.append(f' {{ {",".join(pos)} }},')
lines.append(f' {{ {",".join(flags)} }},')
lines.append('};')
lines.append('#endif')

return lines

Expand Down

0 comments on commit 440c40e

Please sign in to comment.