Add shared JC3636W518 board library and PlatformIO config

- shared/lib/JC3636W518: display/touch/backlight init with LVGL 9 glue
  (from scr_st77916.h), pin map, perf monitor (FPS/refresh/CPU)
- shared/include/lv_conf.h: LVGL 9.6 config for all projects
- shared/jc3636w518.ini: common platform/board/build settings
- display_gif_embedded uses it (23.2 fps, 86% CPU)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patriandClaude Opus 5.5 committed 2026-10-23 01:11:02 +02:00
1 parent 9684ab39f2
commit d6982ab7e7
14 files changed
+799 -2357

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
{
"name": "JC3636W518",
"version": "1.0.0",
"description": "Board support for the JC3636W518 (ESP32-S3, ST77916 360x360 QSPI LCD, CST816S touch) with LVGL 9 glue and a performance monitor",
"frameworks": "arduino",
"platforms": "espressif32"
}
+439
View File
@@ -0,0 +1,439 @@
#include "jc3636w518.h"
#include <Arduino.h>
#include <ESP_IOExpander.h>
#include <ESP_Panel_Library.h>
static uint8_t *disp_draw_buf;
static uint8_t *disp_draw_buf2; // second buffer: LVGL renders into one while the other is sent to the LCD
static lv_display_t *disp = NULL;
static lv_indev_t *indev_touchpad;
static ESP_PanelBacklight *backlight = NULL;
static ESP_PanelLcd *lcd = NULL;
static ESP_PanelTouch *touch = NULL;
#define USE_CUSTOM_INIT_CMD 0 // 1 = use the vendor init sequence below instead of the library default
#if TOUCH_PIN_NUM_INT >= 0
IRAM_ATTR bool onTouchInterruptCallback(void *user_data)
{
return false;
}
#endif
#if USE_CUSTOM_INIT_CMD
// Vendor ST77916 init sequence (from the original scr_st77916.h)
const esp_lcd_panel_vendor_init_cmd_t lcd_init_cmd[] = {
{0xF0, (uint8_t[]){0x08}, 1, 0},
{0xF2, (uint8_t[]){0x08}, 1, 0},
{0x9B, (uint8_t[]){0x51}, 1, 0},
{0x86, (uint8_t[]){0x53}, 1, 0},
{0xF2, (uint8_t[]){0x80}, 1, 0},
{0xF0, (uint8_t[]){0x00}, 1, 0},
{0xF0, (uint8_t[]){0x01}, 1, 0},
{0xF1, (uint8_t[]){0x01}, 1, 0},
{0xB0, (uint8_t[]){0x54}, 1, 0},
{0xB1, (uint8_t[]){0x3F}, 1, 0},
{0xB2, (uint8_t[]){0x2A}, 1, 0},
{0xB4, (uint8_t[]){0x46}, 1, 0},
{0xB5, (uint8_t[]){0x34}, 1, 0},
{0xB6, (uint8_t[]){0xD5}, 1, 0},
{0xB7, (uint8_t[]){0x30}, 1, 0},
{0xBA, (uint8_t[]){0x00}, 1, 0},
{0xBB, (uint8_t[]){0x08}, 1, 0},
{0xBC, (uint8_t[]){0x08}, 1, 0},
{0xBD, (uint8_t[]){0x00}, 1, 0},
{0xC0, (uint8_t[]){0x80}, 1, 0},
{0xC1, (uint8_t[]){0x10}, 1, 0},
{0xC2, (uint8_t[]){0x37}, 1, 0},
{0xC3, (uint8_t[]){0x80}, 1, 0},
{0xC4, (uint8_t[]){0x10}, 1, 0},
{0xC5, (uint8_t[]){0x37}, 1, 0},
{0xC6, (uint8_t[]){0xA9}, 1, 0},
{0xC7, (uint8_t[]){0x41}, 1, 0},
{0xC8, (uint8_t[]){0x51}, 1, 0},
{0xC9, (uint8_t[]){0xA9}, 1, 0},
{0xCA, (uint8_t[]){0x41}, 1, 0},
{0xCB, (uint8_t[]){0x51}, 1, 0},
{0xD0, (uint8_t[]){0x91}, 1, 0},
{0xD1, (uint8_t[]){0x68}, 1, 0},
{0xD2, (uint8_t[]){0x69}, 1, 0},
{0xF5, (uint8_t[]){0x00, 0xA5}, 2, 0},
{0xDD, (uint8_t[]){0x3F}, 1, 0},
{0xDE, (uint8_t[]){0x3F}, 1, 0},
{0xF1, (uint8_t[]){0x10}, 1, 0},
{0xF0, (uint8_t[]){0x00}, 1, 0},
{0xF0, (uint8_t[]){0x02}, 1, 0},
{0xE0, (uint8_t[]){0x70, 0x09, 0x12, 0x0C, 0x0B, 0x27, 0x38, 0x54, 0x4E, 0x19, 0x15, 0x15, 0x2C, 0x2F}, 14, 0},
{0xE1, (uint8_t[]){0x70, 0x08, 0x11, 0x0C, 0x0B, 0x27, 0x38, 0x43, 0x4C, 0x18, 0x14, 0x14, 0x2B, 0x2D}, 14, 0},
{0xF0, (uint8_t[]){0x10}, 1, 0},
{0xF3, (uint8_t[]){0x10}, 1, 0},
{0xE0, (uint8_t[]){0x08}, 1, 0},
{0xE1, (uint8_t[]){0x00}, 1, 0},
{0xE2, (uint8_t[]){0x00}, 1, 0},
{0xE3, (uint8_t[]){0x00}, 1, 0},
{0xE4, (uint8_t[]){0xE0}, 1, 0},
{0xE5, (uint8_t[]){0x06}, 1, 0},
{0xE6, (uint8_t[]){0x21}, 1, 0},
{0xE7, (uint8_t[]){0x00}, 1, 0},
{0xE8, (uint8_t[]){0x05}, 1, 0},
{0xE9, (uint8_t[]){0x82}, 1, 0},
{0xEA, (uint8_t[]){0xDF}, 1, 0},
{0xEB, (uint8_t[]){0x89}, 1, 0},
{0xEC, (uint8_t[]){0x20}, 1, 0},
{0xED, (uint8_t[]){0x14}, 1, 0},
{0xEE, (uint8_t[]){0xFF}, 1, 0},
{0xEF, (uint8_t[]){0x00}, 1, 0},
{0xF8, (uint8_t[]){0xFF}, 1, 0},
{0xF9, (uint8_t[]){0x00}, 1, 0},
{0xFA, (uint8_t[]){0x00}, 1, 0},
{0xFB, (uint8_t[]){0x30}, 1, 0},
{0xFC, (uint8_t[]){0x00}, 1, 0},
{0xFD, (uint8_t[]){0x00}, 1, 0},
{0xFE, (uint8_t[]){0x00}, 1, 0},
{0xFF, (uint8_t[]){0x00}, 1, 0},
{0x60, (uint8_t[]){0x42}, 1, 0},
{0x61, (uint8_t[]){0xE0}, 1, 0},
{0x62, (uint8_t[]){0x40}, 1, 0},
{0x63, (uint8_t[]){0x40}, 1, 0},
{0x64, (uint8_t[]){0x02}, 1, 0},
{0x65, (uint8_t[]){0x00}, 1, 0},
{0x66, (uint8_t[]){0x40}, 1, 0},
{0x67, (uint8_t[]){0x03}, 1, 0},
{0x68, (uint8_t[]){0x00}, 1, 0},
{0x69, (uint8_t[]){0x00}, 1, 0},
{0x6A, (uint8_t[]){0x00}, 1, 0},
{0x6B, (uint8_t[]){0x00}, 1, 0},
{0x70, (uint8_t[]){0x42}, 1, 0},
{0x71, (uint8_t[]){0xE0}, 1, 0},
{0x72, (uint8_t[]){0x40}, 1, 0},
{0x73, (uint8_t[]){0x40}, 1, 0},
{0x74, (uint8_t[]){0x02}, 1, 0},
{0x75, (uint8_t[]){0x00}, 1, 0},
{0x76, (uint8_t[]){0x40}, 1, 0},
{0x77, (uint8_t[]){0x03}, 1, 0},
{0x78, (uint8_t[]){0x00}, 1, 0},
{0x79, (uint8_t[]){0x00}, 1, 0},
{0x7A, (uint8_t[]){0x00}, 1, 0},
{0x7B, (uint8_t[]){0x00}, 1, 0},
{0x80, (uint8_t[]){0x48}, 1, 0},
{0x81, (uint8_t[]){0x00}, 1, 0},
{0x82, (uint8_t[]){0x05}, 1, 0},
{0x83, (uint8_t[]){0x02}, 1, 0},
{0x84, (uint8_t[]){0xDD}, 1, 0},
{0x85, (uint8_t[]){0x00}, 1, 0},
{0x86, (uint8_t[]){0x00}, 1, 0},
{0x87, (uint8_t[]){0x00}, 1, 0},
{0x88, (uint8_t[]){0x48}, 1, 0},
{0x89, (uint8_t[]){0x00}, 1, 0},
{0x8A, (uint8_t[]){0x07}, 1, 0},
{0x8B, (uint8_t[]){0x02}, 1, 0},
{0x8C, (uint8_t[]){0xDF}, 1, 0},
{0x8D, (uint8_t[]){0x00}, 1, 0},
{0x8E, (uint8_t[]){0x00}, 1, 0},
{0x8F, (uint8_t[]){0x00}, 1, 0},
{0x90, (uint8_t[]){0x48}, 1, 0},
{0x91, (uint8_t[]){0x00}, 1, 0},
{0x92, (uint8_t[]){0x09}, 1, 0},
{0x93, (uint8_t[]){0x02}, 1, 0},
{0x94, (uint8_t[]){0xE1}, 1, 0},
{0x95, (uint8_t[]){0x00}, 1, 0},
{0x96, (uint8_t[]){0x00}, 1, 0},
{0x97, (uint8_t[]){0x00}, 1, 0},
{0x98, (uint8_t[]){0x48}, 1, 0},
{0x99, (uint8_t[]){0x00}, 1, 0},
{0x9A, (uint8_t[]){0x0B}, 1, 0},
{0x9B, (uint8_t[]){0x02}, 1, 0},
{0x9C, (uint8_t[]){0xE3}, 1, 0},
{0x9D, (uint8_t[]){0x00}, 1, 0},
{0x9E, (uint8_t[]){0x00}, 1, 0},
{0x9F, (uint8_t[]){0x00}, 1, 0},
{0xA0, (uint8_t[]){0x48}, 1, 0},
{0xA1, (uint8_t[]){0x00}, 1, 0},
{0xA2, (uint8_t[]){0x04}, 1, 0},
{0xA3, (uint8_t[]){0x02}, 1, 0},
{0xA4, (uint8_t[]){0xDC}, 1, 0},
{0xA5, (uint8_t[]){0x00}, 1, 0},
{0xA6, (uint8_t[]){0x00}, 1, 0},
{0xA7, (uint8_t[]){0x00}, 1, 0},
{0xA8, (uint8_t[]){0x48}, 1, 0},
{0xA9, (uint8_t[]){0x00}, 1, 0},
{0xAA, (uint8_t[]){0x06}, 1, 0},
{0xAB, (uint8_t[]){0x02}, 1, 0},
{0xAC, (uint8_t[]){0xDE}, 1, 0},
{0xAD, (uint8_t[]){0x00}, 1, 0},
{0xAE, (uint8_t[]){0x00}, 1, 0},
{0xAF, (uint8_t[]){0x00}, 1, 0},
{0xB0, (uint8_t[]){0x48}, 1, 0},
{0xB1, (uint8_t[]){0x00}, 1, 0},
{0xB2, (uint8_t[]){0x08}, 1, 0},
{0xB3, (uint8_t[]){0x02}, 1, 0},
{0xB4, (uint8_t[]){0xE0}, 1, 0},
{0xB5, (uint8_t[]){0x00}, 1, 0},
{0xB6, (uint8_t[]){0x00}, 1, 0},
{0xB7, (uint8_t[]){0x00}, 1, 0},
{0xB8, (uint8_t[]){0x48}, 1, 0},
{0xB9, (uint8_t[]){0x00}, 1, 0},
{0xBA, (uint8_t[]){0x0A}, 1, 0},
{0xBB, (uint8_t[]){0x02}, 1, 0},
{0xBC, (uint8_t[]){0xE2}, 1, 0},
{0xBD, (uint8_t[]){0x00}, 1, 0},
{0xBE, (uint8_t[]){0x00}, 1, 0},
{0xBF, (uint8_t[]){0x00}, 1, 0},
{0xC0, (uint8_t[]){0x12}, 1, 0},
{0xC1, (uint8_t[]){0xAA}, 1, 0},
{0xC2, (uint8_t[]){0x65}, 1, 0},
{0xC3, (uint8_t[]){0x74}, 1, 0},
{0xC4, (uint8_t[]){0x47}, 1, 0},
{0xC5, (uint8_t[]){0x56}, 1, 0},
{0xC6, (uint8_t[]){0x00}, 1, 0},
{0xC7, (uint8_t[]){0x88}, 1, 0},
{0xC8, (uint8_t[]){0x99}, 1, 0},
{0xC9, (uint8_t[]){0x33}, 1, 0},
{0xD0, (uint8_t[]){0x21}, 1, 0},
{0xD1, (uint8_t[]){0xAA}, 1, 0},
{0xD2, (uint8_t[]){0x65}, 1, 0},
{0xD3, (uint8_t[]){0x74}, 1, 0},
{0xD4, (uint8_t[]){0x47}, 1, 0},
{0xD5, (uint8_t[]){0x56}, 1, 0},
{0xD6, (uint8_t[]){0x00}, 1, 0},
{0xD7, (uint8_t[]){0x88}, 1, 0},
{0xD8, (uint8_t[]){0x99}, 1, 0},
{0xD9, (uint8_t[]){0x33}, 1, 0},
{0xF3, (uint8_t[]){0x01}, 1, 0},
{0xF0, (uint8_t[]){0x00}, 1, 0},
{0xF0, (uint8_t[]){0x01}, 1, 0},
{0xF1, (uint8_t[]){0x01}, 1, 0},
{0xA0, (uint8_t[]){0x0B}, 1, 0},
{0xA3, (uint8_t[]){0x2A}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x2B}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x2C}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x2D}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x2E}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x2F}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x30}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x31}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x32}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x33}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA0, (uint8_t[]){0x09}, 1, 0},
{0xF1, (uint8_t[]){0x10}, 1, 0},
{0xF0, (uint8_t[]){0x00}, 1, 0},
{0x2A, (uint8_t[]){0x00, 0x00, 0x01, 0x67}, 4, 0},
{0x2B, (uint8_t[]){0x01, 0x68, 0x01, 0x68}, 4, 0},
{0x4D, (uint8_t[]){0x00}, 1, 0},
{0x4E, (uint8_t[]){0x00}, 1, 0},
{0x4F, (uint8_t[]){0x00}, 1, 0},
{0x4C, (uint8_t[]){0x01}, 1, 10},
{0x4C, (uint8_t[]){0x00}, 1, 0},
{0x2A, (uint8_t[]){0x00, 0x00, 0x01, 0x67}, 4, 0},
{0x2B, (uint8_t[]){0x00, 0x00, 0x01, 0x67}, 4, 0},
{0x21, (uint8_t[]){0x00}, 1, 0},
//{0x3A, (uint8_t[]){0x55}, 1, 0}, // color=16
{0x11, (uint8_t[]){0x00}, 1, 120},
{0x29, (uint8_t[]){0x00}, 1, 0},
};
#endif
#define TFT_SPI_FREQ_HZ (50 * 1000 * 1000)
// LVGL tick source
static uint32_t lv_tick_millis(void)
{
return millis();
}
static void my_disp_flush(lv_display_t *disp, const lv_area_t *area, uint8_t *px_map)
{
ESP_PanelLcd *lcd = (ESP_PanelLcd *)lv_display_get_user_data(disp);
const int w = lv_area_get_width(area);
const int h = lv_area_get_height(area);
#if LV_COLOR_FORMAT_DEFAULT == LV_COLOR_FORMAT_RGB565
// LVGL renders little-endian RGB565, the ST77916 expects big-endian
lv_draw_rgb565_swap(px_map, w * h);
#endif
lcd->drawBitmap(area->x1, area->y1, w, h, (const uint8_t *)px_map);
}
IRAM_ATTR bool onRefreshFinishCallback(void *user_data)
{
lv_display_flush_ready((lv_display_t *)user_data);
return false;
}
void setRotation(uint8_t rot)
{
if (rot > 3)
return;
if (lcd == NULL || touch == NULL)
return;
switch (rot)
{
case 1: // 90° clockwise
lcd->swapXY(true);
lcd->mirrorX(true);
lcd->mirrorY(false);
touch->swapXY(true);
touch->mirrorX(true);
touch->mirrorY(false);
break;
case 2:
lcd->swapXY(false);
lcd->mirrorX(true);
lcd->mirrorY(true);
touch->swapXY(false);
touch->mirrorX(true);
touch->mirrorY(true);
break;
case 3:
lcd->swapXY(true);
lcd->mirrorX(false);
lcd->mirrorY(true);
touch->swapXY(true);
touch->mirrorX(false);
touch->mirrorY(true);
break;
default:
lcd->swapXY(false);
lcd->mirrorX(false);
lcd->mirrorY(false);
touch->swapXY(false);
touch->mirrorX(false);
touch->mirrorY(false);
break;
}
}
void screen_switch(bool on)
{
if (NULL == backlight)
return;
if (on)
backlight->on();
else
backlight->off();
}
void set_brightness(uint8_t bri)
{
if (NULL == backlight)
return;
backlight->setBrightness(bri);
}
static void touchpad_read(lv_indev_t *indev, lv_indev_data_t *data)
{
ESP_PanelTouch *tp = (ESP_PanelTouch *)lv_indev_get_user_data(indev);
ESP_PanelTouchPoint point;
int read_touch_result = tp->readPoints(&point, 1);
if (read_touch_result > 0)
{
data->point.x = point.x;
data->point.y = point.y;
data->state = LV_INDEV_STATE_PRESSED;
}
else
{
data->state = LV_INDEV_STATE_RELEASED;
}
}
static lv_indev_t *indev_init(ESP_PanelTouch *tp)
{
ESP_PANEL_CHECK_FALSE_RET(tp != nullptr, nullptr, "Invalid touch device");
ESP_PANEL_CHECK_FALSE_RET(tp->getHandle() != nullptr, nullptr, "Touch device is not initialized");
lv_indev_t *indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev, touchpad_read);
lv_indev_set_user_data(indev, (void *)tp);
return indev;
}
lv_display_t *scr_lvgl_init()
{
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.duty_resolution = LEDC_TIMER_13_BIT,
.timer_num = LEDC_TIMER_0,
.freq_hz = 5000,
.clk_cfg = LEDC_AUTO_CLK};
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
ledc_channel_config_t ledc_channel = {
.gpio_num = (TFT_BLK),
.speed_mode = LEDC_LOW_SPEED_MODE,
.channel = LEDC_CHANNEL_0,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = LEDC_TIMER_0,
.duty = 0,
.hpoint = 0};
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
backlight = new ESP_PanelBacklight(ledc_timer, ledc_channel);
backlight->begin();
backlight->off();
ESP_PanelBus_I2C *touch_bus = new ESP_PanelBus_I2C(TOUCH_PIN_NUM_I2C_SCL, TOUCH_PIN_NUM_I2C_SDA, ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG());
touch_bus->configI2cFreqHz(400000);
touch_bus->begin();
touch = new ESP_PanelTouch_CST816S(touch_bus, SCREEN_RES_HOR, SCREEN_RES_VER, TOUCH_PIN_NUM_RST, TOUCH_PIN_NUM_INT);
touch->init();
touch->begin();
#if TOUCH_PIN_NUM_INT >= 0
touch->attachInterruptCallback(onTouchInterruptCallback, NULL);
#endif
ESP_PanelBus_QSPI *panel_bus = new ESP_PanelBus_QSPI(TFT_CS, TFT_SCK, TFT_SDA0, TFT_SDA1, TFT_SDA2, TFT_SDA3);
panel_bus->configQspiFreqHz(TFT_SPI_FREQ_HZ);
panel_bus->begin();
lcd = new ESP_PanelLcd_ST77916(panel_bus, 16, TFT_RST);
// vendor init commands must be configured before init()
#if USE_CUSTOM_INIT_CMD
lcd->configVendorCommands(lcd_init_cmd, sizeof(lcd_init_cmd) / sizeof(lcd_init_cmd[0]));
#endif
lcd->init();
lcd->reset();
lcd->begin();
lcd->invertColor(true);
lcd->displayOn();
screen_switch(true);
backlight->setBrightness(100);
size_t buf_bytes = JC_DRAW_BUF_ROWS * SCREEN_RES_HOR * 2; // RGB565
disp_draw_buf = (uint8_t *)heap_caps_malloc(buf_bytes, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
disp_draw_buf2 = (uint8_t *)heap_caps_malloc(buf_bytes, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
lv_init();
lv_tick_set_cb(lv_tick_millis);
disp = lv_display_create(SCREEN_RES_HOR, SCREEN_RES_VER);
lv_display_set_flush_cb(disp, my_disp_flush);
lv_display_set_buffers(disp, disp_draw_buf, disp_draw_buf2, buf_bytes, LV_DISPLAY_RENDER_MODE_PARTIAL);
lv_display_set_user_data(disp, (void *)lcd);
if (lcd->getBus()->getType() != ESP_PANEL_BUS_TYPE_RGB)
{
lcd->attachRefreshFinishCallback(onRefreshFinishCallback, (void *)disp);
}
indev_touchpad = indev_init(touch);
return disp;
}
+28
View File
@@ -0,0 +1,28 @@
// JC3636W518 board support: ST77916 QSPI LCD (360x360), CST816S touch, PWM backlight, LVGL 9 glue.
// Shared by all JC3636W518 projects (see shared/README.md).
#ifndef _JC3636W518_H_
#define _JC3636W518_H_
#include <lvgl.h>
#include "pincfg.h"
#define SCREEN_RES_HOR 360
#define SCREEN_RES_VER 360
// Rows per LVGL draw buffer (two buffers, internal RAM, RGB565). Override with -DJC_DRAW_BUF_ROWS=<n>.
#ifndef JC_DRAW_BUF_ROWS
#define JC_DRAW_BUF_ROWS 72
#endif
// Initializes backlight, touch, LCD and LVGL (lv_init, tick, display, touch input). Returns the display.
lv_display_t *scr_lvgl_init();
// 0 = normal, 1 = 90° clockwise, 2 = 180°, 3 = 270° (LCD and touch together)
void setRotation(uint8_t rot);
void screen_switch(bool on);
// 0-100
void set_brightness(uint8_t bri);
#endif
@@ -0,0 +1,64 @@
#include "perf_monitor.h"
#include <Arduino.h>
static uint32_t refr_count = 0; // refreshes that actually rendered something
static uint32_t refr_time_us = 0; // time spent in those refreshes
static uint32_t busy_us = 0; // time spent inside lv_timer_handler()
static void refr_event_cb(lv_event_t *e)
{
static uint32_t refr_start_us = 0;
static bool rendered = false;
switch (lv_event_get_code(e))
{
case LV_EVENT_REFR_START:
refr_start_us = micros();
rendered = false;
break;
case LV_EVENT_RENDER_START:
rendered = true;
break;
case LV_EVENT_REFR_READY:
if (rendered)
{
refr_count++;
refr_time_us += micros() - refr_start_us;
}
break;
default:
break;
}
}
void perf_monitor_begin(lv_display_t *disp)
{
lv_display_add_event_cb(disp, refr_event_cb, LV_EVENT_ALL, NULL);
}
uint32_t perf_timer_handler()
{
uint32_t t0 = micros();
uint32_t next = lv_timer_handler();
busy_us += micros() - t0;
return next;
}
void perf_monitor_print()
{
static uint32_t last_us = 0;
uint32_t now = micros();
uint32_t elapsed = now - last_us;
if (elapsed < 1000000)
return;
uint32_t other_us = busy_us > refr_time_us ? busy_us - refr_time_us : 0;
Serial.printf("FPS: %.1f refresh: %.1f ms other: %.1f ms cpu: %.0f%%\n",
refr_count * 1e6f / elapsed,
refr_count ? refr_time_us / 1000.0f / refr_count : 0.0f,
refr_count ? other_us / 1000.0f / refr_count : 0.0f,
busy_us * 100.0f / elapsed);
refr_count = 0;
refr_time_us = 0;
busy_us = 0;
last_us = now;
}
+19
View File
@@ -0,0 +1,19 @@
// Simple LVGL performance monitor, printed to Serial once per second:
// FPS: rendered frames/s refresh: avg ms per rendered frame (render + flush)
// other: avg ms per frame spent in LVGL timers outside refresh (e.g. GIF decode)
// cpu: % of time inside lv_timer_handler()
#ifndef _PERF_MONITOR_H_
#define _PERF_MONITOR_H_
#include <lvgl.h>
// Hook the display's refresh events.
void perf_monitor_begin(lv_display_t *disp);
// Call instead of lv_timer_handler(); measures the time spent in it.
uint32_t perf_timer_handler();
// Prints the statistics once per second (call every loop).
void perf_monitor_print();
#endif
+38
View File
@@ -0,0 +1,38 @@
#ifndef _PINCFG_H_
#define _PINCFG_H_
#define TFT_BLK 15
#define TFT_RST 47
#define TFT_CS 10
#define TFT_SCK 9
#define TFT_SDA0 11
#define TFT_SDA1 12
#define TFT_SDA2 13
#define TFT_SDA3 14
#define BTN_PIN 0
#define TOUCH_PIN_NUM_I2C_SCL 8
#define TOUCH_PIN_NUM_I2C_SDA 7
#define TOUCH_PIN_NUM_INT 41
#define TOUCH_PIN_NUM_RST 40
#define SD_MMC_D0_PIN 2
#define SD_MMC_D1_PIN 1
#define SD_MMC_D2_PIN 6
#define SD_MMC_D3_PIN 5
#define SD_MMC_CLK_PIN 3
#define SD_MMC_CMD_PIN 4
#define AUDIO_I2S_MCK_IO -1 // MCK
#define AUDIO_I2S_BCK_IO 18 // BCK
#define AUDIO_I2S_WS_IO 16 // LCK
#define AUDIO_I2S_DO_IO 17 // DIN
#define AUDIO_MUTE_PIN 48 // 低电平静音
#define MIC_I2S_WS 45
#define MIC_I2S_SD 46
#define MIC_I2S_SCK 42
#endif