X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fi2c%2Fi2c.py;h=53321eb02c401525e78fc3bd59774117a1078589;hb=f84d82c0aba0d249c085efa9532761941d0792b2;hp=2c11be096529549f0be4714a3c7a8f2c1dc1e2ab;hpb=2b7160383cc189f721600c04be17a980e216dfd6;p=libsigrokdecode.git diff --git a/decoders/i2c/i2c.py b/decoders/i2c/i2c.py index 2c11be0..53321eb 100644 --- a/decoders/i2c/i2c.py +++ b/decoders/i2c/i2c.py @@ -38,7 +38,7 @@ ANN_SHIFTED_SHORT = 1 ANN_RAW = 2 # Values are verbose and short annotation, respectively. -protocol = { +proto = { 'START': ['START', 'S'], 'START REPEAT': ['START REPEAT', 'Sr'], 'STOP': ['STOP', 'P'], @@ -55,7 +55,7 @@ class Decoder(srd.Decoder): id = 'i2c' name = 'I2C' longname = 'Inter-Integrated Circuit' - desc = 'I2C is a two-wire, multi-master, serial bus.' + desc = 'Two-wire, multi-master, serial bus.' license = 'gplv2+' inputs = ['logic'] outputs = ['i2c'] @@ -88,6 +88,7 @@ class Decoder(srd.Decoder): self.state = 'FIND START' self.oldscl = None self.oldsda = None + self.oldpins = None def start(self, metadata): self.out_proto = self.add(srd.OUTPUT_PROTO, 'i2c') @@ -119,8 +120,8 @@ class Decoder(srd.Decoder): cmd = 'START REPEAT' if (self.is_repeat_start == 1) else 'START' self.put(self.out_proto, [cmd, None]) - self.put(self.out_ann, [ANN_SHIFTED, [protocol[cmd][0]]]) - self.put(self.out_ann, [ANN_SHIFTED_SHORT, [protocol[cmd][1]]]) + self.put(self.out_ann, [ANN_SHIFTED, [proto[cmd][0]]]) + self.put(self.out_ann, [ANN_SHIFTED_SHORT, [proto[cmd][1]]]) self.state = 'FIND ADDRESS' self.bitcount = self.databyte = 0 @@ -165,8 +166,8 @@ class Decoder(srd.Decoder): cmd = 'DATA READ' self.put(self.out_proto, [cmd, d]) - self.put(self.out_ann, [ANN_SHIFTED, [protocol[cmd][0], '0x%02x' % d]]) - self.put(self.out_ann, [ANN_SHIFTED_SHORT, [protocol[cmd][1], '0x%02x' % d]]) + self.put(self.out_ann, [ANN_SHIFTED, [proto[cmd][0], '0x%02x' % d]]) + self.put(self.out_ann, [ANN_SHIFTED_SHORT, [proto[cmd][1], '0x%02x' % d]]) # Done with this packet. self.startsample = -1 @@ -177,8 +178,8 @@ class Decoder(srd.Decoder): self.startsample = self.samplenum ack_bit = 'NACK' if (sda == 1) else 'ACK' self.put(self.out_proto, [ack_bit, None]) - self.put(self.out_ann, [ANN_SHIFTED, [protocol[ack_bit][0]]]) - self.put(self.out_ann, [ANN_SHIFTED_SHORT, [protocol[ack_bit][1]]]) + self.put(self.out_ann, [ANN_SHIFTED, [proto[ack_bit][0]]]) + self.put(self.out_ann, [ANN_SHIFTED_SHORT, [proto[ack_bit][1]]]) # There could be multiple data bytes in a row, so either find # another data byte or a STOP condition next. self.state = 'FIND DATA' @@ -186,8 +187,8 @@ class Decoder(srd.Decoder): def found_stop(self, scl, sda): self.startsample = self.samplenum self.put(self.out_proto, ['STOP', None]) - self.put(self.out_ann, [ANN_SHIFTED, [protocol['STOP'][0]]]) - self.put(self.out_ann, [ANN_SHIFTED_SHORT, [protocol['STOP'][1]]]) + self.put(self.out_ann, [ANN_SHIFTED, [proto['STOP'][0]]]) + self.put(self.out_ann, [ANN_SHIFTED_SHORT, [proto['STOP'][1]]]) self.state = 'FIND START' self.is_repeat_start = 0 @@ -198,8 +199,12 @@ class Decoder(srd.Decoder): super(Decoder, self).put(self.startsample, self.samplenum, output_id, data) def decode(self, ss, es, data): - for samplenum, (scl, sda) in data: - self.samplenum = samplenum + for (self.samplenum, pins) in data: + + # Ignore identical samples early on (for performance reasons). + if self.oldpins == pins: + continue + self.oldpins, (scl, sda) = pins, pins # First sample: Save SCL/SDA value. if self.oldscl == None: