]>
Commit | Line | Data |
---|---|---|
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 | # | |
eb7082c9 UH |
26 | # Details: |
27 | # https://en.wikipedia.org/wiki/Display_Data_Channel | |
28 | # | |
7ce7775c | 29 | |
677d597b | 30 | import sigrokdecode as srd |
7ce7775c | 31 | |
677d597b | 32 | class Decoder(srd.Decoder): |
7ce7775c BV |
33 | id = 'ddc' |
34 | name = 'DDC' | |
35 | longname = 'Display Data Channel' | |
eb7082c9 | 36 | desc = 'A protocol for communication between computers and displays.' |
7ce7775c BV |
37 | longdesc = '' |
38 | author = 'Bert Vermeulen <bert@biot.com>' | |
9a12a6e7 | 39 | email = '<bert@biot.com>' |
7ce7775c BV |
40 | license = 'gplv3+' |
41 | inputs = ['i2c'] | |
42 | outputs = ['ddc'] | |
9a12a6e7 UH |
43 | probes = [] |
44 | options = {} | |
e97b6ef5 | 45 | annotations = [ |
eb7082c9 | 46 | ['Byte stream', 'DDC byte stream as read from display.'], |
7ce7775c BV |
47 | ] |
48 | ||
49 | def __init__(self, **kwargs): | |
50 | self.state = None | |
51 | ||
52 | def start(self, metadata): | |
56202222 | 53 | self.out_ann = self.add(srd.OUTPUT_ANN, 'ddc') |
7ce7775c BV |
54 | |
55 | def decode(self, start_sample, end_sample, i2c_data): | |
56 | try: | |
57 | cmd, data, ack_bit = i2c_data | |
58 | except Exception as e: | |
eb7082c9 | 59 | raise Exception('malformed I2C input: %s' % str(e)) from e |
7ce7775c BV |
60 | |
61 | if self.state is None: | |
eb7082c9 | 62 | # Wait for the DDC session to start. |
7ce7775c BV |
63 | if cmd in ('START', 'START_REPEAT'): |
64 | self.state = 'start' | |
65 | elif self.state == 'start': | |
66 | if cmd == 'ADDRESS_READ' and data == 80: | |
67 | # 80 is the I2C slave address of a connected display, | |
68 | # so this marks the start of the DDC data transfer. | |
69 | self.state = 'transfer' | |
70 | elif cmd == 'STOP': | |
eb7082c9 | 71 | # Got back to the idle state. |
7ce7775c BV |
72 | self.state = None |
73 | elif self.state == 'transfer': | |
74 | if cmd == 'DATA_READ': | |
eb7082c9 UH |
75 | # There shouldn't be anything but data reads on this |
76 | # address, so ignore everything else. | |
c9b24fc3 | 77 | self.put(start_sample, end_sample, self.out_ann, |
eb7082c9 | 78 | [0, ['0x%.2x' % data]]) |
7ce7775c | 79 |