X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Fddc.py;h=9b5bc5fdd525a053892993a8e32362c12305792d;hp=c4978c9f0b4edb044027bbaad51595b0991920a9;hb=2b9837d9fc5f9b4eca52327527e18db4bfb730ff;hpb=c9b24fc3d2f8c84338f07239edc1d4850164ae0c diff --git a/decoders/ddc.py b/decoders/ddc.py index c4978c9..9b5bc5f 100644 --- a/decoders/ddc.py +++ b/decoders/ddc.py @@ -23,38 +23,43 @@ # This decoder extracts a DDC stream from an I2C session between a computer # and a display device. The stream is output as plain bytes. # +# Details: +# https://en.wikipedia.org/wiki/Display_Data_Channel +# -import sigrokdecode - +import sigrokdecode as srd -class Decoder(sigrokdecode.Decoder): +class Decoder(srd.Decoder): id = 'ddc' name = 'DDC' longname = 'Display Data Channel' - desc = 'DDC is a protocol for communication between computers and displays.' + desc = 'A protocol for communication between computers and displays.' longdesc = '' author = 'Bert Vermeulen ' + email = '' license = 'gplv3+' inputs = ['i2c'] outputs = ['ddc'] - annotation = [ - ["Byte stream", "DDC byte stream as read from display."], + probes = [] + options = {} + annotations = [ + ['Byte stream', 'DDC byte stream as read from display.'], ] def __init__(self, **kwargs): self.state = None def start(self, metadata): - self.out_ann = self.add(sigrokdecode.SRD_OUTPUT_ANNOTATION, 'ddc') + self.out_ann = self.add(srd.OUTPUT_ANN, 'ddc') - def decode(self, start_sample, end_sample, i2c_data): + def decode(self, ss, es, data): try: - cmd, data, ack_bit = i2c_data + cmd, data, ack_bit = data except Exception as e: - raise Exception("malformed I2C input: %s" % str(e)) from e + raise Exception('malformed I2C input: %s' % str(e)) from e if self.state is None: - # waiting for the DDC session to start + # Wait for the DDC session to start. if cmd in ('START', 'START_REPEAT'): self.state = 'start' elif self.state == 'start': @@ -63,12 +68,11 @@ class Decoder(sigrokdecode.Decoder): # so this marks the start of the DDC data transfer. self.state = 'transfer' elif cmd == 'STOP': - # back to idle + # Got back to the idle state. self.state = None elif self.state == 'transfer': if cmd == 'DATA_READ': - # there shouldn't be anything but data reads on this - # address, so ignore everything else - self.put(start_sample, end_sample, self.out_ann, - [0, ["0x%.2x" % data]]) + # There shouldn't be anything but data reads on this + # address, so ignore everything else. + self.put(ss, es, self.out_ann, [0, ['0x%.2x' % data]])