Files
touchbtntest/firmware/export_from_build.ps1
DESKTOP-PUHFO60\dsx2016 e70fbd1d7f Fix 3.5C board support per CYD_PROJECT_GUIDE: BL=27, GT911 INT separate.
Correct ST7796/cyd_35r backlight, leave INT as input after reset, export firmware/cyd_35r.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-25 11:51:07 +08:00

106 lines
3.3 KiB
PowerShell

# Export firmware bins from PlatformIO build.
# Default: 2.8" (cyd -> firmware/cyd)
# 3.5": .\firmware\export_from_build.ps1 -Env cyd_35r
# (only after: pio run -e cyd_35r)
param(
[switch]$SkipBuild,
[ValidateSet("cyd", "cyd_35r")]
[string]$Env = "cyd"
)
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
Set-Location $root
$env:Path = "C:\Users\dsx2016\AppData\Local\Programs\Python\Python312\Scripts;" + $env:Path
if (-not $SkipBuild) {
pio run -e $Env
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
$src = Join-Path $root (".pio\build\" + $Env)
if ($Env -eq "cyd_35r") {
$dstName = "cyd_35r"
$boardLine = "board: ESP32-3248S035 (ST7796)"
$boardIdHint = "esp32-3248s035"
$featLine = "features: SoftSPI/GT911 touch, LVGL, capacitive touch btn GPIO22, BL=27"
} else {
$dstName = "cyd"
$boardLine = "board: ESP32-2432S028R (ILI9341)"
$boardIdHint = "esp32-2432s028"
$featLine = "features: SoftSPI touch, LVGL, capacitive touch btn GPIO22, BL=21"
}
$dst = Join-Path $root ("firmware\" + $dstName)
New-Item -ItemType Directory -Force -Path $dst | Out-Null
foreach ($f in @("bootloader.bin", "partitions.bin", "firmware.bin")) {
$p = Join-Path $src $f
if (-not (Test-Path $p)) { Write-Error "Missing build artifact: $p — build with: pio run -e $Env" }
Copy-Item $p $dst -Force
}
$bootApp = Join-Path $env:USERPROFILE ".platformio\packages\framework-arduinoespressif32\tools\partitions\boot_app0.bin"
if (-not (Test-Path $bootApp)) {
Write-Error "boot_app0.bin not found under PlatformIO packages"
}
Copy-Item $bootApp (Join-Path $dst "boot_app0.bin") -Force
# Ensure flash scripts exist (copy from sibling folder if needed)
foreach ($script in @("flash.ps1", "flash.bat")) {
$here = Join-Path $dst $script
if (-not (Test-Path $here)) {
$sibling = if ($Env -eq "cyd_35r") {
Join-Path $root "firmware\cyd\$script"
} else {
Join-Path $root "firmware\cyd_35r\$script"
}
if (Test-Path $sibling) {
Copy-Item $sibling $here -Force
}
}
}
$git = ""
try { $git = (git -C $root rev-parse --short HEAD).Trim() } catch { $git = "unknown" }
$date = Get-Date -Format "yyyy-MM-dd"
$hashes = Get-ChildItem (Join-Path $dst "*.bin") | Get-FileHash -Algorithm SHA256
$lines = @(
"name: CYD Touch Button ($dstName)",
"git: $git",
"date: $date",
$boardLine,
$featLine,
"flash_size: 4MB",
"offsets:",
" 0x1000 bootloader.bin",
" 0x8000 partitions.bin",
" 0xe000 boot_app0.bin",
" 0x10000 firmware.bin",
"sha256:"
)
foreach ($h in $hashes) {
$lines += (" {0,-15} {1}" -f (Split-Path $h.Path -Leaf), $h.Hash)
}
$lines | Set-Content -Encoding utf8 (Join-Path $dst "VERSION.txt")
# Keep / refresh meta.json boardId for catalog filtering
$metaPath = Join-Path $dst "meta.json"
if (Test-Path $metaPath) {
try {
$meta = Get-Content $metaPath -Raw | ConvertFrom-Json
$meta.boardId = $boardIdHint
if ($Env -eq "cyd_35r" -and $meta.name -notmatch '3\.5') {
$meta.name = ($meta.name -replace '\s*$','') + ' (3.5")'
}
$meta | ConvertTo-Json -Depth 8 | Set-Content -Encoding utf8 $metaPath
} catch {
Write-Host "meta.json update skipped: $_"
}
} elseif ($Env -eq "cyd_35r") {
Write-Host "Note: add firmware/cyd_35r/meta.json with boardId=$boardIdHint for the web catalog"
}
Write-Host "Exported -> $dst (env=$Env git=$git)"