summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2020-08-29 12:31:31 +0200
committerGerhard Sittig <gerhard.sittig@gmx.net>2020-08-30 07:23:58 +0200
commit1dfaf1e8a7df8e4cc251aeea4afb35cfa3fa219c (patch)
treec1dac13f50d5ee8b00ff2a69b4dace63f826e5f6 /decoders
parente4f70391abbb153364a534d45a59026961ce1b1f (diff)
downloadlibsigrokdecode-1dfaf1e8a7df8e4cc251aeea4afb35cfa3fa219c.tar.gz
libsigrokdecode-1dfaf1e8a7df8e4cc251aeea4afb35cfa3fa219c.zip
sle44xx: rephrase ss/es passing for annotation emission
Coupling the logic which interprets input signals at different levels and the helpers which emit annotations by means of "global" variables (public members of the decoder object) is unfortunate. It complicates the logic, adds unnecessary dependencies, and makes maintenance rather tedious and error prone. Pass ss/es times to put() routines the same way as annotation classes and annotation texts are passed. This simplifies the logic where bits and bytes levels and additional rows are handled. The data values and their spans all become local information that gets determined in the same context. Which dramatically simplifies review.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/sle44xx/pd.py26
1 files changed, 10 insertions, 16 deletions
diff --git a/decoders/sle44xx/pd.py b/decoders/sle44xx/pd.py
index 775ee3c..866ebd5 100644
--- a/decoders/sle44xx/pd.py
+++ b/decoders/sle44xx/pd.py
@@ -81,7 +81,6 @@ class Decoder(srd.Decoder):
self.reset()
def reset(self):
- self.ss = self.es = self.ss_byte = -1
self.bits = []
self.cmd = None
@@ -93,24 +92,22 @@ class Decoder(srd.Decoder):
self.out_ann = self.register(srd.OUTPUT_ANN)
self.out_binary = self.register(srd.OUTPUT_BINARY)
- def putx(self, data):
- self.put(self.ss, self.es, self.out_ann, data)
+ def putx(self, ss, es, cls, data):
+ self.put(ss, es, self.out_ann, [cls, data,])
- def putb(self, data):
- self.put(self.ss, self.es, self.out_binary, data)
+ def putb(self, ss, es, cls , data):
+ self.put(ss, es, self.out_binary, [cls, data,])
def handle_reset(self, pins):
- self.ss, self.es = self.samplenum, self.samplenum
self.cmd = 'RESET'
cls, texts = lookup_proto_ann_txt(self.cmd, {})
- self.putx([cls, texts])
+ self.putx(self.samplenum, self.samplenum, cls, texts)
self.bits = []
# Next data bytes will be Answer To Reset.
self.cmd = 'ATR'
def handle_command(self, pins):
rst, clk, io = pins
- self.ss, self.es = self.samplenum, self.samplenum
# XXX Is the comment inverted?
# If I/O is rising -> command START
# if I/O is falling -> command STOP and response data incoming
@@ -128,8 +125,6 @@ class Decoder(srd.Decoder):
# slightly stretched clock period throws off the following bit
# annotation. Better look for more reliable conditions. Available
# documentation suggests bit values are valid during high CLK.
- if not self.bits:
- self.ss_byte = self.samplenum
bit_val = io
bit_ss = self.samplenum
bit_es = bit_ss # self.bitwidth is not known yet.
@@ -143,20 +138,19 @@ class Decoder(srd.Decoder):
# Get the data byte value, and byte's ss/es.
databyte = bitpack_lsb(self.bits, 0)
- self.ss_byte = self.bits[0][1]
- self.es_byte = self.bits[-1][2]
+ byte_ss = self.bits[0][1]
+ byte_es = self.bits[-1][2]
- self.ss, self.es = self.ss_byte, self.es_byte
- self.putb([Bin.SEND_DATA, bytes([databyte])])
+ self.putb(byte_ss, byte_es, Bin.SEND_DATA, bytes([databyte]))
# TODO Present bit values earlier. As soon as their es is known.
for bit_val, bit_ss, bit_es in self.bits:
cls, texts = lookup_proto_ann_txt('BIT', {'bit': bit_val})
- self.put(bit_ss, bit_es, self.out_ann, [cls, texts])
+ self.putx(bit_ss, bit_es, cls, texts)
cls, texts = lookup_proto_ann_txt(self.cmd, {'data': databyte})
if cls:
- self.putx([cls, texts])
+ self.putx(byte_ss, byte_es, cls, texts)
# Done with this packet.
self.bits = []