Skip to content

Commit

Permalink
AP_HAL_ChibiOS: process @include lines within hwdef files
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Jul 4, 2023
1 parent 53e6f28 commit d0b9670
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
# setup for LEDs on chan9
SERVO9_FUNCTION 120
# Default VTX power to on
RELAY_DEFAULT 1
# UART1 for DJI Goggles
SERIAL1_PROTOCOL 33

@include ../KakuteH7Mini/defaults.parm
33 changes: 32 additions & 1 deletion libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -2736,6 +2736,32 @@ def build_peripheral_list(self):
done.add(type)
return peripherals

def get_processed_defaults_file(self, defaults_filepath, depth=0):
'''reads defaults_filepath, expanding any @include lines to include
the contents of the so-references file - recursively.'''
if depth > 10:
raise Exception("include loop")
ret = ""
with open(defaults_filepath, 'r') as defaults_fh:
while True:
line = defaults_fh.readline()
if line == "":
break
m = re.match("^@include\s*([^\s]+)", line)
if m is None:
ret += line
continue
# we've found an include; do that...
include_filepath = os.path.join(os.path.dirname(defaults_filepath), m.group(1))
try:
# ret += "# Begin included file (%s)" % include_filepath
ret += self.get_processed_defaults_file(include_filepath, depth=depth+1)
# ret += "# End included file (%s)" % include_filepath
except FileNotFoundError:
raise Exception("%s includes %s but that filepath was not found" %
(defaults_filepath, include_filepath))
return ret


def write_processed_defaults_file(self, filepath):
# see if board has a defaults.parm file or a --default-parameters file was specified
Expand All @@ -2754,7 +2780,12 @@ def write_processed_defaults_file(self, filepath):
print("No default parameter file found")
return

self.env_vars['DEFAULT_PARAMETERS'] = defaults_abspath
content = self.get_processed_defaults_file(defaults_abspath)

with open(filepath, "w") as processed_defaults_fh:
processed_defaults_fh.write(content)

self.env_vars['DEFAULT_PARAMETERS'] = filepath


def write_env_py(self, filename):
Expand Down

0 comments on commit d0b9670

Please sign in to comment.