xref: /OK3568_Linux_fs/app/lvgl_demo/hal/hal_sdl.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 #ifdef USE_SDL_GPU
2 #define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
3 #include <SDL2/SDL.h>
4 #include "lvgl/lvgl.h"
5 #include "lvgl/lv_conf.h"
6 #include "lv_drivers/sdl/sdl_gpu.h"
7 
hal_sdl_init(lv_coord_t hor_res,lv_coord_t ver_res,int rotated)8 void hal_sdl_init(lv_coord_t hor_res, lv_coord_t ver_res, int rotated)
9 {
10   /* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/
11   monitor_init();
12   /* Tick init.
13    * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about
14    * how much time were elapsed Create an SDL thread to do this*/
15   SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN);
16 
17   /*Create a display*/
18   static lv_disp_drv_t disp_drv;
19   disp_drv.rotated = rotated;
20   sdl_disp_drv_init(&disp_drv, hor_res, ver_res);
21 
22   lv_disp_t * disp = lv_disp_drv_register(&disp_drv);
23 
24 #if 0
25   lv_theme_t * th = lv_theme_default_init(disp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), LV_THEME_DEFAULT_DARK, LV_FONT_DEFAULT);
26   lv_disp_set_theme(disp, th);
27 
28   lv_group_t * g = lv_group_create();
29   lv_group_set_default(g);
30 
31   /* Add the mouse as input device
32    * Use the 'mouse' driver which reads the PC's mouse*/
33   //mouse_init();
34   static lv_indev_drv_t indev_drv_1;
35   lv_indev_drv_init(&indev_drv_1); /*Basic initialization*/
36   indev_drv_1.type = LV_INDEV_TYPE_POINTER;
37 
38   /*This function will be called periodically (by the library) to get the mouse position and state*/
39   indev_drv_1.read_cb = sdl_mouse_read;
40   lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv_1);
41   if (!mouse_indev)
42     LV_LOG_WARN("Register indev failed");
43 
44   //keyboard_init();
45   static lv_indev_drv_t indev_drv_2;
46   lv_indev_drv_init(&indev_drv_2); /*Basic initialization*/
47   indev_drv_2.type = LV_INDEV_TYPE_KEYPAD;
48   indev_drv_2.read_cb = sdl_keyboard_read;
49   lv_indev_t *kb_indev = lv_indev_drv_register(&indev_drv_2);
50   lv_indev_set_group(kb_indev, g);
51   //mousewheel_init();
52   static lv_indev_drv_t indev_drv_3;
53   lv_indev_drv_init(&indev_drv_3); /*Basic initialization*/
54   indev_drv_3.type = LV_INDEV_TYPE_ENCODER;
55   indev_drv_3.read_cb = sdl_mousewheel_read;
56 
57   lv_indev_t * enc_indev = lv_indev_drv_register(&indev_drv_3);
58   lv_indev_set_group(enc_indev, g);
59 #endif
60 }
61 #endif
62 
63