Add auto_int for range args

This commit is contained in:
Patrick Moessler 2022-01-10 01:22:38 +01:00
parent 87c68c1a0a
commit f349efff80

View file

@ -3,6 +3,11 @@ import argparse
from tw88xx import TW88xx from tw88xx import TW88xx
parser = argparse.ArgumentParser(description='TW88xx debug utility.') parser = argparse.ArgumentParser(description='TW88xx debug utility.')
def auto_int(x):
return int(x, 0)
parser.add_argument('command', parser.add_argument('command',
help='the command to execute', help='the command to execute',
choices=('dump_flash', 'get_id', 'dump_regs', 'dump_lut') choices=('dump_flash', 'get_id', 'dump_regs', 'dump_lut')
@ -30,11 +35,13 @@ parser.add_argument('-t', '--type',
) )
parser.add_argument('--start', parser.add_argument('--start',
help='begin of reading range', help='begin of reading range',
default='0' type=auto_int,
default=0
) )
parser.add_argument('--length', parser.add_argument('--length',
help='amount to read', help='amount to read',
default='0' type=auto_int,
default=0
) )
args = parser.parse_args() args = parser.parse_args()
@ -78,9 +85,9 @@ elif args.command == 'dump_regs':
if not args.start: if not args.start:
tw88xx.dump_regs() tw88xx.dump_regs()
else: else:
for r in range(args.start,args.start+args.length+1): for r in range(args.start, args.start+args.length+1):
if r in tw88xx.REGS: if r in tw88xx.REGS:
v=tw88xx.read_reg(r) v = tw88xx.read_reg(r)
print(f'{r:03x} = {v:02x} ({tw88xx.REGS[r]})') print(f'{r:03x} = {v:02x} ({tw88xx.REGS[r]})')
elif args.command == 'dump_lut': elif args.command == 'dump_lut':