X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fi2c%2Fpd.py;h=0408c7d40c6ec7c4bf5f1cc9c773d4ba3b98e001;hb=1f6f2ad8c33e58cfd40ea0370e6d2dfbd6040026;hp=6bf12b97e525721b149ca3d42a0478f06e3f0906;hpb=6a15597a7b3f901b566b7bfc8c484a14e0fb6a11;p=libsigrokdecode.git diff --git a/decoders/i2c/pd.py b/decoders/i2c/pd.py index 6bf12b9..0408c7d 100644 --- a/decoders/i2c/pd.py +++ b/decoders/i2c/pd.py @@ -28,10 +28,10 @@ import sigrokdecode as srd ''' OUTPUT_PYTHON format: -I²C packet: -[, ] +Packet: +[, ] - is one of: +: - 'START' (START condition) - 'START REPEAT' (Repeated START condition) - 'ADDRESS READ' (Slave address, read) @@ -41,12 +41,12 @@ I²C packet: - 'STOP' (STOP condition) - 'ACK' (ACK bit) - 'NACK' (NACK bit) - - 'BITS' (: list of data/address bits and their ss/es numbers) + - 'BITS' (: list of data/address bits and their ss/es numbers) - is the data or address byte associated with the 'ADDRESS*' and 'DATA*' + is the data or address byte associated with the 'ADDRESS*' and 'DATA*' command. Slave addresses do not include bit 0 (the READ/WRITE indication bit). For example, a slave address field could be 0x51 (instead of 0xa2). -For 'START', 'START REPEAT', 'STOP', 'ACK', and 'NACK' is None. +For 'START', 'START REPEAT', 'STOP', 'ACK', and 'NACK' is None. ''' # CMD: [annotation-type-index, long annotation, short annotation] @@ -63,8 +63,11 @@ proto = { 'DATA WRITE': [9, 'Data write', 'DW'], } +class SamplerateError(Exception): + pass + class Decoder(srd.Decoder): - api_version = 1 + api_version = 2 id = 'i2c' name = 'I²C' longname = 'Inter-Integrated Circuit' @@ -265,8 +268,8 @@ class Decoder(srd.Decoder): self.bits = [] 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, pins) in data: # Ignore identical samples early on (for performance reasons). @@ -293,9 +296,6 @@ class Decoder(srd.Decoder): elif self.state == 'FIND ACK': if self.is_data_bit(scl, sda): self.get_ack(scl, sda) - else: - raise Exception('Invalid state: %s' % self.state) # Save current SDA/SCL values for the next round. self.oldscl, self.oldsda = scl, sda -