LittlevGL提供的模擬器有很多種:
我使用的是VS版本的模擬器進行測試,github主頁:https://github.com/littlevgl/pc_simulator_sdl_visual_studio,這個項目就是LittlevGL模擬器的VisualStudio工程,裏面的visual_studio_2017_sdl文件夾就是源碼存放位置,和使用Linux下的FrameBuffer的操作一樣,將lv_drivers、lv_examples、lvgl三個文件夾中的內容單獨下載下來,但是一定注意 lvgl 文件夾中的內容不要使用前面基於FrameBuffer的Demo中的 lvgl 文件夾,這樣會導致編譯錯誤:“CL.exe returned with code 2”,因爲基於FrameBuffer的Demo使用的LittlevGL版本和模擬器使用的LittlevGL版本是不一樣的,後者的源碼中沒有src/lv_misc/lv_async.c文件,所以導致了報錯(狗屎VS)。
編譯運行結果:
使用這個調試起來就很方便了,所有設計現在PC上測試可以節省很多時間。
這裏貼出來在Windows上進行仿真時使用的顯示器驅動和輸入設備驅動的代碼:
/**
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library
*/
static void hal_init(void)
{
/* Add a display
* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/
monitor_init();
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
static lv_disp_buf_t disp_buf1;
static lv_color_t buf1_1[LV_HOR_RES_MAX*LV_VER_RES_MAX];
lv_disp_buf_init(&disp_buf1, buf1_1, NULL, LV_HOR_RES_MAX*LV_VER_RES_MAX);
disp_drv.buffer = &disp_buf1;
disp_drv.flush_cb = monitor_flush;
lv_disp_drv_register(&disp_drv);
/* Add the mouse (or touchpad) as input device
* Use the 'mouse' driver which reads the PC's mouse*/
mouse_init();
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/
lv_indev_drv_register(&indev_drv);
/* If the PC keyboard driver is enabled in`lv_drv_conf.h`
* add this as an input device. It might be used in some examples. */
#if USE_KEYBOARD
lv_indev_drv_t kb_drv;
lv_indev_drv_init(&kb_drv);
kb_drv.type = LV_INDEV_TYPE_KEYPAD;
kb_drv.read_cb = keyboard_read;
kb_indev = lv_indev_drv_register(&kb_drv);
#endif
/* Tick init.
* You have to call 'lv_tick_inc()' in every milliseconds
* Create an SDL thread to do this*/
SDL_CreateThread(tick_thread, "tick", NULL);
}
/**
* A task to measure the elapsed time for LittlevGL
* @param data unused
* @return never return
*/
static int tick_thread(void *data)
{
while (1) {
lv_tick_inc(5);
SDL_Delay(5); /*Sleep for 1 millisecond*/
}
return 0;
}