X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Fspi.py;h=7c56aed6fb3a2aa60a62e9327a9a242e8bb49105;hp=2f692f08f28c40ffce6ceed0ed0f1e59b7d0554a;hb=cc2047464a6b01474721557f32acafd9f1f00cb9;hpb=238b4080f5de6e12f36d66c93e0fa8afb9688233 diff --git a/decoders/spi.py b/decoders/spi.py index 2f692f0..7c56aed 100644 --- a/decoders/spi.py +++ b/decoders/spi.py @@ -35,7 +35,7 @@ CPHA_1 = 1 # Data is valid on the falling clock edge # Bit order options MSB_FIRST = 0 -LSB_FIRST = 0 +LSB_FIRST = 1 # Annotation formats ANN_HEX = 0 @@ -78,6 +78,13 @@ class Decoder(srd.Decoder): self.bytesreceived = 0 self.samplenum = -1 + # Set protocol decoder option defaults. + self.cs_active_low = Decoder.options['cs_active_low'][1] + self.clock_polarity = Decoder.options['clock_polarity'][1] + self.clock_phase = Decoder.options['clock_phase'][1] + self.bit_order = Decoder.options['bit_order'][1] + self.word_size = Decoder.options['word_size'][1] + def start(self, metadata): self.out_proto = self.add(srd.OUTPUT_PROTO, 'spi') self.out_ann = self.add(srd.OUTPUT_ANN, 'spi') @@ -105,16 +112,22 @@ class Decoder(srd.Decoder): if self.bitcount == 0: self.start_sample = samplenum - # Receive bit into our shift register. - if mosi == 1: - self.mosidata |= 1 << (7 - self.bitcount) - if miso == 1: - self.misodata |= 1 << (7 - self.bitcount) + # Receive MOSI bit into our shift register. + if self.bit_order == MSB_FIRST: + self.mosidata |= mosi << (self.wordsize - 1 - self.bitcount) + else: + self.mosidata |= mosi << self.bitcount + + # Receive MISO bit into our shift register. + if self.bit_order == MSB_FIRST: + self.misodata |= miso << (self.wordsize - 1 - self.bitcount) + else: + self.misodata |= miso << self.bitcount self.bitcount += 1 # Continue to receive if not a byte yet. - if self.bitcount != 8: + if self.bitcount != self.wordsize: continue self.put(self.start_sample, self.samplenum, self.out_proto,