diff --git a/esp32_marauder/configs.h b/esp32_marauder/configs.h index 97a6908..311ad7d 100644 --- a/esp32_marauder/configs.h +++ b/esp32_marauder/configs.h @@ -2711,6 +2711,11 @@ #undef HAS_MAX1704X #undef HAS_AXP192 + #elif defined(HAS_IP5306) + #undef HAS_AXP2101 + #undef HAS_MAX1704X + #undef HAS_AXP192 + #elif defined(HAS_AXP192) #undef HAS_AXP2101 #undef HAS_IP5306 diff --git a/tools/check_battery_driver_macros.ps1 b/tools/check_battery_driver_macros.ps1 new file mode 100644 index 0000000..97fa7dd --- /dev/null +++ b/tools/check_battery_driver_macros.ps1 @@ -0,0 +1,73 @@ +$ErrorActionPreference = "Stop" + +$repoRoot = Split-Path -Parent $PSScriptRoot +$configsPath = Join-Path $repoRoot "esp32_marauder/configs.h" +$configs = Get-Content -LiteralPath $configsPath -Raw + +function Assert-Match { + param( + [string]$Text, + [string]$Pattern, + [string]$Message + ) + + if ($Text -notmatch $Pattern) { + throw $Message + } +} + +function Get-MatchOrFail { + param( + [string]$Text, + [string]$Pattern, + [string]$Message + ) + + $match = [regex]::Match($Text, $Pattern, [System.Text.RegularExpressions.RegexOptions]::Singleline) + + if (-not $match.Success) { + throw $Message + } + + return $match +} + +Assert-Match ` + -Text $configs ` + -Pattern "(?s)#if defined\(MARAUDER_V6\) \|\| defined\(MARAUDER_V6_1\).*?#define HAS_BATTERY.*?#define HAS_IP5306" ` + -Message "MARAUDER_V6/MARAUDER_V6_1 must keep IP5306 battery support enabled." + +$cleanupMatch = Get-MatchOrFail ` + -Text $configs ` + -Pattern "(?s)// If we know what we have, we can delete what we're not using(?.*?)#endif\s+// HAS_BATTERY" ` + -Message "Could not find battery driver cleanup section." + +$cleanup = $cleanupMatch.Groups["cleanup"].Value + +$ip5306Match = Get-MatchOrFail ` + -Text $cleanup ` + -Pattern "(?s)#elif defined\(HAS_IP5306\)(?.*?)(?=\r?\n\s*#elif|\r?\n\s*#else|\r?\n\s*#endif)" ` + -Message "HAS_IP5306 must have an explicit cleanup branch before the generic fallback." + +$ip5306Branch = $ip5306Match.Groups["ip5306Branch"].Value + +Assert-Match ` + -Text $ip5306Branch ` + -Pattern "#undef HAS_AXP2101" ` + -Message "HAS_IP5306 cleanup must disable HAS_AXP2101." + +Assert-Match ` + -Text $ip5306Branch ` + -Pattern "#undef HAS_MAX1704X" ` + -Message "HAS_IP5306 cleanup must disable HAS_MAX1704X." + +Assert-Match ` + -Text $ip5306Branch ` + -Pattern "#undef HAS_AXP192" ` + -Message "HAS_IP5306 cleanup must disable HAS_AXP192." + +if ($ip5306Branch -match "#undef HAS_IP5306") { + throw "HAS_IP5306 cleanup must preserve HAS_IP5306 for v6/v6.1 battery support." +} + +Write-Host "Battery driver macro checks passed."