]>
Commit | Line | Data |
---|---|---|
91b2e171 | 1 | ## |
50bd5d25 | 2 | ## This file is part of the libsigrokdecode project. |
91b2e171 BV |
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, see <http://www.gnu.org/licenses/>. | |
18 | ## | |
19 | ||
91b2e171 BV |
20 | # TODO: |
21 | # - EDID < 1.3 | |
1063646c | 22 | # - add short annotations |
91b2e171 BV |
23 | # - Signal level standard field in basic display parameters block |
24 | # - Additional color point descriptors | |
25 | # - Additional standard timing descriptors | |
26 | # - Extensions | |
27 | ||
28 | import sigrokdecode as srd | |
29 | import os | |
30 | ||
31 | EDID_HEADER = [0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00] | |
32 | OFF_VENDOR = 8 | |
33 | OFF_VERSION = 18 | |
34 | OFF_BASIC = 20 | |
35 | OFF_CHROM = 25 | |
36 | OFF_EST_TIMING = 35 | |
37 | OFF_STD_TIMING = 38 | |
38 | OFF_DET_TIMING = 54 | |
39 | OFF_NUM_EXT = 126 | |
40 | OFF_CHECKSUM = 127 | |
41 | ||
91b2e171 BV |
42 | # Pre-EDID established timing modes |
43 | est_modes = [ | |
09059016 UH |
44 | '720x400@70Hz', |
45 | '720x400@88Hz', | |
46 | '640x480@60Hz', | |
47 | '640x480@67Hz', | |
48 | '640x480@72Hz', | |
49 | '640x480@75Hz', | |
50 | '800x600@56Hz', | |
51 | '800x600@60Hz', | |
52 | '800x600@72Hz', | |
53 | '800x600@75Hz', | |
54 | '832x624@75Hz', | |
55 | '1024x768@87Hz(i)', | |
56 | '1024x768@60Hz', | |
57 | '1024x768@70Hz', | |
58 | '1024x768@75Hz', | |
59 | '1280x1024@75Hz', | |
60 | '1152x870@75Hz', | |
91b2e171 BV |
61 | ] |
62 | ||
63 | # X:Y display aspect ratios, as used in standard timing modes | |
64 | xy_ratio = [ | |
65 | (16, 10), | |
66 | (4, 3), | |
67 | (5, 4), | |
e4f82268 | 68 | (16, 9), |
91b2e171 BV |
69 | ] |
70 | ||
5cdc02d4 | 71 | # Annotation classes |
91b2e171 BV |
72 | ANN_FIELDS = 0 |
73 | ANN_SECTIONS = 1 | |
74 | ||
75 | class Decoder(srd.Decoder): | |
2ba06442 | 76 | api_version = 3 |
91b2e171 BV |
77 | id = 'edid' |
78 | name = 'EDID' | |
b7a7e6f5 | 79 | longname = 'Extended Display Identification Data' |
a465436e | 80 | desc = 'Data structure describing display device capabilities.' |
91b2e171 | 81 | license = 'gplv3+' |
9e1437a0 | 82 | inputs = ['i2c'] |
91b2e171 | 83 | outputs = ['edid'] |
da9bcbd9 BV |
84 | annotations = ( |
85 | ('fields', 'EDID structure fields'), | |
86 | ('sections', 'EDID structure sections'), | |
87 | ) | |
be42cffc BV |
88 | annotation_rows = ( |
89 | ('sections', 'Sections', (1,)), | |
90 | ('fields', 'Fields', (0,)), | |
91 | ) | |
91b2e171 | 92 | |
92b7b49f | 93 | def __init__(self): |
2ba06442 UH |
94 | self.reset() |
95 | ||
96 | def reset(self): | |
91b2e171 BV |
97 | self.state = None |
98 | # Received data items, used as an index into samplenum/data | |
99 | self.cnt = 0 | |
100 | # Start/end sample numbers per data item | |
101 | self.sn = [] | |
102 | # Received data | |
103 | self.cache = [] | |
104 | ||
8915b346 | 105 | def start(self): |
be465111 | 106 | self.out_ann = self.register(srd.OUTPUT_ANN) |
91b2e171 BV |
107 | |
108 | def decode(self, ss, es, data): | |
48eee789 UH |
109 | cmd, data = data |
110 | ||
111 | # We only care about actual data bytes that are read (for now). | |
112 | if cmd != 'DATA READ': | |
113 | return | |
114 | ||
91b2e171 | 115 | self.cnt += 1 |
e4f82268 | 116 | self.sn.append([ss, es]) |
91b2e171 | 117 | self.cache.append(data) |
2a706c20 | 118 | # debug |
91b2e171 BV |
119 | |
120 | if self.state is None: | |
121 | # Wait for the EDID header | |
122 | if self.cnt >= OFF_VENDOR: | |
123 | if self.cache[-8:] == EDID_HEADER: | |
124 | # Throw away any garbage before the header | |
125 | self.sn = self.sn[-8:] | |
126 | self.cache = self.cache[-8:] | |
2a706c20 | 127 | self.cnt = 8 |
91b2e171 | 128 | self.state = 'edid' |
2ef80066 BV |
129 | self.put(self.sn[0][0], es, self.out_ann, |
130 | [ANN_SECTIONS, ['Header']]) | |
131 | self.put(self.sn[0][0], es, self.out_ann, | |
132 | [ANN_FIELDS, ['Header pattern']]) | |
91b2e171 BV |
133 | elif self.state == 'edid': |
134 | if self.cnt == OFF_VERSION: | |
135 | self.decode_vid(-10) | |
136 | self.decode_pid(-8) | |
137 | self.decode_serial(-6) | |
138 | self.decode_mfrdate(-2) | |
2ef80066 BV |
139 | self.put(self.sn[OFF_VENDOR][0], es, self.out_ann, |
140 | [ANN_SECTIONS, ['Vendor/product']]) | |
91b2e171 | 141 | elif self.cnt == OFF_BASIC: |
2ef80066 BV |
142 | self.put(self.sn[OFF_VERSION][0], es, self.out_ann, |
143 | [ANN_SECTIONS, ['EDID Version']]) | |
144 | self.put(self.sn[OFF_VERSION][0], self.sn[OFF_VERSION][1], | |
145 | self.out_ann, [ANN_FIELDS, | |
a9f7935a | 146 | ['Version %d' % self.cache[-2]]]) |
2ef80066 BV |
147 | self.put(self.sn[OFF_VERSION+1][0], self.sn[OFF_VERSION+1][1], |
148 | self.out_ann, [ANN_FIELDS, | |
a9f7935a | 149 | ['Revision %d' % self.cache[-1]]]) |
91b2e171 | 150 | elif self.cnt == OFF_CHROM: |
2ef80066 BV |
151 | self.put(self.sn[OFF_BASIC][0], es, self.out_ann, |
152 | [ANN_SECTIONS, ['Basic display']]) | |
91b2e171 BV |
153 | self.decode_basicdisplay(-5) |
154 | elif self.cnt == OFF_EST_TIMING: | |
2ef80066 BV |
155 | self.put(self.sn[OFF_CHROM][0], es, self.out_ann, |
156 | [ANN_SECTIONS, ['Color characteristics']]) | |
91b2e171 BV |
157 | self.decode_chromaticity(-10) |
158 | elif self.cnt == OFF_STD_TIMING: | |
2ef80066 BV |
159 | self.put(self.sn[OFF_EST_TIMING][0], es, self.out_ann, |
160 | [ANN_SECTIONS, ['Established timings']]) | |
91b2e171 BV |
161 | self.decode_est_timing(-3) |
162 | elif self.cnt == OFF_DET_TIMING: | |
2ef80066 BV |
163 | self.put(self.sn[OFF_STD_TIMING][0], es, self.out_ann, |
164 | [ANN_SECTIONS, ['Standard timings']]) | |
165 | self.decode_std_timing(self.cnt - 16) | |
91b2e171 BV |
166 | elif self.cnt == OFF_NUM_EXT: |
167 | self.decode_descriptors(-72) | |
168 | elif self.cnt == OFF_CHECKSUM: | |
09059016 UH |
169 | self.put(ss, es, self.out_ann, |
170 | [0, ['Extensions present: %d' % self.cache[self.cnt-1]]]) | |
91b2e171 BV |
171 | elif self.cnt == OFF_CHECKSUM+1: |
172 | checksum = 0 | |
173 | for i in range(128): | |
174 | checksum += self.cache[i] | |
175 | if checksum % 256 == 0: | |
09059016 | 176 | csstr = 'OK' |
91b2e171 | 177 | else: |
09059016 UH |
178 | csstr = 'WRONG!' |
179 | self.put(ss, es, self.out_ann, [0, ['Checksum: %d (%s)' % ( | |
180 | self.cache[self.cnt-1], csstr)]]) | |
91b2e171 BV |
181 | self.state = 'extensions' |
182 | elif self.state == 'extensions': | |
183 | pass | |
184 | ||
185 | def ann_field(self, start, end, annotation): | |
09059016 UH |
186 | self.put(self.sn[start][0], self.sn[end][1], |
187 | self.out_ann, [ANN_FIELDS, [annotation]]) | |
91b2e171 BV |
188 | |
189 | def lookup_pnpid(self, pnpid): | |
1063646c | 190 | pnpid_file = os.path.join(os.path.dirname(__file__), 'pnpids.txt') |
91b2e171 BV |
191 | if os.path.exists(pnpid_file): |
192 | for line in open(pnpid_file).readlines(): | |
193 | if line.find(pnpid + ';') == 0: | |
194 | return line[4:].strip() | |
195 | return '' | |
196 | ||
197 | def decode_vid(self, offset): | |
198 | pnpid = chr(64 + ((self.cache[offset] & 0x7c) >> 2)) | |
199 | pnpid += chr(64 + (((self.cache[offset] & 0x03) << 3) | |
200 | | ((self.cache[offset+1] & 0xe0) >> 5))) | |
201 | pnpid += chr(64 + (self.cache[offset+1] & 0x1f)) | |
202 | vendor = self.lookup_pnpid(pnpid) | |
203 | if vendor: | |
09059016 | 204 | pnpid += ' (%s)' % vendor |
91b2e171 BV |
205 | self.ann_field(offset, offset+1, pnpid) |
206 | ||
207 | def decode_pid(self, offset): | |
09059016 | 208 | pidstr = 'Product 0x%.2x%.2x' % (self.cache[offset+1], self.cache[offset]) |
91b2e171 BV |
209 | self.ann_field(offset, offset+1, pidstr) |
210 | ||
211 | def decode_serial(self, offset): | |
212 | serialnum = (self.cache[offset+3] << 24) \ | |
213 | + (self.cache[offset+2] << 16) \ | |
214 | + (self.cache[offset+1] << 8) \ | |
215 | + self.cache[offset] | |
216 | serialstr = '' | |
217 | is_alnum = True | |
218 | for i in range(4): | |
219 | if not chr(self.cache[offset+3-i]).isalnum(): | |
220 | is_alnum = False | |
221 | break | |
222 | serialstr += chr(self.cache[offset+3-i]) | |
09059016 UH |
223 | serial = serialstr if is_alnum else str(serialnum) |
224 | self.ann_field(offset, offset+3, 'Serial ' + serial) | |
91b2e171 BV |
225 | |
226 | def decode_mfrdate(self, offset): | |
227 | datestr = '' | |
228 | if self.cache[offset]: | |
09059016 | 229 | datestr += 'week %d, ' % self.cache[offset] |
91b2e171 BV |
230 | datestr += str(1990 + self.cache[offset+1]) |
231 | if datestr: | |
09059016 | 232 | self.ann_field(offset, offset+1, 'Manufactured ' + datestr) |
91b2e171 BV |
233 | |
234 | def decode_basicdisplay(self, offset): | |
235 | # Video input definition | |
236 | vid = self.cache[offset] | |
237 | if vid & 0x80: | |
238 | # Digital | |
09059016 | 239 | self.ann_field(offset, offset, 'Video input: VESA DFP 1.') |
91b2e171 BV |
240 | else: |
241 | # Analog | |
242 | sls = (vid & 60) >> 5 | |
09059016 | 243 | self.ann_field(offset, offset, 'Signal level standard: %.2x' % sls) |
91b2e171 | 244 | if vid & 0x10: |
09059016 | 245 | self.ann_field(offset, offset, 'Blank-to-black setup expected') |
91b2e171 BV |
246 | syncs = '' |
247 | if vid & 0x08: | |
248 | syncs += 'separate syncs, ' | |
249 | if vid & 0x04: | |
250 | syncs += 'composite syncs, ' | |
251 | if vid & 0x02: | |
252 | syncs += 'sync on green, ' | |
253 | if vid & 0x01: | |
254 | syncs += 'Vsync serration required, ' | |
255 | if syncs: | |
09059016 | 256 | self.ann_field(offset, offset, 'Supported syncs: %s' % syncs[:-2]) |
91b2e171 BV |
257 | # Max horizontal/vertical image size |
258 | if self.cache[offset+1] != 0 and self.cache[offset+2] != 0: | |
259 | # Projectors have this set to 0 | |
09059016 UH |
260 | sizestr = '%dx%dcm' % (self.cache[offset+1], self.cache[offset+2]) |
261 | self.ann_field(offset+1, offset+2, 'Physical size: ' + sizestr) | |
91b2e171 BV |
262 | # Display transfer characteristic (gamma) |
263 | if self.cache[offset+3] != 0xff: | |
264 | gamma = (self.cache[offset+3] + 100) / 100 | |
09059016 | 265 | self.ann_field(offset+3, offset+3, 'Gamma: %1.2f' % gamma) |
91b2e171 BV |
266 | # Feature support |
267 | fs = self.cache[offset+4] | |
268 | dpms = '' | |
269 | if fs & 0x80: | |
270 | dpms += 'standby, ' | |
271 | if fs & 0x40: | |
272 | dpms += 'suspend, ' | |
273 | if fs & 0x20: | |
274 | dpms += 'active off, ' | |
275 | if dpms: | |
09059016 | 276 | self.ann_field(offset+4, offset+4, 'DPMS support: %s' % dpms[:-2]) |
91b2e171 BV |
277 | dt = (fs & 0x18) >> 3 |
278 | dtstr = '' | |
279 | if dt == 0: | |
280 | dtstr = 'Monochrome' | |
281 | elif dt == 1: | |
282 | dtstr = 'RGB color' | |
283 | elif dt == 2: | |
e4f82268 | 284 | dtstr = 'non-RGB multicolor' |
91b2e171 | 285 | if dtstr: |
09059016 | 286 | self.ann_field(offset+4, offset+4, 'Display type: %s' % dtstr) |
91b2e171 | 287 | if fs & 0x04: |
09059016 | 288 | self.ann_field(offset+4, offset+4, 'Color space: standard sRGB') |
91b2e171 BV |
289 | # Save this for when we decode the first detailed timing descriptor |
290 | self.have_preferred_timing = (fs & 0x02) == 0x02 | |
291 | if fs & 0x01: | |
292 | gft = '' | |
293 | else: | |
294 | gft = 'not ' | |
09059016 UH |
295 | self.ann_field(offset+4, offset+4, |
296 | 'Generalized timing formula: %ssupported' % gft) | |
91b2e171 BV |
297 | |
298 | def convert_color(self, value): | |
299 | # Convert from 10-bit packet format to float | |
300 | outval = 0.0 | |
301 | for i in range(10): | |
302 | if value & 0x01: | |
303 | outval += 2 ** -(10-i) | |
304 | value >>= 1 | |
305 | return outval | |
306 | ||
307 | def decode_chromaticity(self, offset): | |
308 | redx = (self.cache[offset+2] << 2) + ((self.cache[offset] & 0xc0) >> 6) | |
309 | redy = (self.cache[offset+3] << 2) + ((self.cache[offset] & 0x30) >> 4) | |
09059016 UH |
310 | self.ann_field(offset, offset+9, 'Chromacity red: X %1.3f, Y %1.3f' % ( |
311 | self.convert_color(redx), self.convert_color(redy))) | |
91b2e171 BV |
312 | |
313 | greenx = (self.cache[offset+4] << 2) + ((self.cache[offset] & 0x0c) >> 6) | |
314 | greeny = (self.cache[offset+5] << 2) + ((self.cache[offset] & 0x03) >> 4) | |
09059016 UH |
315 | self.ann_field(offset, offset+9, 'Chromacity green: X %1.3f, Y %1.3f' % ( |
316 | self.convert_color(greenx), self.convert_color(greeny))) | |
91b2e171 BV |
317 | |
318 | bluex = (self.cache[offset+6] << 2) + ((self.cache[offset+1] & 0xc0) >> 6) | |
319 | bluey = (self.cache[offset+7] << 2) + ((self.cache[offset+1] & 0x30) >> 4) | |
09059016 UH |
320 | self.ann_field(offset, offset+9, 'Chromacity blue: X %1.3f, Y %1.3f' % ( |
321 | self.convert_color(bluex), self.convert_color(bluey))) | |
91b2e171 BV |
322 | |
323 | whitex = (self.cache[offset+8] << 2) + ((self.cache[offset+1] & 0x0c) >> 6) | |
324 | whitey = (self.cache[offset+9] << 2) + ((self.cache[offset+1] & 0x03) >> 4) | |
09059016 UH |
325 | self.ann_field(offset, offset+9, 'Chromacity white: X %1.3f, Y %1.3f' % ( |
326 | self.convert_color(whitex), self.convert_color(whitey))) | |
91b2e171 BV |
327 | |
328 | def decode_est_timing(self, offset): | |
329 | # Pre-EDID modes | |
330 | bitmap = (self.cache[offset] << 9) \ | |
331 | + (self.cache[offset+1] << 1) \ | |
332 | + ((self.cache[offset+2] & 0x80) >> 7) | |
333 | modestr = '' | |
334 | for i in range(17): | |
335 | if bitmap & (1 << (16-i)): | |
336 | modestr += est_modes[i] + ', ' | |
337 | if modestr: | |
09059016 | 338 | self.ann_field(offset, offset+2, |
868fd207 | 339 | 'Supported established modes: %s' % modestr[:-2]) |
91b2e171 BV |
340 | |
341 | def decode_std_timing(self, offset): | |
342 | modestr = '' | |
343 | for i in range(0, 16, 2): | |
344 | if self.cache[offset+i] == 0x01 and self.cache[offset+i+1] == 0x01: | |
345 | # Unused field | |
346 | continue | |
347 | x = (self.cache[offset+i] + 31) * 8 | |
348 | ratio = (self.cache[offset+i+1] & 0xc0) >> 6 | |
349 | ratio_x, ratio_y = xy_ratio[ratio] | |
350 | y = x / ratio_x * ratio_y | |
351 | refresh = (self.cache[offset+i+1] & 0x3f) + 60 | |
09059016 | 352 | modestr += '%dx%d@%dHz, ' % (x, y, refresh) |
91b2e171 | 353 | if modestr: |
2ef80066 BV |
354 | self.ann_field(offset, offset + 15, |
355 | 'Supported standard modes: %s' % modestr[:-2]) | |
91b2e171 BV |
356 | |
357 | def decode_detailed_timing(self, offset): | |
358 | if offset == -72 and self.have_preferred_timing: | |
359 | # Only on first detailed timing descriptor | |
360 | section = 'Preferred' | |
361 | else: | |
362 | section = 'Detailed' | |
363 | section += ' timing descriptor' | |
2ef80066 | 364 | self.put(self.sn[offset][0], self.sn[offset+17][1], |
91b2e171 BV |
365 | self.out_ann, [ANN_SECTIONS, [section]]) |
366 | ||
367 | pixclock = float((self.cache[offset+1] << 8) + self.cache[offset]) / 100 | |
09059016 | 368 | self.ann_field(offset, offset+1, 'Pixel clock: %.2f MHz' % pixclock) |
91b2e171 BV |
369 | |
370 | horiz_active = ((self.cache[offset+4] & 0xf0) << 4) + self.cache[offset+2] | |
09059016 | 371 | self.ann_field(offset+2, offset+4, 'Horizontal active: %d' % horiz_active) |
91b2e171 BV |
372 | |
373 | horiz_blank = ((self.cache[offset+4] & 0x0f) << 8) + self.cache[offset+3] | |
2ef80066 | 374 | self.ann_field(offset+2, offset+4, 'Horizontal blanking: %d' % horiz_blank) |
91b2e171 BV |
375 | |
376 | vert_active = ((self.cache[offset+7] & 0xf0) << 4) + self.cache[offset+5] | |
09059016 | 377 | self.ann_field(offset+5, offset+7, 'Vertical active: %d' % vert_active) |
91b2e171 BV |
378 | |
379 | vert_blank = ((self.cache[offset+7] & 0x0f) << 8) + self.cache[offset+6] | |
2ef80066 | 380 | self.ann_field(offset+5, offset+7, 'Vertical blanking: %d' % vert_blank) |
91b2e171 BV |
381 | |
382 | horiz_sync_off = ((self.cache[offset+11] & 0xc0) << 2) + self.cache[offset+8] | |
09059016 | 383 | self.ann_field(offset+8, offset+11, 'Horizontal sync offset: %d' % horiz_sync_off) |
91b2e171 BV |
384 | |
385 | horiz_sync_pw = ((self.cache[offset+11] & 0x30) << 4) + self.cache[offset+9] | |
2ef80066 | 386 | self.ann_field(offset+8, offset+11, 'Horizontal sync pulse width: %d' % horiz_sync_pw) |
91b2e171 BV |
387 | |
388 | vert_sync_off = ((self.cache[offset+11] & 0x0c) << 2) \ | |
389 | + ((self.cache[offset+10] & 0xf0) >> 4) | |
2ef80066 | 390 | self.ann_field(offset+8, offset+11, 'Vertical sync offset: %d' % vert_sync_off) |
91b2e171 BV |
391 | |
392 | vert_sync_pw = ((self.cache[offset+11] & 0x03) << 4) \ | |
393 | + (self.cache[offset+10] & 0x0f) | |
2ef80066 | 394 | self.ann_field(offset+8, offset+11, 'Vertical sync pulse width: %d' % vert_sync_pw) |
91b2e171 BV |
395 | |
396 | horiz_size = ((self.cache[offset+14] & 0xf0) << 4) + self.cache[offset+12] | |
397 | vert_size = ((self.cache[offset+14] & 0x0f) << 8) + self.cache[offset+13] | |
09059016 | 398 | self.ann_field(offset+12, offset+14, 'Physical size: %dx%dmm' % (horiz_size, vert_size)) |
91b2e171 BV |
399 | |
400 | horiz_border = self.cache[offset+15] | |
2ef80066 | 401 | self.ann_field(offset+15, offset+15, 'Horizontal border: %d pixels' % horiz_border) |
91b2e171 | 402 | vert_border = self.cache[offset+16] |
2ef80066 | 403 | self.ann_field(offset+16, offset+16, 'Vertical border: %d lines' % vert_border) |
91b2e171 BV |
404 | |
405 | features = 'Flags: ' | |
406 | if self.cache[offset+17] & 0x80: | |
407 | features += 'interlaced, ' | |
408 | stereo = (self.cache[offset+17] & 0x60) >> 5 | |
409 | if stereo: | |
410 | if self.cache[offset+17] & 0x01: | |
411 | features += '2-way interleaved stereo (' | |
09059016 UH |
412 | features += ['right image on even lines', |
413 | 'left image on even lines', | |
91b2e171 BV |
414 | 'side-by-side'][stereo-1] |
415 | features += '), ' | |
416 | else: | |
417 | features += 'field sequential stereo (' | |
418 | features += ['right image on sync=1', 'left image on sync=1', | |
419 | '4-way interleaved'][stereo-1] | |
420 | features += '), ' | |
421 | sync = (self.cache[offset+17] & 0x18) >> 3 | |
422 | sync2 = (self.cache[offset+17] & 0x06) >> 1 | |
423 | posneg = ['negative', 'positive'] | |
424 | features += 'sync type ' | |
425 | if sync == 0x00: | |
426 | features += 'analog composite (serrate on RGB)' | |
427 | elif sync == 0x01: | |
428 | features += 'bipolar analog composite (serrate on RGB)' | |
429 | elif sync == 0x02: | |
430 | features += 'digital composite (serrate on composite polarity ' \ | |
09059016 | 431 | + (posneg[sync2 & 0x01]) + ')' |
91b2e171 BV |
432 | elif sync == 0x03: |
433 | features += 'digital separate (' | |
2a706c20 | 434 | features += 'Vsync polarity ' + (posneg[(sync2 & 0x02) >> 1]) |
91b2e171 BV |
435 | features += ', Hsync polarity ' + (posneg[sync2 & 0x01]) |
436 | features += ')' | |
437 | features += ', ' | |
438 | self.ann_field(offset+17, offset+17, features[:-2]) | |
439 | ||
440 | def decode_descriptor(self, offset): | |
441 | tag = self.cache[offset+3] | |
442 | if tag == 0xff: | |
443 | # Monitor serial number | |
2ef80066 BV |
444 | self.put(self.sn[offset][0], self.sn[offset+17][1], self.out_ann, |
445 | [ANN_SECTIONS, ['Serial number']]) | |
91b2e171 | 446 | text = bytes(self.cache[offset+5:][:13]).decode(encoding='cp437', errors='replace') |
2ef80066 | 447 | self.ann_field(offset, offset+17, text.strip()) |
91b2e171 BV |
448 | elif tag == 0xfe: |
449 | # Text | |
2ef80066 BV |
450 | self.put(self.sn[offset][0], self.sn[offset+17][1], self.out_ann, |
451 | [ANN_SECTIONS, ['Text']]) | |
91b2e171 | 452 | text = bytes(self.cache[offset+5:][:13]).decode(encoding='cp437', errors='replace') |
2ef80066 | 453 | self.ann_field(offset, offset+17, text.strip()) |
91b2e171 BV |
454 | elif tag == 0xfc: |
455 | # Monitor name | |
2ef80066 BV |
456 | self.put(self.sn[offset][0], self.sn[offset+17][1], self.out_ann, |
457 | [ANN_SECTIONS, ['Monitor name']]) | |
91b2e171 | 458 | text = bytes(self.cache[offset+5:][:13]).decode(encoding='cp437', errors='replace') |
2ef80066 | 459 | self.ann_field(offset, offset+17, text.strip()) |
91b2e171 BV |
460 | elif tag == 0xfd: |
461 | # Monitor range limits | |
462 | self.put(self.sn[offset][0], self.sn[offset+17][1], self.out_ann, | |
09059016 UH |
463 | [ANN_SECTIONS, ['Monitor range limits']]) |
464 | self.ann_field(offset+5, offset+5, 'Minimum vertical rate: %dHz' % | |
91b2e171 | 465 | self.cache[offset+5]) |
09059016 | 466 | self.ann_field(offset+6, offset+6, 'Maximum vertical rate: %dHz' % |
91b2e171 | 467 | self.cache[offset+6]) |
09059016 | 468 | self.ann_field(offset+7, offset+7, 'Minimum horizontal rate: %dkHz' % |
91b2e171 | 469 | self.cache[offset+7]) |
09059016 | 470 | self.ann_field(offset+8, offset+8, 'Maximum horizontal rate: %dkHz' % |
91b2e171 | 471 | self.cache[offset+8]) |
09059016 | 472 | self.ann_field(offset+9, offset+9, 'Maximum pixel clock: %dMHz' % |
91b2e171 BV |
473 | (self.cache[offset+9] * 10)) |
474 | if self.cache[offset+10] == 0x02: | |
475 | # Secondary GTF curve supported | |
09059016 | 476 | self.ann_field(offset+10, offset+17, 'Secondary timing formula supported') |
91b2e171 BV |
477 | elif tag == 0xfb: |
478 | # Additional color point data | |
479 | self.put(self.sn[offset][0], self.sn[offset+17][1], self.out_ann, | |
09059016 | 480 | [ANN_SECTIONS, ['Additional color point data']]) |
91b2e171 BV |
481 | elif tag == 0xfa: |
482 | # Additional standard timing definitions | |
483 | self.put(self.sn[offset][0], self.sn[offset+17][1], self.out_ann, | |
09059016 | 484 | [ANN_SECTIONS, ['Additional standard timing definitions']]) |
91b2e171 BV |
485 | else: |
486 | self.put(self.sn[offset][0], self.sn[offset+17][1], self.out_ann, | |
09059016 | 487 | [ANN_SECTIONS, ['Unknown descriptor']]) |
91b2e171 BV |
488 | |
489 | def decode_descriptors(self, offset): | |
490 | # 4 consecutive 18-byte descriptor blocks | |
491 | for i in range(offset, 0, 18): | |
492 | if self.cache[i] != 0 and self.cache[i+1] != 0: | |
493 | self.decode_detailed_timing(i) | |
494 | else: | |
1063646c | 495 | if self.cache[i+2] == 0 or self.cache[i+4] == 0: |
91b2e171 | 496 | self.decode_descriptor(i) |