| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1 | -- |
| 2 | -- Copyright (C) 2016 secunet Security Networks AG |
| 3 | -- |
| 4 | -- This program is free software; you can redistribute it and/or modify |
| 5 | -- it under the terms of the GNU General Public License as published by |
| Nico Huber | 125a29e | 2016-10-18 00:23:54 +0200 | [diff] [blame] | 6 | -- the Free Software Foundation; either version 2 of the License, or |
| 7 | -- (at your option) any later version. |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 8 | -- |
| 9 | -- This program is distributed in the hope that it will be useful, |
| 10 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | -- GNU General Public License for more details. |
| 13 | -- |
| 14 | |
| 15 | package HW.GFX.EDID |
| 16 | is |
| 17 | |
| 18 | use type Word8; |
| 19 | use type Word16; |
| 20 | |
| 21 | subtype Raw_EDID_Index is Natural range 0 .. 127; |
| 22 | subtype Raw_EDID_Data is Buffer (Raw_EDID_Index); |
| 23 | |
| 24 | function Valid (Raw_EDID : Raw_EDID_Data) return Boolean; |
| Nico Huber | 88a7f17 | 2016-11-18 21:19:46 +0100 | [diff] [blame] | 25 | procedure Sanitize (Raw_EDID : in out Raw_EDID_Data; Success : out Boolean) |
| 26 | with |
| 27 | Post => (if Success then Valid (Raw_EDID)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 28 | |
| 29 | DESCRIPTOR_1 : constant := 54; |
| 30 | |
| 31 | function Read_LE16 |
| 32 | (Raw_EDID : Raw_EDID_Data; |
| 33 | Offset : Raw_EDID_Index) |
| 34 | return Word16 |
| 35 | with |
| 36 | Pre => Offset < Raw_EDID_Index'Last; |
| 37 | |
| Nico Huber | 393aa8a | 2016-10-21 14:18:53 +0200 | [diff] [blame] | 38 | function Compatible_Display |
| 39 | (Raw_EDID : Raw_EDID_Data; |
| 40 | Display : Display_Type) |
| 41 | return Boolean |
| 42 | with |
| 43 | Pre => Valid (Raw_EDID); |
| 44 | |
| Nico Huber | 7eb1350 | 2018-06-04 14:42:13 +0200 | [diff] [blame] | 45 | function Has_Preferred_Mode (Raw_EDID : Raw_EDID_Data) return Boolean is |
| 46 | (Int64 (Read_LE16 (Raw_EDID, DESCRIPTOR_1)) * 10_000 in Frequency_Type and |
| 47 | ( Raw_EDID (DESCRIPTOR_1 + 2) /= 0 or |
| 48 | (Raw_EDID (DESCRIPTOR_1 + 4) and 16#f0#) /= 0) and |
| 49 | ( Raw_EDID (DESCRIPTOR_1 + 8) /= 0 or |
| 50 | (Raw_EDID (DESCRIPTOR_1 + 11) and 16#c0#) /= 0) and |
| 51 | ( Raw_EDID (DESCRIPTOR_1 + 9) /= 0 or |
| 52 | (Raw_EDID (DESCRIPTOR_1 + 11) and 16#30#) /= 0) and |
| 53 | ( Raw_EDID (DESCRIPTOR_1 + 3) /= 0 or |
| 54 | (Raw_EDID (DESCRIPTOR_1 + 4) and 16#0f#) /= 0) and |
| 55 | ( Raw_EDID (DESCRIPTOR_1 + 5) /= 0 or |
| 56 | (Raw_EDID (DESCRIPTOR_1 + 7) and 16#f0#) /= 0) and |
| 57 | ((Raw_EDID (DESCRIPTOR_1 + 10) and 16#f0#) /= 0 or |
| 58 | (Raw_EDID (DESCRIPTOR_1 + 11) and 16#0c#) /= 0) and |
| 59 | ((Raw_EDID (DESCRIPTOR_1 + 10) and 16#0f#) /= 0 or |
| 60 | (Raw_EDID (DESCRIPTOR_1 + 11) and 16#03#) /= 0) and |
| 61 | ( Raw_EDID (DESCRIPTOR_1 + 6) /= 0 or |
| 62 | (Raw_EDID (DESCRIPTOR_1 + 7) and 16#0f#) /= 0)) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 63 | with |
| Nico Huber | 7eb1350 | 2018-06-04 14:42:13 +0200 | [diff] [blame] | 64 | Pre => Valid (Raw_EDID); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 65 | function Preferred_Mode (Raw_EDID : Raw_EDID_Data) return Mode_Type |
| 66 | with |
| Nico Huber | 7eb1350 | 2018-06-04 14:42:13 +0200 | [diff] [blame] | 67 | Pre => Valid (Raw_EDID) and then Has_Preferred_Mode (Raw_EDID); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 68 | |
| 69 | end HW.GFX.EDID; |