Skip to content

Commit 967e5ab

Browse files
danieldegrassedecsny
authored andcommitted
mcux: scripts: pinctrl: update comment syntax
Update code from writing descriptions given in pin control groups to handle multiline descriptions as block comments. Also, update comment code to write name of generation script correctly- since pin control scripts are all called from gen_board_pinctrl.py Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
1 parent cfa6aad commit 967e5ab

File tree

3 files changed

+50
-18
lines changed

3 files changed

+50
-18
lines changed

mcux/scripts/pinctrl/imx/imx_cfg_utils.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
import pathlib
1313
import logging
14+
import __main__
1415

1516
# MEX file has a default namespace, map it here
1617
NAMESPACES = {'mex' : 'http://mcuxpresso.nxp.com/XSD/mex_configuration_14'}
@@ -586,7 +587,8 @@ def __init__(self, function, signal_map, rt):
586587
description = function.find('mex:description', NAMESPACES)
587588
pins = function.find('mex:pins', NAMESPACES)
588589
if description is not None and description.text is not None:
589-
self._description = description.text
590+
# Replace <br> html tag with newline
591+
self._description = description.text.replace("&lt;br/&gt;", "\n")
590592
else:
591593
self._description = ""
592594
# Build dictionary mapping pin properties to pins. This allows us to
@@ -752,8 +754,12 @@ def _props_to_dts(self, props, defaults):
752754
zephyr_props = []
753755
prop_mapping = {
754756
'MHZ_50': '50-mhz',
757+
'MHZ_100_01': '100-mhz',
758+
# On some iMX RT10xx SOCs, 150 MHz is mapped to this value. However,
759+
# this is not consistent for all iMX RT10xx supported by
760+
# config tools. Therefore, we just force both MHZ_100_01 and
761+
# MHZ_100 to 100-mhz.
755762
'MHZ_100': '100-mhz',
756-
'MHZ_150': '150-mhz',
757763
'MHZ_200': '200-mhz',
758764
'R0': 'r0',
759765
'R0_2': 'r0-2',
@@ -922,7 +928,7 @@ def write_gpio_mux(self, outputfile):
922928
with open(outputfile, "w", encoding='utf8') as gpio_dsti:
923929
# Write header
924930
gpio_dsti.write(f"/*\n"
925-
f" * File created by {os.path.basename(__file__)}\n"
931+
f" * File created by {os.path.basename(__main__.__file__)}\n"
926932
" * not intended for direct usage. Hand edit these DTS\n"
927933
" * nodes as needed to integrate them into Zephyr.\n"
928934
" */\n\n")
@@ -996,7 +1002,7 @@ def write_pinctrl_defs(self, outputfile):
9961002
header = (f"/*\n"
9971003
f" * {self._copyright}\n"
9981004
f" *\n"
999-
f" * Note: File generated by {os.path.basename(__file__)}\n"
1005+
f" * Note: File generated by {os.path.basename(__main__.__file__)}\n"
10001006
f" * from configuration data for {self._soc_sku}\n"
10011007
" */\n\n")
10021008
soc_dtsi.write(header)
@@ -1058,7 +1064,7 @@ def write_pinctrl_groups(self, mexfile, outputfile):
10581064
header = (f"/*\n"
10591065
f" * {self._copyright}\n"
10601066
f" *\n"
1061-
f" * Note: File generated by {os.path.basename(__file__)}\n"
1067+
f" * Note: File generated by {os.path.basename(__main__.__file__)}\n"
10621068
f" * from {os.path.basename(mexfile)}\n"
10631069
" */\n\n")
10641070
with open(outputfile, "w", encoding="utf8") as dts_file:
@@ -1070,12 +1076,19 @@ def write_pinctrl_groups(self, mexfile, outputfile):
10701076
dts_file.write("#include <nxp/nxp_imx/"
10711077
f"{self.get_part_num().lower()}-pinctrl.dtsi>\n\n")
10721078
dts_file.write("&pinctrl {\n")
1073-
for pin_group in sorted(pin_groups.values()):
1079+
for pin_group in pin_groups.values():
10741080
pin_props = pin_group.get_pin_props()
10751081
description = pin_group.get_description()
10761082
# if a description is present, write it
10771083
if description != "":
1078-
dts_file.write(f"\t/* {description} */\n")
1084+
description_lines = description.split("\n")
1085+
if len(description_lines) == 1:
1086+
dts_file.write(f"\t/* {description} */\n")
1087+
else:
1088+
dts_file.write("\t/*\n")
1089+
for line in description_lines:
1090+
dts_file.write(f"\t * {line}\n")
1091+
dts_file.write("\t */\n")
10791092
# Write pin group name
10801093
name = pin_group.get_name().lower()
10811094
dts_file.write(f"\t{name}: {name} {{\n")

mcux/scripts/pinctrl/kinetis/kinetis_cfg_utils.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import collections
1515
import logging
1616
import pathlib
17+
import __main__
1718

1819
# layout/index of pins tuple
1920
PIN = collections.namedtuple('PIN', ['PERIPH', 'NAME_PART', 'SIGNAL', 'PORT',
@@ -290,7 +291,8 @@ def __init__(self, function, signal_map):
290291
pins = function.find('mex:pins', NAMESPACES)
291292
description = function.find('mex:description', NAMESPACES)
292293
if description is not None and description.text is not None:
293-
self._description = description.text
294+
# Replace <br> html tag with newline
295+
self._description = description.text.replace("&lt;br/&gt;", "\n")
294296
else:
295297
self._description = ""
296298
# Build dictionary mapping pin properties to pins. This allows us to
@@ -511,7 +513,7 @@ def write_pinctrl_defs(self, outputfile):
511513
pinmux_opts.extend(pin.get_mux_options())
512514
pcr_pins = list(filter(lambda p: (p.get_periph() not in ["FB", "EZPORT"]), pinmux_opts))
513515
file_header = ("/*\n"
514-
f" * NOTE: Autogenerated file by {os.path.basename(__file__)}\n"
516+
f" * NOTE: Autogenerated file by {os.path.basename(__main__.__file__)}\n"
515517
f" * for {self._part_num}/signal_configuration.xml\n"
516518
" *\n"
517519
f" * {self._copyright}\n"
@@ -571,7 +573,7 @@ def write_pinctrl_groups(self, mexfile, outputfile):
571573
@param outputfile: DTS pinctrl file to write pin groups to
572574
"""
573575
file_header = ("/*\n"
574-
f" * NOTE: Autogenerated file by {os.path.basename(__file__)}\n"
576+
f" * NOTE: Autogenerated file by {os.path.basename(__main__.__file__)}\n"
575577
f" * for {self._part_num}/signal_configuration.xml\n"
576578
" *\n"
577579
f" * {self._copyright}\n"
@@ -583,15 +585,23 @@ def write_pinctrl_groups(self, mexfile, outputfile):
583585
file.write(f"\n#include <nxp/kinetis/{get_package_name(mexfile)}-pinctrl.h>\n\n")
584586
file.write("&pinctrl {\n")
585587
# Write pin groups back out to disk
586-
for group in sorted(pin_groups.values()):
588+
for group in pin_groups.values():
587589
pin_props = group.get_pin_props()
588590
if len(pin_props) == 0:
589591
# Do not write to disk
590592
continue
591593
logging.info("Writing pin group %s to disk", group.get_name())
592594
# Write description as comment if group has one
593-
if group.get_description() != "":
594-
file.write(f"\t/* {group.get_description()} */\n")
595+
description = group.get_description()
596+
if description != "":
597+
description_lines = description.split("\n")
598+
if len(description_lines) == 1:
599+
file.write(f"\t/* {description} */\n")
600+
else:
601+
file.write("\t/*\n")
602+
for line in description_lines:
603+
file.write(f"\t * {line}\n")
604+
file.write("\t */\n")
595605
file.write(f"\t{group.get_name().lower()}: {group.get_name().lower()} {{\n")
596606
idx = 0
597607
for pin_prop in sorted(pin_props):

mcux/scripts/pinctrl/lpc/lpc_cfg_utils.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import logging
1616
import os
1717
import pathlib
18+
import __main__
1819

1920
NAMESPACES = {'mex': 'http://mcuxpresso.nxp.com/XSD/mex_configuration_14'}
2021

@@ -362,7 +363,8 @@ def __init__(self, function, signal_map, imx_rt = False):
362363
pins = function.find('mex:pins', NAMESPACES)
363364
description = function.find('mex:description', NAMESPACES)
364365
if description is not None and description.text is not None:
365-
self._description = description.text
366+
# Replace <br> html tag with newline
367+
self._description = description.text.replace("&lt;br/&gt;", "\n")
366368
else:
367369
self._description = ""
368370
# Build dictionary mapping pin properties to pins. This allows us to
@@ -633,7 +635,7 @@ def write_pinctrl_defs(self, outputfile):
633635
@param outputfile: file to write output pinctrl defs to
634636
"""
635637
file_header = ("/*\n"
636-
f" * NOTE: File generated by {os.path.basename(__file__)}\n"
638+
f" * NOTE: File generated by {os.path.basename(__main__.__file__)}\n"
637639
f" * from {self._part_num}/signal_configuration.xml\n"
638640
" *\n"
639641
f" * {self._copyright}\n"
@@ -732,7 +734,7 @@ def write_pinctrl_groups(self, mexfile, outputfile):
732734
"""
733735

734736
file_header = ("/*\n"
735-
f" * NOTE: File generated by {os.path.basename(__file__)}\n"
737+
f" * NOTE: File generated by {os.path.basename(__main__.__file__)}\n"
736738
f" * from {os.path.basename(mexfile)}\n"
737739
" *\n"
738740
f" * {self._copyright}\n"
@@ -747,12 +749,19 @@ def write_pinctrl_groups(self, mexfile, outputfile):
747749
file.write(f"\n#include <nxp/lpc/{get_package_name(mexfile)}-pinctrl.h>\n\n")
748750
file.write("&pinctrl {\n")
749751
# Write pin groups back out to disk
750-
for group in sorted(pin_groups.values()):
752+
for group in pin_groups.values():
751753
pin_props = group.get_pin_props()
752754
description = group.get_description()
753755
# if a description is present, write it
754756
if description != "":
755-
file.write(f"\t/* {description} */\n")
757+
description_lines = description.split("\n")
758+
if len(description_lines) == 1:
759+
file.write(f"\t/* {description} */\n")
760+
else:
761+
file.write("\t/*\n")
762+
for line in description_lines:
763+
file.write(f"\t * {line}\n")
764+
file.write("\t */\n")
756765
logging.info("Writing pin group %s to disk", group.get_name())
757766
file.write(f"\t{group.get_name().lower()}: {group.get_name().lower()} {{\n")
758767
idx = 0

0 commit comments

Comments
 (0)