diff --git a/.gitignore b/.gitignore index 296f525..398aa70 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,9 @@ __pycache__/ .DS_Store Thumbs.db assets/ -*.bin +# 构建产物忽略;firmware/ 下预编译包需要入库 *.elf +.pio/**/*.bin +!.pio/ +!firmware/ +!firmware/**/*.bin diff --git a/CHANGELOG.md b/CHANGELOG.md index 8061899..ba9c32e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 2026-10-17 — Prebuilt firmware folder + +- Add `firmware/cyd/` with bin + `flash.ps1` / `flash.bat` (same pattern as temperature). +- Add `firmware/export_from_build.ps1` to refresh archived binaries after builds. +- Track `firmware/**/*.bin` in git; document flash-without-compile in README. + ## 2026-10-17 — Touch speaker control + music - SoftSPI XPT2046 touch (GPIO 32/39/25/33/36), coexists with SD. diff --git a/README.md b/README.md index 0f0a037..a866bbb 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,28 @@ - Audio:当前音频状态 - 用量进度条 -## 编译烧录 +## 预编译固件(随时刷,不必编译) + +与 `temperature` 工程相同:归档在 [`firmware/cyd/`](firmware/cyd/)(含 bootloader / partitions / app): + +```powershell +cd firmware\cyd +.\flash.ps1 +# 或 .\flash.ps1 -Port COM3 +``` + +说明见 [`firmware/README.md`](firmware/README.md)。源码更新后重新打包: + +```powershell +.\firmware\export_from_build.ps1 +# 已编译过、只复制: +.\firmware\export_from_build.ps1 -SkipBuild +``` + +## 从源码编译烧录 ```bash -pio run -t upload +pio run -e cyd -t upload pio device monitor ``` @@ -44,7 +62,7 @@ pio device monitor - TF 需 **FAT/FAT32**。 - 若触屏坐标偏移,改 `src/touch.cpp` 里 `map(...)` 校准范围。 - 若点按无反应,检查排线/旋转;可尝试交换 raw_x/raw_y 映射。 -- 变更请更新 `CHANGELOG.md` 并提交本地 git。 +- 变更请更新 `CHANGELOG.md`、必要时重新 `export_from_build.ps1`,并提交本地 git。 ## 版本 diff --git a/firmware/README.md b/firmware/README.md new file mode 100644 index 0000000..359f8f9 --- /dev/null +++ b/firmware/README.md @@ -0,0 +1,47 @@ +# 预编译固件(可随时刷写) + +当前归档目录:[`cyd/`](cyd/) + +对应板子:**CYD ESP32-2432S028R**(ILI9341) +功能:TF 卡信息 + 触屏扬声器控制 +版本信息见 [`cyd/VERSION.txt`](cyd/VERSION.txt)。 + +## 直接刷写(无需重新编译) + +1. USB 连接板子 +2. 执行: + +```powershell +cd firmware\cyd +.\flash.ps1 +# 或指定端口 +.\flash.ps1 -Port COM3 +``` + +也可运行 `flash.bat`。 + +依赖其一即可: + +- 已安装 PlatformIO(`pio`,自带 esptool) +- 或 `pip install esptool` + +## 手动 esptool + +```bash +esptool.py --chip esp32 --port COM3 --baud 921600 write_flash -z ^ + --flash_mode dio --flash_freq 40m --flash_size 4MB ^ + 0x1000 bootloader.bin ^ + 0x8000 partitions.bin ^ + 0xe000 boot_app0.bin ^ + 0x10000 firmware.bin +``` + +## 从源码重新打包进本目录 + +在仓库根目录: + +```powershell +.\firmware\export_from_build.ps1 +# 仅复制、不编译: +.\firmware\export_from_build.ps1 -SkipBuild +``` diff --git a/firmware/cyd/VERSION.txt b/firmware/cyd/VERSION.txt new file mode 100644 index 0000000..6a8c5a1 --- /dev/null +++ b/firmware/cyd/VERSION.txt @@ -0,0 +1,16 @@ +name: CYD TF card + touch speaker (cyd) +git: f05c5d6 +date: 2026-10-17 +board: ESP32-2432S028R (ILI9341) +features: TF/SD info, SoftSPI touch, GPIO26 speaker +flash_size: 4MB +offsets: + 0x1000 bootloader.bin + 0x8000 partitions.bin + 0xe000 boot_app0.bin + 0x10000 firmware.bin +sha256: + bootloader.bin 3D234A7471F67B013686DABD4DEE7C1FA915C9928463616A94BC9297ACF1ABF8 + boot_app0.bin F94C5D786A7A8FAB06AC5D10E33BF37711A6697636DC037559EA19CC410A17F0 + firmware.bin 1FB845985551DBB1C92D5510278EFAF773311F4CE370B06F78585D397144FE87 + partitions.bin 148B959CBFF1C38AA8E1D5C0BA9D612C54997B945E56A63F41223EEF650653A1 diff --git a/firmware/cyd/boot_app0.bin b/firmware/cyd/boot_app0.bin new file mode 100644 index 0000000..13562ca Binary files /dev/null and b/firmware/cyd/boot_app0.bin differ diff --git a/firmware/cyd/bootloader.bin b/firmware/cyd/bootloader.bin new file mode 100644 index 0000000..d592359 Binary files /dev/null and b/firmware/cyd/bootloader.bin differ diff --git a/firmware/cyd/firmware.bin b/firmware/cyd/firmware.bin new file mode 100644 index 0000000..898706c Binary files /dev/null and b/firmware/cyd/firmware.bin differ diff --git a/firmware/cyd/flash.bat b/firmware/cyd/flash.bat new file mode 100644 index 0000000..bf983b3 --- /dev/null +++ b/firmware/cyd/flash.bat @@ -0,0 +1,5 @@ +@echo off +setlocal +cd /d "%~dp0" +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0flash.ps1" %* +exit /b %ERRORLEVEL% diff --git a/firmware/cyd/flash.ps1 b/firmware/cyd/flash.ps1 new file mode 100644 index 0000000..c80479b --- /dev/null +++ b/firmware/cyd/flash.ps1 @@ -0,0 +1,98 @@ +# Flash archived CYD TF+Speaker firmware (no rebuild needed) +# Usage: +# .\flash.ps1 +# .\flash.ps1 -Port COM5 +# .\flash.ps1 -Port COM5 -Baud 460800 + +param( + [string]$Port = "", + [int]$Baud = 921600 +) + +$ErrorActionPreference = "Stop" +$here = Split-Path -Parent $MyInvocation.MyCommand.Path +Set-Location $here + +function Find-Esptool { + $pio = Get-Command pio -ErrorAction SilentlyContinue + if (-not $pio) { + $pioPath = Join-Path $env:USERPROFILE "AppData\Local\Programs\Python\Python312\Scripts\pio.exe" + if (Test-Path $pioPath) { + $env:Path = "$(Split-Path $pioPath);$env:Path" + $pio = Get-Command pio -ErrorAction SilentlyContinue + } + } + if ($pio) { + $pkg = Join-Path $env:USERPROFILE ".platformio\packages\tool-esptoolpy\esptool.py" + if (Test-Path $pkg) { return @{ Kind = "py"; Path = $pkg } } + } + $py = Get-Command python -ErrorAction SilentlyContinue + if ($py) { + try { + & python -c "import esptool" 2>$null + if ($LASTEXITCODE -eq 0) { return @{ Kind = "mod"; Path = "esptool" } } + } catch {} + } + $esp = Get-Command esptool.py -ErrorAction SilentlyContinue + if ($esp) { return @{ Kind = "py"; Path = $esp.Source } } + return $null +} + +if (-not $Port) { + $ports = @() + try { + Add-Type -AssemblyName System.IO.Ports -ErrorAction SilentlyContinue | Out-Null + $ports = [System.IO.Ports.SerialPort]::GetPortNames() | Sort-Object + } catch {} + if (-not $ports -or $ports.Count -eq 0) { + $ports = Get-CimInstance Win32_SerialPort -ErrorAction SilentlyContinue | + Select-Object -ExpandProperty DeviceID | Sort-Object + } + if (-not $ports -or $ports.Count -eq 0) { + Write-Error "No serial ports found. Plug in the CYD USB cable, then retry with -Port COMx" + } + if ($ports.Count -eq 1) { + $Port = $ports[0] + } else { + Write-Host "Available ports: $($ports -join ', ')" + $Port = $ports[-1] + Write-Host "Using last port: $Port (override with -Port)" + } +} + +$tool = Find-Esptool +if (-not $tool) { + Write-Error "esptool not found. Install PlatformIO (`pio`) or: pip install esptool" +} + +$needed = @("bootloader.bin", "partitions.bin", "boot_app0.bin", "firmware.bin") +foreach ($f in $needed) { + if (-not (Test-Path (Join-Path $here $f))) { + Write-Error "Missing $f — run ..\export_from_build.ps1 from repo root first" + } +} + +$argsCommon = @( + "--chip", "esp32", + "--port", $Port, + "--baud", "$Baud", + "--before", "default_reset", + "--after", "hard_reset", + "write_flash", "-z", + "--flash_mode", "dio", + "--flash_freq", "40m", + "--flash_size", "4MB", + "0x1000", "bootloader.bin", + "0x8000", "partitions.bin", + "0xe000", "boot_app0.bin", + "0x10000", "firmware.bin" +) + +Write-Host "Flashing $here -> $Port @ $Baud" +if ($tool.Kind -eq "mod") { + & python -m esptool @argsCommon +} else { + & python $tool.Path @argsCommon +} +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } +Write-Host "Done. Open serial monitor at 115200 if needed." diff --git a/firmware/cyd/partitions.bin b/firmware/cyd/partitions.bin new file mode 100644 index 0000000..2108af9 Binary files /dev/null and b/firmware/cyd/partitions.bin differ diff --git a/firmware/export_from_build.ps1 b/firmware/export_from_build.ps1 new file mode 100644 index 0000000..d049dd1 --- /dev/null +++ b/firmware/export_from_build.ps1 @@ -0,0 +1,58 @@ +# Rebuild (optional) and refresh firmware/cyd from PlatformIO build output. +# Usage: +# .\firmware\export_from_build.ps1 +# .\firmware\export_from_build.ps1 -SkipBuild + +param([switch]$SkipBuild) + +$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 cyd + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } +} + +$src = Join-Path $root ".pio\build\cyd" +$dst = Join-Path $root "firmware\cyd" +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" } + 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 + +# Keep flash scripts if already present +$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 TF card + touch speaker (cyd)", + "git: $git", + "date: $date", + "board: ESP32-2432S028R (ILI9341)", + "features: TF/SD info, SoftSPI touch, GPIO26 speaker", + "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") +Write-Host "Exported -> $dst (git $git)"