X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fi2cfilter%2Fi2cfilter.py;h=64010cb2a3f0404aba7e79031fa3b058f614144c;hb=080243a8224c8453c4993ad22f5bdc63e1dba2de;hp=4b88befbcfa147ec9ed838daa8ac1190073d0a24;hpb=61c2bd366eba64b50009c604c382c547f6cfdd88;p=libsigrokdecode.git diff --git a/decoders/i2cfilter/i2cfilter.py b/decoders/i2cfilter/i2cfilter.py index 4b88bef..64010cb 100644 --- a/decoders/i2cfilter/i2cfilter.py +++ b/decoders/i2cfilter/i2cfilter.py @@ -17,22 +17,26 @@ ## along with this program; if not, see . ## -import sigrokdecode as srd +# Generic I2C filtering protocol decoder +import sigrokdecode as srd class Decoder(srd.Decoder): api_version = 1 id = 'i2cfilter' name = 'I2C filter' longname = 'I2C filter' - desc = 'Filter out specific addresses/directions in an I2C stream.' + desc = 'Filter out addresses/directions in an I2C stream.' license = 'gplv3+' inputs = ['i2c'] outputs = [] + probes = [] + optional_probes = [] options = { 'address': ['Address to filter out of the I2C stream', 0], 'direction': ['Direction to filter (read/write)', ''] } + annotations = [] def __init__(self, **kwargs): self.state = None @@ -40,11 +44,14 @@ class Decoder(srd.Decoder): def start(self, metadata): self.out_proto = self.add(srd.OUTPUT_PROTO, 'i2cdata') if self.options['direction'] not in ('', 'read', 'write'): - raise Exception("Invalid direction: expected 'read' or 'write'") + raise Exception('Invalid direction: expected "read" or "write"') + + def report(self): + pass def decode(self, ss, es, data): try: - cmd, data, ack_bit = data + cmd, data = data except Exception as e: raise Exception('Malformed I2C input: %s' % str(e)) from e @@ -56,6 +63,9 @@ class Decoder(srd.Decoder): if cmd == 'STOP': self.state = None return + if cmd in ('ACK', 'NACK'): + # Don't care, we just want data. + return if self.state == 'start': # Start of a transfer, see if we want this one. @@ -73,4 +83,3 @@ class Decoder(srd.Decoder): else: raise Exception('Invalid state: %s' % self.state) -