From af409d0a4667a12c788d6d67c361ec3d603b20c8 Mon Sep 17 00:00:00 2001 From: IFX-Anusha Date: Mon, 26 Aug 2024 11:12:42 +0530 Subject: [PATCH] :ports/psoc6: Remove csv file generation. Signed-off-by: IFX-Anusha --- ports/psoc6/Makefile | 4 +- ports/psoc6/boards/make-pins.py | 126 ++++++++++++++------------------ 2 files changed, 55 insertions(+), 75 deletions(-) diff --git a/ports/psoc6/Makefile b/ports/psoc6/Makefile index a49b5d4c26e53..b70f8e35a3e4e 100644 --- a/ports/psoc6/Makefile +++ b/ports/psoc6/Makefile @@ -100,15 +100,13 @@ GEN_PINS_SRC := $(BUILD)/pins_$(BOARD).c HEADER_BUILD := $(BUILD)/genhdr GEN_PINS_HDR := $(BUILD)/genhdr/pins.h GEN_PINS_QSTR := $(BUILD)/pins_qstr.h -BOARD_PINS := pins.csv -BOARD_AF_PINS := pins_details.csv GENERATED_PINS = $(GEN_PINS_SRC) $(GEN_PINS_HDR) $(GEN_PINS_QSTR) $(GENERATED_PINS): @echo "Generating $@" $(MKDIR) -p $(BUILD)/genhdr - $(PYTHON) boards/make-pins.py --gen-pin-for $(PIN_PACKAGE_FILE) --save-pins-csv-at $(BOARD_PINS) --save-pins-details-csv-at $(BOARD_AF_PINS) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) > $(GEN_PINS_SRC) + $(PYTHON) boards/make-pins.py --gen-pin-for $(PIN_PACKAGE_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) > $(GEN_PINS_SRC) rm -rf $(BOARD_PINS) $(BOARD_AF_PINS) # Flags for optional C++ source code diff --git a/ports/psoc6/boards/make-pins.py b/ports/psoc6/boards/make-pins.py index 7a7e95bbd13f3..b7905254338b4 100755 --- a/ports/psoc6/boards/make-pins.py +++ b/ports/psoc6/boards/make-pins.py @@ -24,6 +24,28 @@ def name(self): return self._name +class PinsTable(object): + def __init__(self): + self.pins = [] + + def add_pin(self, pin_name, pin_addr): + self.pins.append([pin_name, pin_addr]) + + def get_pins(self): + return self.pins + + +class PinsDetailsTable(object): + def __init__(self): + self.pins_details = [] + + def add_pin_details(self, pin_name, pin_addr, pin_exp): + self.pins_details.append([pin_name, pin_addr, pin_exp]) + + def get_pins_details(self): + return self.pins_details + + class Pin(object): def __init__(self, name, pin_addr, pin_exp): self._name = name @@ -90,33 +112,22 @@ def print_const_table(self): pin.print_const_table_entry() print("};") - def parse_pin_details_file(self): - with open("./pins_details.csv", "r") as csvfile: - rows = csv.reader(csvfile) - for row in rows: - try: - pin_name = row[0] - pin_addr = row[1] - pin_exp = row[2].strip('"') - except: - continue - pin = Pin(pin_name, pin_addr, pin_exp) - self.cpu_pins.append(NamedPin(pin_name, pin)) - - def parse_board_file(self): - # Assuming the same path has required board files - with open("./pins.csv", "r") as csvfile: - rows = csv.reader(csvfile) - for row in rows: - try: - board_pin_name = row[0] - cpu_pin_name = row[1] - except: - continue - pin = self.find_pin(cpu_pin_name) - if pin: - pin.set_is_board_pin() - self.board_pins.append(NamedPin(board_pin_name, pin)) + def parse_pin_details_file(self, pins_details_table): + for pin in pins_details_table.get_pins_details(): + pin_name = pin[0] + pin_addr = pin[1] + pin_exp = pin[2].strip('"') + pin = Pin(pin_name, pin_addr, pin_exp) + self.cpu_pins.append(NamedPin(pin_name, pin)) + + def parse_board_file(self, pins_table): + for pin in pins_table.get_pins(): + board_pin_name = pin[0] + cpu_pin_name = pin[1] + pin = self.find_pin(cpu_pin_name) + if pin: + pin.set_is_board_pin() + self.board_pins.append(NamedPin(board_pin_name, pin)) def print_named(self, label, named_pins): print( @@ -158,7 +169,6 @@ def print_qstr(self, qstr_filename): for named_pin in self.board_pins: qstr_set |= set([named_pin.name()]) for qstr in sorted(qstr_set): - # cond_var = None print("Q({})".format(qstr), file=qstr_file) def get_pin_addr_helper(self, pin_def): @@ -180,50 +190,36 @@ def get_pin_package_path(self, filename): return file_path return None - def generate_pins_csv( - self, pin_package_filename, pins_csv_filename, pins_details_csv_filename - ): - file_path = self.get_pin_package_path(pin_package_filename) + def generate_pins_table(self, pin_pacakge_file_name): + file_path = self.get_pin_package_path(pin_pacakge_file_name) if file_path is None: sys.exit(1) - # Read the header file with open(file_path, "r") as file: content = file.read() - # Find the starting and ending points of the enum declaration enum_start = content.find("typedef enum {") enum_end = content.find("}") if enum_start != -1 and enum_end != -1: enum_content = content[enum_start:enum_end] - - # Extract enum values using regex enum_values = re.findall(r"\b(\w+)\s*=", enum_content) pin_name = re.findall(r"\b(?!NC\b)(\w+)\s*=", enum_content) pin_defs = re.findall(r"=\s*(.*?\))", enum_content) - # Write enum values to a CSV file - with open("./" + pins_csv_filename, "w", newline="") as csv_file: - csv_writer = csv.writer(csv_file) - csv_writer.writerows( - [ - [value, value] - for value in enum_values - if value.startswith("P") or value.startswith("N") - ] - ) + pins_table = PinsTable() + pins_details_table = PinsDetailsTable() - with open("./" + pins_details_csv_filename, "w", newline="") as csv_file: - NC_pin = ["NC", 255, "CYHAL_GET_GPIO(CYHAL_PORT_31, 7)"] # non-existent port - csv_writer = csv.writer(csv_file) - csv_writer.writerow(NC_pin) - for pname, pdef in zip(pin_name, pin_defs): - val = self.get_pin_addr_helper(pdef) - csv_writer.writerow([pname, val, pdef.strip('"')]) + for value in enum_values: + if value.startswith("P") or value.startswith("N"): + pins_table.add_pin(value, value) - print("// pins.csv and pins_details.csv generated successfully") + pins_details_table.add_pin_details("NC", 255, "CYHAL_GET_GPIO(CYHAL_PORT_31, 7)") + for pname, pdef in zip(pin_name, pin_defs): + val = self.get_pin_addr_helper(pdef) + pins_details_table.add_pin_details(pname, val, pdef.strip('"')) + return pins_table, pins_details_table else: print("// Error: pins.csv and pins_details.csv generation failed") @@ -242,20 +238,6 @@ def main(): help="Specifies the pin package file from mtb assets to generate pins.csv", ) - parser.add_argument( - "-p", - "--save-pins-csv-at", - dest="pins_csv", - help="Specifies name of generated pins csv file", - ) - - parser.add_argument( - "-gaf", - "--save-pins-details-csv-at", - dest="pins_details_csv", - help="Specifies name of generated pins details csv file", - ) - parser.add_argument( "-q", "--qstr", @@ -274,15 +256,15 @@ def main(): pins = Pins() - if args.pin_package_filename and args.pins_csv and args.pins_details_csv: + if args.pin_package_filename: print("// Generating pins csv file") print("// - --gen-pin-for {:s}".format(args.pin_package_filename)) - pins.generate_pins_csv(args.pin_package_filename, args.pins_csv, args.pins_details_csv) + pins_table, pins_details_table = pins.generate_pins_table(args.pin_package_filename) - pins.parse_pin_details_file() + pins.parse_pin_details_file(pins_details_table) if args.hdr_filename and args.qstr_filename: - pins.parse_board_file() + pins.parse_board_file(pins_table) pins.update_num_cpu_pins() pins.print_const_table() pins.print()