From bb0706e7b7ef948aa26924832620ab555b5115e5 Mon Sep 17 00:00:00 2001 From: chenjiangqun Date: Tue, 30 Jun 2026 20:13:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DAMD=E6=98=BE=E5=8D=A1?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E6=97=B6=E4=B8=8D=E8=83=BD=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WinISP/FormISP_MSI.cs | 139 +++++++----------- 1 file changed, 54 insertions(+), 85 deletions(-) diff --git a/WIN10_WinISP_SrcCode_For_MOKA_20250416_1/WinISP/FormISP_MSI.cs b/WIN10_WinISP_SrcCode_For_MOKA_20250416_1/WinISP/FormISP_MSI.cs index 0562dd6..6f2f9f1 100644 --- a/WIN10_WinISP_SrcCode_For_MOKA_20250416_1/WinISP/FormISP_MSI.cs +++ b/WIN10_WinISP_SrcCode_For_MOKA_20250416_1/WinISP/FormISP_MSI.cs @@ -370,8 +370,11 @@ namespace WinISP if (string.IsNullOrWhiteSpace(_fwBoardName)) _fwBoardName = DDC_GetMonitorName(MS_GET_BOARD_NAME); if (string.IsNullOrWhiteSpace(_fwVersionFromDDC)) + { _fwVersionFromDDC = DDC_GetMonitorName(MS_GET_FW_VERSION); - + frmISP.WriteLog($"DDC_GetMonitorName:_fwVersionFromDDC{_fwVersionFromDDC}", "debug"); + } + // Only model name (0x36) is required; chip/panel/board may not be supported on all DDC paths. if (!string.IsNullOrWhiteSpace(_fwModelName)) return true; @@ -405,49 +408,6 @@ namespace WinISP return normalizedValue; } - private string GetModelMismatchMessage(string monitorModelName, string binModelName) - { - return "Model not match."; - } - - private bool IsModelNameMatch(string u8Model_Name) - { - string monitorValue = NormalizeMonitorModelName(_monitorModelName); - if (String.IsNullOrEmpty(monitorValue)) - return true; - - return string.Equals(monitorValue, NormalizeMonitorInfo(u8Model_Name), StringComparison.Ordinal); - } - private bool IsChipNameMatch(string u8Chi_pName) - { - string monitorValue = NormalizeMonitorInfo(_monitorChipName); - if (String.IsNullOrEmpty(monitorValue)) - return true; - - return string.Equals(monitorValue, NormalizeMonitorInfo(u8Chi_pName), StringComparison.Ordinal); - } - private bool IsPanelNameMatch(string u8Panel_Name) - { - string monitorValue = NormalizeMonitorInfo(_monitorPanelName); - if (String.IsNullOrEmpty(monitorValue)) - return true; - - return string.Equals(monitorValue, NormalizeMonitorInfo(u8Panel_Name), StringComparison.Ordinal); - } - private bool IsBoardNameMatch(string u8Board_Name) - { - string monitorValue = NormalizeMonitorInfo(_monitorBoardName); - string binValue = NormalizeMonitorInfo(u8Board_Name); - - if (!String.IsNullOrEmpty(monitorValue)) - return string.Equals(monitorValue, binValue, StringComparison.Ordinal); - - if (binValue.Length < 4) - return false; - - return binValue[0] == 'F' && binValue[1] == 'W' && binValue[2] == '.' && binValue[3] == '0'; - } - private void btnLoadFile_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); @@ -582,23 +542,31 @@ namespace WinISP private string ReadMonitorFieldRobust(byte subCmd, int expectLen, int maxRounds = 30) { string best = string.Empty; + int stableCount = 0; // 连续读到相同最长值的次数 + for (int round = 0; round < maxRounds; round++) { - // DDC_GetMonitorName 内部已做 recv[1]==0x80 过滤 + 找 \0 结束符 string v = DDC_GetMonitorName(subCmd, 300); if (!string.IsNullOrWhiteSpace(v)) { - // 记录最长的结果(AMD 可能先读到残片 "MA",后读到完整 "MAG 322URD16") if (v.Length > best.Length) { best = v; + stableCount = 0; // 读到更长的,重置稳定计数 frmISP.WriteLog($"[AMD-Identity] cmd=0x{subCmd:X2} round#{round} got='{v}' (len={v.Length})", "debug"); } - // 完整性判断:读到的长度接近期望值,认为读全了,提前退出 - if (v.Length >= expectLen - 2 || v.Length >= 6) + else if (v.Length == best.Length && v == best) + { + stableCount++; // 连续读到相同的完整值 + } + + // 完整性判断(二选一即退出): + // 1) 读到的长度已接近期望最大长度 → 认为读全 + // 2) 同一个完整值连续稳定读到 2 次 → 认为读全(应对实际长度 < expectLen 的字段) + if (best.Length >= expectLen - 1 || stableCount >= 2) break; } - WinIOLib.DelayMs(50); // AMD 通道恢复间隔 + WinIOLib.DelayMs(50); } return best; } @@ -749,16 +717,8 @@ namespace WinISP // Intel IGCL and AMD can complete the FE handshake but still time out on optional // identity queries during connect. Skip those reads here so connect stays usable. - if (!isIntel && !isAmd) // >>> 改动:用缓存的 isIntel/isAmd 替换原三段强转判断(逻辑等价) - { - QueryConnectedMonitorInfo(); - } - else - { - //ClearConnectedMonitorInfo(); - QueryConnectedMonitorInfo(); - frmISP.WriteLog("Skip optional monitor identity query on AMD/Intel path.", "debug"); - } + // 所有显卡都要读,不要忽视 + QueryConnectedMonitorInfo(); } if (IsConnect == false) @@ -776,15 +736,10 @@ namespace WinISP case 2: { frmISP.WriteLog("MTKChipType=MST9U", "info"); } break; } Application.DoEvents(); - if (!isIntel && !isAmd) // >>> 改动:等价替换 - { - DDC_GetVersion(); - } - else - { - DDC_GetVersion(); - frmISP.WriteLog("Skip optional firmware version query on AMD/Intel path.", "debug"); - } + + // 不忽视,都要读取 + DDC_GetVersion(); + DDC_SetToolFlag(false); int pktDelayTime = 0; @@ -911,13 +866,13 @@ namespace WinISP private void DDC_SetToolFlag(bool en) { - // AMD and Intel DDC paths do not support the tool-flag handshake command. - // Sending it causes repeated DDC timeout errors, so skip entirely. - if (IsAmdOrIntelPath()) - { - frmISP.WriteLog("DDC_SetToolFlag skipped on AMD/Intel path.", "debug"); - return; - } + //// AMD and Intel DDC paths do not support the tool-flag handshake command. + //// Sending it causes repeated DDC timeout errors, so skip entirely. + //if (IsAmdOrIntelPath()) + //{ + // frmISP.WriteLog("DDC_SetToolFlag skipped on AMD/Intel path.", "debug"); + // return; + //} Byte[] buf = { 0xCC, 0x90, 0x00 }; if (en) @@ -1537,18 +1492,28 @@ namespace WinISP private bool ValidateMonitorVsBin(out string errMsg) { errMsg = String.Empty; + bool isAmdOrIntel = IsAmdOrIntelPath(); + + // >>> 优先采用 QueryConnectedMonitorInfo 已读到的真实显示器信息 + // (AMD/Intel 路径在 Connect 时已通过 ReadMonitorFieldRobust 读取) + if (string.IsNullOrWhiteSpace(_fwModelName) && !string.IsNullOrWhiteSpace(_monitorModelName)) + _fwModelName = _monitorModelName; + if (string.IsNullOrWhiteSpace(_fwChipName) && !string.IsNullOrWhiteSpace(_monitorChipName)) + _fwChipName = _monitorChipName; + if (string.IsNullOrWhiteSpace(_fwPanelName) && !string.IsNullOrWhiteSpace(_monitorPanelName)) + _fwPanelName = _monitorPanelName; + if (string.IsNullOrWhiteSpace(_fwBoardName) && !string.IsNullOrWhiteSpace(_monitorBoardName)) + _fwBoardName = _monitorBoardName; + + if (string.IsNullOrWhiteSpace(_fwVersionFromDDC)) + { + _fwVersionFromDDC = DDC_GetMonitorName(MS_GET_FW_VERSION); + frmISP.WriteLog($"DDC_GetMonitorName:_fwVersionFromDDC{_fwVersionFromDDC}", "debug"); + } if (string.IsNullOrWhiteSpace(_fwModelName)) - { - // On AMD/Intel the DDC identity commands are not supported; skip the - // retry loop to avoid flooding the log with timeout errors. The - // legacy-fallback logic below will supply hardcoded identifiers instead. - if (!IsAmdOrIntelPath()) - TryReadMonitorIdentity(10, 100); - } - else - { - _fwModelName = NormalizeMonitorModelName(_fwModelName); + { + TryReadMonitorIdentity(10, 100); } // ----------------------------------------------------------------------- @@ -1582,6 +1547,7 @@ namespace WinISP : (usingLegacyFallback ? LegacyChip : string.Empty); string effPanel = !string.IsNullOrWhiteSpace(_fwPanelName) ? _fwPanelName : (usingLegacyFallback ? LegacyPanel : string.Empty); + // effVer: prefer actual DDC read; fall back to LegacyFWVer when in legacy-fallback mode // (covers AMD/Intel path where DDC identity commands are not supported). string effVer = !string.IsNullOrWhiteSpace(_fwVersionFromDDC) ? _fwVersionFromDDC @@ -1622,6 +1588,7 @@ namespace WinISP } frmISP.WriteLog("ValidateMonitorVsBin: Chip prefix-match accepted: FW=" + effChip + " BIN=" + _u8ChipName, "debug"); } + if (!string.IsNullOrWhiteSpace(effPanel)) { if (string.IsNullOrWhiteSpace(_u8PanelName)) @@ -1659,6 +1626,7 @@ namespace WinISP errMsg = "FW Version not match." ; return false; } + string normalizedMonVer = NormalizeFwVersionForCompare(effVer); string normalizedBinVer = NormalizeFwVersionForCompare(_u8FWVersion); frmISP.WriteLog("ValidateMonitorVsBin: normalizedMonVer=" + normalizedMonVer + " normalizedBinVer=" + normalizedBinVer, "debug"); @@ -1675,6 +1643,7 @@ namespace WinISP return true; } + List flashSectorInfo = new List(); private void btnAuto_Click(object sender, EventArgs e) {