]> sigrok.org Git - libsigrokdecode.git/blame - decoders/ddc.py
srd: Finish consistency rename to ANN/PROTO.
[libsigrokdecode.git] / decoders / ddc.py
CommitLineData
7ce7775c
BV
1##
2## This file is part of the sigrok project.
3##
4## Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
5##
6## This program is free software; you can redistribute it and/or modify
7## it under the terms of the GNU General Public License as published by
8## the Free Software Foundation; either version 3 of the License, or
9## (at your option) any later version.
10##
11## This program is distributed in the hope that it will be useful,
12## but WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14## GNU General Public License for more details.
15##
16## You should have received a copy of the GNU General Public License
17## along with this program; if not, If not, see <http://www.gnu.org/licenses/>.
18##
19
20#
21# DDC protocol decoder
22#
23# This decoder extracts a DDC stream from an I2C session between a computer
24# and a display device. The stream is output as plain bytes.
25#
26
27import sigrokdecode
28
29
30class Decoder(sigrokdecode.Decoder):
31 id = 'ddc'
32 name = 'DDC'
33 longname = 'Display Data Channel'
34 desc = 'DDC is a protocol for communication between computers and displays.'
35 longdesc = ''
36 author = 'Bert Vermeulen <bert@biot.com>'
37 license = 'gplv3+'
38 inputs = ['i2c']
39 outputs = ['ddc']
40 annotation = [
41 ["Byte stream", "DDC byte stream as read from display."],
42 ]
43
44 def __init__(self, **kwargs):
45 self.state = None
46
47 def start(self, metadata):
94d43b37 48 self.out_ann = self.add(sigrokdecode.SRD_OUTPUT_ANN, 'ddc')
7ce7775c
BV
49
50 def decode(self, start_sample, end_sample, i2c_data):
51 try:
52 cmd, data, ack_bit = i2c_data
53 except Exception as e:
54 raise Exception("malformed I2C input: %s" % str(e)) from e
55
56 if self.state is None:
57 # waiting for the DDC session to start
58 if cmd in ('START', 'START_REPEAT'):
59 self.state = 'start'
60 elif self.state == 'start':
61 if cmd == 'ADDRESS_READ' and data == 80:
62 # 80 is the I2C slave address of a connected display,
63 # so this marks the start of the DDC data transfer.
64 self.state = 'transfer'
65 elif cmd == 'STOP':
66 # back to idle
67 self.state = None
68 elif self.state == 'transfer':
69 if cmd == 'DATA_READ':
70 # there shouldn't be anything but data reads on this
71 # address, so ignore everything else
c9b24fc3 72 self.put(start_sample, end_sample, self.out_ann,
7ce7775c
BV
73 [0, ["0x%.2x" % data]])
74