|
79 | 79 | 'SYSTEM_SLEEP': 'SUSPEND'
|
80 | 80 | }
|
81 | 81 |
|
82 |
| -def extract_scancodes(includedir: str, common_keymap_h: str, is_qmk: bool) -> List[Tuple[str, int]]: |
| 82 | +def extract_scancodes(ecdir: str, is_qmk: bool) -> List[Tuple[str, int]]: |
83 | 83 | "Extract mapping from scancode names to numbers"
|
84 | 84 |
|
85 | 85 | if is_qmk:
|
86 |
| - include = "common/keycode.h" |
87 |
| - else: |
88 |
| - include = "common/keymap.h" |
89 |
| - |
90 |
| - if is_qmk: |
| 86 | + includes = [f"{ecdir}/tmk_core/common/keycode.h"] |
| 87 | + common_keymap_h = open(includes[0]).read() |
91 | 88 | scancode_defines = re.findall(
|
92 | 89 | ' (KC_[^,\s]+)', common_keymap_h)
|
93 | 90 | else:
|
| 91 | + includes = [f"{ecdir}/src/common/include/common/keymap.h"] |
| 92 | + common_keymap_h = open(includes[0]).read() |
94 | 93 | scancode_defines = re.findall(
|
95 | 94 | '#define.*((?:K_\S+)|(?:KT_FN))', common_keymap_h)
|
96 | 95 |
|
97 | 96 | tmpdir = tempfile.mkdtemp()
|
98 | 97 | with open(f'{tmpdir}/keysym-extract.c', 'w') as f:
|
99 | 98 | f.write('#include <stdio.h>\n')
|
100 |
| - f.write(f'#include "{include}"\n') |
101 | 99 | f.write('int main() {\n')
|
102 | 100 | for i in scancode_defines:
|
103 | 101 | f.write(f'printf("%d ", {i});\n')
|
104 | 102 | f.write('}\n')
|
105 | 103 |
|
106 |
| - subprocess.check_call(['gcc', f'-I{includedir}', |
107 |
| - '-o', f'{tmpdir}/keysym-extract', f'{tmpdir}/keysym-extract.c']) |
| 104 | + cmd = ['gcc'] |
| 105 | + for i in includes: |
| 106 | + cmd.append('-include') |
| 107 | + cmd.append(i) |
| 108 | + cmd += ['-o', f'{tmpdir}/keysym-extract', f'{tmpdir}/keysym-extract.c'] |
| 109 | + subprocess.check_call(cmd) |
| 110 | + |
108 | 111 | output = subprocess.check_output(
|
109 | 112 | f'{tmpdir}/keysym-extract', universal_newlines=True)
|
110 | 113 |
|
111 | 114 | shutil.rmtree(tmpdir)
|
112 | 115 |
|
113 | 116 | scancode_names = (i.split('_', 1)[1] for i in scancode_defines)
|
114 | 117 | if is_qmk:
|
115 |
| - scancode_names = (QMK_MAPPING.get(i, i) for i in scancode_names) |
| 118 | + scancode_names = [QMK_MAPPING.get(i, i) for i in scancode_names] |
116 | 119 | scancodes = (int(i) for i in output.split())
|
117 | 120 | scancode_list = list(zip(scancode_names, scancodes))
|
118 | 121 |
|
@@ -211,24 +214,19 @@ def generate_layout_dir(ecdir: str, board: str, is_qmk: bool) -> None:
|
211 | 214 | print(f'Generating {layoutdir}...')
|
212 | 215 |
|
213 | 216 | if is_qmk:
|
214 |
| - common_keymap_h = open(f"{ecdir}/tmk_core/common/keycode.h").read() |
215 | 217 | keymap_h = open(
|
216 | 218 | f"{ecdir}/keyboards/{board}/{board.split('/')[-1]}.h").read()
|
217 | 219 | default_c = open(
|
218 | 220 | f"{ecdir}/keyboards/{board}/keymaps/default/keymap.c").read()
|
219 |
| - includedir = f'{ecdir}/tmk_core' |
220 | 221 | else:
|
221 |
| - common_keymap_h = open( |
222 |
| - f"{ecdir}/src/common/include/common/keymap.h").read() |
223 | 222 | keymap_h = open(
|
224 | 223 | f"{ecdir}/src/board/{board}/include/board/keymap.h").read()
|
225 | 224 | default_c = open(f"{ecdir}/src/board/{board}/keymap/default.c").read()
|
226 |
| - includedir = f'{ecdir}/src/common/include' |
227 | 225 |
|
228 | 226 | os.makedirs(f'{layoutdir}', exist_ok=True)
|
229 | 227 |
|
230 | 228 | physical, physical2 = parse_layout_define(keymap_h, is_qmk)
|
231 |
| - scancodes = extract_scancodes(includedir, common_keymap_h, is_qmk) |
| 229 | + scancodes = extract_scancodes(ecdir, is_qmk) |
232 | 230 | default_keymap = parse_keymap(default_c, physical, is_qmk)
|
233 | 231 | gen_layout_json(f'{layoutdir}/layout.json', physical, physical2)
|
234 | 232 | gen_keymap_json(f'{layoutdir}/keymap.json', scancodes)
|
|
0 commit comments