summaryrefslogtreecommitdiff
path: root/decoders/i2s
diff options
context:
space:
mode:
authorJoel Holdsworth <joel@airwebreathe.org.uk>2012-04-06 22:01:30 +0100
committerJoel Holdsworth <joel@airwebreathe.org.uk>2012-04-06 22:29:49 +0100
commit780a5beeaf36e7af20f4f37c0f13473f3f9bb1d3 (patch)
tree6f7935c43b6a1bc151915ceca38df436bf11cc63 /decoders/i2s
parentabbbd2ba56a70b9978c4f31a4988102364807997 (diff)
downloadlibsigrokdecode-780a5beeaf36e7af20f4f37c0f13473f3f9bb1d3.tar.gz
libsigrokdecode-780a5beeaf36e7af20f4f37c0f13473f3f9bb1d3.zip
srd/i2s: Added sample-rate and bit-depth to report
Diffstat (limited to 'decoders/i2s')
-rw-r--r--decoders/i2s/i2s.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/decoders/i2s/i2s.py b/decoders/i2s/i2s.py
index 23f625d..d627ebb 100644
--- a/decoders/i2s/i2s.py
+++ b/decoders/i2s/i2s.py
@@ -50,16 +50,29 @@ class Decoder(srd.Decoder):
self.bitcount = 0
self.data = 0
self.samplesreceived = 0
+ self.first_sample = None
self.start_sample = None
self.samplenum = -1
self.wordlength = -1
def start(self, metadata):
+ self.samplerate = metadata['samplerate']
self.out_proto = self.add(srd.OUTPUT_PROTO, 'i2s')
self.out_ann = self.add(srd.OUTPUT_ANN, 'i2s')
def report(self):
- return 'I2S: %d samples received' % self.samplesreceived
+
+ # Calculate the sample rate
+ samplerate = '?'
+ if self.start_sample != None and \
+ self.first_sample != None and \
+ self.start_sample > self.first_sample:
+ samplerate = "%d" % (self.samplesreceived *
+ self.samplerate / (self.start_sample -
+ self.first_sample))
+
+ return 'I2S: %d %d-bit samples received at %sHz' % \
+ (self.samplesreceived, self.wordlength, samplerate)
def decode(self, ss, es, data):
for samplenum, (sck, ws, sd) in data:
@@ -101,6 +114,10 @@ class Decoder(srd.Decoder):
self.data = 0
self.bitcount = 0
self.start_sample = self.samplenum
-
+
+ # Save the first sample position
+ if self.first_sample == None:
+ self.first_sample = self.samplenum
+
self.oldws = ws
\ No newline at end of file