From: Andreas Sandberg Date: Fri, 13 Feb 2015 21:42:01 +0000 (+0000) Subject: spi: Don't decode data lines if CS isn't asserted X-Git-Tag: libsigrokdecode-0.4.0~122 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cdceaa9438e889e55d7f5c364f05548afba66bc3;p=libsigrokdecode.git spi: Don't decode data lines if CS isn't asserted Avoid decoding and outputting data from the SPI bus if the CS pin hasn't been asserted. This avoids confusing both users and stacked decoders which otherwise end up seeing traffic intended for other chips (or just noise). Note: The old behavior of decoding all traffic is still in place if no CS pin has been wired up to the decoder. This fixes bug #559. --- diff --git a/decoders/spi/pd.py b/decoders/spi/pd.py index 3abcd68..4a686dd 100644 --- a/decoders/spi/pd.py +++ b/decoders/spi/pd.py @@ -183,14 +183,16 @@ class Decoder(srd.Decoder): self.mosibits = [] if self.have_mosi else None self.bitcount = 0 + def cs_asserted(self, cs): + active_low = (self.options['cs_polarity'] == 'active-low') + return (cs == 0) if active_low else (cs == 1) + def handle_bit(self, miso, mosi, clk, cs): # If this is the first bit of a dataword, save its sample number. if self.bitcount == 0: self.ss_block = self.samplenum - self.cs_was_deasserted = False - if self.have_cs: - active_low = (self.options['cs_polarity'] == 'active-low') - self.cs_was_deasserted = (cs == 1) if active_low else (cs == 0) + self.cs_was_deasserted = \ + not self.cs_asserted(cs) if self.have_cs else False ws = self.options['wordsize'] @@ -254,6 +256,10 @@ class Decoder(srd.Decoder): # Reset decoder state when CS# changes (and the CS# pin is used). self.reset_decoder_state() + # We only care about samples if CS# is asserted. + if self.have_cs and not self.cs_asserted(cs): + return + # Ignore sample if the clock pin hasn't changed. if clk == self.oldclk: return