### Install Yocto SDK Source: https://lvgl.io/docs/open/9.5/integration/embedded_linux/os/yocto/lvgl_recipe Example of executing the generated SDK installer script and providing a custom installation directory. ```bash $ ./sdk/poky-glibc-x86_64-core-image-base-cortexa53-raspberrypi3-64-toolchain-5.0.4.sh Poky (Yocto Project Reference Distro) SDK installer version 5.0.4 ================================================================= Enter target directory for SDK (default: /opt/poky/5.0.4): /opt/poky/sdk-with-lvgl You are about to install the SDK to "/opt/poky/sdk-with-lvgl". Proceed [Y/n]? y ``` -------------------------------- ### Basic Setup Example Source: https://lvgl.io/docs/open/9.5/libs/gltf This example demonstrates the initialization of LVGL, setting up an OpenGL ES window and display, and loading a glTF demo model. It includes the main loop for handling LVGL timers and display updates. ```c int main(void) { /* Initialize LVGL */ lv_init(); /* GLFW setup */ lv_opengles_window_t * window = lv_opengles_glfw_window_create(WINDOW_WIDTH, WINDOW_HEIGHT, true); lv_display_t * display = lv_opengles_texture_create(WINDOW_WIDTH, WINDOW_HEIGHT); unsigned int texture_id = lv_opengles_texture_get_texture_id(display); lv_opengles_window_add_texture(window, texture_id, WINDOW_WIDTH, WINDOW_HEIGHT); /* Load and display glTF demo */ lv_demo_gltf("A:"); while (1) { uint32_t time_until_next = lv_timer_handler(); if (time_until_next == LV_NO_TIMER_READY) { time_until_next = LV_DEF_REFR_PERIOD; } lv_delay_ms(time_until_next); } return 0; } ``` -------------------------------- ### Minimal UEFI LVGL Initialization Example Source: https://lvgl.io/docs/open/9.5/integration/pc/uefi A minimal example demonstrating the initialization of LVGL in a UEFI environment, including display and input device setup. ```c #include "lvgl/lvgl.h" #include "lvgl/examples/lv_examples.h" #include "lvgl/demos/lv_demos.h" EFI_STATUS EFIAPI EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { lv_uefi_init(ImageHandle, SystemTable); lv_init(); if (!lv_is_initialized()) return EFI_NOT_READY; EFI_HANDLE handle = lv_uefi_display_get_active(); if (!handle) handle = lv_uefi_display_get_any(); if (!handle) { lv_deinit(); return EFI_UNSUPPORTED; } lv_display_t *display = lv_uefi_display_create(handle); lv_display_set_default(display); lv_group_t *group = lv_group_create(); lv_group_set_default(group); lv_obj_t *cursor = lv_image_create(lv_layer_top()); lv_image_set_src(cursor, "E:cursor.png"); lv_indev_t *indev; indev = lv_uefi_simple_text_input_indev_create(); lv_indev_set_group(indev, group); lv_uefi_simple_text_input_indev_add_all(indev); indev = lv_uefi_simple_pointer_indev_create(NULL); lv_uefi_simple_pointer_indev_add_all(indev); lv_indev_set_cursor(indev, cursor); indev = lv_uefi_absolute_pointer_indev_create(NULL); lv_uefi_absolute_pointer_indev_add_all(indev); lv_demo_widgets(); size_t counter = 0; while (counter < 10000) { counter++; gBS->Stall(1000); lv_tick_inc(1); lv_timer_handler(); } return EFI_SUCCESS; } ``` -------------------------------- ### Basic Calendar Setup Source: https://lvgl.io/docs/open/widgets/calendar Demonstrates the basic setup and usage of the LVGL Calendar Widget. This example shows how to initialize a calendar and set its current date. ```c void lv_example_calendar_basic(void) { lv_obj_t * calendar; calendar = lv_calendar_create(lv_screen_active()); lv_obj_center(calendar); /* Set the current date (today) */ lv_calendar_set_today_date(calendar, 2023, 10, 26); /* Set the shown month */ lv_calendar_set_month_shown(calendar, 2023, 10); lv_obj_set_size(calendar, 250, 200); } ``` -------------------------------- ### Basic LVGL and GStreamer Setup Source: https://lvgl.io/docs/open/9.5/libs/video_support/gstreamer This example demonstrates the basic initialization of LVGL and the creation of a GStreamer application. Ensure your display driver is configured before calling lv_example_gstreamer_1(). ```c int main(void) { /* Initialize LVGL */ lv_init(); /* Setup display driver */ lv_display_t *display = lv_display_create(800, 480); /* ... configure display driver ... */ /* Create and run your GStreamer application */ lv_example_gstreamer_1(); while (1) { lv_timer_handler(); } return 0; } ``` -------------------------------- ### Basic LVGL Setup with OpenGL ES Source: https://lvgl.io/docs/open/libs/gltf Initializes LVGL, sets up an OpenGL ES window and display, and loads a glTF demo. This example requires a running event loop. ```c int main(void) { /* Initialize LVGL */ lv_init(); /* GLFW setup */ lv_opengles_window_t * window = lv_opengles_glfw_window_create(WINDOW_WIDTH, WINDOW_HEIGHT, true); lv_display_t *display = lv_opengles_texture_create(WINDOW_WIDTH, WINDOW_HEIGHT); unsigned int texture_id = lv_opengles_texture_get_texture_id(display); lv_opengles_window_add_texture(window, texture_id, WINDOW_WIDTH, WINDOW_HEIGHT); /* Load and display glTF demo */ lv_demo_gltf("A:"); while (1) { uint32_t time_until_next = lv_timer_handler(); if (time_until_next == LV_NO_TIMER_READY) { time_until_next = LV_DEF_REFR_PERIOD; } lv_delay_ms(time_until_next); } return 0; } ``` -------------------------------- ### Start LVGL Component using bsp_display_start Source: https://lvgl.io/docs/open/9.5/integration/chip_vendors/espressif/add_lvgl_to_esp32_idf_project Example of starting the LVGL subsystem using `bsp_display_start()` and `bsp_display_backlight_on()`. LVGL runs in the background without needing manual `lv_timer_handler()` calls. ```c void app_main(void) { bsp_display_start(); bsp_display_backlight_on(); bsp_display_lock(0); lv_demo_benchmark(); bsp_display_unlock(); } ``` -------------------------------- ### LVGL File Explorer Basic Setup Source: https://lvgl.io/docs/open/9.5/others/file_explorer Initializes and opens a directory in the LVGL File Explorer. This snippet shows how to create the widget and set the starting path. It includes platform-specific path configurations for Windows and Linux. ```c #include "../../lv_examples.h" #if LV_USE_TABLE && LV_USE_DROPDOWN && LV_USE_FILE_EXPLORER && (LV_USE_FS_STDIO || LV_USE_FS_POSIX || LV_USE_FS_WIN32 || LV_USE_FS_FATFS) && LV_BUILD_EXAMPLES #include #include static void file_explorer_event_handler(lv_event_t * e) { lv_event_code_t code = lv_event_get_code(e); lv_obj_t * obj = lv_event_get_target_obj(e); if(code == LV_EVENT_VALUE_CHANGED) { const char * cur_path = lv_file_explorer_get_current_path(obj); const char * sel_fn = lv_file_explorer_get_selected_file_name(obj); LV_LOG_USER("%s%s", cur_path, sel_fn); } } #if LV_FILE_EXPLORER_QUICK_ACCESS static void btn_event_handler(lv_event_t * e) { lv_event_code_t code = lv_event_get_code(e); lv_obj_t * btn = lv_event_get_target_obj(e); lv_obj_t * file_explorer = (lv_obj_t *) lv_event_get_user_data(e); if(code == LV_EVENT_VALUE_CHANGED) { if(lv_obj_has_state(btn, LV_STATE_CHECKED)) lv_obj_add_flag(file_explorer, LV_OBJ_FLAG_HIDDEN); else lv_obj_remove_flag(file_explorer, LV_OBJ_FLAG_HIDDEN); } } static void dd_event_handler(lv_event_t * e) { lv_event_code_t code = lv_event_get_code(e); lv_obj_t * dd = lv_event_get_target_obj(e); lv_obj_t * fe_quick_access_obj = (lv_obj_t *) lv_event_get_user_data(e); if(code == LV_EVENT_VALUE_CHANGED) { char buf[32]; lv_dropdown_get_selected_str(dd, buf, sizeof(buf)); if(strcmp(buf, "NONE") == 0) { lv_file_explorer_set_sort(fe_quick_access_obj, LV_EXPLORER_SORT_NONE); } else if(strcmp(buf, "KIND") == 0) { lv_file_explorer_set_sort(fe_quick_access_obj, LV_EXPLORER_SORT_KIND); } } } #endif void lv_example_file_explorer_2(void) { lv_obj_t * file_explorer = lv_file_explorer_create(lv_screen_active()); #if LV_USE_FS_WIN32 /* Note to Windows users: the initial "C:" on these paths corresponds to * the value of `LV_FS_WIN32_LETTER` in `lv_conf.h`, and should not be * confused with the Windows/DOS drive letter. It is an identifier that * is used to enable LVGL to look up the appropriate driver from a list of * registered file-system drivers. `lv_fs_win32_init()` happens to use the * identifier letter 'C' so "C:" is the driver-identifier-prefix used here. * The "C:" following that is indeed the Windows/DOS drive letter and is * part of the actual path that gets passed to the OS-level functions. * * See https://lvgl.io/docs/open/master/main-modules/fs.html for details. * File Explorer uses `lv_fs` internally, thus the required prefix in path strings. */ lv_file_explorer_open_dir(file_explorer, "C:C:/"); #if LV_FILE_EXPLORER_QUICK_ACCESS lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_HOME_DIR, "C:C:/Users/Public/Desktop"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_VIDEO_DIR, "C:C:/Users/Public/Videos"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_PICTURES_DIR, "C:C:/Users/Public/Pictures"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_MUSIC_DIR, "C:C:/Users/Public/Music"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_DOCS_DIR, "C:C:/Users/Public/Documents"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_FS_DIR, "C:C:/"); #endif #else /* linux */ lv_file_explorer_open_dir(file_explorer, "A:/"); #if LV_FILE_EXPLORER_QUICK_ACCESS const char * envvar = "HOME"; char home_dir[LV_FS_MAX_PATH_LENGTH]; strcpy(home_dir, "A:"); /* get the user's home directory from the HOME environment variable*/ strcat(home_dir, getenv(envvar)); LV_LOG_USER("home_dir: %s\n", home_dir); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_HOME_DIR, home_dir); char video_dir[LV_FS_MAX_PATH_LENGTH]; strcpy(video_dir, home_dir); strcat(video_dir, "/Videos"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_VIDEO_DIR, video_dir); char picture_dir[LV_FS_MAX_PATH_LENGTH]; strcpy(picture_dir, home_dir); strcat(picture_dir, "/Pictures"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_PICTURES_DIR, picture_dir); char music_dir[LV_FS_MAX_PATH_LENGTH]; strcpy(music_dir, home_dir); strcat(music_dir, "/Music"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_MUSIC_DIR, music_dir); char document_dir[LV_FS_MAX_PATH_LENGTH]; strcpy(document_dir, home_dir); strcat(document_dir, "/Documents"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_DOCS_DIR, document_dir); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_FS_DIR, "A:/"); #endif #endif lv_obj_add_event_cb(file_explorer, file_explorer_event_handler, LV_EVENT_ALL, NULL); } #endif ``` -------------------------------- ### LVGL Example: Decode Video using FFmpeg Source: https://lvgl.io/docs/open/9.5/libs/video_support/ffmpeg Shows how to create and control an FFmpeg video player within LVGL. This example demonstrates setting the decoder, source file, auto-restart, and starting playback. Ensure LV_USE_FFMPEG is enabled. ```c #include "../../lv_examples.h" #if LV_BUILD_EXAMPLES #if LV_USE_FFMPEG #if LV_FFMPEG_PLAYER_USE_LV_FS #define PATH_PREFIX "A:" #else #define PATH_PREFIX "./" #endif /** * Open a video from a file */ void lv_example_ffmpeg_2(void) { /*birds.mp4 is downloaded from http://www.videezy.com (Free Stock Footage by Videezy!) *https://www.videezy.com/abstract/44864-silhouettes-of-birds-over-the-sunset*/ /*It will use the LVGL filesystem abstraction (not the OS filesystem) *if `LV_FFMPEG_PLAYER_USE_LV_FS` is set.* lv_obj_t * player = lv_ffmpeg_player_create(lv_screen_active()); /*Note: "h264_v4l2m2m" is a Linux-specific hardware decoder example, available only on Linux systems with V4L2 support. *In the absence of support, it will fall back to software decoding.* lv_ffmpeg_player_set_decoder(player, "h264_v4l2m2m"); lv_ffmpeg_player_set_src(player, PATH_PREFIX "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_center(player); } #else void lv_example_ffmpeg_2(void) { /*TODO *fallback for online examples*/ lv_obj_t * label = lv_label_create(lv_screen_active()); lv_label_set_text(label, "FFmpeg is not installed"); lv_obj_center(label); } #endif #endif ``` -------------------------------- ### LVGL MIPI Display Initialization and Configuration Source: https://lvgl.io/docs/open/integration/external_display_controllers/gen_mipi Example of initializing LVGL, setting up custom I/O functions for a MIPI display, and creating the LVGL display object. This snippet demonstrates the core setup for a generic MIPI display driver. ```c #include "src/drivers/display/st7789/lv_st7789.h" #define LCD_H_RES 240 #define LCD_V_RES 320 #define LCD_BUF_LINES 60 lv_display_t * my_disp; /* Initialize LCD I/O bus, reset LCD */ static int32_t my_lcd_io_init(void) { /* ... */ return HAL_OK; } /* Send command to the LCD controller */ static void my_lcd_send_cmd(lv_display_t * disp, const uint8_t * cmd, size_t cmd_size, const uint8_t *param, size_t param_size) { MY_PIN_PREP_TO_SEND_CMD(); MY_PIN_LCD_CONTROLLER_CHIP_SELECT(); /* Any delay here needed to meet LCD controller requirements. */ /* Send command to LCD controller here. */ MY_PIN_PREP_TO_SEND_DATA(); /* Any delay here needed to meet LCD controller requirements. */ /* Send data to LCD controller here. */ MY_PIN_LCD_CONTROLLER_CHIP_DESELECT(); /* Any delay here needed to meet LCD controller requirements. */ } /* Send pixel data to the LCD controller */ static void my_lcd_send_color(lv_display_t * disp, const uint8_t * cmd, size_t cmd_size, uint8_t * param, size_t param_size) { MY_PIN_PREP_TO_SEND_CMD(); MY_PIN_LCD_CONTROLLER_CHIP_SELECT(); /* Any delay here needed to meet LCD controller requirements. */ /* Send command to LCD controller here. */ MY_PIN_PREP_TO_SEND_DATA(); /* Any delay here needed to meet LCD controller requirements. */ /* Send data to LCD controller here in a manner efficient for large blocks of data. */ /* If data transfer is done with DMA, these 2 steps are not made here, but * are instead made immediately after the DMA transfer completes. */ MY_PIN_LCD_CONTROLLER_CHIP_DESELECT(); lv_display_flush_ready(disp); } int main(int argc, char ** argv) { /* ... */ /* Initialize LVGL */ lv_init(); /* Initialize LCD bus I/O */ if (my_lcd_io_init() != 0) return; /* Create the LVGL display object and the LCD display driver */ my_disp = lv_lcd_generic_mipi_create(LCD_H_RES, LCD_V_RES, LV_LCD_FLAG_NONE, my_lcd_send_cmd, my_lcd_send_color); /* Set display orientation to landscape */ lv_display_set_rotation(my_disp, LV_DISPLAY_ROTATION_90); /* Configure draw buffers, etc. */ uint8_t * buf1 = NULL; uint8_t * buf2 = NULL; uint32_t buf_size = LCD_H_RES * LCD_BUF_LINES * lv_color_format_get_size(lv_display_get_color_format(my_disp)); buf1 = lv_malloc(buf_size); if(buf1 == NULL) { LV_LOG_ERROR("display draw buffer malloc failed"); return; } /* Allocate secondary buffer if needed */ /* ... */ lv_display_set_buffers(my_disp, buf1, buf2, buf_size, LV_DISPLAY_RENDER_MODE_PARTIAL); ui_init(my_disp); while(true) { /* ... */ /* Periodically call the lv_timer handler */ lv_timer_handler(); } } ``` -------------------------------- ### Example: Voltage/Current Measurement Observer Setup Source: https://lvgl.io/docs/open/main-modules/observer/observer Sets up subjects for mode, value, and unit, initializes them, creates a subject group, and adds an observer to update a label based on group changes. ```c lv_obj_t * label = lv_label_create(lv_screen_active()); lv_subject_t subject_mode; lv_subject_t subject_value; lv_subject_t subject_unit; lv_subject_t subject_all; lv_subject_t * subject_list[3] = {&subject_mode, &subject_value, &subject_unit}; /* The elements of the group */ lv_subject_init_int(&subject_mode, 0); // Let's say 0 is Voltage, 1 is Current lv_subject_init_int(&subject_value, 0); lv_subject_init_pointer(&subject_unit, "V"); lv_subject_init_group(&subject_all, subject_list, 3); lv_subject_add_observer_obj(&subject_all, all_observer_cb, label, NULL); ``` -------------------------------- ### Include LVGL Demos and Examples in PlatformIO Build Source: https://lvgl.io/docs/open/9.5/integration/framework/platformio Add these lines to your `platformio.ini` file to force PlatformIO to compile all LVGL demos and examples. Remember to remove them when you start working on your own project. ```ini build_src_filter = +<*> ; Force compile LVGL demos and examples, remove when working on your own project +<../.pio/libdeps/${PIOENV}/lvgl/demos> +<../.pio/libdeps/${PIOENV}/lvgl/examples> ``` -------------------------------- ### Configure Hardware Button Input Device Source: https://lvgl.io/docs/open/main-modules/indev/button A complete example demonstrating the setup of a hardware button input device. This includes creating the input device, setting its type to button, assigning the coordinate points, and defining the read callback function. ```c static const lv_point_t points_array[] = { {12,30}, /* First button is assigned to x=12; y=30 */ {60,90} /* Second button is assigned to x=60; y=90 */ }; lv_indev_t * indev = lv_indev_create(); lv_indev_set_type(indev, LV_INDEV_TYPE_BUTTON); lv_indev_set_button_points(indev, points_array); lv_indev_set_read_cb(indev, button_read); ... void button_read(lv_indev_t * indev, lv_indev_data_t * data) { /* Get the ID (0,1,2...) of the pressed button. * Let's say it returns -1 if no button was pressed */ int btn_pr = my_btn_read(); /* Is there a button press? */ if(btn_pr >= 0) { data->btn_id = btn_pr; /* Save the ID of the pressed button */ data->state = LV_INDEV_STATE_PRESSED; /* Set the pressed state */ } else { data->state = LV_INDEV_STATE_RELEASED; /* Set the released state */ } } ``` -------------------------------- ### LVGL Configuration Example Source: https://lvgl.io/docs/open/integration/frameworks/platformio Example of basic LVGL configuration macros for color depth and logging. ```c #define LV_COLOR_DEPTH 16 #define LV_USE_LOG 1 ``` -------------------------------- ### Install libwebp Source: https://lvgl.io/docs/open/9.5/libs/image_support/libwebp Install the libwebp development library on Linux or macOS. ```bash # Linux sudo apt install libwebp-dev # macOS brew install webp ``` -------------------------------- ### Full Subject Group Example Source: https://lvgl.io/docs/open/9.5/main-modules/observer/observer Demonstrates the complete setup for a Subject Group, including initializing individual subjects, the group, and adding an observer to update a label based on multiple inputs. ```c lv_obj_t * label = lv_label_create(lv_screen_active()); lv_subject_t subject_mode; // Voltage or Current lv_subject_t subject_value; // Measured value lv_subject_t subject_unit; // The unit lv_subject_t subject_all; // Subject group that connects the above 3 Subjects lv_subject_t * subject_list[3] = {&subject_mode, &subject_value, &subject_unit}; // The elements of the group lv_subject_init_int(&subject_mode, 0); // Let's say 0 is Voltage, 1 is Current lv_subject_init_int(&subject_value, 0); lv_subject_init_pointer(&subject_unit, "V"); lv_subject_init_group(&subject_all, subject_list, 3); lv_subject_add_observer_obj(&subject_all, all_observer_cb, label, NULL); ... ``` -------------------------------- ### Clone Buildroot Repository Source: https://lvgl.io/docs/open/9.5/integration/embedded_linux/os/buildroot/quick_setup Clone the LVGL Buildroot repository to get started with the setup. Ensure submodules are also recurred. ```bash git clone --recurse-submodules https://github.com/lvgl/lv_buildroot.git ``` -------------------------------- ### FreeType Compilation and Installation for UNIX Source: https://lvgl.io/docs/open/9.5/libs/font_support/freetype Recommended steps to compile and install FreeType libraries on UNIX-like systems. Includes commands for compilation, installation, and setting include paths and library links for GCC. ```bash make sudo make install # Add include path: /usr/include/freetype2 (for GCC: -I/usr/include/freetype2 -L/usr/local/lib) # Link against library: freetype (for GCC: -L/usr/local/lib -lfreetype) ``` -------------------------------- ### Clone Buildroot Repository Source: https://lvgl.io/docs/open/integration/embedded_linux/distros/buildroot/quick_start Clone the LVGL Buildroot repository to get started with a pre-configured setup. Ensure submodules are also cloned. ```bash git clone --recurse-submodules https://github.com/lvgl/lv_buildroot.git ``` -------------------------------- ### QNX LVGL "Hello World" Application Source: https://lvgl.io/docs/open/9.5/integration/rtos/qnx Example code demonstrating how to initialize LVGL, create a window, add input devices, and display a "Hello world" message on QNX. ```c #include int main(int argc, char **argv) { /* Initialize the library. */ lv_init(); /* Create a 800x480 window. */ lv_display_t *disp = lv_qnx_window_create(800, 480); lv_qnx_window_set_title(disp, "LVGL Example"); /* Add keyboard and mouse devices. */ lv_qnx_add_keyboard_device(disp); lv_qnx_add_pointer_device(disp); /* Generate the UI. */ lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(0x003a57), LV_PART_MAIN); lv_obj_t * label = lv_label_create(lv_screen_active()); lv_label_set_text(label, "Hello world"); lv_obj_set_style_text_color(lv_screen_active(), lv_color_hex(0xffffff), LV_PART_MAIN); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); /* Run the event loop until it exits. */ return lv_qnx_event_loop(disp); } ``` -------------------------------- ### Get Start Value Source: https://lvgl.io/docs/open/9.5/API/widgets/bar/lv_bar_h Retrieves the start value of the bar. ```APIDOC ## lv_bar_get_start_value ### Description Get the start value of a bar. ### Parameters * **obj** (const lv_obj_t *) - pointer to a bar object ### Returns * int32_t - the start value of the bar ``` -------------------------------- ### Initialize LVGL and Create a Button with Label in MicroPython Source: https://lvgl.io/docs/open/integration/bindings/micropython This snippet demonstrates the basic setup for LVGL in MicroPython, including initializing the display driver and LVGL, creating a screen, adding a button, and setting its label text. It's a starting point for building simple UIs. ```python # Initialize import display_driver import lvgl as lv # Create a button with a label scr = lv.obj() btn = lv.button(scr) btn.align(lv.ALIGN.CENTER, 0, 0) label = lv.label(btn) label.set_text('Hello World!') lv.screen_load(scr) ``` -------------------------------- ### Get Bar Start Value Source: https://lvgl.io/docs/open/api/widgets/lv_bar_h Retrieves the current start value of the bar. Returns an `int32_t` representing the bar's start value. ```c int32_t lv_bar_get_start_value(const lv_obj_t *obj) ``` -------------------------------- ### Basic LVGL Windows Application Setup Source: https://lvgl.io/docs/open/9.5/integration/pc/windows This C code demonstrates the basic setup for an LVGL application on Windows. It initializes LVGL, creates a display window, acquires input devices (pointer, keypad, encoder), and runs a demo. Ensure LV_USE_WINDOWS is enabled. ```c #include #include "lvgl/lvgl.h" #include "lvgl/examples/lv_examples.h" #include "lvgl/demos/lv_demos.h" int main() { lv_init(); int32_t zoom_level = 100; bool allow_dpi_override = false; bool simulator_mode = false; lv_display_t* display = lv_windows_create_display( L"LVGL Display Window", 800, 480, zoom_level, allow_dpi_override, simulator_mode); if (!display) return -1; lv_lock(); lv_indev_t* pointer_device = lv_windows_acquire_pointer_indev(display); if (!pointer_device) return -1; lv_indev_t* keypad_device = lv_windows_acquire_keypad_indev(display); if (!keypad_device) return -1; lv_indev_t* encoder_device = lv_windows_acquire_encoder_indev(display); if (!encoder_device) return -1; lv_demo_widgets(); lv_unlock(); while (1) { uint32_t time_till_next = lv_timer_handler(); // handle LV_NO_TIMER_READY. Another option is to always sleep a few milliseconds if(time_till_next == LV_NO_TIMER_READY) time_till_next = LV_DEF_REFR_PERIOD; lv_sleep_ms(time_till_next); } return 0; } ``` -------------------------------- ### Install Buildroot Prerequisites Source: https://lvgl.io/docs/open/9.5/integration/embedded_linux/os/buildroot/image_generation Installs the necessary packages on an Ubuntu system required for Buildroot to function correctly. Ensure you have `sudo` privileges. ```bash sudo apt install sed make binutils gcc g++ bash patch gzip bzip2 perl tar \ cpio python3 unzip rsync wget libncurses-dev ``` -------------------------------- ### Build and Install SDK Source: https://lvgl.io/docs/open/9.5/integration/embedded_linux/os/buildroot/quick_setup Navigate to the output directory, build the SDK, and extract it to a specified location for application development. ```bash cd output make sdk mkdir -p ~/sdk tar -xzf images/aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz -C ~/sdk ``` -------------------------------- ### Get Start Angle Source: https://lvgl.io/docs/open/9.5/API/widgets/arc/lv_arc_h Retrieves the current start angle of the arc. The angle is returned in degrees. ```APIDOC ## lv_arc_get_angle_start ### Description Get the start angle of an arc. ### Parameters #### Path Parameters - **obj** (lv_obj_t *) - pointer to an arc object ### Returns - lv_value_precise_t - the start angle [0..360] (if `LV_USE_FLOAT` is enabled it can be fractional too.) ``` -------------------------------- ### lv_arclabel_get_angle_start Source: https://lvgl.io/docs/open/9.5/API/widgets/arclabel/lv_arclabel_h Gets the start angle of an arc label. ```APIDOC ## lv_arclabel_get_angle_start ### Description Get the start angle of an arc label. ### Parameters * **obj** (lv_obj_t *) - pointer to an arc label object ### Returns the start angle [0..360] (if `LV_USE_FLOAT` is enabled it can be fractional too.) ``` -------------------------------- ### Basic LVGL Integration Example Source: https://lvgl.io/docs/open/9.5/getting_started/learn_the_basics This example demonstrates the core steps for initializing LVGL, setting up a display with a partial buffer, defining a flush callback, creating a simple label widget, and running the LVGL timer handler loop. User-defined functions like `your_driver_init`, `my_get_millis`, `my_sleep`, and `my_display_update` must be implemented separately. ```c void main(void) { your_driver_init(); lv_init(); lv_tick_set_cb(my_get_millis); lv_display_t * display = lv_display_create(320, 240); /* LVGL will render to this 1/10 screen sized buffer for 2 bytes/pixel */ static uint8_t buf[320 * 240 / 10 * 2]; lv_display_set_buffers(display, buf, NULL, LV_DISPLAY_RENDER_MODE_PARTIAL); /* This callback will display the rendered image */ lv_display_set_flush_cb(display, my_flush_cb); /* Create widgets */ lv_obj_t * label = lv_label_create(lv_screen_active()); lv_label_set_text(label, "Hello LVGL!"); /* Make LVGL periodically execute its tasks */ while(1) { /* Provide updates to currently-displayed Widgets here. */ lv_timer_handler(); my_sleep(5); /*Wait 5 milliseconds before processing LVGL timer again*/ } } /* Return the elapsed milliseconds since startup. * It needs to be implemented by the user */ uint32_t my_get_millis(void) { return my_tick_ms; } /* Copy rendered image to screen. * This needs to be implemented by the user. */ void my_flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * px_buf) { /* Show the rendered image on the display */ my_display_update(area, px_buf); /* Indicate that the buffer is available. * If DMA were used, call in the DMA complete interrupt. */ lv_display_flush_ready(); } ``` -------------------------------- ### Basic lv_conf.h Setup Source: https://lvgl.io/docs/open/9.5/integration/overview Copy `lv_conf_template.h` to `lv_conf.h` and enable it by changing `#if 0` to `1`. Ensure `LV_COLOR_DEPTH` matches your display. ```c #include "lvgl/lvgl.h" #include "lv_conf.h" // ... your application code ... ``` -------------------------------- ### Get Animation Timeline Start Delay Source: https://lvgl.io/docs/open/api/core/lv_anim_timeline_h Retrieves the delay time set before the animation starts or repeats from the end. The value is in milliseconds. ```c uint32_t lv_anim_timeline_get_delay(lv_anim_timeline_t *at) ``` -------------------------------- ### lv_arclabel_get_text_angle Source: https://lvgl.io/docs/open/9.5/API/widgets/arclabel/lv_arclabel_h Get the starting angle of the text in the arc label. ```APIDOC ## lv_arclabel_get_text_angle ### Description Get the starting angle of the text in the arc label. ### Function Signature ```c static inline int16_t lv_arclabel_get_text_angle(const lv_obj_t * arc_label) ``` ### Parameters * **arc_label** (const lv_obj_t *) - Pointer to the arc label object. ``` -------------------------------- ### Create Project Directory and Clone Repositories Source: https://lvgl.io/docs/open/9.5/integration/embedded_linux/os/torizon/torizon_os Set up the project directory structure and download the necessary LVGL and porting repositories. ```bash mkdir -p ~/lvgl_torizon_os/ cd ~/lvgl_torizon_os/ touch Dockerfile git clone --depth 1 https://github.com/lvgl/lv_port_linux git -C lv_port_linux submodule update --init ``` -------------------------------- ### Get Text Selection Start Index Source: https://lvgl.io/docs/open/api/widgets/lv_label_h Retrieves the starting index of the currently selected text within the label. Returns LV_LABEL_TEXT_SELECTION_OFF if no text is selected. ```c uint32_t lv_label_get_text_selection_start(const lv_obj_t *obj) ``` -------------------------------- ### LVGL Integration Example Source: https://lvgl.io/docs/open/getting_started/learn_the_basics Demonstrates the basic steps to initialize LVGL, set up a display with a flush callback, create a simple label widget, and handle LVGL tasks in a loop. This example requires user-defined functions for driver initialization, tick retrieval, display flushing, and sleeping. ```c void main(void) { your_driver_init(); lv_init(); lv_tick_set_cb(my_get_millis); lv_display_t * display = lv_display_create(320, 240); /* LVGL will render to this 1/10 screen sized buffer for 2 bytes/pixel */ static uint8_t buf[320 * 240 / 10 * 2]; lv_display_set_buffers(display, buf, NULL, LV_DISPLAY_RENDER_MODE_PARTIAL); /* This callback will display the rendered image */ lv_display_set_flush_cb(display, my_flush_cb); /* Create widgets */ lv_obj_t * label = lv_label_create(lv_screen_active()); lv_label_set_text(label, "Hello LVGL!"); /* Make LVGL periodically execute its tasks */ while(1) { /* Provide updates to currently-displayed Widgets here. */ lv_timer_handler(); my_sleep(5); /*Wait 5 milliseconds before processing LVGL timer again*/ } } /* Return the elapsed milliseconds since startup. * It needs to be implemented by the user */ uint32_t my_get_millis(void) { return my_tick_ms; } /* Copy rendered image to screen. * This needs to be implemented by the user. */ void my_flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * px_buf) { /* Show the rendered image on the display */ my_display_update(area, px_buf); /* Indicate that the buffer is available. * If DMA were used, call in the DMA complete interrupt. */ lv_display_flush_ready(); } ``` -------------------------------- ### Get Background Main Stop Style Source: https://lvgl.io/docs/open/api/core/lv_obj_style_gen_h Retrieves the starting point for the background color in gradients. A value of 0 means the color starts from the top/left, and 255 means it starts from the bottom/right. The default value is 0. ```c static int32_t lv_obj_get_style_bg_main_stop(const lv_obj_t *obj, lv_part_t part) ``` -------------------------------- ### Get Next Timer in Sequence Source: https://lvgl.io/docs/open/api/core/lv_timer_h Iterate through the list of active timers. Pass NULL to start the iteration or the previously returned timer to get the subsequent one. ```c lv_timer_t * lv_timer_get_next(lv_timer_t *timer) ``` -------------------------------- ### Minimal UEFI LVGL Example Source: https://lvgl.io/docs/open/integration/pc/uefi A basic example demonstrating LVGL initialization, display and input device creation, and running a demo within a UEFI environment. ```c #include "lvgl/lvgl.h" #include "lvgl/examples/lv_examples.h" #include "lvgl/demos/lv_demos.h" EFI_STATUS EFIAPI EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { lv_uefi_init(ImageHandle, SystemTable); lv_init(); if (!lv_is_initialized()) return EFI_NOT_READY; EFI_HANDLE handle = lv_uefi_display_get_active(); if (!handle) handle = lv_uefi_display_get_any(); if (!handle) { lv_deinit(); return EFI_UNSUPPORTED; } lv_display_t *display = lv_uefi_display_create(handle); lv_display_set_default(display); lv_group_t *group = lv_group_create(); lv_group_set_default(group); lv_obj_t *cursor = lv_image_create(lv_layer_top()); lv_image_set_src(cursor, "E:cursor.png"); lv_indev_t *indev; indev = lv_uefi_simple_text_input_indev_create(); lv_indev_set_group(indev, group); lv_uefi_simple_text_input_indev_add_all(indev); indev = lv_uefi_simple_pointer_indev_create(NULL); lv_uefi_simple_pointer_indev_add_all(indev); lv_indev_set_cursor(indev, cursor); indev = lv_uefi_absolute_pointer_indev_create(NULL); lv_uefi_absolute_pointer_indev_add_all(indev); lv_demo_widgets(); size_t counter = 0; while (counter < 10000) { counter++; gBS->Stall(1000); lv_tick_inc(1); lv_timer_handler(); } return EFI_SUCCESS; } ``` -------------------------------- ### Enable Example Builds Source: https://lvgl.io/docs/open/api/config/lv_conf_internal_h Controls whether examples are built with the library. Used for enabling external data and destructor functions. ```c #define LV_BUILD_EXAMPLES 1 ``` -------------------------------- ### Get Start Write Count Source: https://lvgl.io/docs/open/api-private/drivers/display/lovyan_gfx/lv_lgfx_user_hpp Retrieves the count of start write operations. The exact usage and meaning of this count may depend on internal library implementation. ```cpp uint32_t LGFX::getStartCount(void) ``` -------------------------------- ### Create X11 Window and Inputs Source: https://lvgl.io/docs/open/9.5/API/drivers/x11/lv_x11_h Demonstrates the minimal initialization for an X11 display driver with keyboard and mouse support. This includes creating the window and then setting up the input devices. ```c lv_display_t* disp = lv_x11_window_create("My Window Title", window_width, window_width); lv_x11_inputs_create(disp, NULL); ``` -------------------------------- ### Get Animation Delay Source: https://lvgl.io/docs/open/api/core/lv_anim_h Retrieves the delay in milliseconds before an animation is scheduled to start. ```c uint32_t lv_anim_get_delay(const lv_anim_t *a) ``` -------------------------------- ### LVGL File Explorer Basic Setup Source: https://lvgl.io/docs/open/9.5/auxiliary-modules/file_explorer Initializes a file explorer widget, sets its sorting mode, and opens a specified directory. It also includes an event handler for value changes. ```c #include "../../lv_examples.h" #if LV_USE_TABLE && LV_USE_FILE_EXPLORER && (LV_USE_FS_STDIO || LV_USE_FS_POSIX || LV_USE_FS_WIN32 || LV_USE_FS_FATFS) && LV_BUILD_EXAMPLES #include #include static void file_explorer_event_handler(lv_event_t * e) { lv_event_code_t code = lv_event_get_code(e); lv_obj_t * obj = lv_event_get_target_obj(e); if(code == LV_EVENT_VALUE_CHANGED) { const char * cur_path = lv_file_explorer_get_current_path(obj); const char * sel_fn = lv_file_explorer_get_selected_file_name(obj); LV_LOG_USER("%s%s", cur_path, sel_fn); } } void lv_example_file_explorer_1(void) { lv_obj_t * file_explorer = lv_file_explorer_create(lv_screen_active()); lv_file_explorer_set_sort(file_explorer, LV_EXPLORER_SORT_KIND); #if LV_USE_FS_WIN32 /* Note to Windows users: the initial "C:" on these paths corresponds to * the value of `LV_FS_WIN32_LETTER` in `lv_conf.h`, and should not be * confused with the Windows/DOS drive letter. It is an identifier that * is used to enable LVGL to look up the appropriate driver from a list of * registered file-system drivers. `lv_fs_win32_init()` happens to use the * identifier letter 'C' so "C:" is the driver-identifier-prefix used here. * The "C:" following that is indeed the Windows/DOS drive letter and is * part of the actual path that gets passed to the OS-level functions. * * See https://lvgl.io/docs/open/master/main-modules/fs.html for details. * File Explorer uses `lv_fs` internally, thus the required prefix in path strings. */ lv_file_explorer_open_dir(file_explorer, "C:C:/"); #if LV_FILE_EXPLORER_QUICK_ACCESS lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_HOME_DIR, "C:C:/Users/Public/Desktop"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_VIDEO_DIR, "C:C:/Users/Public/Videos"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_PICTURES_DIR, "C:C:/Users/Public/Pictures"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_MUSIC_DIR, "C:C:/Users/Public/Music"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_DOCS_DIR, "C:C:/Users/Public/Documents"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_FS_DIR, "C:C:/"); #endif #else /* linux */ lv_file_explorer_open_dir(file_explorer, "A:/"); #if LV_FILE_EXPLORER_QUICK_ACCESS const char * envvar = "HOME"; char home_dir[LV_FS_MAX_PATH_LENGTH]; strcpy(home_dir, "A:"); /* get the user's home directory from the HOME environment variable*/ strcat(home_dir, getenv(envvar)); LV_LOG_USER("home_dir: %s\n", home_dir); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_HOME_DIR, home_dir); char video_dir[LV_FS_MAX_PATH_LENGTH]; strcpy(video_dir, home_dir); strcat(video_dir, "/Videos"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_VIDEO_DIR, video_dir); char picture_dir[LV_FS_MAX_PATH_LENGTH]; strcpy(picture_dir, home_dir); strcat(picture_dir, "/Pictures"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_PICTURES_DIR, picture_dir); char music_dir[LV_FS_MAX_PATH_LENGTH]; strcpy(music_dir, home_dir); strcat(music_dir, "/Music"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_MUSIC_DIR, music_dir); char document_dir[LV_FS_MAX_PATH_LENGTH]; strcpy(document_dir, home_dir); strcat(document_dir, "/Documents"); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_DOCS_DIR, document_dir); lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_FS_DIR, "A:/"); #endif #endif lv_obj_add_event_cb(file_explorer, file_explorer_event_handler, LV_EVENT_ALL, NULL); } #endif ``` -------------------------------- ### Get Chart X-Axis Start Point Index Source: https://lvgl.io/docs/open/api/widgets/lv_chart_h Retrieves the index of the current starting point for the X-axis in the data array of a specific series. Useful for scrolled charts. ```c uint32_t lv_chart_get_x_start_point(const lv_obj_t * obj, lv_chart_series_t * ser) ``` -------------------------------- ### Using an 'get' Element in a View Source: https://lvgl.io/docs/open/9.5/xml/ui_elements/api Example of how to reference an implicitly created element ('get' type) within a widget definition in a view. Specifies attributes for accessing and configuring the element. ```xml ``` -------------------------------- ### Initialize LVGL Source: https://lvgl.io/docs/open/9.5/integration/overview Include the LVGL header, initialize your hardware, and then call `lv_init()` to initialize the LVGL library. ```c #include "lvgl/lvgl.h" // Initialize your hardware (clock, peripherals, etc.) lv_init(); ``` -------------------------------- ### Step-by-Step Test Execution Initialization Source: https://lvgl.io/docs/open/9.5/xml/features/tests Prepares the environment for executing test steps one by one. It cleans the screen and sets up a fresh UI instance. ```c lv_xml_test_run_init() ``` -------------------------------- ### Simple Switch Example Source: https://lvgl.io/docs/open/9.5/widgets/switch Demonstrates the creation of multiple switch widgets with different initial states and disabled states. It also shows how to attach an event handler to log state changes. ```c #include "../../lv_examples.h" #if LV_USE_SWITCH && LV_BUILD_EXAMPLES static void event_handler(lv_event_t * e) { lv_event_code_t code = lv_event_get_code(e); lv_obj_t * obj = lv_event_get_target_obj(e); LV_UNUSED(obj); if(code == LV_EVENT_VALUE_CHANGED) { LV_LOG_USER("State: %s\n", lv_obj_has_state(obj, LV_STATE_CHECKED) ? "On" : "Off"); } } void lv_example_switch_1(void) { lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); lv_obj_t * sw; sw = lv_switch_create(lv_screen_active()); lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL); lv_obj_add_flag(sw, LV_OBJ_FLAG_EVENT_BUBBLE); sw = lv_switch_create(lv_screen_active()); lv_obj_add_state(sw, LV_STATE_CHECKED); lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL); sw = lv_switch_create(lv_screen_active()); lv_obj_add_state(sw, LV_STATE_DISABLED); lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL); sw = lv_switch_create(lv_screen_active()); lv_obj_add_state(sw, LV_STATE_CHECKED); lv_obj_add_state(sw, LV_STATE_DISABLED); lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL); } #endif ``` -------------------------------- ### Create and Load Basic GStreamer Player Source: https://lvgl.io/docs/open/9.5/libs/video_support/gstreamer Demonstrates the creation of a GStreamer object and setting its media source using a URI. ```c /* Create a GStreamer object */ lv_obj_t * streamer = lv_gstreamer_create(lv_screen_active()); /* Set the media source using URI factory */ lv_result_t result = lv_gstreamer_set_src(streamer, LV_GSTREAMER_FACTORY_URI_DECODE, LV_GSTREAMER_PROPERTY_URI_DECODE, "https://example.com/video.webm"); if (result != LV_RESULT_OK) { LV_LOG_ERROR("Failed to set GStreamer source"); return; } /* Start playback */ lv_gstreamer_play(streamer); ```