From: Gerhard Sittig Date: Mon, 27 Jul 2020 18:20:52 +0000 (+0200) Subject: sle44xx: use symbolic identifiers for annotation classes X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=52f08e6d879d8f82e01eb581646a5c929f21d6b8;p=libsigrokdecode.git sle44xx: use symbolic identifiers for annotation classes Eliminate magic numbers for annotation classes, prefer symbolic names instead to improve readability. Put the annotation classes in an order which matches the annotation rows' order. Reduce indentation in the 'proto' table while we are here (yet keep the vertical alignment). --- diff --git a/decoders/sle44xx/pd.py b/decoders/sle44xx/pd.py index 1c0cdb4..25b1cc2 100644 --- a/decoders/sle44xx/pd.py +++ b/decoders/sle44xx/pd.py @@ -22,12 +22,18 @@ import sigrokdecode as srd class Pin: RST, CLK, IO, = range(3) -# CMD: [annotation-type-index, long annotation, short annotation] +class Ann: + BIT, ATR, CMD, DATA, RESET, = range(5) + +class Bin: + SEND_DATA, = range(1) + +# CMD: [annotation class index, long annotation, short annotation] proto = { - 'RESET': [0, 'Reset', 'R'], - 'ATR': [1, 'ATR', 'ATR'], - 'CMD': [2, 'Command', 'C'], - 'DATA': [3, 'Data', 'D'], + 'ATR': [Ann.ATR, 'ATR', 'ATR'], + 'CMD': [Ann.CMD, 'Command', 'C'], + 'DATA': [Ann.DATA, 'Data', 'D'], + 'RESET': [Ann.RESET, 'Reset', 'R'], } class Decoder(srd.Decoder): @@ -46,16 +52,16 @@ class Decoder(srd.Decoder): {'id': 'io', 'name': 'I/O', 'desc': 'I/O data line'}, ) annotations = ( - ('reset', 'Reset'), + ('bit', 'Bit'), ('atr', 'ATR'), ('cmd', 'Command'), ('data', 'Data exchange'), - ('bit', 'Bit'), + ('reset', 'Reset'), ) annotation_rows = ( - ('bits', 'Bits', (4,)), - ('fields', 'Fields', (1, 2, 3)), - ('interrupts', 'Interrupts', (0,)), + ('bits', 'Bits', (Ann.BIT,)), + ('fields', 'Fields', (Ann.ATR, Ann.CMD, Ann.DATA)), + ('interrupts', 'Interrupts', (Ann.RESET,)), ) binary = ( ('send-data', 'Send data'), @@ -129,10 +135,10 @@ class Decoder(srd.Decoder): self.ss, self.es = self.ss_byte, self.samplenum + self.bitwidth - self.putb([0, bytes([self.databyte])]) + self.putb([Bin.SEND_DATA, bytes([self.databyte])]) for bit in self.bits: - self.put(bit[1], bit[2], self.out_ann, [4, ['%d' % bit[0]]]) + self.put(bit[1], bit[2], self.out_ann, [Ann.BIT, ['%d' % bit[0]]]) self.putx([proto[self.cmd][0], ['%s: %02X' % (proto[self.cmd][1], self.databyte), '%s: %02X' % (proto[self.cmd][2], self.databyte), '%02X' % self.databyte]])