Skip to content

Commit

Permalink
espefuse: Adds external esp instance
Browse files Browse the repository at this point in the history
Closes #873
  • Loading branch information
KonstantinKondrashov committed May 2, 2023
1 parent 6068b03 commit 534bac4
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions espefuse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,21 @@ def split_on_groups(all_args):
return groups, used_cmds


def main(custom_commandline=None):
def main(custom_commandline=None, esp=None):
"""
Main function for espefuse
custom_commandline - Optional override for default arguments parsing
(that uses sys.argv), can be a list of custom arguments as strings.
Arguments and their values need to be added as individual items to the list
e.g. "--port /dev/ttyUSB1" thus becomes ['--port', '/dev/ttyUSB1'].
esp - Optional override of the connected device previously
returned by esptool.get_default_connected_device()
"""

external_esp = esp is not None

init_parser = argparse.ArgumentParser(
description="espefuse.py v%s - [ESP32xx] efuse get/set tool"
% esptool.__version__,
Expand Down Expand Up @@ -211,22 +217,24 @@ def main(custom_commandline=None):

print("espefuse.py v{}".format(esptool.__version__))

try:
esp = get_esp(
common_args.port,
common_args.baud,
common_args.before,
common_args.chip,
just_print_help,
common_args.virt,
common_args.debug,
common_args.path_efuse_file,
)
except esptool.FatalError as e:
raise esptool.FatalError(
f"{e}\nPlease make sure that you have specified "
"the right port with the --port argument"
) # TODO: Require the --port argument in the next major release, ESPTOOL-490
if not external_esp:
try:
esp = get_esp(
common_args.port,
common_args.baud,
common_args.before,
common_args.chip,
just_print_help,
common_args.virt,
common_args.debug,
common_args.path_efuse_file,
)
except esptool.FatalError as e:
raise esptool.FatalError(
f"{e}\nPlease make sure that you have specified "
"the right port with the --port argument"
)
# TODO: Require the --port argument in the next major release, ESPTOOL-490

efuses, efuse_operations = get_efuses(
esp, just_print_help, debug_mode, common_args.do_not_confirm
Expand Down Expand Up @@ -276,7 +284,7 @@ def main(custom_commandline=None):
if not efuses.burn_all(check_batch_mode=True):
raise esptool.FatalError("BURN was not done")
finally:
if not common_args.virt and esp._port:
if not external_esp and not common_args.virt and esp._port:
esp._port.close()


Expand Down

0 comments on commit 534bac4

Please sign in to comment.