]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/i2c.py
srd: Consistent PD option defaults handling.
[libsigrokdecode.git] / decoders / i2c.py
index edaeb9487b7c782c2479c2168ea5028907fd30d1..b0273c092b453cc105d3efabb259d5b206e1fb90 100644 (file)
@@ -120,7 +120,7 @@ FIND_DATA = 2
 class Decoder(srd.Decoder):
     id = 'i2c'
     name = 'I2C'
-    longname = 'Inter-Integrated Circuit (I2C) bus'
+    longname = 'Inter-Integrated Circuit'
     desc = 'I2C is a two-wire, multi-master, serial bus.'
     longdesc = '...'
     author = 'Uwe Hermann'
@@ -133,7 +133,7 @@ class Decoder(srd.Decoder):
         {'id': 'sda', 'name': 'SDA', 'desc': 'Serial data line'},
     ]
     options = {
-        'address-space': ['Address space (in bits)', 7],
+        'addressing': ['Slave addressing (in bits)', 7], # 7 or 10
     }
     annotations = [
         # ANN_SHIFTED
@@ -157,6 +157,9 @@ class Decoder(srd.Decoder):
         self.oldscl = None
         self.oldsda = None
 
+        # Set protocol decoder option defaults.
+        self.addressing = Decoder.options['addressing'][1]
+
     def start(self, metadata):
         self.out_proto = self.add(srd.OUTPUT_PROTO, 'i2c')
         self.out_ann = self.add(srd.OUTPUT_ANN, 'i2c')
@@ -183,10 +186,7 @@ class Decoder(srd.Decoder):
         return False
 
     def found_start(self, scl, sda):
-        if self.is_repeat_start == 1:
-            cmd = 'START_REPEAT'
-        else:
-            cmd = 'START'
+        cmd = 'START_REPEAT' if (self.is_repeat_start == 1) else 'START'
 
         self.put(self.out_proto, [cmd, None, None])
         self.put(self.out_ann, [ANN_SHIFTED, [protocol[cmd][0]]])
@@ -222,10 +222,7 @@ class Decoder(srd.Decoder):
 
         if self.state == FIND_ADDRESS:
             # The READ/WRITE bit is only in address bytes, not data bytes.
-            if self.databyte & 1:
-                self.wr = 0
-            else:
-                self.wr = 1
+            self.wr = 0 if (self.databyte & 1) else 1
             d = self.databyte >> 1
         elif self.state == FIND_DATA:
             d = self.databyte
@@ -234,10 +231,7 @@ class Decoder(srd.Decoder):
             pass
 
         # Last bit that came in was the ACK/NACK bit (1 = NACK).
-        if sda == 1:
-            ack_bit = 'NACK'
-        else:
-            ack_bit = 'ACK'
+        ack_bit = 'NACK' if (sda == 1) else 'ACK'
 
         if self.state == FIND_ADDRESS and self.wr == 1:
             cmd = 'ADDRESS_WRITE'
@@ -249,16 +243,10 @@ class Decoder(srd.Decoder):
             cmd = 'DATA_READ'
 
         self.put(self.out_proto, [cmd, d, ack_bit])
-        self.put(self.out_ann, [ANN_SHIFTED, [
-                '%s' % protocol[cmd][0],
-                '0x%02x' % d,
-                '%s' % protocol[ack_bit][0]]
-            ])
-        self.put(self.out_ann, [ANN_SHIFTED_SHORT, [
-                '%s' % protocol[cmd][1],
-                '0x%02x' % d,
-                '%s' % protocol[ack_bit][1]]
-            ])
+        self.put(self.out_ann, [ANN_SHIFTED,
+                 [protocol[cmd][0], '0x%02x' % d, protocol[ack_bit][0]]])
+        self.put(self.out_ann, [ANN_SHIFTED_SHORT,
+                 [protocol[cmd][1], '0x%02x' % d, protocol[ack_bit][1]]])
 
         self.bitcount = self.databyte = 0
         self.startsample = -1
@@ -284,7 +272,7 @@ class Decoder(srd.Decoder):
         # TODO: 0-0 sample range for now.
         super(Decoder, self).put(0, 0, output_id, data)
 
-    def decode(self, timeoffset, duration, data):
+    def decode(self, ss, es, data):
         for samplenum, (scl, sda) in data:
             self.samplecnt += 1