diff --git a/ports/psoc6/Makefile b/ports/psoc6/Makefile index d4a60c0669d2..dc886df49fe8 100644 --- a/ports/psoc6/Makefile +++ b/ports/psoc6/Makefile @@ -13,15 +13,35 @@ ifeq ($(wildcard $(BOARD_DIR)/.),) $(error Invalid BOARD specified) endif +# Supporting variables for make-pins.py script execution +MAKE_PINS_CSV = ./boards/make-pins-csv.py +MAKE_PINS = ./boards/make-pins.py + +ifeq ($(BOARD), CY8CPROTO-062-4343W) +PIN_PACKAGE_FILE = cyhal_psoc6_02_124_bga.h +endif +ifeq ($(BOARD), CY8CPROTO-063-BLE) +PIN_PACKAGE_FILE = cyhal_psoc6_01_116_bga_ble.h #ToDo: Check the right file and replace +endif + +#ToDo: Post adding af functionality, refactor to minimize dependent variables in py script if possible +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_af.csv +PREFIX_FILE := ./psoc6_prefix.c # get path to this file MPY_PATH_TO_MAIN_MAKEFILE := $(abspath $(lastword $(MAKEFILE_LIST))) MPY_DIR_OF_MAIN_MAKEFILE := $(dir $(MPY_PATH_TO_MAIN_MAKEFILE)) - +# Files that are generated and needed before the QSTR build. +QSTR_GENERATED_HEADERS = build/pins_qstr.h # qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h -QSTR_GLOBAL_DEPENDENCIES += $(BOARD_DIR)/mpconfigboard.h +QSTR_DEFS = qstrdefsport.h $(QSTR_GENERATED_HEADERS) +QSTR_GLOBAL_DEPENDENCIES += $(BOARD_DIR)/mpconfigboard.h $(QSTR_GENERATED_HEADERS) MICROPY_FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py FROZEN_MANIFEST ?= $(MICROPY_FROZEN_MANIFEST) @@ -94,6 +114,22 @@ endif $(info Compiling in $(CONFIG) mode !) +# Rule to generate pins.csv +make_pins_csv: + @echo "Generating $@" + $(PYTHON) $(MAKE_PINS_CSV) --gen-pin-for $(PIN_PACKAGE_FILE) --save-pins-csv-at $(BOARD_PINS) --save-pins-af-csv-at $(BOARD_AF_PINS) + $(MAKE) make_pins + +make_pins: $(GEN_PINS_SRC) $(GEN_PINS_HDR) $(GEN_PINS_QSTR) +$(GEN_PINS_SRC) $(GEN_PINS_HDR) $(GEN_PINS_QSTR): $(BOARD_PINS) $(MAKE_PINS) $(BOARD_AF_PINS) | $(HEADER_BUILD) + $(ECHO) "GEN $@" + $(PYTHON) $(MAKE_PINS) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) > $(GEN_PINS_SRC) + +clean_csv: + rm -rf $(BOARD_PINS) $(BOARD_AF_PINS) + +$(OBJ): | $(GEN_PINS_HDR) + # Flags for optional C++ source code CXXFLAGS += $(filter-out -std=c99,$(CFLAGS)) @@ -176,7 +212,7 @@ OBJ += $(addprefix $(BUILD)/, $(MOD_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_ASM:.s=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o)) - +OBJ += $(GEN_PINS_SRC:.c=.o) # switch for debug mode, also added to mpconfigport.h # TODO: keep the more suitable one, delete the other MP_LOGGER_DEBUG ?= 0 @@ -185,7 +221,6 @@ ifeq ($(MP_LOGGER_DEBUG), 1) CFLAGS += -DMICROPY_LOGGER_DEBUG=1 endif - $(MPY_MAIN_BUILD_DIR)/firmware.elf: $(OBJ) $(MPY_MTB_LIBRARIES) $(LIBS) $(info ) $(info Linking $@ $^ $(LIBS) ...) @@ -202,12 +237,9 @@ $(MPY_MAIN_BUILD_DIR)/firmware.hex: $(MPY_MAIN_BUILD_DIR)/firmware.elf # include adapter makefile include mtb-libs/makefile_mtb.mk -# include py core make definitions -include $(TOP)/py/mkrules.mk - MPY_CROSS_FLAGS += -march=armv7m -build: mtb_get_build_flags $(MPY_PATH_TO_MAIN_MAKEFILE) $(MPY_MAIN_BUILD_DIR)/firmware.hex +build: mtb_get_build_flags make_pins_csv $(MPY_PATH_TO_MAIN_MAKEFILE) $(MPY_MAIN_BUILD_DIR)/firmware.hex clean_csv all: build @@ -298,4 +330,7 @@ help: $(info - mtb_set_bsp Set the board as active in the ModusToolbox project. ) -.PHONY: build test test_multi program_multi help \ No newline at end of file +.PHONY: build test test_multi program_multi help make_pins_csv make_pins clean_csv + +# include py core make definitions +include $(TOP)/py/mkrules.mk \ No newline at end of file diff --git a/ports/psoc6/boards/make-pins-csv.py b/ports/psoc6/boards/make-pins-csv.py new file mode 100644 index 000000000000..2f58d7e90b16 --- /dev/null +++ b/ports/psoc6/boards/make-pins-csv.py @@ -0,0 +1,135 @@ +from __future__ import print_function +import argparse +import sys +import csv +import re +import os + + +def get_pin_addr_helper(pin_def): + pattern = r"CYHAL_PORT_(\d+),\s*(\d+)" + match = re.search(pattern, pin_def) + port_number = match.group(1) + pin_number = match.group(2) + 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 + + +def generate_pins_csv(pin_package_filename, pins_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(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) + # 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")] + ) + print("// pins.csv generated successfully") + else: + print("// Error: pins.csv generation failed") + + +def generate_af_pins_csv(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(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 + pin_name = re.findall(r"\b(?!NC\b)(\w+)\s*=", enum_content) + pin_def = re.findall(r"=\s*(.*?\))", enum_content) + # Write enum values to a CSV file + with open("./" + pins_af_csv_filename, "w", newline="") as csv_file: + csv_writer = csv.writer(csv_file) + for pname, pdef in zip(pin_name, pin_def): + # if pin_name[pname].startswith('P'): + val = get_pin_addr_helper(pdef) + csv_writer.writerow([pname, val, pdef.strip('"')]) + + print("// pins_af.csv generated successfully") + else: + print("Error: pins_af.csv generation failed") + + +def main(): + parser = argparse.ArgumentParser( + prog="make-pins-csv.py", + usage="%(prog)s [options] [command]", + description="Generate intermediate board specific pin csv files to be used by make-pins script", + ) + + parser.add_argument( + "-g", + "--gen-pin-for", + dest="pin_package_filename", + 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-af-csv-at", + dest="pins_af_csv", + help="Specifies name of generated alternate functions pins csv file", + ) + + args = parser.parse_args(sys.argv[1:]) + + if args.pin_package_filename and args.pins_csv: + print("// Generating pins csv file") + print("// - --gen-pin-for {:s}".format(args.pin_package_filename)) + print("// - --save-pins-csv-at {:s}".format(args.pins_csv)) + generate_pins_csv(args.pin_package_filename, args.pins_csv) + + if args.pin_package_filename and args.pins_af_csv: + print("// Generating alternate functions pins csv file") + print("// - --save-pins-csv-at {:s}".format(args.pins_af_csv)) + generate_af_pins_csv(args.pin_package_filename, args.pins_af_csv) + + +if __name__ == "__main__": + main() diff --git a/ports/psoc6/boards/make-pins.py b/ports/psoc6/boards/make-pins.py new file mode 100755 index 000000000000..9c5ebb357b54 --- /dev/null +++ b/ports/psoc6/boards/make-pins.py @@ -0,0 +1,228 @@ +from __future__ import print_function +import argparse +import sys +import csv +import re +import os + +prefix_content = '#include \n \ +#include "py/obj.h" \n \ +#include "py/mphal.h" \n \ +#include "modules/machine/pins.h"\n ' + + +class NamedPin(object): + def __init__(self, name, pin): + self._name = name + self._pin = pin + + def pin(self): + return self._pin + + def name(self): + return self._name + + +class Pin(object): + def __init__(self, name, pin_addr, pin_exp): + self._name = name + self._pin_addr = pin_addr + self._pin_exp = pin_exp + self._board_pin = False + + def cpu_pin_name(self): + return self._name + + def is_board_pin(self): + return self._board_pin + + def set_is_board_pin(self): + self._board_pin = True + + def set_board_index(self, index): + self.board_index = index + + def print(self): + """print( + "const machine_pin_obj_t pin_{:s}_obj = PIN({:s}, {:s});".format( + self._name, + self._name, + self._pin_addr, + ) + )""" + # print("") + + def print_header(self, hdr_file): + n = self.cpu_pin_name() + hdr_file.write("extern const machine_pin_obj_t pin_{:s}_obj;\n".format(n)) + + def qstr_list(self): + return [self._name] + + def print_const_table_entry(self): + print('{{{{ &machine_pin_type}},{:s}, "{:s}"}},'.format(self._pin_exp, self._name)) + + +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: + pin = named_pin.pin() + if pin.cpu_pin_name() == cpu_pin_name: + return pin + + def print_const_table(self): + num_cpu_pins = 0 + for named_pin in self.cpu_pins: + pin = named_pin.pin() + if pin.is_board_pin(): + pin.set_board_index(num_cpu_pins) + num_cpu_pins += 1 + print("") + print(prefix_content) + print("const uint8_t machine_pin_num_of_cpu_pins = {:d};".format(num_cpu_pins)) + print("") + print("const machine_pin_obj_t machine_pin_obj[{:d}] = {{".format(num_cpu_pins)) + for named_pin in self.cpu_pins: + pin = named_pin.pin() + if pin.is_board_pin(): + pin.print_const_table_entry() + print("};") + + # ToDo: Complete for alternate functions + def parse_af_file(self): + with open("./pins_af.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 print_named(self, label, named_pins): + print( + "STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label) + ) + num_cpu_pins = 0 + for named_pin in named_pins: + pin = named_pin.pin() + if pin.is_board_pin(): + print( + " {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_PTR(&machine_pin_obj[{:d}]) }},".format( + named_pin.name(), num_cpu_pins + ) + ) + num_cpu_pins += 1 + print("};") + print( + "MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);".format( + label, label + ) + ) + + def print(self): + self.print_named("cpu", self.cpu_pins) + print("") + + def print_header(self, hdr_filename): + with open(hdr_filename, "wt") as hdr_file: + for named_pin in self.cpu_pins: + pin = named_pin.pin() + if pin.is_board_pin(): + pin.print_header(hdr_file) + + def print_qstr(self, qstr_filename): + with open(qstr_filename, "wt") as qstr_file: + qstr_set = set([]) + for named_pin in self.cpu_pins: + pin = named_pin.pin() + if pin.is_board_pin(): + qstr_set |= set(pin.qstr_list()) + qstr_set |= set([named_pin.name()]) + for named_pin in self.board_pins: + qstr_set |= set([named_pin.name()]) + for qstr in sorted(qstr_set): + # cond_var = None + + # ToDO: For next iteration + """if qstr.startswith("AF"): + af_words = qstr.split("_") + cond_var = conditional_var(af_words[1]) + print_conditional_if(cond_var, file=qstr_file)""" + print("Q({})".format(qstr), file=qstr_file) + + +def main(): + parser = argparse.ArgumentParser( + prog="make-pins.py", + usage="%(prog)s [options] [command]", + description="Generate board specific pin file", + ) + + """parser.add_argument( + "-pr", + "--prefix", + dest="prefix_filename", + help="Specifies beginning portion of generated pins file", + default="psoc6_prefix.c", + )""" + + parser.add_argument( + "-q", + "--qstr", + dest="qstr_filename", + help="Specifies name of generated qstr header file", + ) + + parser.add_argument( + "-r", + "--hdr", + dest="hdr_filename", + help="Specifies name of generated pin header file", + ) + + args = parser.parse_args(sys.argv[1:]) + + pins = Pins() + + pins.parse_af_file() + + """if args.prefix_filename: + print("// --prefix {:s}".format(args.prefix_filename)) + print("") + with open(args.prefix_filename, "r") as prefix_file: + print(prefix_file.read())""" + + if args.hdr_filename and args.qstr_filename: + pins.parse_board_file() + pins.print_const_table() + pins.print() + pins.print_header(args.hdr_filename) + pins.print_qstr(args.qstr_filename) + + +if __name__ == "__main__": + main() diff --git a/ports/psoc6/modules/machine/machine_adcblock.c b/ports/psoc6/modules/machine/machine_adcblock.c index 76ece0a9f18a..b0d48adf307d 100644 --- a/ports/psoc6/modules/machine/machine_adcblock.c +++ b/ports/psoc6/modules/machine/machine_adcblock.c @@ -13,12 +13,12 @@ extern machine_adc_obj_t *adc_create_and_init_new_channel_obj(machine_adcblock_o machine_adcblock_obj_t *adc_block[MAX_BLOCKS] = {NULL}; const adc_block_channel_pin_map_t adc_block_pin_map[] = { - {ADCBLOCK0, 0, PIN_P10_0}, - {ADCBLOCK0, 1, PIN_P10_1}, - {ADCBLOCK0, 2, PIN_P10_2}, - {ADCBLOCK0, 3, PIN_P10_3}, - {ADCBLOCK0, 4, PIN_P10_4}, - {ADCBLOCK0, 5, PIN_P10_5} + {ADCBLOCK0, 0, CYHAL_GET_GPIO(CYHAL_PORT_10, 0)}, + {ADCBLOCK0, 1, CYHAL_GET_GPIO(CYHAL_PORT_10, 1)}, + {ADCBLOCK0, 2, CYHAL_GET_GPIO(CYHAL_PORT_10, 2)}, + {ADCBLOCK0, 3, CYHAL_GET_GPIO(CYHAL_PORT_10, 3)}, + {ADCBLOCK0, 4, CYHAL_GET_GPIO(CYHAL_PORT_10, 4)}, + {ADCBLOCK0, 5, CYHAL_GET_GPIO(CYHAL_PORT_10, 5)} }; // will belong to only a particular bsp /******************************************************************************/ diff --git a/ports/psoc6/modules/machine/pins.c b/ports/psoc6/modules/machine/pins.c index cedee83e2c16..a1c534c58d78 100644 --- a/ports/psoc6/modules/machine/pins.c +++ b/ports/psoc6/modules/machine/pins.c @@ -6,6 +6,15 @@ #include "pins.h" +extern const uint8_t machine_pin_num_of_cpu_pins; + +MP_DEFINE_CONST_OBJ_TYPE( + pin_cpu_pins_obj_type, + MP_QSTR_cpu, + MP_TYPE_FLAG_NONE, + locals_dict, &pin_cpu_pins_locals_dict + ); + // Function definitions // helper function to translate pin_name(string) into machine_pin_obj_t index. int pin_find(mp_obj_t pin) { @@ -17,7 +26,7 @@ int pin_find(mp_obj_t pin) { // Search by name size_t slen; const char *s = mp_obj_str_get_data(pin, &slen); - for (int i = 0; i < MP_ARRAY_SIZE(machine_pin_obj); i++) { + for (int i = 0; i < machine_pin_num_of_cpu_pins; i++) { if (slen == strlen(machine_pin_obj[i].pin_name) && strncmp(s, machine_pin_obj[i].pin_name, slen) == 0) { wanted_pin = i; break; @@ -25,7 +34,7 @@ int pin_find(mp_obj_t pin) { } } - if (!(0 <= wanted_pin && wanted_pin < MP_ARRAY_SIZE(machine_pin_obj))) { + if (!(0 <= wanted_pin && wanted_pin < machine_pin_num_of_cpu_pins)) { mp_raise_ValueError(MP_ERROR_TEXT("invalid pin: Pin not defined!")); } @@ -40,126 +49,3 @@ int pin_addr_by_name(mp_obj_t pin) { return -1; // expecting a str as input } } - - -// Pin object instantiations on the basis of selected board (chip package) -// Generated manually w.r.t cyhal_gpio_psoc6_02_124_bga_t enum for the package present in the CYPROTO-062-4343 target -// TODO: automate this generation using a python script, same as other ports. -const machine_pin_obj_t machine_pin_obj[] = { - {{&machine_pin_type}, PIN_P0_0, "P0_0"}, - {{&machine_pin_type}, PIN_P0_1, "P0_1"}, - {{&machine_pin_type}, PIN_P0_2, "P0_2"}, - {{&machine_pin_type}, PIN_P0_3, "P0_3"}, - {{&machine_pin_type}, PIN_P0_4, "P0_4"}, - {{&machine_pin_type}, PIN_P0_5, "P0_5"}, - - {{&machine_pin_type}, PIN_P1_0, "P1_0"}, - {{&machine_pin_type}, PIN_P1_1, "P1_1"}, - {{&machine_pin_type}, PIN_P1_2, "P1_2"}, - {{&machine_pin_type}, PIN_P1_3, "P1_3"}, - {{&machine_pin_type}, PIN_P1_4, "P1_4"}, - {{&machine_pin_type}, PIN_P1_5, "P1_5"}, - - {{&machine_pin_type}, PIN_P2_0, "P2_0"}, - {{&machine_pin_type}, PIN_P2_1, "P2_1"}, - {{&machine_pin_type}, PIN_P2_2, "P2_2"}, - {{&machine_pin_type}, PIN_P2_3, "P2_3"}, - {{&machine_pin_type}, PIN_P2_4, "P2_4"}, - {{&machine_pin_type}, PIN_P2_5, "P2_5"}, - {{&machine_pin_type}, PIN_P2_6, "P2_6"}, - {{&machine_pin_type}, PIN_P2_7, "P2_7"}, - - {{&machine_pin_type}, PIN_P3_0, "P3_0"}, - {{&machine_pin_type}, PIN_P3_1, "P3_1"}, - {{&machine_pin_type}, PIN_P3_2, "P3_2"}, - {{&machine_pin_type}, PIN_P3_3, "P3_3"}, - {{&machine_pin_type}, PIN_P3_4, "P3_4"}, - {{&machine_pin_type}, PIN_P3_5, "P3_5"}, - - {{&machine_pin_type}, PIN_P4_0, "P4_0"}, - {{&machine_pin_type}, PIN_P4_1, "P4_1"}, - - {{&machine_pin_type}, PIN_P5_0, "P5_0"}, - {{&machine_pin_type}, PIN_P5_1, "P5_1"}, - {{&machine_pin_type}, PIN_P5_2, "P5_2"}, - {{&machine_pin_type}, PIN_P5_3, "P5_3"}, - {{&machine_pin_type}, PIN_P5_4, "P5_4"}, - {{&machine_pin_type}, PIN_P5_5, "P5_5"}, - {{&machine_pin_type}, PIN_P5_6, "P5_6"}, - {{&machine_pin_type}, PIN_P5_7, "P5_7"}, - - {{&machine_pin_type}, PIN_P6_0, "P6_0"}, - {{&machine_pin_type}, PIN_P6_1, "P6_1"}, - {{&machine_pin_type}, PIN_P6_2, "P6_2"}, - {{&machine_pin_type}, PIN_P6_3, "P6_3"}, - {{&machine_pin_type}, PIN_P6_4, "P6_4"}, - {{&machine_pin_type}, PIN_P6_5, "P6_5"}, - {{&machine_pin_type}, PIN_P6_6, "P6_6"}, - {{&machine_pin_type}, PIN_P6_7, "P6_7"}, - - {{&machine_pin_type}, PIN_P7_0, "P7_0"}, - {{&machine_pin_type}, PIN_P7_1, "P7_1"}, - {{&machine_pin_type}, PIN_P7_2, "P7_2"}, - {{&machine_pin_type}, PIN_P7_3, "P7_3"}, - {{&machine_pin_type}, PIN_P7_4, "P7_4"}, - {{&machine_pin_type}, PIN_P7_5, "P7_5"}, - {{&machine_pin_type}, PIN_P7_6, "P7_6"}, - {{&machine_pin_type}, PIN_P7_7, "P7_7"}, - - {{&machine_pin_type}, PIN_P8_0, "P8_0"}, - {{&machine_pin_type}, PIN_P8_1, "P8_1"}, - {{&machine_pin_type}, PIN_P8_2, "P8_2"}, - {{&machine_pin_type}, PIN_P8_3, "P8_3"}, - {{&machine_pin_type}, PIN_P8_4, "P8_4"}, - {{&machine_pin_type}, PIN_P8_5, "P8_5"}, - {{&machine_pin_type}, PIN_P8_6, "P8_6"}, - {{&machine_pin_type}, PIN_P8_7, "P8_7"}, - - {{&machine_pin_type}, PIN_P9_0, "P9_0"}, - {{&machine_pin_type}, PIN_P9_1, "P9_1"}, - {{&machine_pin_type}, PIN_P9_2, "P9_2"}, - {{&machine_pin_type}, PIN_P9_3, "P9_3"}, - {{&machine_pin_type}, PIN_P9_4, "P9_4"}, - {{&machine_pin_type}, PIN_P9_5, "P9_5"}, - {{&machine_pin_type}, PIN_P9_6, "P9_6"}, - {{&machine_pin_type}, PIN_P9_7, "P9_7"}, - - {{&machine_pin_type}, PIN_P10_0, "P10_0"}, - {{&machine_pin_type}, PIN_P10_1, "P10_1"}, - {{&machine_pin_type}, PIN_P10_2, "P10_2"}, - {{&machine_pin_type}, PIN_P10_3, "P10_3"}, - {{&machine_pin_type}, PIN_P10_4, "P10_4"}, - {{&machine_pin_type}, PIN_P10_5, "P10_5"}, - {{&machine_pin_type}, PIN_P10_6, "P10_6"}, - {{&machine_pin_type}, PIN_P10_7, "P10_7"}, - - {{&machine_pin_type}, PIN_P11_0, "P11_0"}, - {{&machine_pin_type}, PIN_P11_1, "P11_1"}, - {{&machine_pin_type}, PIN_P11_2, "P11_2"}, - {{&machine_pin_type}, PIN_P11_3, "P11_3"}, - {{&machine_pin_type}, PIN_P11_4, "P11_4"}, - {{&machine_pin_type}, PIN_P11_5, "P11_5"}, - {{&machine_pin_type}, PIN_P11_6, "P11_6"}, - {{&machine_pin_type}, PIN_P11_7, "P11_7"}, - - {{&machine_pin_type}, PIN_P12_0, "P12_0"}, - {{&machine_pin_type}, PIN_P12_1, "P12_1"}, - {{&machine_pin_type}, PIN_P12_2, "P12_2"}, - {{&machine_pin_type}, PIN_P12_3, "P12_3"}, - {{&machine_pin_type}, PIN_P12_4, "P12_4"}, - {{&machine_pin_type}, PIN_P12_5, "P12_5"}, - {{&machine_pin_type}, PIN_P12_6, "P12_6"}, - {{&machine_pin_type}, PIN_P12_7, "P12_7"}, - - {{&machine_pin_type}, PIN_P13_0, "P13_0"}, - {{&machine_pin_type}, PIN_P13_1, "P13_1"}, - {{&machine_pin_type}, PIN_P13_2, "P13_2"}, - {{&machine_pin_type}, PIN_P13_3, "P13_3"}, - {{&machine_pin_type}, PIN_P13_4, "P13_4"}, - {{&machine_pin_type}, PIN_P13_5, "P13_5"}, - {{&machine_pin_type}, PIN_P13_6, "P13_6"}, - {{&machine_pin_type}, PIN_P13_7, "P13_7"}, - - {{&machine_pin_type}, PIN_USBDP, "USBDP"}, - {{&machine_pin_type}, PIN_USBDM, "USBDM"}, -}; diff --git a/ports/psoc6/modules/machine/pins.h b/ports/psoc6/modules/machine/pins.h index 1367a325872e..f9d91d65287e 100644 --- a/ports/psoc6/modules/machine/pins.h +++ b/ports/psoc6/modules/machine/pins.h @@ -9,130 +9,6 @@ // cy includes #include "cyhal.h" - -// mpy include - - -/* Include Pin definitions to make it visible at py side*/ -// Generated manually w.r.t cyhal_gpio_psoc6_02_124_bga_t enum for the package present in the CYPROTO-062-4343 target -// TODO: automate this generation using a python script, same as other ports. -#define PIN_P0_0 CYHAL_GET_GPIO(CYHAL_PORT_0, 0)// !< Port 0 Pin 0 -#define PIN_P0_1 CYHAL_GET_GPIO(CYHAL_PORT_0, 1)// !< Port 0 Pin 1 -#define PIN_P0_2 CYHAL_GET_GPIO(CYHAL_PORT_0, 2)// !< Port 0 Pin 2 -#define PIN_P0_3 CYHAL_GET_GPIO(CYHAL_PORT_0, 3)// !< Port 0 Pin 3 -#define PIN_P0_4 CYHAL_GET_GPIO(CYHAL_PORT_0, 4)// !< Port 0 Pin 4 -#define PIN_P0_5 CYHAL_GET_GPIO(CYHAL_PORT_0, 5)// !< Port 0 Pin 5 - -#define PIN_P1_0 CYHAL_GET_GPIO(CYHAL_PORT_1, 0)// !< Port 1 Pin 0 -#define PIN_P1_1 CYHAL_GET_GPIO(CYHAL_PORT_1, 1)// !< Port 1 Pin 1 -#define PIN_P1_2 CYHAL_GET_GPIO(CYHAL_PORT_1, 2)// !< Port 1 Pin 2 -#define PIN_P1_3 CYHAL_GET_GPIO(CYHAL_PORT_1, 3)// !< Port 1 Pin 3 -#define PIN_P1_4 CYHAL_GET_GPIO(CYHAL_PORT_1, 4)// !< Port 1 Pin 4 -#define PIN_P1_5 CYHAL_GET_GPIO(CYHAL_PORT_1, 5)// !< Port 1 Pin 5 - -#define PIN_P2_0 CYHAL_GET_GPIO(CYHAL_PORT_2, 0)// !< Port 2 Pin 0 -#define PIN_P2_1 CYHAL_GET_GPIO(CYHAL_PORT_2, 1)// !< Port 2 Pin 1 -#define PIN_P2_2 CYHAL_GET_GPIO(CYHAL_PORT_2, 2)// !< Port 2 Pin 2 -#define PIN_P2_3 CYHAL_GET_GPIO(CYHAL_PORT_2, 3)// !< Port 2 Pin 3 -#define PIN_P2_4 CYHAL_GET_GPIO(CYHAL_PORT_2, 4)// !< Port 2 Pin 4 -#define PIN_P2_5 CYHAL_GET_GPIO(CYHAL_PORT_2, 5)// !< Port 2 Pin 5 -#define PIN_P2_6 CYHAL_GET_GPIO(CYHAL_PORT_2, 6)// !< Port 2 Pin 6 -#define PIN_P2_7 CYHAL_GET_GPIO(CYHAL_PORT_2, 7)// !< Port 2 Pin 7 - -#define PIN_P3_0 CYHAL_GET_GPIO(CYHAL_PORT_3, 0)// !< Port 3 Pin 0 -#define PIN_P3_1 CYHAL_GET_GPIO(CYHAL_PORT_3, 1)// !< Port 3 Pin 1 -#define PIN_P3_2 CYHAL_GET_GPIO(CYHAL_PORT_3, 2)// !< Port 3 Pin 2 -#define PIN_P3_3 CYHAL_GET_GPIO(CYHAL_PORT_3, 3)// !< Port 3 Pin 3 -#define PIN_P3_4 CYHAL_GET_GPIO(CYHAL_PORT_3, 4)// !< Port 3 Pin 4 -#define PIN_P3_5 CYHAL_GET_GPIO(CYHAL_PORT_3, 5)// !< Port 3 Pin 5 - -#define PIN_P4_0 CYHAL_GET_GPIO(CYHAL_PORT_4, 0)// !< Port 4 Pin 0 -#define PIN_P4_1 CYHAL_GET_GPIO(CYHAL_PORT_4, 1)// !< Port 4 Pin 1 - -#define PIN_P5_0 CYHAL_GET_GPIO(CYHAL_PORT_5, 0)// !< Port 5 Pin 0 -#define PIN_P5_1 CYHAL_GET_GPIO(CYHAL_PORT_5, 1)// !< Port 5 Pin 1 -#define PIN_P5_2 CYHAL_GET_GPIO(CYHAL_PORT_5, 2)// !< Port 5 Pin 2 -#define PIN_P5_3 CYHAL_GET_GPIO(CYHAL_PORT_5, 3)// !< Port 5 Pin 3 -#define PIN_P5_4 CYHAL_GET_GPIO(CYHAL_PORT_5, 4)// !< Port 5 Pin 4 -#define PIN_P5_5 CYHAL_GET_GPIO(CYHAL_PORT_5, 5)// !< Port 5 Pin 5 -#define PIN_P5_6 CYHAL_GET_GPIO(CYHAL_PORT_5, 6)// !< Port 5 Pin 6 -#define PIN_P5_7 CYHAL_GET_GPIO(CYHAL_PORT_5, 7)// !< Port 5 Pin 7 - -#define PIN_P6_0 CYHAL_GET_GPIO(CYHAL_PORT_6, 0)// !< Port 6 Pin 0 -#define PIN_P6_1 CYHAL_GET_GPIO(CYHAL_PORT_6, 1)// !< Port 6 Pin 1 -#define PIN_P6_2 CYHAL_GET_GPIO(CYHAL_PORT_6, 2)// !< Port 6 Pin 2 -#define PIN_P6_3 CYHAL_GET_GPIO(CYHAL_PORT_6, 3)// !< Port 6 Pin 3 -#define PIN_P6_4 CYHAL_GET_GPIO(CYHAL_PORT_6, 4)// !< Port 6 Pin 4 -#define PIN_P6_5 CYHAL_GET_GPIO(CYHAL_PORT_6, 5)// !< Port 6 Pin 5 -#define PIN_P6_6 CYHAL_GET_GPIO(CYHAL_PORT_6, 6)// !< Port 6 Pin 6 -#define PIN_P6_7 CYHAL_GET_GPIO(CYHAL_PORT_6, 7)// !< Port 6 Pin 7 - -#define PIN_P7_0 CYHAL_GET_GPIO(CYHAL_PORT_7, 0)// !< Port 7 Pin 0 -#define PIN_P7_1 CYHAL_GET_GPIO(CYHAL_PORT_7, 1)// !< Port 7 Pin 1 -#define PIN_P7_2 CYHAL_GET_GPIO(CYHAL_PORT_7, 2)// !< Port 7 Pin 2 -#define PIN_P7_3 CYHAL_GET_GPIO(CYHAL_PORT_7, 3)// !< Port 7 Pin 3 -#define PIN_P7_4 CYHAL_GET_GPIO(CYHAL_PORT_7, 4)// !< Port 7 Pin 4 -#define PIN_P7_5 CYHAL_GET_GPIO(CYHAL_PORT_7, 5)// !< Port 7 Pin 5 -#define PIN_P7_6 CYHAL_GET_GPIO(CYHAL_PORT_7, 6)// !< Port 7 Pin 6 -#define PIN_P7_7 CYHAL_GET_GPIO(CYHAL_PORT_7, 7)// !< Port 7 Pin 7 - -#define PIN_P8_0 CYHAL_GET_GPIO(CYHAL_PORT_8, 0)// !< Port 8 Pin 0 -#define PIN_P8_1 CYHAL_GET_GPIO(CYHAL_PORT_8, 1)// !< Port 8 Pin 1 -#define PIN_P8_2 CYHAL_GET_GPIO(CYHAL_PORT_8, 2)// !< Port 8 Pin 2 -#define PIN_P8_3 CYHAL_GET_GPIO(CYHAL_PORT_8, 3)// !< Port 8 Pin 3 -#define PIN_P8_4 CYHAL_GET_GPIO(CYHAL_PORT_8, 4)// !< Port 8 Pin 4 -#define PIN_P8_5 CYHAL_GET_GPIO(CYHAL_PORT_8, 5)// !< Port 8 Pin 5 -#define PIN_P8_6 CYHAL_GET_GPIO(CYHAL_PORT_8, 6)// !< Port 8 Pin 6 -#define PIN_P8_7 CYHAL_GET_GPIO(CYHAL_PORT_8, 7)// !< Port 8 Pin 7 - -#define PIN_P9_0 CYHAL_GET_GPIO(CYHAL_PORT_9, 0)// !< Port 9 Pin 0 -#define PIN_P9_1 CYHAL_GET_GPIO(CYHAL_PORT_9, 1)// !< Port 9 Pin 1 -#define PIN_P9_2 CYHAL_GET_GPIO(CYHAL_PORT_9, 2)// !< Port 9 Pin 2 -#define PIN_P9_3 CYHAL_GET_GPIO(CYHAL_PORT_9, 3)// !< Port 9 Pin 3 -#define PIN_P9_4 CYHAL_GET_GPIO(CYHAL_PORT_9, 4)// !< Port 9 Pin 4 -#define PIN_P9_5 CYHAL_GET_GPIO(CYHAL_PORT_9, 5)// !< Port 9 Pin 5 -#define PIN_P9_6 CYHAL_GET_GPIO(CYHAL_PORT_9, 6)// !< Port 9 Pin 6 -#define PIN_P9_7 CYHAL_GET_GPIO(CYHAL_PORT_9, 7)// !< Port 9 Pin 7 - -#define PIN_P10_0 CYHAL_GET_GPIO(CYHAL_PORT_10, 0)// !< Port 10 Pin 0 -#define PIN_P10_1 CYHAL_GET_GPIO(CYHAL_PORT_10, 1)// !< Port 10 Pin 1 -#define PIN_P10_2 CYHAL_GET_GPIO(CYHAL_PORT_10, 2)// !< Port 10 Pin 2 -#define PIN_P10_3 CYHAL_GET_GPIO(CYHAL_PORT_10, 3)// !< Port 10 Pin 3 -#define PIN_P10_4 CYHAL_GET_GPIO(CYHAL_PORT_10, 4)// !< Port 10 Pin 4 -#define PIN_P10_5 CYHAL_GET_GPIO(CYHAL_PORT_10, 5)// !< Port 10 Pin 5 -#define PIN_P10_6 CYHAL_GET_GPIO(CYHAL_PORT_10, 6)// !< Port 10 Pin 6 -#define PIN_P10_7 CYHAL_GET_GPIO(CYHAL_PORT_10, 7)// !< Port 10 Pin 7 - -#define PIN_P11_0 CYHAL_GET_GPIO(CYHAL_PORT_11, 0)// !< Port 11 Pin 0 -#define PIN_P11_1 CYHAL_GET_GPIO(CYHAL_PORT_11, 1)// !< Port 11 Pin 1 -#define PIN_P11_2 CYHAL_GET_GPIO(CYHAL_PORT_11, 2)// !< Port 11 Pin 2 -#define PIN_P11_3 CYHAL_GET_GPIO(CYHAL_PORT_11, 3)// !< Port 11 Pin 3 -#define PIN_P11_4 CYHAL_GET_GPIO(CYHAL_PORT_11, 4)// !< Port 11 Pin 4 -#define PIN_P11_5 CYHAL_GET_GPIO(CYHAL_PORT_11, 5)// !< Port 11 Pin 5 -#define PIN_P11_6 CYHAL_GET_GPIO(CYHAL_PORT_11, 6)// !< Port 11 Pin 6 -#define PIN_P11_7 CYHAL_GET_GPIO(CYHAL_PORT_11, 7)// !< Port 11 Pin 7 - -#define PIN_P12_0 CYHAL_GET_GPIO(CYHAL_PORT_12, 0)// !< Port 12 Pin 0 -#define PIN_P12_1 CYHAL_GET_GPIO(CYHAL_PORT_12, 1)// !< Port 12 Pin 1 -#define PIN_P12_2 CYHAL_GET_GPIO(CYHAL_PORT_12, 2)// !< Port 12 Pin 2 -#define PIN_P12_3 CYHAL_GET_GPIO(CYHAL_PORT_12, 3)// !< Port 12 Pin 3 -#define PIN_P12_4 CYHAL_GET_GPIO(CYHAL_PORT_12, 4)// !< Port 12 Pin 4 -#define PIN_P12_5 CYHAL_GET_GPIO(CYHAL_PORT_12, 5)// !< Port 12 Pin 5 -#define PIN_P12_6 CYHAL_GET_GPIO(CYHAL_PORT_12, 6)// !< Port 12 Pin 6 -#define PIN_P12_7 CYHAL_GET_GPIO(CYHAL_PORT_12, 7)// !< Port 12 Pin 7 - -#define PIN_P13_0 CYHAL_GET_GPIO(CYHAL_PORT_13, 0)// !< Port 13 Pin 0 -#define PIN_P13_1 CYHAL_GET_GPIO(CYHAL_PORT_13, 1)// !< Port 13 Pin 1 -#define PIN_P13_2 CYHAL_GET_GPIO(CYHAL_PORT_13, 2)// !< Port 13 Pin 2 -#define PIN_P13_3 CYHAL_GET_GPIO(CYHAL_PORT_13, 3)// !< Port 13 Pin 3 -#define PIN_P13_4 CYHAL_GET_GPIO(CYHAL_PORT_13, 4)// !< Port 13 Pin 4 -#define PIN_P13_5 CYHAL_GET_GPIO(CYHAL_PORT_13, 5)// !< Port 13 Pin 5 -#define PIN_P13_6 CYHAL_GET_GPIO(CYHAL_PORT_13, 6)// !< Port 13 Pin 6 -#define PIN_P13_7 CYHAL_GET_GPIO(CYHAL_PORT_13, 7)// !< Port 13 Pin 7 - -#define PIN_USBDP CYHAL_GET_GPIO(CYHAL_PORT_14, 0)// !< Port 14 Pin 0 -#define PIN_USBDM CYHAL_GET_GPIO(CYHAL_PORT_14, 1)// !< Port 14 Pin 1 - // Add all machine pin objects - GPIO , I2C, ADC etc. typedef struct _machine_pin_obj_t { mp_obj_base_t base; @@ -140,15 +16,20 @@ typedef struct _machine_pin_obj_t { char *pin_name; } machine_pin_obj_t; +#include "genhdr/pins.h" + // Function Prototypes to support interaction between c<->py int pin_find(mp_obj_t obj); int pin_addr_by_name(mp_obj_t obj); +extern const mp_obj_type_t pin_cpu_pins_obj_type; +extern const mp_obj_dict_t pin_cpu_pins_locals_dict; + /* TODO: to auto-generate the pin instances in the pin_obj array and thereby capture the obj count. It cannot be declared without a defined size, since there are sizeof() and other functions in machine_pin which act on this array and need a deterministic size of the array to compile. */ -extern const machine_pin_obj_t machine_pin_obj[102]; +extern const machine_pin_obj_t machine_pin_obj[]; #endif // MICROPY_INCLUDED_PSOC6_PINS_H