Add lut dump
This commit is contained in:
parent
88129b7ea2
commit
a87c81d15a
2 changed files with 30 additions and 5 deletions
26
tw88xx.py
26
tw88xx.py
|
@ -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
|
||||||
|
@ -84,7 +88,7 @@ class TW88xx:
|
||||||
self.write_reg(TW88xx.Reg.DMA_LENGTH_LOW_BYTE, read_len)
|
self.write_reg(TW88xx.Reg.DMA_LENGTH_LOW_BYTE, read_len)
|
||||||
self.write_reg(TW88xx.Reg.DMA_LENGTH_HIGH_BYTE, 0)
|
self.write_reg(TW88xx.Reg.DMA_LENGTH_HIGH_BYTE, 0)
|
||||||
|
|
||||||
|
|
||||||
def do_flash_cmd(self, cmd, read_len):
|
def do_flash_cmd(self, cmd, read_len):
|
||||||
for i in range(len(cmd)):
|
for i in range(len(cmd)):
|
||||||
self.write_reg(TW88xx.Reg.DMA_COMMAND_BUFFER + i, cmd[i])
|
self.write_reg(TW88xx.Reg.DMA_COMMAND_BUFFER + i, cmd[i])
|
||||||
|
@ -98,9 +102,23 @@ class TW88xx:
|
||||||
data = []
|
data = []
|
||||||
for i in range(read_len):
|
for i in range(read_len):
|
||||||
data.append(self.read_reg(TW88xx.Reg.DMA_READWRITE_BUFFER + i))
|
data.append(self.read_reg(TW88xx.Reg.DMA_READWRITE_BUFFER + i))
|
||||||
return bytes(data)
|
return bytes(data)
|
||||||
|
|
||||||
def dump_regs(self):
|
def dump_regs(self):
|
||||||
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
|
||||||
|
|
|
@ -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')
|
||||||
|
|
Loading…
Reference in a new issue