- ['Start', 'Start condition'],
- ['Repeat start', 'Repeat start condition'],
- ['Stop', 'Stop condition'],
- ['ACK', 'ACK'],
- ['NACK', 'NACK'],
- ['Address read', 'Address read'],
- ['Address write', 'Address write'],
- ['Data read', 'Data read'],
- ['Data write', 'Data write'],
- ['Warnings', 'Human-readable warnings'],
+ ['start', 'Start condition'],
+ ['repeat-start', 'Repeat start condition'],
+ ['stop', 'Stop condition'],
+ ['ack', 'ACK'],
+ ['nack', 'NACK'],
+ ['address-read', 'Address read'],
+ ['address-write', 'Address write'],
+ ['data-read', 'Data read'],
+ ['data-write', 'Data write'],
+ ['warnings', 'Human-readable warnings'],
+ binary = (
+ ('address-read', 'Address read'),
+ ('address-write', 'Address write'),
+ ('data-read', 'Data read'),
+ ('data-write', 'Data write'),
+ )
- def start(self):
- self.out_proto = self.add(srd.OUTPUT_PYTHON, 'i2c')
- self.out_ann = self.add(srd.OUTPUT_ANN, 'i2c')
+ def metadata(self, key, value):
+ if key == srd.SRD_CONF_SAMPLERATE:
+ self.samplerate = value
- def report(self):
- pass
+ def start(self):
+ self.out_proto = self.register(srd.OUTPUT_PYTHON)
+ self.out_ann = self.register(srd.OUTPUT_ANN)
+ self.out_binary = self.add(srd.OUTPUT_BINARY)
+ self.out_bitrate = self.register(srd.OUTPUT_META,
+ meta=(int, 'Bitrate', 'Bitrate from Start bit to Stop bit'))
def putx(self, data):
self.put(self.startsample, self.samplenum, self.out_ann, data)
def putx(self, data):
self.put(self.startsample, self.samplenum, self.out_ann, data)
def putp(self, data):
self.put(self.startsample, self.samplenum, self.out_proto, data)
def putp(self, data):
self.put(self.startsample, self.samplenum, self.out_proto, data)
def is_start_condition(self, scl, sda):
# START condition (S): SDA = falling, SCL = high
if (self.oldsda == 1 and sda == 0) and scl == 1:
def is_start_condition(self, scl, sda):
# START condition (S): SDA = falling, SCL = high
if (self.oldsda == 1 and sda == 0) and scl == 1:
def found_start(self, scl, sda):
self.startsample = self.samplenum
def found_start(self, scl, sda):
self.startsample = self.samplenum
cmd = 'START REPEAT' if (self.is_repeat_start == 1) else 'START'
self.putp([cmd, None])
self.putx([proto[cmd][0], proto[cmd][1:]])
cmd = 'START REPEAT' if (self.is_repeat_start == 1) else 'START'
self.putp([cmd, None])
self.putx([proto[cmd][0], proto[cmd][1:]])
self.putp([cmd, d])
self.putx([proto[cmd][0], ['%s: %02X' % (proto[cmd][1], d),
'%s: %02X' % (proto[cmd][2], d), '%02X' % d]])
self.putp([cmd, d])
self.putx([proto[cmd][0], ['%s: %02X' % (proto[cmd][1], d),
'%s: %02X' % (proto[cmd][2], d), '%02X' % d]])
+ # Meta bitrate
+ elapsed = 1 / float(self.samplerate) * (self.samplenum - self.pdu_start + 1)
+ bitrate = int(1 / elapsed * self.pdu_bits)
+ self.put(self.startsample, self.samplenum, self.out_bitrate, bitrate)
+
self.wr = -1
def decode(self, ss, es, data):
self.wr = -1
def decode(self, ss, es, data):
for (self.samplenum, pins) in data:
# Ignore identical samples early on (for performance reasons).
for (self.samplenum, pins) in data:
# Ignore identical samples early on (for performance reasons).
continue
self.oldpins, (scl, sda) = pins, pins
continue
self.oldpins, (scl, sda) = pins, pins