Initial CYD TF card info display with LVGL.
Mount microSD on VSPI and show type, format, and capacity on the CYD screen. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
74
src/main.cpp
Normal file
74
src/main.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include <Arduino.h>
|
||||
#include <TFT_eSPI.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
#include "pins.h"
|
||||
#include "sd_info.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 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\n", info.type);
|
||||
Serial.printf("FS: %s\n", info.filesystem);
|
||||
Serial.printf("Card: %s\n", format_bytes(info.card_bytes).c_str());
|
||||
Serial.printf("Part: %s\n", format_bytes(info.total_bytes).c_str());
|
||||
Serial.printf("Used: %s\n", format_bytes(info.used_bytes).c_str());
|
||||
Serial.printf("Free: %s\n", format_bytes(info.free_bytes).c_str());
|
||||
Serial.printf("Root entries: %lu\n",
|
||||
static_cast<unsigned long>(info.root_files));
|
||||
}
|
||||
|
||||
ui_update(info);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(200);
|
||||
Serial.println();
|
||||
Serial.printf("LVGL %d.%d.%d | CYD TF info\n", lv_version_major(),
|
||||
lv_version_minor(), lv_version_patch());
|
||||
|
||||
pinMode(TFT_BL_PIN, OUTPUT);
|
||||
digitalWrite(TFT_BL_PIN, HIGH);
|
||||
|
||||
lv_init();
|
||||
|
||||
lv_display_t *disp =
|
||||
lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
|
||||
// 横屏:320x240
|
||||
lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270);
|
||||
|
||||
ui_create();
|
||||
|
||||
if (!sd_init()) {
|
||||
Serial.println("SD mount failed at boot");
|
||||
}
|
||||
|
||||
refresh_sd_ui();
|
||||
last_refresh_ms = millis();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
lv_timer_handler();
|
||||
lv_tick_inc(5);
|
||||
|
||||
uint32_t now = millis();
|
||||
if (now - last_refresh_ms >= REFRESH_MS) {
|
||||
last_refresh_ms = now;
|
||||
refresh_sd_ui();
|
||||
}
|
||||
|
||||
delay(5);
|
||||
}
|
||||
Reference in New Issue
Block a user