diff --git a/ports/psoc6/Makefile b/ports/psoc6/Makefile index 31243379ac46c..5bbd61d5d9d33 100644 --- a/ports/psoc6/Makefile +++ b/ports/psoc6/Makefile @@ -230,13 +230,14 @@ test_multi: # Supporting variables for make-pins.py script execution MAKE_PINS = boards/make-pins.py -MTB_PIN_PACKAGES_PATH := mtb_shared/mtb-hal-cat1/release-v2.4.1/COMPONENT_CAT1A/include/pin_packages +#MTB_PIN_PACKAGES_PATH := mtb_shared/mtb-hal-cat1/ +MTB_PIN_PACKAGES_PATH := mtb_shared/mtb-hal-cat1/release-v2.4.2/COMPONENT_CAT1A/include/pin_packages ifeq ($(BOARD), CY8CPROTO-062-4343W) -PIN_PACKAGE_FILE = $(MTB_PIN_PACKAGES_PATH)/cyhal_psoc6_02_124_bga.h +PIN_PACKAGE_FILE = cyhal_psoc6_02_124_bga.h endif ifeq ($(BOARD), CY8CPROTO-063-BLE) -PIN_PACKAGE_FILE = $(MTB_PIN_PACKAGES_PATH)/cyhal_psoc6_03_68_qfn.h #ToDo: Check the right file and replace +PIN_PACKAGE_FILE = cyhal_psoc6_03_68_qfn.h #ToDo: Check the right file and replace endif #ToDo: Post adding af functionality, refactor to minimize dependent variables in py script if possible @@ -249,6 +250,7 @@ PREFIX_FILE := psoc6_prefix.c HEADER_BUILD := $(BUILD)/genhdr # Rule to generate pins.csv +#ToDo: Move to python script when af completed $(BOARD_PINS): @echo "Creating $(BOARD_PINS)" @touch $(BOARD_PINS) @@ -264,11 +266,9 @@ $(HEADER_BUILD): #ToDO: --board $(BOARD_PINS) pass board name make_pins: @echo "Generating pin structures" - $(PYTHON) $(MAKE_PINS) --gen-pin-for $(PIN_PACKAGE_FILE) --save-pins-csv-at $(BOARD_PINS) --save-pins-af-csv-at $(BOARD_AF_PINS) --prefix $(PREFIX_FILE) --board $(BOARD_PINS) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) + $(PYTHON) $(MAKE_PINS) --gen-pin-for $(PIN_PACKAGE_FILE) --save-pins-csv-at $(BOARD_PINS) --save-pins-af-csv-at $(BOARD_AF_PINS) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) > $(GEN_PINS_SRC) rm -rf $(BOARD_PINS) $(BOARD_AF_PINS) -#$(PYTHON) $(MAKE_PINS) --gen-pin-for $(PIN_PACKAGE_FILE) --save-pins-csv-at $(BOARD_PINS) --save-pins-af-csv-at $(BOARD_AF_PINS) --prefix $(PREFIX_FILE) --board $(BOARD_PINS) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) > $(GEN_PINS_SRC) - help: @: $(info ) diff --git a/ports/psoc6/boards/make-pins.py b/ports/psoc6/boards/make-pins.py index fda4ca1778276..2307e474343cf 100755 --- a/ports/psoc6/boards/make-pins.py +++ b/ports/psoc6/boards/make-pins.py @@ -14,6 +14,19 @@ def get_pin_addr_helper(pin_def): return (int(port_number) << 3) + int(pin_number) +def get_pin_package_path(filename): + root_dir = "./mtb_shared/mtb-hal-cat1" + mid_dir = "COMPONENT_CAT1A/include/pin_packages" + for dirpath, dirnames, filenames in os.walk(root_dir): + for dirname in dirnames: + if dirname.startswith("release-"): + release_version = dirname + file_path = os.path.join(root_dir, release_version, mid_dir, filename) + if os.path.isfile(file_path): + return file_path + return None + + class NamedPin(object): def __init__(self, name, pin): self._name = name @@ -64,6 +77,7 @@ class Pins(object): def __init__(self): self.cpu_pins = [] # list of NamedPin objects self.board_pins = [] # list of NamedPin objects + self.board_pin_csv_path = "" def find_pin(self, cpu_pin_name): for named_pin in self.cpu_pins: @@ -72,19 +86,13 @@ def find_pin(self, cpu_pin_name): return pin def generate_pins_csv(self, pin_package_filename, pins_csv_filename): + file_path = get_pin_package_path(pin_package_filename) - directory_name = "./mtb_shared/mtb-hal-cat1/" - try: - os.chdir(directory_name) - print(f"Changed to directory: {directory_name}") - except FileNotFoundError: - print(f"Directory not found: {directory_name}") - current_directory = os.getcwd() - print("//Current directory: ", current_directory) - print("//List files: ", os.listdir(current_directory)) + if file_path is None: + sys.exit(1) # Read the header file - with open(pin_package_filename, "r") as file: + with open(file_path, "r") as file: content = file.read() # Find the starting and ending points of the enum declaration @@ -101,14 +109,19 @@ def generate_pins_csv(self, pin_package_filename, pins_csv_filename): 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]) + self.board_pin_csv_path = pins_csv_filename print("// pins.csv generated successfully") else: print("// Error: pins.csv generation failed") def generate_af_pins_csv(self, pin_package_filename, pins_af_csv_filename): + file_path = get_pin_package_path(pin_package_filename) + + if file_path is None: + sys.exit(1) # Read the header file - with open(pin_package_filename, "r") as file: + with open(file_path, "r") as file: content = file.read() # Find the starting and ending points of the enum declaration @@ -146,7 +159,7 @@ def parse_af_file(self, filename): self.cpu_pins.append(NamedPin(pin_name, pin)) def parse_board_file(self, filename): - with open("./" + filename, "r") as csvfile: + with open(self.board_pin_csv_path, "r") as csvfile: rows = csv.reader(csvfile) for row in rows: try: @@ -242,13 +255,6 @@ def main(): help="Specifies name of generated alternate functions pins csv file", ) - parser.add_argument( - "-b", - "--board", - dest="board_filename", - help="Specifies the generated board pins csv file", - ) - parser.add_argument( "-pr", "--prefix", @@ -290,10 +296,6 @@ def main(): print("// --save-pins-af-csv-at {:s}".format(args.pins_af_csv)) pins.parse_af_file(args.pins_af_csv) - if args.board_filename: - print("// --board {:s}".format(args.board_filename)) - pins.parse_board_file(args.board_filename) - if args.prefix_filename: print("// --prefix {:s}".format(args.prefix_filename)) print("")