• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "edid_helper.h"
18 
19 #include <android-base/parseint.h>
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 
24 namespace hcct {
25 namespace edid {
26 
27 namespace {
28 
29 std::unordered_map<EdpMonitorName, std::string> edpMonitorNameToEdidHex = {
30   {EdpMonitorName::REDRIX,
31     "00ffffffffffff0009e5760a00000000"
32     "191f0104a51c137803ee95a3544c9926"
33     "0f505400000001010101010101010101"
34     "010101010101125cd01881e02d503020"
35     "36001dbe1000001a623dd01881e02d50"
36     "302036001dbe1000001a000000000000"
37     "00000000000000000000000000000002"
38     "000d28ff0a3cc80f0b23c800000000cc"},
39 };
40 
41 std::unordered_map<DpMonitorName, std::string> dpMonitorNameToEdidHex = {
42   {DpMonitorName::ACI_9713_ASUS_VE258_DP,
43     "00ffffffffffff000469f125f3c60100"
44     "1d150104a5371f783a7695a5544ba226"
45     "115054bfef00714f81c0814081809500"
46     "950fb300d1c0023a801871382d40582c"
47     "450029372100001e000000ff0042374c"
48     "4d54463131363436370a000000fd0032"
49     "4b185311041100f0f838f03c000000fc"
50     "00415355532056453235380a202001b7"
51     "020322714f0102031112130414051f90"
52     "0e0f1d1e2309170783010000656e0c00"
53     "10008c0ad08a20e02d10103e96002937"
54     "21000018011d007251d01e206e285500"
55     "29372100001e011d00bc52d01e20b828"
56     "554029372100001e8c0ad09020403120"
57     "0c405500293721000018000000000000"
58     "000000000000000000000000000000aa"},
59 
60   {DpMonitorName::DEL_61463_DELL_U2410_DP,
61     "00ffffffffffff0010ac17f04c334a31"
62     "08150104b53420783a1ec5ae4f34b126"
63     "0e5054a54b008180a940d100714f0101"
64     "010101010101283c80a070b023403020"
65     "360006442100001a000000ff00463532"
66     "354d313247314a334c0a000000fc0044"
67     "454c4c2055323431300a2020000000fd"
68     "00384c1e5111000a20202020202001ff"
69     "02031df15090050403020716011f1213"
70     "14201511062309070783010000023a80"
71     "1871382d40582c450006442100001e01"
72     "1d8018711c1620582c25000644210000"
73     "9e011d007251d01e206e285500064421"
74     "00001e8c0ad08a20e02d10103e960006"
75     "44210000180000000000000000000000"
76     "00000000000000000000000000000021"},
77 
78     {DpMonitorName::HP_Spectre32_4K_DP,
79     "00FFFFFFFFFFFF0022F01A3200000000"
80     "2E180104B54728783A87D5A8554D9F25"
81     "0E5054210800D1C0A9C081C0D100B300"
82     "9500A94081804DD000A0F0703E803020"
83     "3500C48F2100001A000000FD00183C1E"
84     "873C000A202020202020000000FC0048"
85     "502053706563747265203332000000FF"
86     "00434E43393430303030310A2020018F"
87     "020318F14B101F041303120211010514"
88     "2309070783010000A36600A0F0701F80"
89     "30203500C48F2100001A565E00A0A0A0"
90     "295030203500C48F2100001AEF5100A0"
91     "F070198030203500C48F2100001AB339"
92     "00A080381F4030203A00C48F2100001A"
93     "283C80A070B0234030203600C48F2100"
94     "001A00000000000000000000000000C4"},
95 
96   {DpMonitorName::HWP_12446_HP_Z24i_DP,
97     "00ffffffffffff0022f09e3000000000"
98     "15180104a5342078264ca5a7554da226"
99     "105054a10800b30095008100a9408180"
100     "d1c081c00101283c80a070b023403020"
101     "360006442100001a000000fd00324c18"
102     "5e11000a202020202020000000fc0048"
103     "50205a3234690a2020202020000000ff"
104     "00434e343432313050334b0a2020006f"},
105 };
106 
107 std::unordered_map<HdmiMonitorName, std::string> hdmiMonitorNameToEdidHex = {
108   {HdmiMonitorName::ACI_9155_ASUS_VH238_HDMI,
109     "00ffffffffffff000469c323fccc0000"
110     "2017010380331d782add45a3554fa027"
111     "125054bfef00714f814081809500b300"
112     "d1c001010101023a801871382d40582c"
113     "4500fd1e1100001e000000ff0044384c"
114     "4d54463035323437360a000000fd0032"
115     "4b1e5011000a202020202020000000fc"
116     "00415355532056483233380a202000be"},
117 
118   {HdmiMonitorName::DEL_61462_DELL_U2410_HDMI,
119     "00ffffffffffff0010ac16f04c4e4332"
120     "1f13010380342078ea1ec5ae4f34b126"
121     "0e5054a54b008180a940d100714f0101"
122     "010101010101283c80a070b023403020"
123     "360006442100001a000000ff00463532"
124     "354d39375332434e4c0a000000fc0044"
125     "454c4c2055323431300a2020000000fd"
126     "00384c1e5111000a202020202020012e"
127     "020329f15090050403020716011f1213"
128     "14201511062309070767030c00100038"
129     "2d83010000e3050301023a801871382d"
130     "40582c450006442100001e011d801871"
131     "1c1620582c250006442100009e011d00"
132     "7251d01e206e28550006442100001e8c"
133     "0ad08a20e02d10103e96000644210000"
134     "1800000000000000000000000000003e"},
135 
136   {HdmiMonitorName::HP_Spectre32_4K_HDMI,
137     "00ffffffffffff0022f01c3201010101"
138     "04190103804728782a87d5a8554d9f25"
139     "0e5054210800d1c0a9c081c0d100b300"
140     "9500a94081804dd000a0f0703e803020"
141     "3500c48f2100001a000000fd00183c1b"
142     "873c000a202020202020000000fc0048"
143     "702053706563747265203332000000ff"
144     "00434e43393430303030310a202001fb"
145     "02033df15361605f5d101f0413031202"
146     "11010514070616152309070783010000"
147     "6c030c001000383c200040010367d85d"
148     "c401788000e40f030000e2002b047400"
149     "30f2705a80b0588a00c48f2100001a56"
150     "5e00a0a0a0295030203500c48f210000"
151     "1eef5100a0f070198030203500c48f21"
152     "00001e000000000000000000000000a8"},
153 
154   {HdmiMonitorName::HWP_12447_HP_Z24i_HDMI,
155     "00ffffffffffff0022f09f3001010101"
156     "1a180103803420782e3c50a7544da226"
157     "105054a1080081009500b3008180a940"
158     "81c0d1c00101283c80a070b023403020"
159     "360006442100001a000000fd00324c18"
160     "5e11000a202020202020000000fc0048"
161     "50205a3234690a2020202020000000ff"
162     "00434e4b343236304c47320a202000d6"},
163 };
164 
hexStringToBinary(const std::string & hexStr)165 std::vector<uint8_t> hexStringToBinary(const std::string &hexStr) {
166   std::vector<uint8_t> binary;
167   binary.reserve(hexStr.length() / 2);
168 
169   for (size_t i = 0; i < hexStr.length(); i += 2) {
170     if (i + 1 < hexStr.length()) {
171       std::string byteString = hexStr.substr(i, 2);
172       uint8_t value = 0;
173       char c1 = byteString[0];
174       char c2 = byteString[1];
175 
176       // Convert first hex digit
177       if (isdigit(c1)) {
178         value = (c1 - '0') << 4;
179       } else if (isxdigit(c1)) {
180         value = (tolower(c1) - 'a' + 10) << 4;
181       }
182 
183       // Convert second hex digit
184       if (isdigit(c2)) {
185         value |= (c2 - '0');
186       } else if (isxdigit(c2)) {
187         value |= (tolower(c2) - 'a' + 10);
188       }
189       binary.push_back(value);
190     }
191   }
192 
193   return binary;
194 }
195 
getEdidHexForMonitor(const MonitorName & monitorName)196 std::string getEdidHexForMonitor(const MonitorName &monitorName) {
197   switch (monitorName.type) {
198   case MonitorName::Type::EDP: {
199     return edpMonitorNameToEdidHex.at(monitorName.edp);
200   }
201   case MonitorName::Type::DP: {
202     return dpMonitorNameToEdidHex.at(monitorName.dp);
203   }
204   case MonitorName::Type::HDMI: {
205     return hdmiMonitorNameToEdidHex.at(monitorName.hdmi);
206   }
207   default:
208     return "";
209   }
210 }
211 } // namespace
212 
getBinaryEdidForMonitor(const MonitorName & monitorName)213 std::vector<uint8_t> getBinaryEdidForMonitor(const MonitorName &monitorName) {
214   std::string edidHex = getEdidHexForMonitor(monitorName);
215   return hexStringToBinary(edidHex);
216 }
217 
218 } // namespace edid
219 } // namespace hcct
220