Esp32_Link调试笔记(Vol.1)

前言

硬件参考 https://github.com/obitvn/felini-firmware
LVGL参考 https://github.com/FASTSHIFT/X-TRACK

基于PlatfromIO开发,在参考项目的基础上LVGL库升级至9.2.2
关键字:esp32s3 st7789 cst618

第一章 点亮屏幕

1. 下载所需库文件
在PlatfromIO的libraries中安装lvgl 9.2.2和TFT_eSP 2.5.43两个库
也可以在项目的platfromio.ini中添加如下代码,项目会自动下载并安装对应的库

点击查看代码
lib_deps =
	lvgl/lvgl@^9.2.2
	bodmer/TFT_eSPI@^2.5.43

2. 修改库文件配置
lvgl库文件夹下复制lv_conf_template.h重命名为lv_config.h,并修改以下配置

image

点击查看代码
/* clang-format off */
必须修改:
#if 1 /*Set it to "1" to enable content*/
#define LV_USE_PRIVATE_API	1
#define LV_USE_TFT_ESPI         1
可选修改:
#define LV_USE_LOG 1    //打印log
#define LV_THEME_DEFAULT_DARK 1  //黑色主题
#define LV_USE_SYSMON  1    //显示FPS和CPU使用率
#define LV_USE_PERF_MONITOR 1

TFT_eSPI库文件夹下,打开对应的宏定义,我这里是st7789,分辨率240x320,SPI的GPIO号
User_Setup.h

点击查看代码
#define ST7789_DRIVER 
#define TFT_WIDTH  240
#define TFT_HEIGHT 320
#define TFT_DC    14
#define TFT_RST   13
#define TFT_MOSI  11   // for hardware SPI data pin (all of available pins)
#define TFT_SCLK 12   // for hardware SPI sclk pin (all of available pins)
#define TFT_BL   17
#define TFT_CS -1
#define TFT_MISO -1

User_Setup_Select.h中取消对应驱动的注释

点击查看代码
#include <User_Setups/Setup18_ST7789.h> 
与之对应的User_Setups\Setup18_ST7789.h 里面也有引脚配置,注释掉或者修改成和User_Setup.h文件一样的。

image

库文件的修改到这里就结束了。

3.代码硬件初始化
将lvgl/example/arduino/LVGL_Arduino/LVGL_Arduino.ino的内容复制到platfronIO项目的main.cpp中。编译下载验证。
重点是LV_USE_TFT_ESPI宏一定是配置成1的,走下面这条语句的初始化。
/TFT_eSPI can be enabled lv_conf.h to initialize the display in a simple way/
disp = lv_tft_espi_create(TFT_HOR_RES, TFT_VER_RES, draw_buf, sizeof(draw_buf));
image

main.cpp代码

点击查看代码
/*Using LVGL with Arduino requires some extra steps:
 *Be sure to read the docs here: https://docs.lvgl.io/master/integration/framework/arduino.html  */

 #include <lvgl.h>

 #if LV_USE_TFT_ESPI
 #include <TFT_eSPI.h>
 #endif
 
 /*To use the built-in examples and demos of LVGL uncomment the includes below respectively.
  *You also need to copy `lvgl/examples` to `lvgl/src/examples`. Similarly for the demos `lvgl/demos` to `lvgl/src/demos`.
  *Note that the `lv_examples` library is for LVGL v7 and you shouldn't install it for this version (since LVGL v8)
  *as the examples and demos are now part of the main LVGL library. */
 
 //#include <examples/lv_examples.h>
 //#include <demos/lv_demos.h>
 
 /*Set to your screen resolution and rotation*/
 #define TFT_HOR_RES   240
 #define TFT_VER_RES   320
 #define TFT_ROTATION  LV_DISPLAY_ROTATION_90
 
 /*LVGL draw into this buffer, 1/10 screen size usually works well. The size is in bytes*/
 #define DRAW_BUF_SIZE (TFT_HOR_RES * TFT_VER_RES / 10 * (LV_COLOR_DEPTH / 8))
 uint32_t draw_buf[DRAW_BUF_SIZE / 4];
 
 #if LV_USE_LOG != 0
 void my_print( lv_log_level_t level, const char * buf )
 {
     LV_UNUSED(level);
     Serial.println(buf);
     Serial.flush();
 }
 #endif
 
 /* LVGL calls it when a rendered image needs to copied to the display*/
 void my_disp_flush( lv_display_t *disp, const lv_area_t *area, uint8_t * px_map)
 {
     /*Copy `px map` to the `area`*/
 
     /*For example ("my_..." functions needs to be implemented by you)
     uint32_t w = lv_area_get_width(area);
     uint32_t h = lv_area_get_height(area);
 
     my_set_window(area->x1, area->y1, w, h);
     my_draw_bitmaps(px_map, w * h);
      */
 
     /*Call it to tell LVGL you are ready*/
     lv_display_flush_ready(disp);
 }
 
 /*Read the touchpad*/
 void my_touchpad_read( lv_indev_t * indev, lv_indev_data_t * data )
 {
     /*For example  ("my_..." functions needs to be implemented by you)
     int32_t x, y;
     bool touched = my_get_touch( &x, &y );
 
     if(!touched) {
         data->state = LV_INDEV_STATE_RELEASED;
     } else {
         data->state = LV_INDEV_STATE_PRESSED;
 
         data->point.x = x;
         data->point.y = y;
     }
      */
 }
 
 /*use Arduinos millis() as tick source*/
 static uint32_t my_tick(void)
 {
     return millis();
 }
 
 void setup()
 {
     String LVGL_Arduino = "Hello Arduino! ";
     LVGL_Arduino += String('V') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
 
     Serial.begin( 115200 );
     Serial.println( LVGL_Arduino );
 
     lv_init();
 
     /*Set a tick source so that LVGL will know how much time elapsed. */
     lv_tick_set_cb(my_tick);
 
     /* register print function for debugging */
 #if LV_USE_LOG != 0
     lv_log_register_print_cb( my_print );
 #endif
 
     lv_display_t * disp;
 #if LV_USE_TFT_ESPI
     /*TFT_eSPI can be enabled lv_conf.h to initialize the display in a simple way*/
     disp = lv_tft_espi_create(TFT_HOR_RES, TFT_VER_RES, draw_buf, sizeof(draw_buf));
     lv_display_set_rotation(disp, TFT_ROTATION);
 
 #else
     /*Else create a display yourself*/
     disp = lv_display_create(TFT_HOR_RES, TFT_VER_RES);
     lv_display_set_flush_cb(disp, my_disp_flush);
     lv_display_set_buffers(disp, draw_buf, NULL, sizeof(draw_buf), LV_DISPLAY_RENDER_MODE_PARTIAL);
 #endif
 
     /*Initialize the (dummy) input device driver*/
     lv_indev_t * indev = lv_indev_create();
     lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER); /*Touchpad should have POINTER type*/
     lv_indev_set_read_cb(indev, my_touchpad_read);
 
     /* Create a simple label
      * ---------------------
      lv_obj_t *label = lv_label_create( lv_screen_active() );
      lv_label_set_text( label, "Hello Arduino, I'm LVGL!" );
      lv_obj_align( label, LV_ALIGN_CENTER, 0, 0 );
 
      * Try an example. See all the examples
      *  - Online: https://docs.lvgl.io/master/examples.html
      *  - Source codes: https://github.com/lvgl/lvgl/tree/master/examples
      * ----------------------------------------------------------------
 
      lv_example_btn_1();
 
      * Or try out a demo. Don't forget to enable the demos in lv_conf.h. E.g. LV_USE_DEMO_WIDGETS
      * -------------------------------------------------------------------------------------------
 
      lv_demo_widgets();
      */
 
     lv_obj_t *label = lv_label_create( lv_screen_active() );
     lv_label_set_text( label, "Hello Arduino, I'm LVGL!" );
     lv_obj_align( label, LV_ALIGN_CENTER, 0, 0 );
 
     Serial.println( "Setup done" );
 }
 
 void loop()
 {
     lv_timer_handler(); /* let the GUI do its work */
     delay(5); /* let this time pass */
 }
 
posted @ 2025-02-19 10:43  一般摸鱼。  阅读(225)  评论(0)    收藏  举报