From: Uwe Hermann Date: Sun, 23 Oct 2016 19:01:08 +0000 (+0200) Subject: spi: Fix binary output for wordsizes > 8. X-Git-Tag: libsigrokdecode-0.5.0~132 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8284ca7360c96ac8085ba90b6f1f0e8fb88e6290;p=libsigrokdecode.git spi: Fix binary output for wordsizes > 8. For wordsizes > 8, multiple bytes are used (big-endian). This fixes bug #686. --- diff --git a/decoders/spi/pd.py b/decoders/spi/pd.py index fc8c7d0..ce007e2 100644 --- a/decoders/spi/pd.py +++ b/decoders/spi/pd.py @@ -152,6 +152,7 @@ class Decoder(srd.Decoder): self.out_binary = self.register(srd.OUTPUT_BINARY) self.out_bitrate = self.register(srd.OUTPUT_META, meta=(int, 'Bitrate', 'Bitrate during transfers')) + self.bw = (self.options['wordsize'] + 7) // 8 def putw(self, data): self.put(self.ss_block, self.samplenum, self.out_ann, data) @@ -165,10 +166,12 @@ class Decoder(srd.Decoder): if self.have_miso: ss, es = self.misobits[-1][1], self.misobits[0][2] - self.put(ss, es, self.out_binary, [0, bytes([so])]) + bdata = so.to_bytes(self.bw, byteorder='big') + self.put(ss, es, self.out_binary, [0, bdata]) if self.have_mosi: ss, es = self.mosibits[-1][1], self.mosibits[0][2] - self.put(ss, es, self.out_binary, [1, bytes([si])]) + bdata = si.to_bytes(self.bw, byteorder='big') + self.put(ss, es, self.out_binary, [1, bdata]) self.put(ss, es, self.out_python, ['BITS', si_bits, so_bits]) self.put(ss, es, self.out_python, ['DATA', si, so])