|
47 | 47 | templates_dir = script_path / "templates" |
48 | 48 | all_ll_h_file = "stm32yyxx_ll.h" |
49 | 49 | ll_h_file = "stm32yyxx_ll_ppp.h" |
50 | | -c_file = "stm32yyxx_zz_ppp.c" |
| 50 | +c_file = "stm32yyxx_feat.c" |
51 | 51 | stm32_def_build_file = "stm32_def_build.h" |
52 | 52 | system_stm32_file = "system_stm32yyxx.c" |
53 | 53 |
|
|
63 | 63 | system_stm32_template = j2_env.get_template(system_stm32_file) |
64 | 64 |
|
65 | 65 | # re |
66 | | -peripheral_c_regex = re.compile(r"stm32\w+_[h]?[al][l]_(.*).c$") |
67 | | -peripheral_h_regex = re.compile(r"stm32\w+_[h]?[al][l]_(.*).h$") |
| 66 | +feat_c_regex = re.compile(r"stm32[^_]+_(.*).c$") |
| 67 | +feat_h_regex = re.compile(r"stm32[^_]+_(.*).h$") |
68 | 68 |
|
69 | 69 |
|
70 | 70 | def checkConfig(arg_core, arg_cmsis): |
@@ -205,79 +205,75 @@ def wrap(arg_core, arg_cmsis, log): |
205 | 205 | legacy = fp.parent.name == "Legacy" |
206 | 206 | # File name |
207 | 207 | fn = fp.name |
208 | | - found = peripheral_c_regex.match(fn) |
209 | 208 | if "_template" in fn: |
210 | 209 | continue |
211 | | - peripheral = found.group(1) if found else "hal" |
| 210 | + found = feat_c_regex.match(fn) |
| 211 | + if not found: |
| 212 | + print(f"File {fn} does not match the expected pattern!") |
| 213 | + continue |
| 214 | + feat = found.group(1) |
212 | 215 | if "_ll_" in fn: |
213 | | - if peripheral in ll_c_dict: |
| 216 | + if feat in ll_c_dict: |
214 | 217 | if legacy: |
215 | 218 | # Change legacy value if exists |
216 | | - current_list = ll_c_dict.pop(peripheral) |
| 219 | + current_list = ll_c_dict.pop(feat) |
217 | 220 | if current_list[-1][0] == lower: |
218 | 221 | current_list.pop() |
219 | 222 | current_list.append((lower, legacy, stm32_dict[series])) |
220 | | - ll_c_dict[peripheral] = current_list |
| 223 | + ll_c_dict[feat] = current_list |
221 | 224 | else: |
222 | | - ll_c_dict[peripheral].append( |
223 | | - (lower, legacy, stm32_dict[series]) |
224 | | - ) |
| 225 | + ll_c_dict[feat].append((lower, legacy, stm32_dict[series])) |
225 | 226 | else: |
226 | | - ll_c_dict[peripheral] = [(lower, legacy, stm32_dict[series])] |
| 227 | + ll_c_dict[feat] = [(lower, legacy, stm32_dict[series])] |
227 | 228 | else: |
228 | | - if peripheral in hal_c_dict: |
| 229 | + if feat in hal_c_dict: |
229 | 230 | if legacy: |
230 | 231 | # Change legacy value if exists |
231 | | - current_list = hal_c_dict.pop(peripheral) |
| 232 | + current_list = hal_c_dict.pop(feat) |
232 | 233 | if current_list[-1][0] == lower: |
233 | 234 | current_list.pop() |
234 | 235 | current_list.append((lower, legacy, stm32_dict[series])) |
235 | | - hal_c_dict[peripheral] = current_list |
| 236 | + hal_c_dict[feat] = current_list |
236 | 237 | else: |
237 | | - hal_c_dict[peripheral].append( |
238 | | - (lower, legacy, stm32_dict[series]) |
239 | | - ) |
| 238 | + hal_c_dict[feat].append((lower, legacy, stm32_dict[series])) |
240 | 239 | else: |
241 | | - hal_c_dict[peripheral] = [(lower, legacy, stm32_dict[series])] |
| 240 | + hal_c_dict[feat] = [(lower, legacy, stm32_dict[series])] |
242 | 241 |
|
243 | 242 | # Search stm32yyxx_ll_*.h file |
244 | 243 | filelist = inc.glob(f"stm32{lower}{nx}_ll_*.h") |
245 | 244 | for fp in filelist: |
246 | 245 | # File name |
247 | 246 | fn = fp.name |
248 | | - found = peripheral_h_regex.match(fn) |
| 247 | + found = feat_h_regex.match(fn) |
249 | 248 | if not found: |
250 | 249 | continue |
251 | | - peripheral = found.group(1) |
| 250 | + feature = found.group(1) |
252 | 251 | # Amend all LL header list |
253 | 252 | all_ll_h_list.append(fn.replace(f"{lower}{nx}", "yyxx")) |
254 | | - if peripheral in ll_h_dict: |
255 | | - ll_h_dict[peripheral].append((lower, stm32_dict[series])) |
| 253 | + if feature in ll_h_dict: |
| 254 | + ll_h_dict[feature].append((lower, stm32_dict[series])) |
256 | 255 | else: |
257 | | - ll_h_dict[peripheral] = [(lower, stm32_dict[series])] |
| 256 | + ll_h_dict[feature] = [(lower, stm32_dict[series])] |
258 | 257 |
|
259 | 258 | # Generate stm32yyxx_hal_*.c file |
260 | 259 | for key, value in hal_c_dict.items(): |
261 | | - if key == "hal": |
262 | | - filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace("_ppp", "") |
263 | | - else: |
264 | | - filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace("ppp", key) |
| 260 | + filepath = HALoutSrc_path / f"stm32yyxx_{key}.c" |
265 | 261 | with open(filepath, "w", newline="\n") as out_file: |
266 | 262 | out_file.write( |
267 | | - c_file_template.render(periph=key, type="hal", serieslist=value) |
| 263 | + c_file_template.render(feat=key, type="HAL", serieslist=value) |
268 | 264 | ) |
269 | 265 | # Generate stm32yyxx_ll_*.c file |
270 | 266 | for key, value in ll_c_dict.items(): |
271 | | - filepath = LLoutSrc_path / c_file.replace("zz", "ll").replace("ppp", key) |
| 267 | + filepath = LLoutSrc_path / f"stm32yyxx_{key}.c" |
272 | 268 | with open(filepath, "w", newline="\n") as out_file: |
273 | 269 | out_file.write( |
274 | | - c_file_template.render(periph=key, type="ll", serieslist=value) |
| 270 | + c_file_template.render(feat=key, type="LL", serieslist=value) |
275 | 271 | ) |
276 | 272 | # Generate stm32yyxx_ll_*.h file |
277 | 273 | for key, value in ll_h_dict.items(): |
278 | | - filepath = LLoutInc_path / ll_h_file.replace("ppp", key) |
| 274 | + filepath = LLoutInc_path / f"stm32yyxx_{key}.h" |
279 | 275 | with open(filepath, "w", newline="\n") as out_file: |
280 | | - out_file.write(ll_h_file_template.render(periph=key, serieslist=value)) |
| 276 | + out_file.write(ll_h_file_template.render(feat=key, serieslist=value)) |
281 | 277 | if log: |
282 | 278 | print("done") |
283 | 279 |
|
|
0 commit comments