diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2017-06-06 23:12:04 +0200 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2017-06-06 23:12:04 +0200 |
commit | fa7fdc54764d574446002c12d328b6f8bbb7e803 (patch) | |
tree | 2ccc6e55d4440e3612a95244a9ccd91ebd01a140 /decoders/spi/pd.py | |
parent | de15aa2a9bbecbd495279ae88e57623b138686da (diff) | |
download | libsigrokdecode-fa7fdc54764d574446002c12d328b6f8bbb7e803.tar.gz libsigrokdecode-fa7fdc54764d574446002c12d328b6f8bbb7e803.zip |
spi: Missing samplerate spec is not fatal
Check for the availability of a samplerate specification, but don't
abort in its absence. Lack of the samplerate only prevents the emission
of throughput annotations, but still allows decoding the clocked signal.
Diffstat (limited to 'decoders/spi/pd.py')
-rw-r--r-- | decoders/spi/pd.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/decoders/spi/pd.py b/decoders/spi/pd.py index aec1fac..b08b8a8 100644 --- a/decoders/spi/pd.py +++ b/decoders/spi/pd.py @@ -70,9 +70,6 @@ spi_mode = { (1, 1): 3, # Mode 3 } -class SamplerateError(Exception): - pass - class ChannelError(Exception): pass @@ -145,8 +142,9 @@ class Decoder(srd.Decoder): self.out_python = self.register(srd.OUTPUT_PYTHON) self.out_ann = self.register(srd.OUTPUT_ANN) self.out_binary = self.register(srd.OUTPUT_BINARY) - self.out_bitrate = self.register(srd.OUTPUT_META, - meta=(int, 'Bitrate', 'Bitrate during transfers')) + if self.samplerate is not None: + 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): @@ -251,10 +249,11 @@ class Decoder(srd.Decoder): self.putdata() # Meta bitrate. - elapsed = 1 / float(self.samplerate) - elapsed *= (self.samplenum - self.ss_block + 1) - bitrate = int(1 / elapsed * self.options['wordsize']) - self.put(self.ss_block, self.samplenum, self.out_bitrate, bitrate) + if self.samplerate is not None: + elapsed = 1 / float(self.samplerate) + elapsed *= (self.samplenum - self.ss_block + 1) + bitrate = int(1 / elapsed * self.options['wordsize']) + self.put(self.ss_block, self.samplenum, self.out_bitrate, bitrate) if self.have_cs and self.cs_was_deasserted: self.putw([4, ['CS# was deasserted during this data word!']]) @@ -302,9 +301,6 @@ class Decoder(srd.Decoder): self.handle_bit(miso, mosi, clk, cs) def decode(self): - if not self.samplerate: - raise SamplerateError('Cannot decode without samplerate.') - # The CLK input is mandatory. Other signals are (individually) # optional. Yet either MISO or MOSI (or both) must be provided. # Tell stacked decoders when we don't have a CS# signal. |