X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Fi2c.py;h=659ea553b6c77949684c849ab1337749d303e45c;hp=93cf16757a438dbafcbb5d70e431bdc4bc6dca59;hb=1b1c914fe5c1b88db6e0b8e49bee896428d483cb;hpb=400f9ae7ff16bb611d758d75ff4931b667561b11 diff --git a/decoders/i2c.py b/decoders/i2c.py index 93cf167..659ea55 100644 --- a/decoders/i2c.py +++ b/decoders/i2c.py @@ -126,6 +126,8 @@ # 'signals': [{'SCL': }]} # +import sigrok + # States FIND_START = 0 FIND_ADDRESS = 1 @@ -142,7 +144,8 @@ def sampleiter(data, unitsize): for i in range(0, len(data), unitsize): yield(Sample(data[i:i+unitsize])) -class Decoder(): +class Decoder(sigrok.Decoder): + id = 'i2c' name = 'I2C' longname = 'Inter-Integrated Circuit (I2C) bus' desc = 'I2C is a two-wire, multi-master, serial bus.' @@ -237,12 +240,12 @@ class Decoder(): # We received 8 address/data bits and the ACK/NACK bit. self.databyte >>= 1 # Shift out unwanted ACK/NACK bit here. - ack = (sda == 1) and 'N' or 'A' + ack = 'N' if (sda == 1) else 'A' if self.state == FIND_ADDRESS: d = self.databyte & 0xfe # The READ/WRITE bit is only in address bytes, not data bytes. - self.wr = (self.databyte & 1) and 1 or 0 + self.wr = 1 if (self.databyte & 1) else 0 elif self.state == FIND_DATA: d = self.databyte else: @@ -347,7 +350,5 @@ class Decoder(): self.oldsda = sda if out != []: - sigrok.put(out) - -import sigrok + self.put(out)