summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2016-08-26 15:19:21 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2016-12-07 22:45:47 +0100
commit5e39fa54152db51fd9bdfb33edfd55a54493821d (patch)
tree2fd7ac1c08f7ea2ed480fbdd1f7cc538fb3be4b8 /decoders
parent8eb06a59636274fe6143aa7d87f7374cd12f3df9 (diff)
downloadlibsigrokdecode-5e39fa54152db51fd9bdfb33edfd55a54493821d.tar.gz
libsigrokdecode-5e39fa54152db51fd9bdfb33edfd55a54493821d.zip
spdif: Convert to PD API version 3.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/spdif/pd.py61
1 files changed, 25 insertions, 36 deletions
diff --git a/decoders/spdif/pd.py b/decoders/spdif/pd.py
index da3ca28..e22f654 100644
--- a/decoders/spdif/pd.py
+++ b/decoders/spdif/pd.py
@@ -24,7 +24,7 @@ class SamplerateError(Exception):
pass
class Decoder(srd.Decoder):
- api_version = 2
+ api_version = 3
id = 'spdif'
name = 'S/PDIF'
longname = 'Sony/Philips Digital Interface Format'
@@ -60,9 +60,9 @@ class Decoder(srd.Decoder):
def __init__(self):
self.state = 'GET FIRST PULSE WIDTH'
- self.olddata = None
self.ss_edge = None
self.first_edge = True
+ self.samplenum_prev_edge = 0
self.pulse_width = 0
self.clocks = []
@@ -80,6 +80,9 @@ class Decoder(srd.Decoder):
def start(self):
self.out_ann = self.register(srd.OUTPUT_ANN)
+ # Assume that the initial pin state is logic 0.
+ self.initial_pins = [0]
+
def metadata(self, key, value):
if key == srd.SRD_CONF_SAMPLERATE:
self.samplerate = value
@@ -218,40 +221,26 @@ class Decoder(srd.Decoder):
self.last_preamble = self.samplenum
- def decode(self, ss, es, data):
+ def decode(self):
if not self.samplerate:
raise SamplerateError('Cannot decode without samplerate.')
- for (self.samplenum, pins) in data:
- data = pins[0]
-
- # Initialize self.olddata with the first sample value.
- if self.olddata is None:
- self.olddata = data
- continue
-
- # First we need to recover the clock.
- if self.olddata == data:
- self.pulse_width += 1
- continue
-
- # Found rising or falling edge.
- if self.first_edge:
- # Throw away first detected edge as it might be mangled data.
- self.first_edge = False
- self.pulse_width = 0
- else:
- if self.state == 'GET FIRST PULSE WIDTH':
- self.find_first_pulse_width()
- elif self.state == 'GET SECOND PULSE WIDTH':
- self.find_second_pulse_width()
- elif self.state == 'GET THIRD PULSE WIDTH':
- self.find_third_pulse_width()
- elif self.state == 'DECODE STREAM':
- self.decode_stream()
- elif self.state == 'DECODE PREAMBLE':
- self.decode_preamble()
-
- self.pulse_width = 0
-
- self.olddata = data
+ # Throw away first detected edge as it might be mangled data.
+ self.wait({0: 'e'})
+
+ while True:
+ # Wait for any edge (rising or falling).
+ (data,) = self.wait({0: 'e'})
+ self.pulse_width = self.samplenum - self.samplenum_prev_edge - 1
+ self.samplenum_prev_edge = self.samplenum
+
+ if self.state == 'GET FIRST PULSE WIDTH':
+ self.find_first_pulse_width()
+ elif self.state == 'GET SECOND PULSE WIDTH':
+ self.find_second_pulse_width()
+ elif self.state == 'GET THIRD PULSE WIDTH':
+ self.find_third_pulse_width()
+ elif self.state == 'DECODE STREAM':
+ self.decode_stream()
+ elif self.state == 'DECODE PREAMBLE':
+ self.decode_preamble()