Skip to content

Commit

Permalink
ports/psoc6: Automatic generation of pins.csv and fixing codeformatting.
Browse files Browse the repository at this point in the history
Signed-off-by: NikhitaR-IFX <Nikhita.Rajasekhar@infineon.com>
  • Loading branch information
NikhitaR-IFX committed Sep 1, 2023
1 parent 9c4aef0 commit 07ea3cb
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 175 deletions.
17 changes: 12 additions & 5 deletions ports/psoc6/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ $(MPY_MAIN_BUILD_DIR)/firmware.elf: $(OBJ) $(MPY_MTB_LIBRARIES) $(LIBS)
$(MPY_MAIN_BUILD_DIR)/firmware.hex: $(MPY_MAIN_BUILD_DIR)/firmware.elf
$(Q) $(OBJCOPY) -O ihex $^ $@

MAKE_PINS = boards/make-pins.py
BOARD_PINS = $(BOARD_DIR)/pins.csv
PREFIX_FILE = boards/ra_pin_prefix.c

# include adapter makefile
include mtb-libs/makefile_mtb.mk

Expand All @@ -204,7 +200,7 @@ 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 $(MPY_PATH_TO_MAIN_MAKEFILE) $(MPY_MAIN_BUILD_DIR)/firmware.hex make_pins

all: build

Expand Down Expand Up @@ -232,6 +228,17 @@ test_multi:

$(Q) cd ../../tests ; ./run-multitests.py -i pyb:$(DEV0) -i pyb:$(DEV1) $(MULTI_TESTS)

# MTB pin packages path
export MTB_PIN_PACKAGES_PATH = ./mtb_shared/mtb-hal-cat1/release-v2.4.1/COMPONENT_CAT1A/include/pin_packages/
export PINS_CSV_PATH = $(BOARD_DIR)/
MAKE_PINS = boards/make-pins.py

make_pins:
$(info )
$(info Executing make-pins.py to generate pin structure automatically)
$(Q)$(PYTHON) $(MAKE_PINS) --gen-pin-for cyhal_psoc6_02_124_bga.h --save-pins-csv-at pins.csv


help:
@:
$(info )
Expand Down
105 changes: 105 additions & 0 deletions ports/psoc6/boards/CY8CPROTO-062-4343W/pins.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
NC,NC
P0_0,P0_0
P0_1,P0_1
P0_2,P0_2
P0_3,P0_3
P0_4,P0_4
P0_5,P0_5
P1_0,P1_0
P1_1,P1_1
P1_2,P1_2
P1_3,P1_3
P1_4,P1_4
P1_5,P1_5
P2_0,P2_0
P2_1,P2_1
P2_2,P2_2
P2_3,P2_3
P2_4,P2_4
P2_5,P2_5
P2_6,P2_6
P2_7,P2_7
P3_0,P3_0
P3_1,P3_1
P3_2,P3_2
P3_3,P3_3
P3_4,P3_4
P3_5,P3_5
P4_0,P4_0
P4_1,P4_1
P5_0,P5_0
P5_1,P5_1
P5_2,P5_2
P5_3,P5_3
P5_4,P5_4
P5_5,P5_5
P5_6,P5_6
P5_7,P5_7
P6_0,P6_0
P6_1,P6_1
P6_2,P6_2
P6_3,P6_3
P6_4,P6_4
P6_5,P6_5
P6_6,P6_6
P6_7,P6_7
P7_0,P7_0
P7_1,P7_1
P7_2,P7_2
P7_3,P7_3
P7_4,P7_4
P7_5,P7_5
P7_6,P7_6
P7_7,P7_7
P8_0,P8_0
P8_1,P8_1
P8_2,P8_2
P8_3,P8_3
P8_4,P8_4
P8_5,P8_5
P8_6,P8_6
P8_7,P8_7
P9_0,P9_0
P9_1,P9_1
P9_2,P9_2
P9_3,P9_3
P9_4,P9_4
P9_5,P9_5
P9_6,P9_6
P9_7,P9_7
P10_0,P10_0
P10_1,P10_1
P10_2,P10_2
P10_3,P10_3
P10_4,P10_4
P10_5,P10_5
P10_6,P10_6
P10_7,P10_7
P11_0,P11_0
P11_1,P11_1
P11_2,P11_2
P11_3,P11_3
P11_4,P11_4
P11_5,P11_5
P11_6,P11_6
P11_7,P11_7
P12_0,P12_0
P12_1,P12_1
P12_2,P12_2
P12_3,P12_3
P12_4,P12_4
P12_5,P12_5
P12_6,P12_6
P12_7,P12_7
P13_0,P13_0
P13_1,P13_1
P13_2,P13_2
P13_3,P13_3
P13_4,P13_4
P13_5,P13_5
P13_6,P13_6
P13_7,P13_7
USBDP,USBDP
P14_0,P14_0
USBDM,USBDM
P14_1,P14_1
3 changes: 0 additions & 3 deletions ports/psoc6/boards/cy8c62xa_af.csv

This file was deleted.

72 changes: 72 additions & 0 deletions ports/psoc6/boards/make-pins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from __future__ import print_function

import argparse
import sys
import csv
import re
import os


class Pins(object):
def generate_pins_csv(self, pin_package_filename, pins_csv_filename):
# Read the header file
with open(os.environ.get("MTB_PIN_PACKAGES_PATH") + pin_package_filename, "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(
os.environ.get("PINS_CSV_PATH") + pins_csv_filename, "w", newline=""
) as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerows([[value, value] for value in enum_values])

print("pins.csv generated successfully")
else:
print("Error: pins.csv generation failed")


def main():
parser = argparse.ArgumentParser(
prog="make-pins.py",
usage="%(prog)s [options] [command]",
description="Generate board specific pin file",
)

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",
default="pins.csv",
)

args = parser.parse_args(sys.argv[1:])

pins = Pins()

if args.pin_package_filename and args.pins_csv:
print("// Generating pins csv file with following parsed arguments")
print("// - --gen-pin-for {:s}".format(args.pin_package_filename))
print("// - --save-pins-csv-at {:s}".format(args.pins_csv))
pins.generate_pins_csv(args.pin_package_filename, args.pins_csv)


if __name__ == "__main__":
main()
151 changes: 0 additions & 151 deletions ports/psoc6/boards/make_pins.py

This file was deleted.

1 change: 0 additions & 1 deletion ports/psoc6/boards/pins.csv

This file was deleted.

7 changes: 3 additions & 4 deletions ports/psoc6/boards/psoc6_prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
#include "py/mphal.h"
#include "pins.h"

#define PIN(p_name, p_pin, p_ad) \
#define PIN(p_name, pin_addr, pin_name) \
{ \
{ &machine_pin_type }, \
.name = MP_QSTR_##p_name, \
.pin = p_pin, \
.ad = p_ad, \
.pin_addr = pin_addr, \
.pin_name = pin_name, \
}
Loading

0 comments on commit 07ea3cb

Please sign in to comment.