Add button counter test on GPIO22 with SoftSPI touch and LVGL.

Each press increments on-screen count; touch Reset clears. Flashable firmware/cyd package.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-23 12:43:09 +08:00
commit 22a3c469d4
23 changed files with 1829 additions and 0 deletions

57
src/main.cpp Normal file
View File

@@ -0,0 +1,57 @@
#include <Arduino.h>
#include <lvgl.h>
#include "button.h"
#include "pins.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];
void setup() {
Serial.begin(460800);
delay(200);
Serial.println();
Serial.printf("LVGL %d.%d.%d | Button sensor GPIO%d\n", lv_version_major(),
lv_version_minor(), lv_version_patch(), BTN_PIN);
Serial.println("BOOT_OK");
pinMode(TFT_BL_PIN, OUTPUT);
digitalWrite(TFT_BL_PIN, HIGH);
touch_init();
button_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();
}
void loop() {
if (button_poll_press()) {
ui_refresh_count();
} else {
// 按下/松开时刷新状态字,但不重复计数
static bool last_down = false;
const bool down = button_is_down();
if (down != last_down) {
last_down = down;
ui_refresh_count();
}
}
lv_timer_handler();
lv_tick_inc(5);
delay(5);
}