X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fi2s%2Fpd.py;h=dc42a4e5d1900a84d892554ed655006fd8b56781;hb=22fc7ace72f3165c98208a8f544156e04a709639;hp=3064b7dae026cb0fafa2eca9bdc6732f8275f9f9;hpb=ef36224880135a05d2fbde8f048ea3fe3f425df9;p=libsigrokdecode.git diff --git a/decoders/i2s/pd.py b/decoders/i2s/pd.py index 3064b7d..dc42a4e 100644 --- a/decoders/i2s/pd.py +++ b/decoders/i2s/pd.py @@ -21,7 +21,7 @@ import sigrokdecode as srd ''' -Protocol output format: +OUTPUT_PYTHON format: Packet: [, ] @@ -33,8 +33,11 @@ Packet: : integer ''' +class SamplerateError(Exception): + pass + class Decoder(srd.Decoder): - api_version = 1 + api_version = 2 id = 'i2s' name = 'I²S' longname = 'Integrated Interchip Sound' @@ -42,18 +45,16 @@ class Decoder(srd.Decoder): license = 'gplv2+' inputs = ['logic'] outputs = ['i2s'] - probes = [ + channels = ( {'id': 'sck', 'name': 'SCK', 'desc': 'Bit clock line'}, {'id': 'ws', 'name': 'WS', 'desc': 'Word select line'}, {'id': 'sd', 'name': 'SD', 'desc': 'Serial data line'}, - ] - optional_probes = [] - options = {} - annotations = [ - ['left', 'Left channel'], - ['right', 'Right channel'], - ['warnings', 'Warnings'], - ] + ) + annotations = ( + ('left', 'Left channel'), + ('right', 'Right channel'), + ('warnings', 'Warnings'), + ) binary = ( ('wav', 'WAV file'), ) @@ -71,7 +72,7 @@ class Decoder(srd.Decoder): self.wrote_wav_header = False def start(self): - self.out_proto = self.register(srd.OUTPUT_PYTHON) + self.out_python = self.register(srd.OUTPUT_PYTHON) self.out_bin = self.register(srd.OUTPUT_BINARY) self.out_ann = self.register(srd.OUTPUT_ANN) @@ -80,7 +81,7 @@ class Decoder(srd.Decoder): self.samplerate = value def putpb(self, data): - self.put(self.start_sample, self.samplenum, self.out_proto, data) + self.put(self.start_sample, self.samplenum, self.out_python, data) def putbin(self, data): self.put(self.start_sample, self.samplenum, self.out_bin, data) @@ -130,8 +131,8 @@ class Decoder(srd.Decoder): return bytes([lo, hi]) def decode(self, ss, es, data): - if self.samplerate is None: - raise Exception("Cannot decode without samplerate.") + if not self.samplerate: + raise SamplerateError('Cannot decode without samplerate.') for self.samplenum, (sck, ws, sd) in data: # Ignore sample if the bit clock hasn't changed.