Skip to content

Commit

Permalink
default_keyboard.h generation tweaks (#24715)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark authored Dec 15, 2024
1 parent 8e6bfbf commit 0f3993b
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/python/qmk/cli/generate/keyboard_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def _generate_layouts(keyboard, kb_info_json):
row_num = kb_info_json['matrix_size']['rows']

lines = []
lines.append('')
lines.append('// Layout content')
lines.append('')
lines.append('#define XXX KC_NO')

for layout_name, layout_data in kb_info_json['layouts'].items():
if layout_data['c_macro']:
continue
Expand All @@ -31,7 +36,7 @@ def _generate_layouts(keyboard, kb_info_json):
continue

layout_keys = []
layout_matrix = [['KC_NO'] * col_num for _ in range(row_num)]
layout_matrix = [['XXX'] * col_num for _ in range(row_num)]

for key_data in layout_data['layout']:
row, col = key_data['matrix']
Expand All @@ -46,7 +51,7 @@ def _generate_layouts(keyboard, kb_info_json):
lines.append('')
lines.append(f'#define {layout_name}({", ".join(layout_keys)}) {{ \\')

rows = ', \\\n'.join(['\t {' + ', '.join(row) + '}' for row in layout_matrix])
rows = ', \\\n'.join([' { ' + ', '.join(row) + ' }' for row in layout_matrix])
rows += ' \\'
lines.append(rows)
lines.append('}')
Expand All @@ -67,6 +72,9 @@ def _generate_keycodes(kb_info_json):
return []

lines = []
lines.append('')
lines.append('// Keycode content')
lines.append('')
lines.append('enum keyboard_keycodes {')

for index, item in enumerate(kb_info_json.get('keycodes')):
Expand Down Expand Up @@ -103,17 +111,14 @@ def generate_keyboard_h(cli):
valid_config = dd_layouts or keyboard_h

# Build the layouts.h file.
keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '#include "quantum.h"']
keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '', '#include "quantum.h"']

keyboard_h_lines.append('')
keyboard_h_lines.append('// Layout content')
if dd_layouts:
keyboard_h_lines.extend(dd_layouts)

if keyboard_h:
keyboard_h_lines.append(f'#include "{Path(keyboard_h).name}"')

keyboard_h_lines.append('')
keyboard_h_lines.append('// Keycode content')
if dd_keycodes:
keyboard_h_lines.extend(dd_keycodes)

Expand Down

0 comments on commit 0f3993b

Please sign in to comment.