X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fi2c%2Fpd.py;h=e70c27de27b301ffcc52d12bf800f141263d3eb1;hb=d1b7bd1b602149cef4183f5a05188c0467bcd280;hp=6172fb438c50f9295c8786fe47d0d9672e4e4f85;hpb=4539e9ca58966ce3c9cad4801b16c315e86ace01;p=libsigrokdecode.git diff --git a/decoders/i2c/pd.py b/decoders/i2c/pd.py index 6172fb4..e70c27d 100644 --- a/decoders/i2c/pd.py +++ b/decoders/i2c/pd.py @@ -18,7 +18,6 @@ ## # TODO: Look into arbitration, collision detection, clock synchronisation, etc. -# TODO: Implement support for 10bit slave addresses. # TODO: Implement support for inverting SDA/SCL levels (0->1 and 1->0). # TODO: Implement support for detecting various bus errors. @@ -62,9 +61,6 @@ proto = { 'DATA WRITE': [9, 'Data write', 'DW'], } -class SamplerateError(Exception): - pass - class Decoder(srd.Decoder): api_version = 3 id = 'i2c' @@ -108,6 +104,9 @@ class Decoder(srd.Decoder): ) def __init__(self): + self.reset() + + def reset(self): self.samplerate = None self.ss = self.es = self.ss_byte = -1 self.bitcount = 0 @@ -130,10 +129,6 @@ class Decoder(srd.Decoder): self.out_bitrate = self.register(srd.OUTPUT_META, meta=(int, 'Bitrate', 'Bitrate from Start bit to Stop bit')) - # Assume that the initial SCL/SDA pin state is high (logic 1). - # This is a good default, since both pins have pullups as per spec. - self.initial_pins = [1, 1] - def putx(self, data): self.put(self.ss, self.es, self.out_ann, data) @@ -240,9 +235,10 @@ class Decoder(srd.Decoder): def handle_stop(self, pins): # Meta bitrate - elapsed = 1 / float(self.samplerate) * (self.samplenum - self.pdu_start + 1) - bitrate = int(1 / elapsed * self.pdu_bits) - self.put(self.ss_byte, self.samplenum, self.out_bitrate, bitrate) + if self.samplerate: + elapsed = 1 / float(self.samplerate) * (self.samplenum - self.pdu_start + 1) + bitrate = int(1 / elapsed * self.pdu_bits) + self.put(self.ss_byte, self.samplenum, self.out_bitrate, bitrate) cmd = 'STOP' self.ss, self.es = self.samplenum, self.samplenum @@ -254,11 +250,6 @@ class Decoder(srd.Decoder): self.bits = [] def decode(self): - if not self.samplerate: - raise SamplerateError('Cannot decode without samplerate.') - - self.wait({}) - while True: # State machine. if self.state == 'FIND START': @@ -272,8 +263,7 @@ class Decoder(srd.Decoder): # a) Data sampling of receiver: SCL = rising, and/or # b) START condition (S): SCL = high, SDA = falling, and/or # c) STOP condition (P): SCL = high, SDA = rising - conds = [{0: 'r'}, {0: 'h', 1: 'f'}, {0: 'h', 1: 'r'}] - pins = self.wait(conds[:]) # TODO + pins = self.wait([{0: 'r'}, {0: 'h', 1: 'f'}, {0: 'h', 1: 'r'}]) # Check which of the condition(s) matched and handle them. if self.matched[0]: