# 'signals': [{'SCL': }]}
#
+import sigrok
+
# States
FIND_START = 0
FIND_ADDRESS = 1
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'
# 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:
self.oldsda = sda
if out != []:
- sigrok.put(out)
-
-import sigrok
-
-sigrok.register(Decoder)
+ self.put(out)