未定义 LVGL 函数 - 为什么?

LVGL functions not defined - why?

我正在使用 LVGL 在 SeeedStudio 的 Wio 终端上实现示例应用程序。我遵循了 LVGL 的移植教程并提出了以下内容:

#include "lib\lvgl\lvgl.h"
#include <SAMDTimerInterrupt.h>
#include <SAMD_ISR_Timer.h>
#include <TFT_eSPI.h>

// Defines --------------------------------------------------------------------

#define DISPLAY_WIDTH (320)
#define DISPLAY_HEIGHT (240)
#define LVGL_TICK_PERIOD_MS (5)

// Public variables -----------------------------------------------------------

// TFT

TFT_eSPI tft;

// LVGL

lv_disp_draw_buf_t lvgl_disp_buf;
lv_color_t lvgl_buffer_1[DISPLAY_WIDTH * 10];
lv_color_t lvgl_buffer_2[DISPLAY_WIDTH * 10];
lv_disp_drv_t lvgl_disp_drv;
lv_disp_t * lvgl_disp;

lv_obj_t * screen;
lv_obj_t * button;
lv_obj_t * label; 

// Timer

SAMDTimer lvgl_timer(TIMER_TC3);

// Public functions -----------------------------------------------------------

void lvgl_flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
  uint16_t c;

  tft.startWrite();                                                                            /* Start new TFT transaction */
  tft.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1)); /* set the working window */
  for (int y = area->y1; y <= area->y2; y++)
  {
    for (int x = area->x1; x <= area->x2; x++)
    {
      c = color_p->full;
      tft.writeColor(c, 1);
      color_p++;
    }
  }
  tft.endWrite();            /* terminate TFT transaction */
  lv_disp_flush_ready(disp); /* tell lvgl that flushing is done */
}

void lvgl_tick()
{
  lv_tick_inc(LVGL_TICK_PERIOD_MS);
}

// Arduino core functions -----------------------------------------------------

void setup()
{
  Serial.begin(9600); /* prepare for possible serial debug */

  // Initialize TFT

  tft = TFT_eSPI();
  tft.begin();        
  tft.setRotation(3); 

  // Initialize LVGL

  lv_init();

  lv_disp_draw_buf_init(&lvgl_disp_buf, lvgl_buffer_1, lvgl_buffer_2, DISPLAY_WIDTH * 10);

  lv_disp_drv_init(&lvgl_disp_drv);
  lvgl_disp_drv.draw_buf = &lvgl_disp_buf;
  lvgl_disp_drv.hor_res = DISPLAY_WIDTH;
  lvgl_disp_drv.ver_res = DISPLAY_HEIGHT;
  lvgl_disp_drv.flush_cb = lvgl_flushDisplay;
  lvgl_disp = lv_disp_drv_register(&lvgl_disp_drv);

  // Initialize timer for LVGL

  lvgl_timer.attachInterruptInterval(LVGL_TICK_PERIOD_MS * 1000, lvgl_tick);

  // Test interface
  screen = lv_obj_create(nullptr);
  button = lv_btn_create(screen);
  lv_obj_set_pos(button, 60, 10);
  lv_obj_set_size(button, 180, 30);
  // lv_obj_set_event_cb(button, buttonEventCallback);
  label = lv_label_create(button);
  lv_label_set_text(label, "Przycisk");
  lv_scr_load(screen);
}

void loop()
{
  lv_timer_handler();
}

请注意,LVGL 存在 在正确的文件夹中,lv_conf.h 配置正确等

如果我现在尝试在 Arduino IDE 中构建这个项目,我会收到以下错误:

sketch\WioStation.ino.cpp.o: In function `lvgl_flushDisplay(_lv_disp_drv_t*, lv_area_t const*, lv_color16_t*)':
D:\Dokumenty\Arduino\WioStation/WioStation.ino:52: undefined reference to `lv_disp_flush_ready'
sketch\WioStation.ino.cpp.o: In function `lvgl_tick()':
D:\Dokumenty\Arduino\WioStation/WioStation.ino:57: undefined reference to `lv_tick_inc'
sketch\WioStation.ino.cpp.o: In function `setup':
D:\Dokumenty\Arduino\WioStation/WioStation.ino:74: undefined reference to `lv_init'
D:\Dokumenty\Arduino\WioStation/WioStation.ino:76: undefined reference to `lv_disp_draw_buf_init'
D:\Dokumenty\Arduino\WioStation/WioStation.ino:78: undefined reference to `lv_disp_drv_init'
D:\Dokumenty\Arduino\WioStation/WioStation.ino:83: undefined reference to `lv_disp_drv_register'
D:\Dokumenty\Arduino\WioStation/WioStation.ino:90: undefined reference to `lv_obj_create'
D:\Dokumenty\Arduino\WioStation/WioStation.ino:91: undefined reference to `lv_btn_create'
D:\Dokumenty\Arduino\WioStation/WioStation.ino:92: undefined reference to `lv_obj_set_pos'
D:\Dokumenty\Arduino\WioStation/WioStation.ino:93: undefined reference to `lv_obj_set_size'
D:\Dokumenty\Arduino\WioStation/WioStation.ino:95: undefined reference to `lv_label_create'
D:\Dokumenty\Arduino\WioStation/WioStation.ino:96: undefined reference to `lv_label_set_text'
sketch\WioStation.ino.cpp.o: In function `lv_scr_load':
D:\Dokumenty\Arduino\WioStation\lib\lvgl\src\core/lv_disp.h:187: undefined reference to `lv_disp_load_scr'
sketch\WioStation.ino.cpp.o: In function `loop':
D:\Dokumenty\Arduino\WioStation/WioStation.ino:102: undefined reference to `lv_timer_handler'
collect2.exe: error: ld returned 1 exit status
Znaleziono wiele bibliotek w "TFT_eSPI.h"
Wykorzystane: C:\Users\Spook\Documents\Arduino\libraries\TFT_eSPI
Niewykorzystane: C:\Users\Spook\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd.8.1\libraries\Seeed_Arduino_LCD
exit status 1
Błąd kompilacji dla płytki Seeeduino Wio Terminal.

令人惊讶的是,如果我只用 SAMDTimerInterrupt.h 和 SAMD_ISR_Timer.h 注释掉 #includes,突然间我再也没有关于 LVGL 的错误了:

WioStation:32:1: error: 'SAMDTimer' does not name a type
 SAMDTimer lvgl_timer(TIMER_TC3);
 ^~~~~~~~~
D:\Dokumenty\Arduino\WioStation\WioStation.ino: In function 'void setup()':
WioStation:87:3: error: 'lvgl_timer' was not declared in this scope
   lvgl_timer.attachInterruptInterval(LVGL_TICK_PERIOD_MS * 1000, lvgl_tick);
   ^~~~~~~~~~
D:\Dokumenty\Arduino\WioStation\WioStation.ino:87:3: note: suggested alternative: 'lvgl_tick'
   lvgl_timer.attachInterruptInterval(LVGL_TICK_PERIOD_MS * 1000, lvgl_tick);
   ^~~~~~~~~~
   lvgl_tick
Znaleziono wiele bibliotek w "TFT_eSPI.h"
Wykorzystane: C:\Users\Spook\Documents\Arduino\libraries\TFT_eSPI
Niewykorzystane: C:\Users\Spook\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd.8.1\libraries\Seeed_Arduino_LCD
exit status 1
'SAMDTimer' does not name a type

我怎么看是在包含 SAMDTimerInterrupt 之后,编译器不知何故突然不处理 lvgl。

我做错了什么?

Arduino Studio IDE 在编译方面存在缺陷:只有草图的 src 子文件夹中的文件会被复制到 tmp 文件夹并进行编译。所以所有非标准库都应该放在 sketch 文件夹的 src 子文件夹中。