Skip to content

Update kinetis pinctrl script for pin mask #582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions mcux/scripts/pinctrl/kinetis/kinetis_cfg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(self, connection, port_type):
self._port = match.group(1)
self._pin = int(match.group(2))
self._mux = int(val, 16)
self._mask = assign.attrib.get('bit_field_mask')
if self._port is None:
# Not a valid port mapping. Clear name
self._name = ''
Expand Down Expand Up @@ -569,21 +570,27 @@ def write_pinctrl_defs(self, outputfile):
# don't conflict with pin configuration settings
# Store the mux value at the offset it will actually be written to the
# configuration register
pin_list = list(self._pins.values())
if n9x_mode:
mux_macro = ("#define N9X_MUX(port, pin, mux)\t\t\\\n"
"\t(((((port) - '0') & 0xF) << 28) |\t\\\n"
"\t(((pin) & 0x3F) << 22) |\t\t\\\n"
"\t(((mux) & 0xF) << 8))\n\n")
"\t(((((port) - '0') & 0xF) << 28) |\t\\\n")
elif a15x_mode:
mux_macro = ("#define A15X_MUX(port, pin, mux)\t\t\\\n"
"\t(((((port) - '0') & 0xF) << 28) |\t\\\n"
"\t(((pin) & 0x3F) << 22) |\t\t\\\n"
"\t(((mux) & 0xF) << 8))\n\n")
"\t(((((port) - '0') & 0xF) << 28) |\t\\\n")
else:
mux_macro = ("#define KINETIS_MUX(port, pin, mux)\t\t\\\n"
"\t(((((port) - 'A') & 0xF) << 28) |\t\\\n"
"\t(((pin) & 0x3F) << 22) |\t\t\\\n"
"\t(((mux) & 0x7) << 8))\n\n")
"\t(((((port) - 'A') & 0xF) << 28) |\t\\\n")
mux_macro += "\t(((pin) & 0x3F) << 22) |\t\t\\\n"


# BitShift pin mask from 0x#00 to 0x# and add it to the macro
pin_mux_opt = pin_list[0]._mux_options
pin_mux_opt_name = list(pin_mux_opt)[0]
macro_mask = pin_mux_opt[pin_mux_opt_name]._mask
macro_mask_after_bitshift = f"0x{int(macro_mask, 0) >> 8:X}"

mux_macro += "\t(((mux) & " + str(macro_mask_after_bitshift) + ") << 8))\n\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to force to str() here, the f-string above will already do that


with open(outputfile, "w", encoding="utf8") as file:
file.write(file_header)
# ifdef guard
Expand Down