summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2022-12-30 14:10:04 +0100
committerGerhard Sittig <gerhard.sittig@gmx.net>2023-01-09 20:13:35 +0100
commit912f4e8a245f014b312bfc90e4ec6dba256379d4 (patch)
tree3c6b96898e6ef694739546003c118ef1097009c7
parent317eaa7fd83fb049db97e863a306992a34fcf490 (diff)
downloadlibsigrokdecode-912f4e8a245f014b312bfc90e4ec6dba256379d4.tar.gz
libsigrokdecode-912f4e8a245f014b312bfc90e4ec6dba256379d4.zip
adf435x: Python list idioms in bits sequence accumulation
Use .extend() and .clear() for the Python list during accumulation of a 32bit word's bits sequence. This shall improve readability. Performance is less of an issue since this decoder's data amount remains small (32bit entities per SPI transfer). Comment on the unexpected(?) SPI decoder's BITS ordering when passing details up to stacked decoders. Raise and keep awareness for this non-obvious implementation detail during decoder maintenance. This implementation accumulates bits in the MSB order as they are sent in SPI frames. Yet keeps the LSB bit order when a completely accumulated 32bit word gets inspected, to reduce the diff size. Bit field extraction and annotation emission code paths assume a specific timestamp ordering. The separation of transport and inspection also simplifies maintenance, should a future SPI decoder provide BITS in their received order.
-rw-r--r--decoders/adf435x/pd.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/decoders/adf435x/pd.py b/decoders/adf435x/pd.py
index 8c31648..7810190 100644
--- a/decoders/adf435x/pd.py
+++ b/decoders/adf435x/pd.py
@@ -135,6 +135,7 @@ class Decoder(srd.Decoder):
if ptype == 'TRANSFER':
if len(self.bits) == 32:
+ self.bits.reverse()
reg_value, reg_pos = self.decode_bits(0, 3)
self.put(reg_pos[0], reg_pos[1], self.out_ann, [ANN_REG,
['Register: %d' % reg_value, 'Reg: %d' % reg_value,
@@ -146,8 +147,14 @@ class Decoder(srd.Decoder):
else:
error = "Frame error: Wrong number of bits: got %d expected 32" % len(self.bits)
self.put(ss, es, self.out_ann, [ANN_WARN, [error, 'Frame error']])
- self.bits = []
+ self.bits.clear()
if ptype == 'BITS':
_, mosi_bits, miso_bits = data
- self.bits = mosi_bits + self.bits
+ # Cope with the lower layer SPI decoder's output convention:
+ # Regardless of wire transfer's frame format, .decode() input
+ # provides BITS in the LE order. Accumulate in MSB order here,
+ # and reverse before data processing when 'TRANSFER' is seen.
+ mosi_bits = mosi_bits.copy()
+ mosi_bits.reverse()
+ self.bits.extend(mosi_bits)