davids5 commented on code in PR #8992: URL: https://github.com/apache/nuttx/pull/8992#discussion_r1169874310
########## tools/stm32_pinmap_tool.py: ########## @@ -0,0 +1,571 @@ +#!/usr/bin/env python3 +############################################################################ +# tools/stm32_pinmap_tool.py +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +# for python2.7 compatibility +from __future__ import print_function + +import argparse +import os +import re +import sys +from argparse import RawTextHelpFormatter +from glob import glob + +suffix = "_0" +remaps_re = re.compile(r"(.*REMAP.*)=y") +ip_block_re = re.compile(r"CONFIG_STM32[A-Z0-9]*_([A-Z0-9]+[0-9]*)=") +stm32f1_re = re.compile(r"stm32f10[0-9][a-z]*_pinmap") +speed_re = re.compile(r"(GPIO_(?:SPEED|MODE)_[zA-Z0-9]+)") +port_re = re.compile(r"GPIO_PORT([A-Z])\|") +pin_re = re.compile(r"GPIO_PIN(\d+)") +define_re = re.compile(r"#\s*define\s+(GPIO.*)\s+(GPIO.*?)\s+") + + +class GPIODef: + def __init__(self, original_name, name, description): + self.original_name = original_name + self.name = name + self.block = name.split("_")[1] + self.speed = None + s = speed_re.search(description) + if s: + self.speed = s.group(1) + s = port_re.search(description) + if s: + self.port = s.group(1) + s = pin_re.search(description) + if s: + self.pin = s.group(1) + + def __str__(self): + fmt = "#define {0: <20} {1} /* P{2} */" + if self.speed: + if "MODE" in self.speed: + if "MHz" in self.speed: + # F1 has mode, MHz is output, we must adjust the speed + fmt = "#define {0: <20} GPIO_ADJUST_MODE({1}, {3}) /* P{2} */ " + else: + # All others had a OSPEDD reg so wee just set it + fmt = "#define {0: <20} ({1} | {3}) /* P{2} */ " + + return fmt.format( + self.original_name, + self.name, + self.port + self.pin, + self.speed, + ) + + def __repr__(self): + return f"<GPIODef block:{self.block} \ + original_name:{self.original_name} \ + name:{self.name} port:{self.port} \ + pin:{self.pin} speed:{self.speed}>" + + +# Detect python version +if sys.version_info[0] < 3: + runningPython3 = False +else: + runningPython3 = True + + +def parse_args(): + # Parse commandline arguments + parser = argparse.ArgumentParser( + formatter_class=RawTextHelpFormatter, + description="""stm32_pinmap_tool.py + + This tool is used to migrate legacy stm32 pinmap files that + had included pin speed (slew rate control) in pinmap pin definitions + + These speeds should have never been part of the defines as these Review Comment: all changes to spelling in stm32_pinmap_tool.py Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org