Lines Matching +full:port +full:- +full:line +full:- +full:mapping
4 # SPDX-License-Identifier: Apache-2.0
11 nRF-based boards using the old <signal>-pin properties to select peripheral
13 file by removing old pin-related properties replacing them with pinctrl states.
14 A board-pinctrl.dtsi file will be generated containing the configuration for
19 This script uses a basic line based parser, therefore not all valid
28 -i path/to/board.dts
29 [--no-backup]
30 [--skip-nrf-check]
31 [--header ""]
35 .. code-block:: devicetree
41 tx-pin = <5>;
42 rx-pin = <33>;
43 rx-pull-up;
49 #include "board-pinctrl.dtsi"
53 pinctrl-0 = <&uart0_default>;
54 pinctrl-1 = <&uart0_sleep>;
55 pinctrl-names = "default", "sleep";
59 /* Generated board-pinctrl.dtsi */
67 bias-pull-up;
75 low-power-enable;
97 PULL_UP = "bias-pull-up"
98 PULL_DOWN = "bias-pull-down"
99 LOW_POWER = "low-power-enable"
112 ) -> None:
121 """Signal mapping (signal<>pin)"""
123 def __init__(self, signal: str, pin: int) -> None:
131 def __init__(self, pins: List[SignalMapping], config: List[PIN_CONFIG]) -> None:
137 """Pin configuration (mapping and configuration)"""
139 def __init__(self, mapping: SignalMapping, config: List[PIN_CONFIG]) -> None:
140 self.mapping = mapping
147 def __init__(self, name: str, pins: List[PinConfiguration]) -> None:
151 def add_signal_config(self, signal: str, config: PIN_CONFIG) -> None:
154 if signal == pin.mapping.signal:
158 self.pins.append(PinConfiguration(SignalMapping(signal, -1), [config]))
160 def set_signal_pin(self, signal: str, pin: int) -> None:
163 if signal == pin_.mapping.signal:
164 pin_.mapping.pin = pin
177 ) -> None:
178 """Generate board-pinctrl.dtsi file
187 pinctrl_file = input_file.parent / (input_file.stem + "-pinctrl.dtsi")
191 for i, line in enumerate(content[::-1]):
192 if re.match(r"\s*};.*", line):
193 last_line = len(content) - (i + 1)
202 for line in content[:last_line]:
203 out.write(line)
212 group.pins.append(pin.mapping)
216 default_groups.append(PinGroup([pin.mapping], pin.config))
221 group.pins.append(pin.mapping)
236 for line in content[last_line:]:
237 out.write(line)
242 def board_is_nrf(content: List[str]) -> bool:
252 for line in content:
253 m = re.match(r'^#include\s+(?:"|<).*nrf.*(?:>|").*', line)
260 def fmt_pinctrl_groups(groups: List[PinGroup]) -> str:
270 bias-pull-up;
283 for i, mapping in enumerate(group.pins):
285 suffix = ";" if i == len(group.pins) - 1 else ","
286 pin = mapping.pin
287 port = 0 if pin < 32 else 1
288 if port == 1:
289 pin -= 32
291 f"\t\t\t{prefix}<NRF_PSEL({mapping.signal}, {port}, {pin})>{suffix}\n"
294 # write all pin configuration (bias, low-power, etc.)
303 def fmt_states(device: str, indent: str, needs_sleep: bool) -> str:
318 f"{indent}pinctrl-0 = <&{device}_default>;",
319 f"{indent}pinctrl-1 = <&{device}_sleep>;",
320 f'{indent}pinctrl-names = "default", "sleep";\n',
326 f"{indent}pinctrl-0 = <&{device}_default>;",
327 f'{indent}pinctrl-names = "default";\n',
332 def insert_pinctrl_include(content: List[str], board: str) -> None:
341 include_last_line = -1
342 root_line = -1
344 for i, line in enumerate(content):
346 m = re.match(r'^#include\s+".*-pinctrl\.dtsi".*', line)
352 m = re.match(r'^#include\s+(?:"|<)(.*)(?:>|").*', line)
358 m = re.match(r"^\s*/\s*{.*", line)
368 line = include_last_line + 1
370 line = max(0, root_line - 1)
372 content.insert(line, f'#include "{board}-pinctrl.dtsi"\n')
375 def adjust_content(content: List[str], board: str) -> List[DeviceConfiguration]:
390 for line in content:
393 m = re.match(r"^[^&]*&([a-z0-9]+)\s*{[^}]*$", line)
411 if re.match(r"[^\/\*]*{.*", line):
414 elif re.match(r"[^\/\*]*}.*", line):
415 level -= 1
419 if re.match(r"[^\/\*]*pinctrl-\d+.*", line):
424 m = re.match(r"(\s+).*", line)
428 # process each device line, append states at the end
431 line = current_device.callback(config, current_device.signals, line)
433 line = (
435 + line
440 if line:
441 new_content.append(line)
457 config: DeviceConfiguration, signals: Dict[str, str], line: str
458 ) -> Optional[str]:
459 """Match and store a pin mapping.
463 signals: Signals name mapping.
464 line: Line containing potential pin mapping.
467 Line if found a pin mapping, None otherwise.
470 # handle qspi special case for io-pins (array case)
471 m = re.match(r"\s*io-pins\s*=\s*([\s<>,0-9]+).*", line)
478 m = re.match(r"\s*([a-z]+\d?)-pins?\s*=\s*<(\d+)>.*", line)
483 return line
491 def process_uart(config: DeviceConfiguration, signals, line: str) -> Optional[str]:
494 # check if line specifies a pin
495 if not match_and_store_pin(config, signals, line):
498 # check if pull-up is specified
499 m = re.match(r"\s*([a-z]+)-pull-up.*", line)
504 return line
507 def process_spi(config: DeviceConfiguration, signals, line: str) -> Optional[str]:
510 # check if line specifies a pin
511 if not match_and_store_pin(config, signals, line):
514 # check if pull-up is specified
515 m = re.match(r"\s*miso-pull-up.*", line)
520 # check if pull-down is specified
521 m = re.match(r"\s*miso-pull-down.*", line)
526 return line
529 def process_pwm(config: DeviceConfiguration, signals, line: str) -> Optional[str]:
532 # check if line specifies a pin
533 if not match_and_store_pin(config, signals, line):
537 m = re.match(r"\s*([a-z0-9]+)-inverted.*", line)
542 return line
635 def main(input_file: Path, no_backup: bool, skip_nrf_check: bool, header: str) -> None:
670 "-i", "--input", type=Path, required=True, help="Board DTS file"
673 "--no-backup", action="store_true", help="Do not create backup files"
676 "--skip-nrf-check",
678 help="Skip checking if board is nRF-based",
681 "--header", default="", type=str, help="Header to be prepended to pinctrl files"