]> sigrok.org Git - libsigrokdecode.git/blame - decoders/ddc.py
srd: Bring back small stuff lost in the merge.
[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##
9e587cc9
UH
19
20'''
87998e97
BV
21This decoder extracts a DDC stream from an I2C session between a computer
22and a display device. The stream is output as plain bytes.
7ce7775c 23
87998e97
BV
24Details:
25https://en.wikipedia.org/wiki/Display_Data_Channel
9e587cc9 26'''
7ce7775c 27
677d597b 28import sigrokdecode as srd
7ce7775c 29
677d597b 30class Decoder(srd.Decoder):
7ce7775c
BV
31 id = 'ddc'
32 name = 'DDC'
33 longname = 'Display Data Channel'
eb7082c9 34 desc = 'A protocol for communication between computers and displays.'
7ce7775c 35 longdesc = ''
526e5804
UH
36 author = 'Bert Vermeulen'
37 email = 'bert@biot.com'
7ce7775c
BV
38 license = 'gplv3+'
39 inputs = ['i2c']
40 outputs = ['ddc']
9a12a6e7
UH
41 probes = []
42 options = {}
e97b6ef5 43 annotations = [
eb7082c9 44 ['Byte stream', 'DDC byte stream as read from display.'],
7ce7775c
BV
45 ]
46
47 def __init__(self, **kwargs):
48 self.state = None
49
50 def start(self, metadata):
56202222 51 self.out_ann = self.add(srd.OUTPUT_ANN, 'ddc')
7ce7775c 52
2b9837d9 53 def decode(self, ss, es, data):
7ce7775c 54 try:
2b9837d9 55 cmd, data, ack_bit = data
7ce7775c 56 except Exception as e:
eb7082c9 57 raise Exception('malformed I2C input: %s' % str(e)) from e
7ce7775c
BV
58
59 if self.state is None:
eb7082c9 60 # Wait for the DDC session to start.
a2d2aff2 61 if cmd in ('START', 'START REPEAT'):
7ce7775c
BV
62 self.state = 'start'
63 elif self.state == 'start':
a2d2aff2 64 if cmd == 'ADDRESS READ' and data == 80:
7ce7775c
BV
65 # 80 is the I2C slave address of a connected display,
66 # so this marks the start of the DDC data transfer.
67 self.state = 'transfer'
68 elif cmd == 'STOP':
eb7082c9 69 # Got back to the idle state.
7ce7775c
BV
70 self.state = None
71 elif self.state == 'transfer':
a2d2aff2 72 if cmd == 'DATA READ':
eb7082c9
UH
73 # There shouldn't be anything but data reads on this
74 # address, so ignore everything else.
2b9837d9 75 self.put(ss, es, self.out_ann, [0, ['0x%.2x' % data]])
7ce7775c 76