diff --git a/.gitmodules b/.gitmodules index 5044fd0..7fd6aaf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "lv_examples"] - path = lv_examples - url = https://github.com/lvgl/lv_examples.git [submodule "lv_drivers"] path = lv_drivers url = https://github.com/lvgl/lv_drivers.git diff --git a/Makefile b/Makefile index a4545b3..2d62c75 100644 --- a/Makefile +++ b/Makefile @@ -29,8 +29,8 @@ CFLAGS := -O0 -g $(WARNINGS) DEFINES := -D SIMULATOR=1 -D LV_BUILD_TEST=0 # Include simulator inc folder first so lv_conf.h from custom UI can be used instead -INC := -I./ui/simulator/inc/ -I./ -I./lvgl/ -LDLIBS := -lSDL2 -lm +INC := -I./ui/simulator/inc/ -I./ -I./lvgl/ #-I/usr/include/freetype2 -L/usr/local/lib +LDLIBS := -lSDL2 -lm #-lfreetype -lavformat -lavcodec -lavutil -lswscale -lm -lz -lpthread BIN := $(BIN_DIR)/demo COMPILE = $(CC) $(CFLAGS) $(INC) $(DEFINES) diff --git a/README.md b/README.md index cfb9af4..fe3c319 100644 --- a/README.md +++ b/README.md @@ -21,18 +21,46 @@ To allow debugging inside VSCode you will also require a GDB [extension](https:/ Clone the PC project and the related sub modules: -``` -git clone --recursive https://github.com/lvgl/lv_sim_vscode_sdl +```bash +git clone --recursive https://github.com/lvgl/lv_port_pc_vscode ``` ### Install SDL You can download SDL from https://www.libsdl.org/ On on Linux you can install it via terminal: -``` +```bash sudo apt-get update && sudo apt-get install -y build-essential libsdl2-dev ``` +### Optional library +There are also FreeType and FFmpeg support. You can install FreeType support with: +```bash +# FreeType support +wget https://kumisystems.dl.sourceforge.net/project/freetype/freetype2/2.13.2/freetype-2.13.2.tar.xz +tar -xf freetype-2.13.2.tar.xz +cd freetype-2.13.2 +make +make install +``` + +The FFmpeg support can be installed with: +```bash +# FFmpeg support +git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg +cd ffmpeg +git checkout release/6.0 +./configure --disable-all --disable-autodetect --disable-podpages --disable-asm --enable-avcodec --enable-avformat --enable-decoders --enable-encoders --enable-demuxers --enable-parsers --enable-protocol='file' --enable-swscale --enable-zlib +make +sudo make install +``` + +And then remove all the comments in the `Makefile` on `INC` and `LDLIBS` lines. They should be: +```Makefile +INC := -I./ui/simulator/inc/ -I./ -I./lvgl/ -I/usr/include/freetype2 -L/usr/local/lib +LDLIBS := -lSDL2 -lm -lfreetype -lavformat -lavcodec -lavutil -lswscale -lm -lz -lpthread +``` + ### Setup To allow custom UI code an `lv_conf.h` file placed at `ui/simulator/inc` will automatically override this projects lv_conf.h file. By default code under `ui` is ignored so you can reuse this repository for multiple projects. You will need to place a call from `main.c` to your UI's entry function. diff --git a/lv_conf.h b/lv_conf.h index f918f14..f4226b9 100644 --- a/lv_conf.h +++ b/lv_conf.h @@ -14,7 +14,7 @@ /*clang-format off*/ #include - +#include "lv_demo_conf.h" /*==================== COLOR SETTINGS @@ -498,6 +498,87 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/ /*A layout similar to Grid in CSS.*/ #define LV_USE_GRID 1 +/*--------------------- + * 3rd party libraries + *--------------------*/ + +/*File system interfaces for common APIs */ + +/*API for fopen, fread, etc*/ +#define LV_USE_FS_STDIO 1 +#if LV_USE_FS_STDIO + #define LV_FS_STDIO_LETTER 'A' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/ + #define LV_FS_STDIO_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/ + #define LV_FS_STDIO_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/ +#endif + +/*API for open, read, etc*/ +#define LV_USE_FS_POSIX 0 +#if LV_USE_FS_POSIX + #define LV_FS_POSIX_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/ + #define LV_FS_POSIX_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/ + #define LV_FS_POSIX_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/ +#endif + +/*API for CreateFile, ReadFile, etc*/ +#define LV_USE_FS_WIN32 0 +#if LV_USE_FS_WIN32 + #define LV_FS_WIN32_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/ + #define LV_FS_WIN32_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/ + #define LV_FS_WIN32_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/ +#endif + +/*API for FATFS (needs to be added separately). Uses f_open, f_read, etc*/ +#define LV_USE_FS_FATFS 0 +#if LV_USE_FS_FATFS + #define LV_FS_FATFS_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/ + #define LV_FS_FATFS_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/ +#endif + +/*PNG decoder library*/ +#define LV_USE_PNG 0 + +/*BMP decoder library*/ +#define LV_USE_BMP 0 + +/* JPG + split JPG decoder library. + * Split JPG is a custom format optimized for embedded systems. */ +#define LV_USE_SJPG 0 + +/*GIF decoder library*/ +#define LV_USE_GIF 0 + +/*QR code library*/ +#define LV_USE_QRCODE 0 + +/*FreeType library*/ +#define LV_USE_FREETYPE 0 +#if LV_USE_FREETYPE + /*Memory used by FreeType to cache characters [bytes] (-1: no caching)*/ + #define LV_FREETYPE_CACHE_SIZE (16 * 1024) + #if LV_FREETYPE_CACHE_SIZE >= 0 + /* 1: bitmap cache use the sbit cache, 0:bitmap cache use the image cache. */ + /* sbit cache:it is much more memory efficient for small bitmaps(font size < 256) */ + /* if font size >= 256, must be configured as image cache */ + #define LV_FREETYPE_SBIT_CACHE 0 + /* Maximum number of opened FT_Face/FT_Size objects managed by this cache instance. */ + /* (0:use system defaults) */ + #define LV_FREETYPE_CACHE_FT_FACES 0 + #define LV_FREETYPE_CACHE_FT_SIZES 0 + #endif +#endif + +/*Rlottie library*/ +#define LV_USE_RLOTTIE 0 + +/*FFmpeg library for image decoding and playing videos + *Supports all major image formats so do not enable other image decoder with it*/ +#define LV_USE_FFMPEG 0 +#if LV_USE_FFMPEG + /*Dump input information to stderr*/ + #define LV_FFMPEG_DUMP_FORMAT 0 +#endif + /*================== * EXAMPLES *==================*/ diff --git a/lv_drivers b/lv_drivers index f14e316..8cdabe8 160000 --- a/lv_drivers +++ b/lv_drivers @@ -1 +1 @@ -Subproject commit f14e31612409fc9216892cb58eb9d851667f8a11 +Subproject commit 8cdabe8d42bf798d5a31e75cbd5a2cd816c29e5c diff --git a/lv_drv_conf.h b/lv_drv_conf.h index fb7c8c6..f906683 100644 --- a/lv_drv_conf.h +++ b/lv_drv_conf.h @@ -1,12 +1,13 @@ /** * @file lv_drv_conf.h - * Configuration file for v8.0.0 + * Configuration file for v8.3.0 */ /* * COPY THIS FILE AS lv_drv_conf.h */ +/* clang-format off */ #if 1 /*Set it to "1" to enable the content*/ #ifndef LV_DRV_CONF_H @@ -79,16 +80,53 @@ * DISPLAY DRIVERS *********************/ +/*------------------- + * SDL + *-------------------*/ + +/* SDL based drivers for display, mouse, mousewheel and keyboard*/ +#ifndef USE_SDL +# define USE_SDL 1 +#endif + +/* Hardware accelerated SDL driver */ +#ifndef USE_SDL_GPU +# define USE_SDL_GPU 0 +#endif + +#if USE_SDL || USE_SDL_GPU +# define SDL_HOR_RES 1024 +# define SDL_VER_RES 1080 + +#define MONITOR_HOR_RES SDL_HOR_RES +#define MONITOR_VER_RES SDL_VER_RES + +/* Scale window by this factor (useful when simulating small screens) */ +# define SDL_ZOOM 1 + +/* Used to test true double buffering with only address changing. + * Use 2 draw buffers, bith with SDL_HOR_RES x SDL_VER_RES size*/ +# define SDL_DOUBLE_BUFFERED 0 + +/*Eclipse: Visual Studio: */ +# define SDL_INCLUDE_PATH + +/*Open two windows to test multi display support*/ +# define SDL_DUAL_DISPLAY 0 +#endif + /*------------------- * Monitor of PC *-------------------*/ + +/*DEPRECATED: Use the SDL driver instead. */ #ifndef USE_MONITOR -# define USE_MONITOR 1 +# define USE_MONITOR 0 #endif #if USE_MONITOR -# define MONITOR_HOR_RES 800 -# define MONITOR_VER_RES 600 +# define MONITOR_HOR_RES 480 +# define MONITOR_VER_RES 320 /* Scale window by this factor (useful when simulating small screens) */ # define MONITOR_ZOOM 1 @@ -143,9 +181,18 @@ #endif #if USE_WAYLAND -# define WAYLAND_HOR_RES 480 -# define WAYLAND_VER_RES 320 -# define WAYLAND_SURF_TITLE "LVGL" +/* Support for client-side decorations */ +# ifndef LV_WAYLAND_CLIENT_SIDE_DECORATIONS +# define LV_WAYLAND_CLIENT_SIDE_DECORATIONS 1 +# endif +/* Support for (deprecated) wl-shell protocol */ +# ifndef LV_WAYLAND_WL_SHELL +# define LV_WAYLAND_WL_SHELL 1 +# endif +/* Support for xdg-shell protocol */ +# ifndef LV_WAYLAND_XDG_SHELL +# define LV_WAYLAND_XDG_SHELL 0 +# endif #endif /*---------------- @@ -276,7 +323,8 @@ #endif #if USE_FBDEV -# define FBDEV_PATH "/dev/fb0" +# define FBDEV_PATH "/dev/fb0" +# define FBDEV_DISPLAY_POWER_ON 1 /* 1 to force display power during initialization */ #endif /*----------------------------------------- @@ -287,7 +335,8 @@ #endif #if USE_BSD_FBDEV -# define FBDEV_PATH "/dev/fb0" +# define FBDEV_PATH "/dev/fb0" +# define FBDEV_DISPLAY_POWER_ON 1 /* 1 to force display power during initialization */ #endif /*----------------------------------------- @@ -352,8 +401,9 @@ /*--------------------------------------- * Mouse or touchpad on PC (using SDL) *-------------------------------------*/ +/*DEPRECATED: Use the SDL driver instead. */ #ifndef USE_MOUSE -# define USE_MOUSE 1 +# define USE_MOUSE 0 #endif #if USE_MOUSE @@ -363,8 +413,9 @@ /*------------------------------------------- * Mousewheel as encoder on PC (using SDL) *------------------------------------------*/ +/*DEPRECATED: Use the SDL driver instead. */ #ifndef USE_MOUSEWHEEL -# define USE_MOUSEWHEEL 1 +# define USE_MOUSEWHEEL 0 #endif #if USE_MOUSEWHEEL @@ -372,15 +423,22 @@ #endif /*------------------------------------------------- - * Touchscreen as libinput interface (for Linux based systems) + * Touchscreen, mouse/touchpad or keyboard as libinput interface (for Linux based systems) *------------------------------------------------*/ #ifndef USE_LIBINPUT # define USE_LIBINPUT 0 #endif -#if USE_LIBINPUT +#ifndef USE_BSD_LIBINPUT +# define USE_BSD_LIBINPUT 0 +#endif + +#if USE_LIBINPUT || USE_BSD_LIBINPUT +/*If only a single device of the same type is connected, you can also auto detect it, e.g.: + *#define LIBINPUT_NAME libinput_find_dev(LIBINPUT_CAPABILITY_TOUCH, false)*/ # define LIBINPUT_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/ -#endif /*USE_LIBINPUT*/ + +#endif /*USE_LIBINPUT || USE_BSD_LIBINPUT*/ /*------------------------------------------------- * Mouse or touchpad as evdev interface (for Linux based systems) @@ -407,11 +465,29 @@ # endif /*EVDEV_CALIBRATE*/ #endif /*USE_EVDEV*/ +/*------------------------------------------------- + * Full keyboard support for evdev and libinput interface + *------------------------------------------------*/ +# ifndef USE_XKB +# define USE_XKB 0 +# endif + +#if USE_LIBINPUT || USE_BSD_LIBINPUT || USE_EVDEV || USE_BSD_EVDEV +# if USE_XKB +# define XKB_KEY_MAP { .rules = NULL, \ + .model = "pc101", \ + .layout = "us", \ + .variant = NULL, \ + .options = NULL } /*"setxkbmap -query" can help find the right values for your keyboard*/ +# endif /*USE_XKB*/ +#endif /*USE_LIBINPUT || USE_BSD_LIBINPUT || USE_EVDEV || USE_BSD_EVDEV*/ + /*------------------------------- * Keyboard of a PC (using SDL) *------------------------------*/ +/*DEPRECATED: Use the SDL driver instead. */ #ifndef USE_KEYBOARD -# define USE_KEYBOARD 1 +# define USE_KEYBOARD 0 #endif #if USE_KEYBOARD diff --git a/lv_examples b/lv_examples deleted file mode 160000 index 4d6f215..0000000 --- a/lv_examples +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4d6f215c2bfd534eda744db512ea30685e5faf75 diff --git a/lvgl b/lvgl index c597d25..fd21ed0 160000 --- a/lvgl +++ b/lvgl @@ -1 +1 @@ -Subproject commit c597d257984e2cd3a1c883dc97a26d4512b5e60a +Subproject commit fd21ed0eb82bacb1e482180ab0aaed6a667f000d diff --git a/main/src/main.c b/main/src/main.c index 7c9fe1a..2753470 100644 --- a/main/src/main.c +++ b/main/src/main.c @@ -14,11 +14,12 @@ #include #include "lvgl/lvgl.h" #include "lvgl/examples/lv_examples.h" -#include "lv_examples/lv_demo.h" -#include "lv_drivers/display/monitor.h" -#include "lv_drivers/indev/mouse.h" -#include "lv_drivers/indev/keyboard.h" -#include "lv_drivers/indev/mousewheel.h" +#include "lvgl/demos/lv_demos.h" +#include "lv_drivers/sdl/sdl.h" +// #include "lv_drivers/display/monitor.h" +// #include "lv_drivers/indev/mouse.h" +// #include "lv_drivers/indev/keyboard.h" +// #include "lv_drivers/indev/mousewheel.h" /********************* * DEFINES @@ -65,6 +66,92 @@ static int tick_thread(void *data); /********************** * GLOBAL FUNCTIONS **********************/ +#if 0 +static void user_image_demo() +{ + lv_obj_t * img = lv_gif_create(lv_scr_act()); + lv_gif_set_src(img, "A:lvgl/examples/libs/gif/bulb.gif"); + lv_obj_align(img, LV_ALIGN_BOTTOM_RIGHT, -20, -20); + + lv_color_t bg_color = lv_palette_lighten(LV_PALETTE_LIGHT_BLUE, 5); + lv_color_t fg_color = lv_palette_darken(LV_PALETTE_BLUE, 4); + + lv_obj_t * qr = lv_qrcode_create(lv_scr_act(), 150, fg_color, bg_color); + + /*Set data*/ + const char * data = "https://lvgl.io"; + lv_qrcode_update(qr, data, strlen(data)); + lv_obj_center(qr); + + /*Add a border with bg_color*/ + lv_obj_set_style_border_color(qr, bg_color, 0); + lv_obj_set_style_border_width(qr, 5, 0); + + /*Create a font*/ + static lv_ft_info_t info; + /*FreeType uses C standard file system, so no driver letter is required.*/ + info.name = "./lvgl/examples/libs/freetype/Lato-Regular.ttf"; + info.weight = 24; + info.style = FT_FONT_STYLE_NORMAL; + info.mem = NULL; + if(!lv_ft_font_init(&info)) { + LV_LOG_ERROR("create failed."); + } + + /*Create style with the new font*/ + static lv_style_t style; + lv_style_init(&style); + lv_style_set_text_font(&style, info.font); + lv_style_set_text_align(&style, LV_TEXT_ALIGN_CENTER); + + /*Create a label with the new style*/ + lv_obj_t * label = lv_label_create(lv_scr_act()); + lv_obj_add_style(label, &style, 0); + lv_label_set_text(label, "Hello world\nI'm a font created with FreeType"); + lv_obj_set_pos(label, 10, 10); + + lv_obj_t * img1 = lv_img_create(lv_scr_act()); + /* Assuming a File system is attached to letter 'A' + * E.g. set LV_USE_FS_STDIO 'A' in lv_conf.h */ + lv_img_set_src(img1, "A:lvgl/examples/libs/png/wink.png"); + lv_obj_align(img1, LV_ALIGN_LEFT_MID, 20, 0); + + lv_obj_t * wp; + + wp = lv_img_create(lv_scr_act()); + /* Assuming a File system is attached to letter 'A' + * E.g. set LV_USE_FS_STDIO 'A' in lv_conf.h */ + lv_img_set_src(wp, "A:lvgl/examples/libs/sjpg/small_image.sjpg"); + lv_obj_align(wp, LV_ALIGN_RIGHT_MID, -20, 0); + + lv_obj_t * img2 = lv_img_create(lv_scr_act()); + /* Assuming a File system is attached to letter 'A' + * E.g. set LV_USE_FS_STDIO 'A' in lv_conf.h */ + lv_img_set_src(img2, "A:lvgl/examples/libs/sjpg/lv_example_jpg.jpg"); + //lv_obj_center(img); + lv_obj_align(img2, LV_ALIGN_TOP_RIGHT, -20, 20); + + lv_obj_t * img3 = lv_img_create(lv_scr_act()); + /* Assuming a File system is attached to letter 'A' + * E.g. set LV_USE_FS_STDIO 'A' in lv_conf.h */ +#if LV_COLOR_DEPTH == 32 + lv_img_set_src(img3, "A:lvgl/examples/libs/bmp/example_32bit.bmp"); +#elif LV_COLOR_DEPTH == 16 + lv_img_set_src(img, "A:lvgl/examples/libs/bmp/example_16bit.bmp"); +#endif + lv_obj_align(img3, LV_ALIGN_BOTTOM_MID, 0, -20); + + lv_obj_t * img4 = lv_img_create(lv_scr_act()); + lv_img_set_src(img4, "A:lvgl/examples/libs/ffmpeg/ffmpeg.png"); + lv_obj_align(img4, LV_ALIGN_BOTTOM_LEFT, 20, -20); + + lv_obj_t * player = lv_ffmpeg_player_create(lv_scr_act()); + lv_ffmpeg_player_set_src(player, "./lvgl/examples/libs/ffmpeg/birds.mp4"); + lv_ffmpeg_player_set_auto_restart(player, true); + lv_ffmpeg_player_set_cmd(player, LV_FFMPEG_PLAYER_CMD_START); + lv_obj_align(player, LV_ALIGN_TOP_MID, 0, 20); +} +#endif int main(int argc, char **argv) { @@ -101,6 +188,8 @@ int main(int argc, char **argv) // lv_demo_stress(); // lv_demo_music(); +// user_image_demo(); + while(1) { /* Periodically call the lv_task handler. * It could be done in a timer interrupt or an OS task too.*/ @@ -122,7 +211,7 @@ int main(int argc, char **argv) static void hal_init(void) { /* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ - monitor_init(); + sdl_init(); /* Tick init. * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about * how much time were elapsed Create an SDL thread to do this*/ @@ -138,7 +227,7 @@ static void hal_init(void) static lv_disp_drv_t disp_drv; lv_disp_drv_init(&disp_drv); /*Basic initialization*/ disp_drv.draw_buf = &disp_buf1; - disp_drv.flush_cb = monitor_flush; + disp_drv.flush_cb = sdl_display_flush; disp_drv.hor_res = MONITOR_HOR_RES; disp_drv.ver_res = MONITOR_VER_RES; disp_drv.antialiasing = 1; @@ -153,27 +242,27 @@ static void hal_init(void) /* Add the mouse as input device * Use the 'mouse' driver which reads the PC's mouse*/ - mouse_init(); + // mouse_init(); static lv_indev_drv_t indev_drv_1; lv_indev_drv_init(&indev_drv_1); /*Basic initialization*/ indev_drv_1.type = LV_INDEV_TYPE_POINTER; /*This function will be called periodically (by the library) to get the mouse position and state*/ - indev_drv_1.read_cb = mouse_read; + indev_drv_1.read_cb = sdl_mouse_read; lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv_1); - keyboard_init(); + // keyboard_init(); static lv_indev_drv_t indev_drv_2; lv_indev_drv_init(&indev_drv_2); /*Basic initialization*/ indev_drv_2.type = LV_INDEV_TYPE_KEYPAD; - indev_drv_2.read_cb = keyboard_read; + indev_drv_2.read_cb = sdl_keyboard_read; lv_indev_t *kb_indev = lv_indev_drv_register(&indev_drv_2); lv_indev_set_group(kb_indev, g); - mousewheel_init(); + // mousewheel_init(); static lv_indev_drv_t indev_drv_3; lv_indev_drv_init(&indev_drv_3); /*Basic initialization*/ indev_drv_3.type = LV_INDEV_TYPE_ENCODER; - indev_drv_3.read_cb = mousewheel_read; + indev_drv_3.read_cb = sdl_mousewheel_read; lv_indev_t * enc_indev = lv_indev_drv_register(&indev_drv_3); lv_indev_set_group(enc_indev, g);