Keep calibrated SoftSPI touch mapping unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
87 lines
2.0 KiB
C++
87 lines
2.0 KiB
C++
#include <Arduino.h>
|
||
#include <lvgl.h>
|
||
|
||
#include "audio_test.h"
|
||
#include "pins.h"
|
||
#include "sd_info.h"
|
||
#include "touch.h"
|
||
#include "ui.h"
|
||
|
||
static constexpr uint32_t DRAW_BUF_SIZE =
|
||
(SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8));
|
||
static uint32_t draw_buf[DRAW_BUF_SIZE / 4];
|
||
|
||
static uint32_t last_refresh_ms = 0;
|
||
static uint32_t last_btn_ui_ms = 0;
|
||
static constexpr uint32_t REFRESH_MS = 3000;
|
||
|
||
static void refresh_sd_ui() {
|
||
SdCardInfo info = sd_read_info();
|
||
|
||
Serial.println("---- TF Card ----");
|
||
if (!info.mounted) {
|
||
Serial.printf("Error: %s\n", info.error.c_str());
|
||
} else {
|
||
Serial.printf("Type: %s FS: %s Cap: %s\n", info.type, info.filesystem,
|
||
format_bytes(info.card_bytes).c_str());
|
||
}
|
||
|
||
ui_update(info);
|
||
}
|
||
|
||
void setup() {
|
||
Serial.begin(115200);
|
||
delay(200);
|
||
Serial.println();
|
||
Serial.printf("LVGL %d.%d.%d | CYD TF + Speaker\n", lv_version_major(),
|
||
lv_version_minor(), lv_version_patch());
|
||
|
||
pinMode(TFT_BL_PIN, OUTPUT);
|
||
digitalWrite(TFT_BL_PIN, HIGH);
|
||
|
||
// 先触摸再 SD:触控 SoftSPI 与 SD VSPI 分脚,映射勿改 touch.cpp
|
||
touch_init();
|
||
audio_init();
|
||
|
||
lv_init();
|
||
|
||
lv_display_t *disp =
|
||
lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
|
||
lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270);
|
||
|
||
lv_indev_t *indev = lv_indev_create();
|
||
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
|
||
lv_indev_set_read_cb(indev, touch_read_cb);
|
||
lv_indev_set_display(indev, disp);
|
||
|
||
ui_create();
|
||
|
||
if (!sd_init()) {
|
||
Serial.println("SD mount failed at boot");
|
||
}
|
||
|
||
refresh_sd_ui();
|
||
last_refresh_ms = millis();
|
||
last_btn_ui_ms = millis();
|
||
}
|
||
|
||
void loop() {
|
||
lv_timer_handler();
|
||
lv_tick_inc(5);
|
||
audio_tick();
|
||
|
||
const uint32_t now = millis();
|
||
if (now - last_refresh_ms >= REFRESH_MS) {
|
||
last_refresh_ms = now;
|
||
refresh_sd_ui();
|
||
}
|
||
|
||
if (now - last_btn_ui_ms >= 200) {
|
||
last_btn_ui_ms = now;
|
||
ui_refresh_audio_buttons();
|
||
ui_set_touch_debug(g_dbg_logic_x, g_dbg_logic_y, g_dbg_touch_down);
|
||
}
|
||
|
||
delay(5);
|
||
}
|