Add lut dump

This commit is contained in:
Asaril 2022-01-09 21:14:53 +00:00
parent 88129b7ea2
commit a87c81d15a
2 changed files with 30 additions and 5 deletions

View file

@ -20,6 +20,10 @@ class TW88xx:
SPI_FLASH_BUSY_CONTROL = 0X4D9 SPI_FLASH_BUSY_CONTROL = 0X4D9
DMA_LENGTH_HIGH_BYTE = 0X4DA DMA_LENGTH_HIGH_BYTE = 0X4DA
LUT_ACCESS_CTRL = 0x410
LUT_ADDR = 0x411
LUT_DATA = 0x412
def __init__(self, i2c: I2CInterface) -> None: def __init__(self, i2c: I2CInterface) -> None:
self.i2c = i2c self.i2c = i2c
self.page = None self.page = None
@ -104,3 +108,17 @@ class TW88xx:
for r in self.REGS: for r in self.REGS:
val = self.read_reg(r) val = self.read_reg(r)
print(f'{r:03x} = {val:02x} ({self.REGS[r]})') print(f'{r:03x} = {val:02x} ({self.REGS[r]})')
def dump_lut(self):
lut_ctrl = self.read_reg(TW88xx.Reg.LUT_ACCESS_CTRL) & 0xF0
tbl = {}
for i in range(512):
data=[]
for b in range(4):
self.write_reg(TW88xx.Reg.LUT_ACCESS_CTRL, lut_ctrl | (8 if i>256 else 0) | b)
self.write_reg(TW88xx.Reg.LUT_ADDR, i & 0xFF)
_ = self.read_reg(TW88xx.Reg.LUT_DATA)
data.append(self.read_reg(TW88xx.Reg.LUT_DATA))
print (f'{i:03x} = {bytes(data).hex()}')
tbl[i] = data
return tbl

View file

@ -5,7 +5,7 @@ parser = argparse.ArgumentParser(description='TW88xx debug utility.')
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') choices=('dump_flash', 'get_id', 'dump_regs', 'dump_lut')
) )
parser.add_argument('-f', '--flash_file', parser.add_argument('-f', '--flash_file',
help='file to read from / write into' help='file to read from / write into'
@ -76,3 +76,10 @@ elif args.command == 'dump_flash':
elif args.command == 'dump_regs': elif args.command == 'dump_regs':
tw88xx.dump_regs() tw88xx.dump_regs()
elif args.command == 'dump_lut':
tbl = tw88xx.dump_lut()
if args.flash_file:
with open(args.flash_file,'w') as f:
for r in sorted(tbl):
f.write(f'{r:03x}={bytes(tbl[r]).hex()}\n')