例子乐鑫官方 esp-iot-solution/examples/hmi/lvgl_example
点左下角齿轮(SDK Configuration Editor)选择开发板为
Saola With Esp32S2 Onboard From Espressif
设置USB输出调试文字
修改头文件中引脚:
D:\esp-iot-solution\examples\common_components\boards\esp32s2-saola-1\board.h
#define BOARD_IO_SPI2_SCK 36 //FSPICLK 接屏幕的SCL引脚
#define BOARD_IO_SPI2_MOSI 35 //FSPID 截屏幕的SDA引脚
#define BOARD_IO_SPI2_MISO 37 //不用接屏幕
修改内容:
D:\esp-iot-solution\examples\hmi\lvgl_example\main\app_main.c
void app_main()
{
printf("Hello world!\n");
/* Print chip information */
esp_chip_info_t chip_info;
uint32_t flash_size;
esp_chip_info(&chip_info);
printf("This is %s chip with %d CPU core(s), WiFi%s%s, ",
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
printf("silicon revision %d, ", chip_info.revision);
// if(lv_list_get_size(NULL, &flash_size) != ESP_OK) {
// printf("Get flash size failed");
// return;
// }
// printf("%uMB %s flash\n", flash_size / (1024 * 1024),
// (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
printf("Minimum free heap size: %d bytes\n", esp_get_minimum_free_heap_size());
for (int i = 5; i >= 0; i--) {
printf("Restarting in %d seconds...\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("Restarting now.\n");
fflush(stdout);
// esp_restart();
iot_board_init();
spi_bus_handle_t spi2_bus = iot_board_get_handle(BOARD_SPI2_ID);
//60MHz刚好合适,高了屏幕闪烁,低了FPS太低
#define BOARD_LCD_SPI_CLOCK_FREQ 60000000
scr_driver_t lcd_drv;
touch_panel_driver_t touch_drv;
scr_interface_spi_config_t spi_lcd_cfg = {
.spi_bus = spi2_bus,
.pin_num_cs = 34, //FSPICS0 接屏幕的CS引脚
.pin_num_dc = 33, //FSPIHD 接屏幕的A0引脚
.clk_freq = BOARD_LCD_SPI_CLOCK_FREQ,
.swap_data = true,
};
scr_interface_driver_t *iface_drv;
scr_interface_create(SCREEN_IFACE_SPI, &spi_lcd_cfg, &iface_drv);
scr_controller_config_t lcd_cfg = {
.interface_drv = iface_drv,
.pin_num_rst = 9, //FSPIHD 接屏幕的RESET引脚
.pin_num_bckl = 38,//FSPIWP 接屏幕的BL引脚 背光
.rst_active_level = 0,
.bckl_active_level = 1,
.offset_hor = 0,
.offset_ver = 0,
.width = 240,
.height = 320,
.rotate = SCR_DIR_TBRL,//防止镜像显示
};
scr_find_driver(SCREEN_CONTROLLER_ST7789, &lcd_drv);
lcd_drv.init(&lcd_cfg);
// touch_panel_config_t touch_cfg = {
// .interface_spi = {
// .spi_bus = spi2_bus,
// .pin_num_cs = BOARD_TOUCH_SPI_CS_PIN,
// .clk_freq = 10000000,
// },
// .interface_type = TOUCH_PANEL_IFACE_SPI,
// .pin_num_int = -1,
// .direction = TOUCH_DIR_TBLR,
// .width = 240,
// .height = 320,
// };
// touch_panel_find_driver(TOUCH_PANEL_CONTROLLER_XPT2046, &touch_drv);
// touch_drv.init(&touch_cfg);
// touch_drv.calibration_run(&lcd_drv, false);
/* Initialize LittlevGL GUI */
lvgl_init(&lcd_drv, NULL);// &touch_drv);
lvgl_acquire();
#ifdef CONFIG_LV_DEMO_BENCHMARK
lv_demo_benchmark();
#elif defined CONFIG_LV_DEMO_PRINTER
lv_demo_printer();
#elif defined CONFIG_LV_DEMO_WIDGETS
lv_demo_widgets();
#elif defined CONFIG_LV_EX_GET_STARTED
lv_ex_get_started_1();
#elif defined CONFIG_LV_DEMO_STRESS
lv_demo_stress();
#elif defined CONFIG_LV_EX_STYLE
lv_ex_style_1();
#endif
lvgl_release();
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
}
BENCHMARK
STRESS
ESP32-S2 SPI TFT彩屏60MHz