summaryrefslogtreecommitdiff
path: root/decoders/usb_signalling
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2013-09-20 16:22:33 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2013-09-20 17:57:53 +0200
commit5bb55598a1868113513f737b2714bcd6e48aa9b3 (patch)
tree735c7244d6b2201cc7300aeb4dacf99b8abede8a /decoders/usb_signalling
parent7d4b5fac7abd39749900a2990f8d0b1b81edd20d (diff)
downloadlibsigrokdecode-5bb55598a1868113513f737b2714bcd6e48aa9b3.tar.gz
libsigrokdecode-5bb55598a1868113513f737b2714bcd6e48aa9b3.zip
usb_signalling: Refactor/simplify bitrate/bitwidth handling.
Diffstat (limited to 'decoders/usb_signalling')
-rw-r--r--decoders/usb_signalling/pd.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/decoders/usb_signalling/pd.py b/decoders/usb_signalling/pd.py
index 75069f4..70ada37 100644
--- a/decoders/usb_signalling/pd.py
+++ b/decoders/usb_signalling/pd.py
@@ -40,6 +40,11 @@ symbols_fs = {
(1, 1): 'SE1',
}
+bitrates = {
+ 'low-speed': 1500000, # 1.5Mb/s (+/- 1.5%)
+ 'full-speed': 12000000, # 12Mb/s (+/- 0.25%)
+}
+
class Decoder(srd.Decoder):
api_version = 1
id = 'usb_signalling'
@@ -67,12 +72,15 @@ class Decoder(srd.Decoder):
self.scount = 0
self.packet = ''
self.syms = []
+ self.bitrate = None
+ self.bitwidth = None
self.oldpins = None
def start(self, metadata):
- self.samplerate = metadata['samplerate']
self.out_proto = self.add(srd.OUTPUT_PROTO, 'usb_signalling')
self.out_ann = self.add(srd.OUTPUT_ANN, 'usb_signalling')
+ self.bitrate = bitrates[self.options['signalling']]
+ self.bitwidth = float(metadata['samplerate']) / float(self.bitrate)
def report(self):
pass
@@ -117,11 +125,7 @@ class Decoder(srd.Decoder):
# How many bits since the last transition?
if self.packet != '' or self.sym != 'J':
- if self.options['signalling'] == 'low-speed':
- bitrate = 1500000 # 1.5Mb/s (+/- 1.5%)
- elif self.options['signalling'] == 'full-speed':
- bitrate = 12000000 # 12Mb/s (+/- 0.25%)
- bitcount = int((self.scount - 1) * bitrate / self.samplerate)
+ bitcount = int((self.scount - 1) / self.bitwidth)
else:
bitcount = 0