generate board_ids.h

This commit is contained in:
andreika-git 2023-08-18 23:07:05 +03:00
parent 939362431c
commit 3612bff930
3 changed files with 51 additions and 0 deletions

3
.gitmodules vendored
View File

@ -11,3 +11,6 @@
[submodule "bin/pcb-tools"]
path = bin/pcb-tools
url = https://github.com/curtacircuitos/pcb-tools.git
[submodule "board_id/libfirmware"]
path = board_id/libfirmware
url = https://github.com/rusefi/libfirmware/

View File

@ -0,0 +1,47 @@
#!/usr/bin/env python
############################################################################################
# Hellen-One: Generates a header file containing the list of Board-IDs.
# The result is stored in 'libfirmware/board_id/boards_id.h' folder.
# (c) andreika <prometheus.pcb@gmail.com>
############################################################################################
import csv, sys, os, re, datetime
board_ids_csv = "board_ids.csv"
libdir = "libfirmware/board_id"
board_ids_h = libdir + "/boards_id.h"
date_time = datetime.datetime.now()
def getBoardName(str):
str = str.replace("-", "_")
return str.upper()
def readCsv(fileName):
rows = list()
with open(fileName, 'rt') as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
# skip empty lines and comments (this is not strictly CSV-compliant, but useful for our purposes)
if (len(row) < 1 or row[0].startswith("#")):
continue
rows.append(row)
return rows
def saveH(fileName, rows):
with open (fileName, 'wt') as new_f:
new_f.write("//\n// was generated automatically by Hellen Board-ID generation tool gen_board_ids_h.py " + str(date_time) + "\n//\n\n#pragma once\n\n")
for row in rows:
new_f.write("#define BOARD_ID_" + getBoardName(row[3]) + "\t\t\t" + row[0] + "\n")
if not os.path.isdir(libdir):
print ("Error! Cannot find the destination folder " + libdir + "! Please make sure that 'libfirmware' submodule was initialized by calling 'git submodule update'")
sys.exit(1)
print ("Reading board ID list from " + board_ids_csv + "...")
boardIdList = readCsv(board_ids_csv)
print ("Saving the header file to " + board_ids_h + "...")
saveH(board_ids_h, boardIdList)
print ("Done!")

1
board_id/libfirmware Submodule

@ -0,0 +1 @@
Subproject commit cd215a965cca31aff98a18a786d5ad626e853b15