diff --git a/firmware/export_from_build.ps1 b/firmware/export_from_build.ps1 index 8314e8c..a1f4755 100644 --- a/firmware/export_from_build.ps1 +++ b/firmware/export_from_build.ps1 @@ -1,9 +1,13 @@ -# Rebuild (optional) and refresh firmware/cyd from PlatformIO build output. -# Usage: -# .\firmware\export_from_build.ps1 -# .\firmware\export_from_build.ps1 -SkipBuild +# 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) +param( + [switch]$SkipBuild, + [ValidateSet("cyd", "cyd_35r")] + [string]$Env = "cyd" +) $ErrorActionPreference = "Stop" $root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path) @@ -12,17 +16,26 @@ Set-Location $root $env:Path = "C:\Users\dsx2016\AppData\Local\Programs\Python\Python312\Scripts;" + $env:Path if (-not $SkipBuild) { - pio run -e cyd + pio run -e $Env if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } } -$src = Join-Path $root ".pio\build\cyd" -$dst = Join-Path $root "firmware\cyd" +$src = Join-Path $root (".pio\build\" + $Env) +if ($Env -eq "cyd_35r") { + $dstName = "cyd_35r" + $boardLine = "board: ESP32-3248S035 (ST7796)" + $boardIdHint = "esp32-3248s035" +} else { + $dstName = "cyd" + $boardLine = "board: ESP32-2432S028R (ILI9341)" + $boardIdHint = "esp32-2432s028" +} +$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" } + if (-not (Test-Path $p)) { Write-Error "Missing build artifact: $p — build with: pio run -e $Env" } Copy-Item $p $dst -Force } @@ -37,11 +50,10 @@ try { $git = (git -C $root rev-parse --short HEAD).Trim() } catch { $git = "unkn $date = Get-Date -Format "yyyy-MM-dd" $hashes = Get-ChildItem (Join-Path $dst "*.bin") | Get-FileHash -Algorithm SHA256 $lines = @( - "name: CYD Touch Button (cyd)", + "name: CYD touchbtntest ($dstName)", "git: $git", "date: $date", - "board: ESP32-2432S028R (ILI9341)", - "features: SoftSPI touch, LVGL, capacitive touch btn on GPIO22", + $boardLine, "flash_size: 4MB", "offsets:", " 0x1000 bootloader.bin", @@ -54,4 +66,22 @@ 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)" + +# 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)" diff --git a/include/pins.h b/include/pins.h index 8b68c93..c56e924 100644 --- a/include/pins.h +++ b/include/pins.h @@ -1,8 +1,20 @@ #pragma once -// CYD ESP32-2432S028R — 触控/屏脚与 tftest / btntest 一致 +// Board pins — 2.8" default; 3.5" when CYD_BOARD_3248S035 is set (env:cyd_35r) +#if defined(CYD_BOARD_3248S035) +#define TFT_BL_PIN 27 +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 480 +#define UI_HOR_RES 480 +#define UI_VER_RES 320 +#else #define TFT_BL_PIN 21 +#define SCREEN_WIDTH 240 +#define SCREEN_HEIGHT 320 +#define UI_HOR_RES 320 +#define UI_VER_RES 240 +#endif #define CYD_TOUCH_IRQ 36 #define CYD_TOUCH_MOSI 32 @@ -10,11 +22,11 @@ #define CYD_TOUCH_CLK 25 #define CYD_TOUCH_CS 33 -// 三脚触控感应模块 OUT/S/DO → GPIO22(VCC→3.3V,GND→GND) -// 典型:TTP223 电容触摸(非机械轻触) -#define BTN_PIN 22 +/* Map 320x240 design coordinates onto the active UI resolution (identity on 2.8"). */ +#define UX(x) ((int)(((long)(x) * (UI_HOR_RES)) / 320)) +#define UY(y) ((int)(((long)(y) * (UI_VER_RES)) / 240)) +#define UW(w) UX(w) +#define UH(h) UY(h) -#define SCREEN_WIDTH 240 -#define SCREEN_HEIGHT 320 -#define UI_HOR_RES 320 -#define UI_VER_RES 240 + +#define BTN_PIN 22 diff --git a/platformio.ini b/platformio.ini index e7142fd..51b22c0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -54,3 +54,20 @@ build_flags = -I${PROJECT_DIR}/include extra_scripts = pre:copy_lv_conf.py + +; Optional 3.5" CYD ESP32-3248S035 (ST7796 resistive). Default remains [env:cyd]. +; Build: pio run -e cyd_35r +[env:cyd_35r] +extends = env:cyd +build_flags = + ${env:cyd.build_flags} + -UILI9341_2_DRIVER + -DST7796_DRIVER=1 + -UTFT_WIDTH + -UTFT_HEIGHT + -DTFT_WIDTH=320 + -DTFT_HEIGHT=480 + -UTFT_BL + -DTFT_BL=27 + -DCYD_BOARD_3248S035=1 + diff --git a/src/ui.cpp b/src/ui.cpp index 2dd6995..fae0235 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -95,41 +95,41 @@ void ui_create() { lv_label_set_text(lbl_title, "Touch"); lv_obj_set_style_text_color(lbl_title, lv_color_hex(COL_INK), 0); lv_obj_set_style_text_font(lbl_title, &lv_font_montserrat_28, 0); - lv_obj_align(lbl_title, LV_ALIGN_TOP_MID, 0, 2); + lv_obj_align(lbl_title, LV_ALIGN_TOP_MID, UX(0), UY(2)); lbl_pin = lv_label_create(scr); lv_label_set_text_fmt(lbl_pin, "Cap OUT->GPIO%d 3.3V", BTN_PIN); lv_obj_set_style_text_color(lbl_pin, lv_color_hex(COL_MUTED), 0); lv_obj_set_style_text_font(lbl_pin, &lv_font_montserrat_14, 0); - lv_obj_align(lbl_pin, LV_ALIGN_TOP_MID, 0, 32); + lv_obj_align(lbl_pin, LV_ALIGN_TOP_MID, UX(0), UY(32)); lbl_count = lv_label_create(scr); lv_label_set_text(lbl_count, "0"); lv_obj_set_style_text_color(lbl_count, lv_color_hex(COL_ACCENT), 0); lv_obj_set_style_text_font(lbl_count, &lv_font_montserrat_28, 0); - lv_obj_align(lbl_count, LV_ALIGN_TOP_MID, 0, 56); + lv_obj_align(lbl_count, LV_ALIGN_TOP_MID, UX(0), UY(56)); lbl_hint = lv_label_create(scr); lv_label_set_text(lbl_hint, "count"); lv_obj_set_style_text_color(lbl_hint, lv_color_hex(COL_MUTED), 0); lv_obj_set_style_text_font(lbl_hint, &lv_font_montserrat_14, 0); - lv_obj_align(lbl_hint, LV_ALIGN_TOP_MID, 0, 90); + lv_obj_align(lbl_hint, LV_ALIGN_TOP_MID, UX(0), UY(90)); lbl_state = lv_label_create(scr); lv_label_set_text(lbl_state, "IDLE"); lv_obj_set_style_text_color(lbl_state, lv_color_hex(COL_MUTED), 0); lv_obj_set_style_text_font(lbl_state, &lv_font_montserrat_20, 0); - lv_obj_align(lbl_state, LV_ALIGN_TOP_MID, 0, 110); + lv_obj_align(lbl_state, LV_ALIGN_TOP_MID, UX(0), UY(110)); lbl_hold = lv_label_create(scr); lv_label_set_text(lbl_hold, "hold --"); lv_obj_set_style_text_color(lbl_hold, lv_color_hex(COL_MUTED), 0); lv_obj_set_style_text_font(lbl_hold, &lv_font_montserrat_14, 0); - lv_obj_align(lbl_hold, LV_ALIGN_TOP_MID, 0, 134); + lv_obj_align(lbl_hold, LV_ALIGN_TOP_MID, UX(0), UY(134)); bar_touch = lv_bar_create(scr); - lv_obj_set_size(bar_touch, UI_HOR_RES - 64, 10); - lv_obj_align(bar_touch, LV_ALIGN_TOP_MID, 0, 154); + lv_obj_set_size(bar_touch, UI_HOR_RES - UW(64), UH(10)); + lv_obj_align(bar_touch, LV_ALIGN_TOP_MID, UX(0), UY(154)); lv_bar_set_range(bar_touch, 0, 100); lv_bar_set_value(bar_touch, 0, LV_ANIM_OFF); lv_obj_set_style_radius(bar_touch, 5, 0); @@ -143,11 +143,11 @@ void ui_create() { lv_label_set_text(lbl_raw, "OUT --"); lv_obj_set_style_text_color(lbl_raw, lv_color_hex(COL_MUTED), 0); lv_obj_set_style_text_font(lbl_raw, &lv_font_montserrat_14, 0); - lv_obj_align(lbl_raw, LV_ALIGN_TOP_MID, 0, 170); + lv_obj_align(lbl_raw, LV_ALIGN_TOP_MID, UX(0), UY(170)); btn_reset = lv_button_create(scr); - lv_obj_set_size(btn_reset, UI_HOR_RES - 48, 40); - lv_obj_align(btn_reset, LV_ALIGN_TOP_MID, 0, 192); + lv_obj_set_size(btn_reset, UI_HOR_RES - UW(48), UH(40)); + lv_obj_align(btn_reset, LV_ALIGN_TOP_MID, UX(0), UY(192)); style_btn(btn_reset, COL_BTN); lv_obj_set_ext_click_area(btn_reset, 12); lv_obj_add_event_cb(btn_reset, on_reset, LV_EVENT_CLICKED, nullptr);