import sigrokdecode as srd
from collections import namedtuple
+from common.srdhelper import SrdIntEnum
from .lists import *
-ANN_STROBE, ANN_SINGLE_READ, ANN_SINGLE_WRITE, ANN_BURST_READ, \
- ANN_BURST_WRITE, ANN_STATUS_READ, ANN_STATUS, ANN_WARN = range(8)
+Ann = SrdIntEnum.from_str('Ann', 'STROBE SINGLE_READ SINGLE_WRITE BURST_READ \
+ BURST_WRITE STATUS_READ STATUS WARN')
Pos = namedtuple('Pos', ['ss', 'es'])
Data = namedtuple('Data', ['mosi', 'miso'])
('warning', 'Warning'),
)
annotation_rows = (
- ('cmds', 'Commands', (ANN_STROBE,)),
- ('data', 'Data', (ANN_SINGLE_READ, ANN_SINGLE_WRITE, ANN_BURST_READ,
- ANN_BURST_WRITE, ANN_STATUS_READ)),
- ('status', 'Status register', (ANN_STATUS,)),
- ('warnings', 'Warnings', (ANN_WARN,)),
+ ('cmds', 'Commands', (Ann.STROBE,)),
+ ('data', 'Data', (Ann.prefixes('SINGLE_ BURST_ STATUS_'))),
+ ('status', 'Status register', (Ann.STATUS,)),
+ ('warnings', 'Warnings', (Ann.WARN,)),
)
def __init__(self):
def warn(self, pos, msg):
'''Put a warning message 'msg' at 'pos'.'''
- self.put(pos.ss, pos.es, self.out_ann, [ANN_WARN, [msg]])
+ self.put(pos.ss, pos.es, self.out_ann, [Ann.WARN, [msg]])
def putp(self, pos, ann, msg):
'''Put an annotation message 'msg' at 'pos'.'''
self.cmd, self.dat, self.min, self.max = c
if self.cmd == 'Strobe':
- self.putp(pos, ANN_STROBE, self.format_command())
+ self.putp(pos, Ann.STROBE, self.format_command())
else:
# Don't output anything now, the command is merged with
# the data bytes following it.
else:
name = regid
- if regid == 'STATUS' and ann == ANN_STATUS:
+ if regid == 'STATUS' and ann == Ann.STATUS:
label = 'Status'
self.decode_status_reg(pos, ann, data, label)
else:
'''Decodes the remaining data bytes at position 'pos'.'''
if self.cmd == 'Write':
- self.decode_reg(pos, ANN_SINGLE_WRITE, self.dat, self.mosi_bytes())
+ self.decode_reg(pos, Ann.SINGLE_WRITE, self.dat, self.mosi_bytes())
elif self.cmd == 'Burst write':
- self.decode_reg(pos, ANN_BURST_WRITE, self.dat, self.mosi_bytes())
+ self.decode_reg(pos, Ann.BURST_WRITE, self.dat, self.mosi_bytes())
elif self.cmd == 'Read':
- self.decode_reg(pos, ANN_SINGLE_READ, self.dat, self.miso_bytes())
+ self.decode_reg(pos, Ann.SINGLE_READ, self.dat, self.miso_bytes())
elif self.cmd == 'Burst read':
- self.decode_reg(pos, ANN_BURST_READ, self.dat, self.miso_bytes())
+ self.decode_reg(pos, Ann.BURST_READ, self.dat, self.miso_bytes())
elif self.cmd == 'Strobe':
- self.decode_reg(pos, ANN_STROBE, self.dat, self.mosi_bytes())
+ self.decode_reg(pos, Ann.STROBE, self.dat, self.mosi_bytes())
elif self.cmd == 'Status read':
- self.decode_reg(pos, ANN_STATUS_READ, self.dat, self.miso_bytes())
+ self.decode_reg(pos, Ann.STATUS_READ, self.dat, self.miso_bytes())
else:
self.warn(pos, 'unhandled command')
# First MOSI byte is always the command.
self.decode_command(pos, mosi)
# First MISO byte is always the status register.
- self.decode_reg(pos, ANN_STATUS, 'STATUS', [miso])
+ self.decode_reg(pos, Ann.STATUS, 'STATUS', [miso])
else:
if not self.cmd or len(self.mb) >= self.max:
self.warn(pos, 'excess byte')