X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fi2s%2Fpd.py;h=8b45a752cbae2c750581a511cff382002734934e;hb=dfbe1fb2a602114f74cc4f7e3610204dbb559012;hp=73bfa6f634bec9547fb387233ec469df59e1054c;hpb=c515eed7ef7a04a42b5b34abd308e08d6942835e;p=libsigrokdecode.git diff --git a/decoders/i2s/pd.py b/decoders/i2s/pd.py index 73bfa6f..8b45a75 100644 --- a/decoders/i2s/pd.py +++ b/decoders/i2s/pd.py @@ -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'), ) @@ -92,8 +93,8 @@ class Decoder(srd.Decoder): # Calculate the sample rate. samplerate = '?' - if self.start_sample != None and \ - self.first_sample != None and \ + if self.start_sample is not None and \ + self.first_sample is not None and \ self.start_sample > self.first_sample: samplerate = '%d' % (self.samplesreceived * self.samplerate / (self.start_sample - @@ -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. @@ -150,7 +151,7 @@ class Decoder(srd.Decoder): continue # Only submit the sample, if we received the beginning of it. - if self.start_sample != None: + if self.start_sample is not None: if not self.wrote_wav_header: self.put(0, 0, self.out_bin, (0, self.wav_header())) @@ -181,8 +182,7 @@ class Decoder(srd.Decoder): self.start_sample = self.samplenum # Save the first sample position. - if self.first_sample == None: + if self.first_sample is None: self.first_sample = self.samplenum self.oldws = ws -