diff options
author | Andreas Sandberg <andreas@sandberg.pp.se> | 2015-02-13 21:42:01 +0000 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2015-04-03 22:49:39 +0200 |
commit | cdceaa9438e889e55d7f5c364f05548afba66bc3 (patch) | |
tree | 4a7cb81f57dda005aca465605d58fc3db3b75799 | |
parent | a7c8dc5e3a2b7ad38eb03a958180f97f3059ea31 (diff) | |
download | libsigrokdecode-cdceaa9438e889e55d7f5c364f05548afba66bc3.tar.gz libsigrokdecode-cdceaa9438e889e55d7f5c364f05548afba66bc3.zip |
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.
-rw-r--r-- | decoders/spi/pd.py | 14 |
1 files changed, 10 insertions, 4 deletions
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 |