X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=inline;f=decoders%2Fcc1101%2Fpd.py;h=f62f18eca9391e200c71f3f9a9bb1c145e826aeb;hb=HEAD;hp=156d4ce18146ddbea107966170a81ffbfc31f1b5;hpb=5ae47601f4935bca731415b23c5f8ad85d6f2309;p=libsigrokdecode.git diff --git a/decoders/cc1101/pd.py b/decoders/cc1101/pd.py index 156d4ce..f62f18e 100644 --- a/decoders/cc1101/pd.py +++ b/decoders/cc1101/pd.py @@ -19,10 +19,11 @@ 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']) @@ -43,15 +44,15 @@ class Decoder(srd.Decoder): ('single_write', 'Single register write'), ('burst_read', 'Burst register read'), ('burst_write', 'Burst register write'), - ('status', 'Status register'), + ('status_read', 'Status read'), + ('status_reg', 'Status register'), ('warning', 'Warning'), ) annotation_rows = ( - ('cmd', '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): @@ -67,7 +68,7 @@ class Decoder(srd.Decoder): 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'.''' @@ -113,7 +114,7 @@ class Decoder(srd.Decoder): 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. @@ -178,7 +179,7 @@ class Decoder(srd.Decoder): 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: @@ -226,17 +227,17 @@ class Decoder(srd.Decoder): '''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') @@ -281,7 +282,7 @@ class Decoder(srd.Decoder): # 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')