Fix 3.5C board pins per CYD guide: BL=27, GY30 SCL=21.
Correct black-screen backlight, free GPIO21 after GT911 init (Wire1), export/flash cyd_35r package. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
54
README.md
54
README.md
@@ -1,20 +1,24 @@
|
||||
# CYD GY30 光照仪表盘
|
||||
|
||||
ESP32 Cheap Yellow Display(ESP32-2432S028R)+ GY30(BH1750)+ LVGL 光照仪表盘。
|
||||
ESP32 Cheap Yellow Display + GY30(BH1750)+ LVGL 光照仪表盘。
|
||||
|
||||
布局与交互参考同目录下的 [temperature](../temperature) / [sgp30test](../sgp30test)。
|
||||
默认 **2.8"**(`cyd_28r`);可选 **3.5C**(`cyd_35r`)。布局与交互参考 [temperature](../temperature) / [sgp30test](../sgp30test);板级约定见 [CYD_PROJECT_GUIDE.md](../CYD_PROJECT_GUIDE.md)。
|
||||
|
||||
## 硬件
|
||||
|
||||
| 项目 | 说明 |
|
||||
|------|------|
|
||||
| 板子 | CYD ESP32-2432S028R(2.8" ILI9341) |
|
||||
| 传感器 | GY30 / BH1750(光照 lux) |
|
||||
| SDA | **GPIO22** |
|
||||
| SCL | **GPIO27** |
|
||||
| 供电 | USB 5V;传感器接 **3.3V** |
|
||||
| 项目 | 2.8"(默认 `cyd_28r`) | 3.5C(`cyd_35r`) |
|
||||
|------|------------------------|-------------------|
|
||||
| 板子 | ESP32-2432S028R(ILI9341) | ESP32-3248S035C(ST7796) |
|
||||
| 触控 | XPT2046 SoftSPI | GT911 I2C(Wire1) |
|
||||
| 背光 | **GPIO21** | **GPIO27** |
|
||||
| GY30 SDA | **GPIO22** | **GPIO22**(不变) |
|
||||
| GY30 SCL | **GPIO27** | **GPIO21**(2.8 的 27→21) |
|
||||
| 供电 | USB 5V;传感器 **3.3V** | 同左 |
|
||||
|
||||
接线:`VCC→3.3V`,`GND→GND`,`SDA→GPIO22`,`SCL→GPIO27`。
|
||||
接线:
|
||||
|
||||
- **2.8**:`VCC→3.3V`,`GND→GND`,`SDA→GPIO22`,`SCL→GPIO27`
|
||||
- **3.5**:`VCC→3.3V`,`GND→GND`,`SDA→GPIO22`,`SCL→GPIO21`(勿接 27,那是背光)
|
||||
|
||||
## 功能
|
||||
|
||||
@@ -29,33 +33,42 @@ ESP32 Cheap Yellow Display(ESP32-2432S028R)+ GY30(BH1750)+ LVGL 光照
|
||||
依赖 [PlatformIO](https://platformio.org/)。
|
||||
|
||||
```bash
|
||||
# 2.8"
|
||||
pio run -e cyd_28r -t upload
|
||||
pio device monitor -b 115200
|
||||
|
||||
# 3.5"
|
||||
pio run -e cyd_35r -t upload
|
||||
```
|
||||
|
||||
### 预编译固件
|
||||
|
||||
```powershell
|
||||
cd firmware\cyd_28r
|
||||
cd firmware\cyd_28r # 或 cyd_35r
|
||||
.\flash.ps1
|
||||
```
|
||||
|
||||
源码更新后重新打包:`.\firmware\export_from_build.ps1`。
|
||||
源码更新后重新打包:
|
||||
|
||||
```powershell
|
||||
.\firmware\export_from_build.ps1 # 2.8
|
||||
.\firmware\export_from_build.ps1 -Env cyd_35r # 3.5
|
||||
```
|
||||
|
||||
| 环境 | 适用 |
|
||||
|------|------|
|
||||
| `cyd_28r` | 标准 ILI9341 CYD(默认) |
|
||||
| `cyd_28r` | 标准 2.8" ILI9341 CYD(默认) |
|
||||
| `cyd_28r_inv` | 颜色反相 / 发白 |
|
||||
| `cyd_28_st7789` | USB-C 双口 / ST7789 变体 |
|
||||
| `cyd_35r` | 3.5" ESP32-3248S035C(ST7796 + GT911) |
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
platformio.ini # 板级与库依赖
|
||||
include/lv_conf.h # LVGL 配置
|
||||
src/main.cpp # 仪表盘主程序
|
||||
scripts/exclude_lvgl_asm.py # 排除 ESP32 不兼容的 LVGL ASM
|
||||
firmware/ # 预编译固件
|
||||
platformio.ini # 板级与库依赖(含 cyd_35r)
|
||||
include/lv_conf.h / touch.h
|
||||
src/main.cpp / touch.cpp
|
||||
scripts/exclude_lvgl_asm.py
|
||||
firmware/cyd_28r/ firmware/cyd_35r/
|
||||
README.md
|
||||
```
|
||||
|
||||
@@ -63,5 +76,6 @@ README.md
|
||||
|
||||
| 日期 | 说明 |
|
||||
|------|------|
|
||||
| 2026-10-20 | 初版:参考 temperature/sgp30test,GY30(BH1750) SDA=GPIO22 / SCL=GPIO27,LUX/LEVEL 双表盘、场景条、趋势图 |
|
||||
| 2026-10-20 | 初版:GY30(BH1750) SDA=GPIO22 / SCL=GPIO27,LUX/LEVEL 双表盘 |
|
||||
| 2026-10-20 | 增加 `meta.json` 与 `media/preview.html`,供 cydweb 本地目录展示 |
|
||||
| 2026-10-25 | 按 CYD_PROJECT_GUIDE 修正 3.5:背光 GPIO27、GY30 SCL=GPIO21、GT911 Wire1、导出/刷写 `cyd_35r` |
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
# 预编译固件(可随时刷写)
|
||||
|
||||
当前归档目录:[`cyd_28r/`](cyd_28r/)
|
||||
| 目录 | 板子 |
|
||||
|------|------|
|
||||
| [`cyd_28r/`](cyd_28r/) | CYD ESP32-2432S028R(2.8" ILI9341),GY30 → SDA=GPIO22 / SCL=GPIO27 |
|
||||
| [`cyd_35r/`](cyd_35r/) | CYD ESP32-3248S035C(3.5" ST7796 + GT911),GY30 → SDA=GPIO22 / SCL=GPIO21 |
|
||||
|
||||
对应板子:**CYD ESP32-2432S028R**(ILI9341),GY30 → SDA=GPIO22 / SCL=GPIO27。
|
||||
版本信息见 [`cyd_28r/VERSION.txt`](cyd_28r/VERSION.txt)。
|
||||
版本信息见各目录 `VERSION.txt`。
|
||||
|
||||
## 直接刷写(无需重新编译)
|
||||
|
||||
```powershell
|
||||
cd firmware\cyd_28r
|
||||
cd firmware\cyd_28r # 或 cyd_35r
|
||||
.\flash.ps1
|
||||
# 或指定端口
|
||||
.\flash.ps1 -Port COM3
|
||||
@@ -23,5 +25,6 @@ cd firmware\cyd_28r
|
||||
在仓库根目录:
|
||||
|
||||
```powershell
|
||||
.\firmware\export_from_build.ps1
|
||||
.\firmware\export_from_build.ps1 # 2.8
|
||||
.\firmware\export_from_build.ps1 -Env cyd_35r # 3.5
|
||||
```
|
||||
|
||||
15
firmware/cyd_35r/VERSION.txt
Normal file
15
firmware/cyd_35r/VERSION.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
name: CYD gy30test (cyd_35r)
|
||||
git: 604fa26
|
||||
date: 2026-10-25
|
||||
board: ESP32-3248S035 (ST7796)
|
||||
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 531415EDA642DD3A6E8CAA0B6D1F42E3EF653C28BC8DC19A359FE45E0BFD3463
|
||||
partitions.bin 0A8B5720E7B77FF11F1462458C3A509DEE79224E5279898F26D6A2E3AE0517B7
|
||||
BIN
firmware/cyd_35r/boot_app0.bin
Normal file
BIN
firmware/cyd_35r/boot_app0.bin
Normal file
Binary file not shown.
BIN
firmware/cyd_35r/bootloader.bin
Normal file
BIN
firmware/cyd_35r/bootloader.bin
Normal file
Binary file not shown.
BIN
firmware/cyd_35r/firmware.bin
Normal file
BIN
firmware/cyd_35r/firmware.bin
Normal file
Binary file not shown.
5
firmware/cyd_35r/flash.bat
Normal file
5
firmware/cyd_35r/flash.bat
Normal file
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
setlocal
|
||||
cd /d "%~dp0"
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0flash.ps1" %*
|
||||
exit /b %ERRORLEVEL%
|
||||
85
firmware/cyd_35r/flash.ps1
Normal file
85
firmware/cyd_35r/flash.ps1
Normal file
@@ -0,0 +1,85 @@
|
||||
# Flash archived CYD climate 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 ($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"
|
||||
}
|
||||
|
||||
$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."
|
||||
|
||||
82
firmware/cyd_35r/media/media/preview.html
Normal file
82
firmware/cyd_35r/media/media/preview.html
Normal file
@@ -0,0 +1,82 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=320" />
|
||||
<title>CLIMATE</title>
|
||||
<style>
|
||||
*{box-sizing:border-box;margin:0;padding:0}
|
||||
html,body{width:320px;height:240px;overflow:hidden;background:#000;margin:0}
|
||||
.bezel{width:320px;height:240px;background:#1a1408}
|
||||
.screen{
|
||||
width:320px;height:240px;background:#0A1018;color:#F2F5FA;
|
||||
font:12px/1.2 system-ui,sans-serif;position:relative;overflow:hidden;
|
||||
}
|
||||
.hdr{display:flex;align-items:center;gap:8px;padding:4px 8px;height:24px}
|
||||
.hdr b{font-size:14px;font-weight:700}
|
||||
.hdr .up{color:#7E90A8}
|
||||
.hdr .sp{margin-left:auto;display:flex;align-items:center;gap:6px;color:#7E90A8}
|
||||
.led{width:9px;height:9px;border-radius:50%;background:#4CAF7A}
|
||||
.row{display:flex;gap:6px;padding:0 8px}
|
||||
.panel{
|
||||
flex:1;height:118px;background:#121C2A;border:1px solid #1E2C40;
|
||||
border-radius:6px;padding:6px 8px;position:relative;
|
||||
}
|
||||
.cap{color:#7E90A8;font-size:11px}
|
||||
.gauge{
|
||||
width:90px;height:90px;margin:4px auto 0;border-radius:50%;
|
||||
background:conic-gradient(#3DBF8C 0 70%, #243247 0);
|
||||
mask:radial-gradient(farthest-side,transparent 62%,#000 63%);
|
||||
-webkit-mask:radial-gradient(farthest-side,transparent 62%,#000 63%);
|
||||
}
|
||||
.panel.hum .gauge{background:conic-gradient(#3DB8A8 0 55%, #243247 0)}
|
||||
.val{position:absolute;left:0;right:0;top:48px;text-align:center;font-size:24px;font-weight:700}
|
||||
.panel.hum .val{color:#3DB8A8}
|
||||
.panel.temp .val{color:#3DBF8C}
|
||||
.unit{font-size:11px;color:#7E90A8;font-weight:500}
|
||||
.rng{position:absolute;left:0;right:0;bottom:6px;text-align:center;color:#7E90A8;font-size:11px}
|
||||
.bot{
|
||||
margin:6px 8px 0;height:78px;background:#121C2A;border:1px solid #1E2C40;
|
||||
border-radius:6px;display:flex;gap:8px;padding:8px;
|
||||
}
|
||||
.info{width:88px}
|
||||
.ok{color:#E6B84D;font-size:14px;font-weight:700}
|
||||
.bar{margin-top:8px;height:8px;background:#243247;border-radius:4px;overflow:hidden}
|
||||
.bar>i{display:block;height:100%;width:62%;background:#E6B84D}
|
||||
.meta{margin-top:10px;color:#7E90A8;font-size:11px}
|
||||
.chart{flex:1;background:#0E1622;border-radius:4px;position:relative;overflow:hidden}
|
||||
.chart svg{width:100%;height:100%}
|
||||
|
||||
/* CYD 3.5" full-bleed: non-uniform scale matches firmware UX()/UY(). */
|
||||
html,body{width:480px!important;height:320px!important;overflow:hidden!important;background:#000!important;margin:0!important;padding:0!important}
|
||||
.cyd35-scale{width:320px;height:240px;transform:scale(1.5,1.3333333333);transform-origin:0 0;overflow:hidden}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="cyd35-scale">
|
||||
|
||||
<div class="bezel"><div class="screen" id="s">
|
||||
<div class="hdr"><b>CLIMATE</b><span class="up">up 01:24</span>
|
||||
<span class="sp"><span>OK</span><span class="led"></span></span></div>
|
||||
<div class="row">
|
||||
<div class="panel temp"><div class="cap">TEMP</div><div class="gauge"></div>
|
||||
<div class="val">24.6<span class="unit">C</span></div><div class="rng">22.1 / 26.0</div></div>
|
||||
<div class="panel hum"><div class="cap">HUM</div><div class="gauge"></div>
|
||||
<div class="val">48<span class="unit">%</span></div><div class="rng">41 / 55</div></div>
|
||||
</div>
|
||||
<div class="bot">
|
||||
<div class="info"><div class="ok">COMFORT</div><div class="bar"><i></i></div>
|
||||
<div class="meta">DHT11 · GPIO22</div></div>
|
||||
<div class="chart"><svg viewBox="0 0 180 60" preserveAspectRatio="none">
|
||||
<polyline fill="none" stroke="#3DBF8C" stroke-width="2"
|
||||
points="0,40 20,35 40,38 60,28 80,30 100,22 120,26 140,18 160,24 180,20"/>
|
||||
<polyline fill="none" stroke="#3DB8A8" stroke-width="2"
|
||||
points="0,45 20,42 40,44 60,40 80,38 100,36 120,39 140,34 160,37 180,35"/>
|
||||
</svg></div>
|
||||
</div>
|
||||
</div></div>
|
||||
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
66
firmware/cyd_35r/media/preview.html
Normal file
66
firmware/cyd_35r/media/preview.html
Normal file
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>LIGHT</title>
|
||||
<style>
|
||||
*{box-sizing:border-box;margin:0;padding:0}
|
||||
html,body{width:320px;height:240px;overflow:hidden;background:#000;margin:0}
|
||||
.bezel{width:320px;height:240px;background:#1a1408}
|
||||
.screen{width:320px;height:240px;background:#0A1018;color:#F2F5FA;font:12px/1.2 system-ui,sans-serif;
|
||||
overflow:hidden}
|
||||
.hdr{display:flex;align-items:center;gap:8px;padding:4px 8px;height:24px}
|
||||
.hdr b{font-size:14px}.up{color:#7E90A8}.sp{margin-left:auto;display:flex;gap:6px;align-items:center;color:#7E90A8}
|
||||
.led{width:9px;height:9px;border-radius:50%;background:#4CAF7A}
|
||||
.row{display:flex;gap:6px;padding:0 8px}
|
||||
.panel{flex:1;height:118px;background:#121C2A;border:1px solid #1E2C40;border-radius:6px;padding:6px 8px;position:relative}
|
||||
.cap{color:#7E90A8;font-size:11px}
|
||||
.gauge{width:90px;height:90px;margin:4px auto 0;border-radius:50%;
|
||||
background:conic-gradient(#F0C040 0 42%, #243247 0);
|
||||
mask:radial-gradient(farthest-side,transparent 62%,#000 63%);
|
||||
-webkit-mask:radial-gradient(farthest-side,transparent 62%,#000 63%)}
|
||||
.panel.lvl .gauge{background:conic-gradient(#4DA3FF 0 58%, #243247 0)}
|
||||
.val{position:absolute;left:0;right:0;top:44px;text-align:center;font-size:20px;font-weight:700;color:#F0C040}
|
||||
.panel.lvl .val{color:#4DA3FF}
|
||||
.unit{font-size:10px;color:#7E90A8}
|
||||
.rng{position:absolute;left:0;right:0;bottom:6px;text-align:center;color:#7E90A8;font-size:11px}
|
||||
.bot{margin:6px 8px 0;height:78px;background:#121C2A;border:1px solid #1E2C40;border-radius:6px;display:flex;gap:8px;padding:8px}
|
||||
.info{width:96px}.ok{color:#4CAF7A;font-size:14px;font-weight:700}
|
||||
.bar{margin-top:8px;height:8px;background:#243247;border-radius:4px;overflow:hidden}
|
||||
.bar>i{display:block;height:100%;width:58%;background:#4DA3FF}
|
||||
.meta{margin-top:8px;color:#7E90A8;font-size:11px}
|
||||
.chart{flex:1;background:#0E1622;border-radius:4px}
|
||||
.chart svg{width:100%;height:100%}
|
||||
|
||||
/* CYD 3.5" full-bleed: non-uniform scale matches firmware UX()/UY(). */
|
||||
html,body{width:480px!important;height:320px!important;overflow:hidden!important;background:#000!important;margin:0!important;padding:0!important}
|
||||
.cyd35-scale{width:320px;height:240px;transform:scale(1.5,1.3333333333);transform-origin:0 0;overflow:hidden}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="cyd35-scale">
|
||||
|
||||
<div class="bezel"><div class="screen" id="s">
|
||||
<div class="hdr"><b>LIGHT</b><span class="up">up 02:18</span>
|
||||
<span class="sp"><span>OK</span><span class="led"></span></span></div>
|
||||
<div class="row">
|
||||
<div class="panel"><div class="cap">LUX</div><div class="gauge"></div>
|
||||
<div class="val">186<span class="unit"> lx</span></div><div class="rng">42 / 420</div></div>
|
||||
<div class="panel lvl"><div class="cap">LEVEL</div><div class="gauge"></div>
|
||||
<div class="val">58<span class="unit"> %</span></div><div class="rng">EV 7.5</div></div>
|
||||
</div>
|
||||
<div class="bot">
|
||||
<div class="info"><div class="ok">INDOOR</div><div class="bar"><i></i></div>
|
||||
<div class="meta">GY30 BH1750<br/>SDA22 · SCL27</div></div>
|
||||
<div class="chart"><svg viewBox="0 0 180 60" preserveAspectRatio="none">
|
||||
<polyline fill="none" stroke="#F0C040" stroke-width="2"
|
||||
points="0,40 20,38 40,32 60,30 80,28 100,34 120,26 140,24 160,22 180,25"/>
|
||||
<polyline fill="none" stroke="#4DA3FF" stroke-width="2"
|
||||
points="0,48 20,46 40,44 60,42 80,40 100,43 120,38 140,36 160,35 180,37"/>
|
||||
</svg></div>
|
||||
</div>
|
||||
</div></div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
15
firmware/cyd_35r/meta.json
Normal file
15
firmware/cyd_35r/meta.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"boardId": "esp32-3248s035",
|
||||
"name": "CYD GY30 light dashboard (3.5\")",
|
||||
"summary": "Lux \u0026 perceived-level gauges with scene bar and chart",
|
||||
"description": "GY30 / BH1750 on SDA=GPIO22 / SCL=GPIO21 (3.5C). Dual arcs for LUX / LEVEL%, scene label, EV, live sparkline. Tap cycles backlight; hold resets min/max.",
|
||||
"tags": [
|
||||
"light",
|
||||
"gy30",
|
||||
"bh1750",
|
||||
"lux"
|
||||
],
|
||||
"media": {
|
||||
"preview": "media/preview.html"
|
||||
}
|
||||
}
|
||||
BIN
firmware/cyd_35r/partitions.bin
Normal file
BIN
firmware/cyd_35r/partitions.bin
Normal file
Binary file not shown.
@@ -73,8 +73,8 @@ 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\")"
|
||||
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 {
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
#define LV_COLOR_DEPTH 16
|
||||
|
||||
#ifndef LV_MEM_SIZE
|
||||
#define LV_MEM_SIZE (48 * 1024U)
|
||||
#endif
|
||||
#define LV_DEF_REFR_PERIOD 16
|
||||
#define LV_DPI_DEF 130
|
||||
|
||||
|
||||
6
include/touch.h
Normal file
6
include/touch.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
void touch_init();
|
||||
void touch_read_cb(lv_indev_t *indev, lv_indev_data_t *data);
|
||||
@@ -1,6 +1,6 @@
|
||||
; CYD ESP32-2432S028R �LVGL GY30(BH1750) 光照仪表�
|
||||
; GY30 SDA -> GPIO22, SCL -> GPIO27
|
||||
|
||||
; CYD — LVGL GY30(BH1750) light dashboard
|
||||
; 2.8": GY30 SDA=GPIO22 SCL=GPIO27, TFT_BL=21
|
||||
; 3.5C: GY30 SDA=GPIO22 SCL=GPIO21, TFT_BL=27 (GT911 on Wire1 33/32)
|
||||
[platformio]
|
||||
default_envs = cyd_28r
|
||||
|
||||
@@ -46,12 +46,12 @@ build_flags =
|
||||
-D LV_CONF_INCLUDE_SIMPLE=1
|
||||
-I include
|
||||
|
||||
; æ ‡å‡† CYD 2.8" 电阻å±?(ILI9341)
|
||||
; 标准 CYD 2.8" 电阻<EFBFBD>?(ILI9341)
|
||||
[env:cyd_28r]
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
|
||||
; 颜色å<EFBFBD><EFBFBD>相版本(若画é<EFBFBD>¢è‰²å<EFBFBD><EFBFBD>/å<>‘白å<C2BD>¯æ”¹ç”¨æ¤çŽ¯å¢ƒï¼?
|
||||
; 颜色反相版本(若画面色偏/发白可改用此环境<E78EAF>?
|
||||
[env:cyd_28r_inv]
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
@@ -66,18 +66,28 @@ build_flags =
|
||||
-D TFT_RGB_ORDER=TFT_BGR
|
||||
-D TFT_INVERSION_ON=1
|
||||
|
||||
; Optional 3.5" CYD ESP32-3248S035 (ST7796 resistive). Default remains cyd_28r.
|
||||
; Optional 3.5" CYD ESP32-3248S035C (ST7796 + GT911 capacitive). Default remains cyd_28r.
|
||||
; Build: pio run -e cyd_35r
|
||||
; Keep TOUCH_CS=-1 — GPIO33 is GT911 SDA, not resistive touch CS.
|
||||
; TFT_BL=GPIO27 (not 21 — 21 is GT911 INT / GY30 SCL). GT911 uses Wire1.
|
||||
[env:cyd_35r]
|
||||
lib_deps =
|
||||
lvgl/lvgl@9.2.2
|
||||
bodmer/TFT_eSPI@2.5.43
|
||||
claws/BH1750@^1.3.0
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-U ILI9341_2_DRIVER
|
||||
-D ST7796_DRIVER=1
|
||||
-U TFT_WIDTH
|
||||
-U TFT_HEIGHT
|
||||
-D TFT_WIDTH=320
|
||||
-D TFT_HEIGHT=480
|
||||
-U TFT_BL
|
||||
-D TFT_BL=27
|
||||
-D CYD_BOARD_3248S035=1
|
||||
-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
|
||||
-DSUPPORT_TRANSACTIONS
|
||||
-DTFT_RGB_ORDER=TFT_BGR
|
||||
-ULV_MEM_SIZE
|
||||
-DLV_MEM_SIZE=32768
|
||||
|
||||
|
||||
71
src/main.cpp
71
src/main.cpp
@@ -1,30 +1,26 @@
|
||||
/**
|
||||
* CYD ESP32-2432S028R — LVGL GY30(BH1750) 光照仪表盘
|
||||
* GY30 SDA -> GPIO22, SCL -> GPIO27
|
||||
* CYD — LVGL GY30(BH1750) 光照仪表盘
|
||||
* 2.8": SDA=GPIO22 SCL=GPIO27, TFT_BL=GPIO21
|
||||
* 3.5C: SDA=GPIO22 SCL=GPIO21, TFT_BL=GPIO27 (GT911 INT=21, polled; Wire1 for touch)
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <lvgl.h>
|
||||
#include <TFT_eSPI.h>
|
||||
#include <XPT2046_Touchscreen.h>
|
||||
#include <BH1750.h>
|
||||
#include <math.h>
|
||||
#include "touch.h"
|
||||
|
||||
#define I2C_SDA 22
|
||||
#define I2C_SCL 27
|
||||
#if defined(CYD_BOARD_3248S035)
|
||||
#define I2C_SCL 21
|
||||
#define TFT_BL_PIN 27
|
||||
#else
|
||||
#define I2C_SCL 27
|
||||
#define TFT_BL_PIN 21
|
||||
#endif
|
||||
|
||||
#define XPT2046_IRQ 36
|
||||
#define XPT2046_MOSI 32
|
||||
#define XPT2046_MISO 39
|
||||
#define XPT2046_CLK 25
|
||||
#define XPT2046_CS 33
|
||||
|
||||
#if defined(CYD_BOARD_3248S035)
|
||||
#define SCREEN_WIDTH 480
|
||||
#define SCREEN_HEIGHT 320
|
||||
@@ -37,7 +33,11 @@
|
||||
#define EMA_ALPHA 0.35f
|
||||
#define HISTORY_LEN 48
|
||||
#define LUX_ARC_MAX 1000
|
||||
#if defined(CYD_BOARD_3248S035)
|
||||
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 20 * (LV_COLOR_DEPTH / 8))
|
||||
#else
|
||||
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
|
||||
#endif
|
||||
|
||||
/* Layout grid — every region has exclusive space, no overlaps */
|
||||
#if defined(CYD_BOARD_3248S035)
|
||||
@@ -78,8 +78,6 @@ static const lv_color_t COL_BAD = lv_color_hex(0xE05A5A);
|
||||
static const lv_color_t COL_ARC_BG = lv_color_hex(0x243247);
|
||||
static const lv_color_t COL_CHART_BG = lv_color_hex(0x0E1622);
|
||||
|
||||
SPIClass touchscreenSPI = SPIClass(VSPI);
|
||||
XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);
|
||||
BH1750 lightMeter;
|
||||
|
||||
static uint32_t draw_buf[DRAW_BUF_SIZE / 4];
|
||||
@@ -190,32 +188,26 @@ static void reset_minmax(void) {
|
||||
}
|
||||
|
||||
static void touchscreen_read(lv_indev_t *indev, lv_indev_data_t *data) {
|
||||
LV_UNUSED(indev);
|
||||
static bool was_pressed = false;
|
||||
static uint32_t press_ms = 0;
|
||||
|
||||
if (touchscreen.tirqTouched() && touchscreen.touched()) {
|
||||
TS_Point p = touchscreen.getPoint();
|
||||
data->point.x = map(p.y, 240, 3800, 1, SCREEN_WIDTH);
|
||||
data->point.y = map(p.x, 200, 3700, SCREEN_HEIGHT, 1);
|
||||
data->state = LV_INDEV_STATE_PRESSED;
|
||||
touch_read_cb(indev, data);
|
||||
|
||||
if (data->state == LV_INDEV_STATE_PRESSED) {
|
||||
if (!was_pressed) {
|
||||
was_pressed = true;
|
||||
press_ms = millis();
|
||||
}
|
||||
} else {
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
if (was_pressed) {
|
||||
was_pressed = false;
|
||||
uint32_t held = millis() - press_ms;
|
||||
if (held >= 700) {
|
||||
reset_minmax();
|
||||
} else if (held < 400) {
|
||||
set_backlight((bright_level + 1) & 0x03);
|
||||
char buf[20];
|
||||
lv_snprintf(buf, sizeof(buf), "brightness %u/3", (unsigned)bright_level);
|
||||
show_hint(buf, 900);
|
||||
}
|
||||
} else if (was_pressed) {
|
||||
was_pressed = false;
|
||||
uint32_t held = millis() - press_ms;
|
||||
if (held >= 700) {
|
||||
reset_minmax();
|
||||
} else if (held < 400) {
|
||||
set_backlight((bright_level + 1) & 0x03);
|
||||
char buf[20];
|
||||
lv_snprintf(buf, sizeof(buf), "brightness %u/3", (unsigned)bright_level);
|
||||
show_hint(buf, 900);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -572,26 +564,26 @@ void setup() {
|
||||
set_backlight(2);
|
||||
|
||||
Serial.println("CYD LVGL GY30 Light Dashboard");
|
||||
Serial.printf("LVGL %d.%d.%d SDA=GPIO%d SCL=GPIO%d\n",
|
||||
Serial.printf("LVGL %d.%d.%d BL=GPIO%d SDA=GPIO%d SCL=GPIO%d\n",
|
||||
lv_version_major(), lv_version_minor(), lv_version_patch(),
|
||||
I2C_SDA, I2C_SCL);
|
||||
TFT_BL_PIN, I2C_SDA, I2C_SCL);
|
||||
|
||||
/* 3.5: GT911 reset briefly drives INT(GPIO21); leave INT as INPUT, then take Wire for GY30. */
|
||||
touch_init();
|
||||
|
||||
Wire.begin(I2C_SDA, I2C_SCL);
|
||||
Wire.setClock(100000);
|
||||
|
||||
if (!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
|
||||
Serial.println("GY30/BH1750 not found — check wiring (SDA22/SCL27)");
|
||||
Serial.printf("GY30/BH1750 not found — check wiring (SDA%d/SCL%d)\n",
|
||||
I2C_SDA, I2C_SCL);
|
||||
} else {
|
||||
Serial.println("GY30/BH1750 OK");
|
||||
}
|
||||
|
||||
lv_init();
|
||||
|
||||
touchscreenSPI.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
|
||||
touchscreen.begin(touchscreenSPI);
|
||||
touchscreen.setRotation(2);
|
||||
|
||||
#if defined(CYD_BOARD_3248S035)
|
||||
#if defined(CYD_BOARD_3248S035)
|
||||
lv_display_t *disp = lv_tft_espi_create(320, 480, draw_buf, sizeof(draw_buf));
|
||||
#else
|
||||
lv_display_t *disp = lv_tft_espi_create(240, 320, draw_buf, sizeof(draw_buf));
|
||||
@@ -601,6 +593,7 @@ void setup() {
|
||||
lv_indev_t *indev = lv_indev_create();
|
||||
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
|
||||
lv_indev_set_read_cb(indev, touchscreen_read);
|
||||
lv_indev_set_display(indev, disp);
|
||||
|
||||
create_ui();
|
||||
delay(200);
|
||||
|
||||
196
src/touch.cpp
Normal file
196
src/touch.cpp
Normal file
@@ -0,0 +1,196 @@
|
||||
#include "touch.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
/**
|
||||
* 2.8": XPT2046 resistive SoftSPI bus (CS33).
|
||||
* 3.5C (3248S035C): GT911 capacitive on Wire1 SDA33/SCL32/INT21/RST25.
|
||||
* Feed coords are always native panel 320x480 for LVGL ROTATION_270.
|
||||
* Wire1 leaves Wire free for GY30 (SDA22 / SCL21). TFT_BL is GPIO27.
|
||||
* After address select, INT returns to INPUT so GPIO21 can be GY30 SCL.
|
||||
*/
|
||||
|
||||
static int16_t clampi(int32_t v, int32_t lo, int32_t hi) {
|
||||
if (v < lo) return (int16_t)lo;
|
||||
if (v > hi) return (int16_t)hi;
|
||||
return (int16_t)v;
|
||||
}
|
||||
|
||||
#if defined(CYD_BOARD_3248S035)
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
/* Native panel size — not UI landscape SCREEN_* (480x320). */
|
||||
static constexpr int16_t PANEL_W = 320;
|
||||
static constexpr int16_t PANEL_H = 480;
|
||||
|
||||
#define CYD_GT911_SDA 33
|
||||
#define CYD_GT911_SCL 32
|
||||
#define CYD_GT911_INT 21
|
||||
#define CYD_GT911_RST 25
|
||||
|
||||
/* Minimal GT911 — no config rewrite (TAMC setResolution can hang Wire). */
|
||||
static uint8_t s_gt_addr = 0x5D;
|
||||
static constexpr uint16_t GT_POINT_INFO = 0x814E;
|
||||
static constexpr uint16_t GT_POINT_1 = 0x814F;
|
||||
|
||||
static bool gt_write8(uint16_t reg, uint8_t val) {
|
||||
Wire1.beginTransmission(s_gt_addr);
|
||||
Wire1.write((uint8_t)(reg >> 8));
|
||||
Wire1.write((uint8_t)(reg & 0xFF));
|
||||
Wire1.write(val);
|
||||
return Wire1.endTransmission() == 0;
|
||||
}
|
||||
|
||||
static bool gt_read(uint16_t reg, uint8_t *buf, uint8_t len) {
|
||||
Wire1.beginTransmission(s_gt_addr);
|
||||
Wire1.write((uint8_t)(reg >> 8));
|
||||
Wire1.write((uint8_t)(reg & 0xFF));
|
||||
if (Wire1.endTransmission(false) != 0) {
|
||||
return false;
|
||||
}
|
||||
const uint8_t n = Wire1.requestFrom(s_gt_addr, len);
|
||||
if (n != len) {
|
||||
return false;
|
||||
}
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
buf[i] = Wire1.read();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool gt_probe(uint8_t addr) {
|
||||
Wire1.beginTransmission(addr);
|
||||
return Wire1.endTransmission() == 0;
|
||||
}
|
||||
|
||||
/* TAMC-compatible address select: INT low => 0x5D, INT high => 0x14 */
|
||||
static void gt_hw_reset(bool addr_0x14) {
|
||||
pinMode(CYD_GT911_INT, OUTPUT);
|
||||
pinMode(CYD_GT911_RST, OUTPUT);
|
||||
digitalWrite(CYD_GT911_INT, LOW);
|
||||
digitalWrite(CYD_GT911_RST, LOW);
|
||||
delay(10);
|
||||
digitalWrite(CYD_GT911_INT, addr_0x14 ? HIGH : LOW);
|
||||
delay(1);
|
||||
digitalWrite(CYD_GT911_RST, HIGH);
|
||||
delay(5);
|
||||
digitalWrite(CYD_GT911_INT, LOW);
|
||||
delay(50);
|
||||
/* Backlight is GPIO27 — leave INT as input so GPIO21 can be GY30 SCL. */
|
||||
pinMode(CYD_GT911_INT, INPUT);
|
||||
delay(50);
|
||||
}
|
||||
|
||||
static bool gt_find_addr() {
|
||||
for (uint8_t a : {uint8_t(0x5D), uint8_t(0x14)}) {
|
||||
if (gt_probe(a)) {
|
||||
s_gt_addr = a;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void touch_init() {
|
||||
Serial.println("Touch: GT911 I2C capacitive (3.5C) minimal Wire1");
|
||||
Wire1.begin(CYD_GT911_SDA, CYD_GT911_SCL);
|
||||
Wire1.setClock(100000);
|
||||
#if defined(WIRE_HAS_TIMEOUT) || defined(ESP32)
|
||||
Wire1.setTimeOut(50);
|
||||
#endif
|
||||
|
||||
if (!gt_find_addr()) {
|
||||
Serial.println("GT911 not found — hw reset 0x5D");
|
||||
gt_hw_reset(false);
|
||||
if (!gt_find_addr()) {
|
||||
Serial.println("GT911 not found — hw reset 0x14");
|
||||
gt_hw_reset(true);
|
||||
gt_find_addr();
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure INT is free for GY30 SCL even if probe skipped hw reset. */
|
||||
pinMode(CYD_GT911_INT, INPUT);
|
||||
|
||||
Serial.printf("GT911 probe 0x5D=%s 0x14=%s using=0x%02X\n",
|
||||
gt_probe(0x5D) ? "OK" : "no", gt_probe(0x14) ? "OK" : "no",
|
||||
s_gt_addr);
|
||||
Serial.printf("GT911 SDA=%d SCL=%d INT=%d RST=%d\n", CYD_GT911_SDA,
|
||||
CYD_GT911_SCL, CYD_GT911_INT, CYD_GT911_RST);
|
||||
}
|
||||
|
||||
void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) {
|
||||
uint8_t info = 0;
|
||||
|
||||
if (!gt_read(GT_POINT_INFO, &info, 1)) {
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t touches = info & 0x0F;
|
||||
const bool buffered = (info & 0x80) != 0;
|
||||
|
||||
if (!buffered || touches == 0) {
|
||||
if (buffered) {
|
||||
gt_write8(GT_POINT_INFO, 0);
|
||||
}
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t pt[7];
|
||||
if (!gt_read(GT_POINT_1, pt, 7)) {
|
||||
gt_write8(GT_POINT_INFO, 0);
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
return;
|
||||
}
|
||||
gt_write8(GT_POINT_INFO, 0);
|
||||
|
||||
const int16_t raw_x = (int16_t)(pt[1] | (pt[2] << 8));
|
||||
const int16_t raw_y = (int16_t)(pt[3] | (pt[4] << 8));
|
||||
|
||||
/* Native 320x480 → LVGL 270. */
|
||||
const int16_t nx = clampi(raw_x, 0, PANEL_W - 1);
|
||||
const int16_t ny = clampi(raw_y, 0, PANEL_H - 1);
|
||||
data->point.x = (int16_t)((PANEL_W - 1) - nx);
|
||||
data->point.y = (int16_t)((PANEL_H - 1) - ny);
|
||||
data->state = LV_INDEV_STATE_PRESSED;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <SPI.h>
|
||||
#include <XPT2046_Touchscreen.h>
|
||||
|
||||
#define XPT2046_IRQ 36
|
||||
#define XPT2046_MOSI 32
|
||||
#define XPT2046_MISO 39
|
||||
#define XPT2046_CLK 25
|
||||
#define XPT2046_CS 33
|
||||
|
||||
static constexpr int16_t UI_W = 320;
|
||||
static constexpr int16_t UI_H = 240;
|
||||
|
||||
static SPIClass touchscreenSPI = SPIClass(VSPI);
|
||||
static XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);
|
||||
|
||||
void touch_init() {
|
||||
touchscreenSPI.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
|
||||
touchscreen.begin(touchscreenSPI);
|
||||
touchscreen.setRotation(2);
|
||||
Serial.println("Touch: XPT2046 resistive (2.8)");
|
||||
}
|
||||
|
||||
void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) {
|
||||
if (touchscreen.tirqTouched() && touchscreen.touched()) {
|
||||
TS_Point p = touchscreen.getPoint();
|
||||
data->point.x = map(p.y, 240, 3800, 1, UI_W);
|
||||
data->point.y = map(p.x, 200, 3700, UI_H, 1);
|
||||
data->state = LV_INDEV_STATE_PRESSED;
|
||||
} else {
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user