summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2020-07-27 20:20:52 +0200
committerGerhard Sittig <gerhard.sittig@gmx.net>2020-08-30 07:23:58 +0200
commit52f08e6d879d8f82e01eb581646a5c929f21d6b8 (patch)
treefcd44bfe5bb26ce16e435f3f9baf3008a87e88cc
parent5c47b179b3e1e90b79478a9feca18990c481d014 (diff)
downloadlibsigrokdecode-52f08e6d879d8f82e01eb581646a5c929f21d6b8.tar.gz
libsigrokdecode-52f08e6d879d8f82e01eb581646a5c929f21d6b8.zip
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).
-rw-r--r--decoders/sle44xx/pd.py30
1 files changed, 18 insertions, 12 deletions
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]])