### Basic Setup Example Source: https://github.com/lvgl/docs/blob/gh-pages/master/libs/gltf.html A minimal C code example demonstrating the initialization of LVGL, OpenGL ES window, and loading a glTF demo. ```APIDOC ```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; } ``` ``` -------------------------------- ### Install Yocto SDK Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/integration/embedded_linux/os/yocto/lvgl_recipe.rst.txt Example of executing the generated SDK installer script and providing installation directory and confirmation. ```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 ``` -------------------------------- ### Redirect to Getting Started Page Source: https://github.com/lvgl/docs/blob/gh-pages/master/intro/getting_started/index.html This JavaScript code handles redirection based on the URL hash, ensuring users are directed to the correct section of the getting started guide. ```javascript var target = "../../getting_started/index.html"; if (window.location.hash) { window.location.replace(target + window.location.hash); } else { window.location.replace(target); } ``` -------------------------------- ### Start Animation on Event Example Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/examples.rst.txt Shows how to start an animation when a specific event occurs. ```c void lv_example_anim_1(void) { lv_obj_t *obj = lv_obj_create(lv_screen_active()); lv_obj_set_size(obj, 100, 100); lv_obj_center(obj); lv_obj_set_style_bg_color(obj, lv_palette_main(LV_PALETTE_RED), 0); lv_obj_add_event_cb(obj, anim_start_event_cb, LV_EVENT_PRESSED, NULL); } static void anim_start_event_cb(lv_event_t *e) { lv_obj_t *obj = lv_event_get_target(e); lv_anim_t anim; lv_anim_init(&anim); lv_anim_set_var(&anim, obj); lv_anim_set_exec_cb(&anim, anim_exec_cb); lv_anim_set_values(&anim, 0, 100); lv_anim_set_time(&anim, 500); lv_anim_set_path(&anim, &lv_anim_path_linear); lv_anim_set_repeat_count(&anim, 2); lv_anim_start(&anim); } static void anim_exec_cb(void *var, int32_t v) { lv_obj_t *obj = (lv_obj_t *)var; lv_obj_set_x(obj, v); } ``` -------------------------------- ### PikaScript Installation and Precompilation Output Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/integration/bindings/pikascript.rst.txt Example output from the PikaScript precompiler after installation, showing installed packages and the compilation process for main.py. ```shell $ ./rust-msc-latest-win10.exe (pikascript) packages installed: pikascript-core==v1.10.0 PikaStdLib==v1.10.0 PikaStdDevice==v1.10.0 (pikascript) pika compiler: scanning main.py... binding pika_lvgl.pyi... ``` -------------------------------- ### Basic GLFW Driver Usage Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/integration/embedded_linux/drivers/glfw.rst.txt Initialize LVGL, create an OpenGL window, set up a display flushing to a texture, and add widgets. This example demonstrates the fundamental setup for using the GLFW driver. ```c #include "lvgl/lvgl.h" #include "lvgl/examples/lv_examples.h" #include "lvgl/demos/lv_demos.h" #define WIDTH 640 #define HEIGHT 480 int main() { /* initialize lvgl */ lv_init(); /* create a window and initialize OpenGL */ lv_opengles_window_t * window = lv_opengles_glfw_window_create(WIDTH, HEIGHT, true); /* create a display that flushes to a texture */ lv_display_t * texture = lv_opengles_texture_create(WIDTH, HEIGHT); lv_display_set_default(texture); /* add the texture to the window */ unsigned int texture_id = lv_opengles_texture_get_texture_id(texture); lv_opengles_window_texture_t * window_texture = lv_opengles_window_add_texture(window, texture_id, WIDTH, HEIGHT); /* get the mouse indev of the window texture */ lv_indev_t * mouse = lv_opengles_window_texture_get_mouse_indev(window_texture); /* add a cursor to the mouse indev */ LV_IMAGE_DECLARE(mouse_cursor_icon); lv_obj_t * cursor_obj = lv_image_create(lv_screen_active()); lv_image_set_src(cursor_obj, &mouse_cursor_icon); lv_indev_set_cursor(mouse, cursor_obj); /* create Widgets on the screen */ lv_demo_widgets(); 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; /*handle LV_NO_TIMER_READY. Another option is to `sleep` for longer*/ lv_delay_ms(time_until_next); } return 0; } ``` -------------------------------- ### Initialize LVGL and Display Driver in main.cpp Source: https://github.com/lvgl/docs/blob/gh-pages/master/integration/frameworks/platformio.html Basic setup for LVGL in your main Arduino sketch, including initialization, setting a tick callback, and creating a display driver instance. This example uses a buffer and assumes a LovyanGFX driver. ```cpp #include #include #define BUF_SIZE 320 * 50 uint8_t lv_buffer[BUF_SIZE]; /* Tick source, tell LVGL how much time (milliseconds) has passed */ static uint32_t my_tick(void) { return millis(); } void setup() { /* Initialize LVGL */ lv_init(); /* Set the tick callback */ lv_tick_set_cb(my_tick); /* Initialize the display driver */ lv_lovyan_gfx_create(320, 480, lv_buffer, BUF_SIZE, true); lv_obj_t *label = lv_label_create(lv_screen_active()); lv_label_set_text(label, "Hello PlatformIO, I\'m LVGL!"); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0 ); } void loop() { lv_timer_handler(); // Update the UI- delay(5); } ``` -------------------------------- ### Install SDK Source: https://github.com/lvgl/docs/blob/gh-pages/master/integration/embedded_linux/os/yocto/lvgl_recipe.html Execute the generated SDK installer script to install the SDK to your preferred directory. This script is found in `build/tmp/deploy/sdk/`. ```bash ./sdk/poky-glibc-x86_64-core-image-base-cortexa53-raspberrypi3-64-toolchain-5.0.4.sh ``` -------------------------------- ### Enable LVGL Examples and Demos Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/integration/building/cmake.rst.txt Build LVGL with its examples and demos enabled by setting CONFIG_LV_BUILD_EXAMPLES and CONFIG_LV_BUILD_DEMOS to ON. ```cmake set(CONFIG_LV_BUILD_EXAMPLES ON) set(CONFIG_LV_BUILD_DEMOS ON) add_subdirectory(lvgl) ``` -------------------------------- ### Hello World Label Example Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/examples.rst.txt A basic LVGL example to display a simple 'hello world' label. ```c void lv_example_get_started_1(void) { lv_obj_t *label = lv_label_create(lv_screen_active()); lv_label_set_text(label, "Hello world!"); lv_obj_center(label); } ``` -------------------------------- ### Install libwebp Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/libs/image_support/libwebp.rst.txt Install the libwebp development library on Linux or macOS. ```bash # Linux sudo apt install libwebp-dev # macOS brew install webp ``` -------------------------------- ### Install libjpeg-turbo Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/libs/image_support/libjpeg_turbo.rst.txt Install the libjpeg-turbo development library using apt. ```bash sudo apt install libjpeg-turbo8-dev ``` -------------------------------- ### Table Widget Example with Data Source: https://github.com/lvgl/docs/blob/gh-pages/master/widgets/table.html A more complete example demonstrating table creation and data population. ```c #include "lv_examples.h" void lv_example_table_1(void) { lv_obj_t * table = lv_table_create(lv_screen_active()); lv_table_set_row_cnt(table, 5); lv_table_set_col_cnt(table, 3); //Set col width lv_table_set_col_width(table, 0, 100); lv_table_set_col_width(table, 1, 100); lv_table_set_col_width(table, 2, 100); //Add first row (header) lv_table_set_cell_type(table, 0, 0, LV_TABLE_CELL_TYPE_HEADER); lv_table_set_cell_value(table, 0, 0, "Header 1"); lv_table_set_cell_type(table, 0, 1, LV_TABLE_CELL_TYPE_HEADER); lv_table_set_cell_value(table, 0, 1, "Header 2"); lv_table_set_cell_type(table, 0, 2, LV_TABLE_CELL_TYPE_HEADER); lv_table_set_cell_value(table, 0, 2, "Header 3"); //Add other rows lv_table_set_cell_value(table, 1, 0, "1"); lv_table_set_cell_value(table, 1, 1, "10"); lv_table_set_cell_value(table, 1, 2, "100"); lv_table_set_cell_value(table, 2, 0, "2"); lv_table_set_cell_value(table, 2, 1, "20"); lv_table_set_cell_value(table, 2, 2, "200"); lv_table_set_cell_value(table, 3, 0, "3"); lv_table_set_cell_value(table, 3, 1, "30"); lv_table_set_cell_value(table, 3, 2, "300"); lv_table_set_cell_value(table, 4, 0, "4"); lv_table_set_cell_value(table, 4, 1, "40"); lv_table_set_cell_value(table, 4, 2, "400"); lv_obj_set_size(table, 300, 200); lv_obj_center(table); } ``` -------------------------------- ### Compile and Install FFmpeg from Source Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/libs/video_support/ffmpeg.rst.txt Configures, compiles, and installs FFmpeg from source. This method allows for fine-grained control over included features. Ensure you have build tools installed. ```shell ./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 ``` -------------------------------- ### Build and Install SDK Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/integration/embedded_linux/os/buildroot/quick_setup.rst.txt Navigate to the output directory, build the SDK, and extract it to a specified location. ```bash cd output make sdk mkdir -p ~/sdk tar -xzf images/aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz -C ~/sdk ``` -------------------------------- ### Initialize LVGL and Create a Basic UI Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/getting_started/learn_the_basics.rst.txt This example demonstrates the core steps for integrating LVGL into a project: initializing the library, setting up a display with a flush callback, creating a simple label widget, and entering the main event loop. Ensure `my_get_millis` and `my_flush_cb` are implemented by the user. ```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(); } ``` -------------------------------- ### Initialize and Run File Explorer Example Source: https://github.com/lvgl/docs/blob/gh-pages/master/auxiliary-modules/file_explorer.html Sets up and displays a file explorer widget on the active screen. It configures sorting, opens a directory, and attaches an event handler. ```c 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); lv_obj_add_event_cb(file_explorer, file_explorer_event_handler, LV_EVENT_ALL, NULL); /* Platform-specific directory opening and quick access path configuration */ #if LV_USE_FS_WIN32 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 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:"); 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 } ``` -------------------------------- ### Get Bar Start Value Source: https://github.com/lvgl/docs/blob/gh-pages/master/API/widgets/bar/lv_bar_h.html Retrieves the start value of the bar, which is relevant for range mode. ```APIDOC ## lv_bar_get_start_value ### Description Gets the start value of the bar. ### Signature ```c int32_t lv_bar_get_start_value(const lv_obj_t * bar) ``` ### Parameters * **bar**: Pointer to the bar object. ### Returns The start value of the bar. ``` -------------------------------- ### Basic LVGL and GStreamer Setup Source: https://github.com/lvgl/docs/blob/gh-pages/master/libs/video_support/gstreamer.html Initialize LVGL, set up the display driver, and create a GStreamer application. This serves as the entry point for an LVGL application using GStreamer. ```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; } ``` -------------------------------- ### lv_arc_get_bg_angle_start Source: https://github.com/lvgl/docs/blob/gh-pages/master/genindex.html Gets the start angle of the arc's background. ```APIDOC ## lv_arc_get_bg_angle_start ### Description Gets the start angle of the arc's background. ### Function Signature ```c++ int32_t lv_arc_get_bg_angle_start(const lv_obj_t * arc) ``` ### Parameters - **arc** (*const lv_obj_t*): Pointer to the arc object. ### Returns - The start angle of the arc's background in degrees. ``` -------------------------------- ### Minimal UEFI LVGL Example Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/integration/pc/uefi.rst.txt A basic example demonstrating the initialization of LVGL with the UEFI driver, setting up display and input devices, and running a demo. ```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; } ``` -------------------------------- ### QNX LVGL "Hello World" Application Source: https://github.com/lvgl/docs/blob/gh-pages/master/integration/rtos/qnx.html A basic LVGL application for QNX demonstrating initialization, window creation, input device addition, UI generation, and running the event loop. This example uses QNX-specific calls for window and input management. ```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); } ``` -------------------------------- ### Minimal UEFI LVGL Initialization Example Source: https://github.com/lvgl/docs/blob/gh-pages/master/integration/pc/uefi.html A basic example demonstrating the initialization of LVGL within a UEFI environment, setting up display and input devices. ```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(); return EFI_SUCCESS; } ``` -------------------------------- ### lv_arc_get_angle_start Source: https://github.com/lvgl/docs/blob/gh-pages/master/genindex.html Gets the start angle of the arc's value indicator. ```APIDOC ## lv_arc_get_angle_start ### Description Gets the start angle of the arc's value indicator. ### Function Signature ```c++ int32_t lv_arc_get_angle_start(const lv_obj_t * arc) ``` ### Parameters - **arc** (*const lv_obj_t*): Pointer to the arc object. ### Returns - The start angle of the arc's value indicator in degrees. ``` -------------------------------- ### Get Angles Source: https://github.com/lvgl/docs/blob/gh-pages/master/API/widgets/arc/lv_arc_h.html Retrieve the start and end angles for the arc and its background. ```APIDOC ## lv_arc_get_angle_start ### Description Get the start angle of an arc. ### Parameters **obj** (*lv_obj_t* *) - pointer to an arc object ### Returns the start angle [0..360] (if `LV_USE_FLOAT` is enabled it can be fractional too.) ## lv_arc_get_angle_end ### Description Get the end angle of an arc. ### Parameters **obj** (*lv_obj_t* *) - pointer to an arc object ### Returns the end angle [0..360] (if `LV_USE_FLOAT` is enabled it can be fractional too.) ## lv_arc_get_bg_angle_start ### Description Get the start angle of an arc background. ### Parameters **obj** (*lv_obj_t* *) - pointer to an arc object ### Returns the start angle [0..360] (if `LV_USE_FLOAT` is enabled it can be fractional too.) ## lv_arc_get_bg_angle_end ### Description Get the end angle of an arc background. ### Parameters **obj** (*lv_obj_t* *) - pointer to an arc object ### Returns the end angle [0..360] (if `LV_USE_FLOAT` is enabled it can be fractional too.) ``` -------------------------------- ### Initialize LVGL and Create a Basic UI Source: https://github.com/lvgl/docs/blob/gh-pages/master/getting_started/learn_the_basics.html This snippet demonstrates the fundamental steps to initialize LVGL, set up a display, and create a simple label widget. It includes essential callbacks for display flushing and tick management. Ensure `your_driver_init()`, `my_get_millis()`, `my_sleep()`, and `my_display_update()` are implemented by the user. ```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*/ } } ``` ```c /* Return the elapsed milliseconds since startup. * It needs to be implemented by the user */ uint32_t my_get_millis(void) { return my_tick_ms; } ``` ```c /* 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 Knob Offset Source: https://github.com/lvgl/docs/blob/gh-pages/master/API/widgets/arc/lv_arc_h.html Gets the current angular offset of the arc's knob. This indicates the knob's position relative to the arc's start. ```APIDOC ## lv_arc_get_knob_offset ### Description Get the current knob angle offset. ### Parameters * **obj** (const lv_obj_t *) - pointer to an arc object ### Returns int32_t - arc's current knob offset ``` -------------------------------- ### Basic LVGL and GStreamer Setup Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/libs/video_support/gstreamer.rst.txt This snippet shows the basic initialization for LVGL and setting up a display driver, which is a prerequisite before integrating GStreamer for media playback. ```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 */ ``` -------------------------------- ### Clone Buildroot Repository Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/integration/embedded_linux/os/buildroot/quick_setup.rst.txt Clone the Buildroot repository with all submodules to get started. ```bash git clone --recurse-submodules https://github.com/lvgl/lv_buildroot.git ``` -------------------------------- ### Pause Animation Example Source: https://github.com/lvgl/docs/blob/gh-pages/master/examples.html Demonstrates pausing a label slide animation for one second shortly after it starts. This example uses a switch to trigger the animation and a timer to control the pause. ```c #include "../lv_examples.h" #if LV_BUILD_EXAMPLES && LV_USE_SWITCH static void anim_x_cb(void * var, int32_t v) { lv_obj_set_x((lv_obj_t *) var, v); } static void timer_cb(lv_timer_t * timer) { lv_anim_t * anim = (lv_anim_t *) lv_timer_get_user_data(timer); lv_anim_pause_for(anim, 1000); lv_timer_delete(timer); } static void sw_event_cb(lv_event_t * e) { lv_obj_t * sw = lv_event_get_target_obj(e); lv_obj_t * label = (lv_obj_t *) lv_event_get_user_data(e); if(lv_obj_has_state(sw, LV_STATE_CHECKED)) { lv_anim_t a; lv_anim_init(&a); lv_anim_set_var(&a, label); lv_anim_set_values(&a, lv_obj_get_x(label), 100); lv_anim_set_duration(&a, 500); lv_anim_set_exec_cb(&a, anim_x_cb); lv_anim_set_path_cb(&a, lv_anim_path_overshoot); lv_timer_create(timer_cb, 200, lv_anim_start(&a)); } else { lv_anim_t a; lv_anim_init(&a); lv_anim_set_var(&a, label); lv_anim_set_values(&a, lv_obj_get_x(label), -lv_obj_get_width(label)); lv_anim_set_duration(&a, 500); lv_anim_set_exec_cb(&a, anim_x_cb); lv_anim_set_path_cb(&a, lv_anim_path_ease_in); lv_timer_create(timer_cb, 200, lv_anim_start(&a)); } } void lv_example_anim_4(void) { lv_obj_t * label = lv_label_create(lv_screen_active()); lv_label_set_text(label, "Hello animations!"); lv_obj_set_pos(label, 100, 10); lv_obj_t * sw = lv_switch_create(lv_screen_active()); lv_obj_center(sw); lv_obj_add_state(sw, LV_STATE_CHECKED); lv_obj_add_event_cb(sw, sw_event_cb, LV_EVENT_VALUE_CHANGED, label); } #endif ``` -------------------------------- ### QNX LVGL "Hello World" Application Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/integration/rtos/qnx.rst.txt This C code demonstrates a basic LVGL application on QNX, including initializing LVGL, creating a window, adding input devices, and setting up a simple UI. It utilizes QNX-specific functions for window and event loop management. ```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); } ``` -------------------------------- ### Arduino Example for NV3007 Display Source: https://github.com/lvgl/docs/blob/gh-pages/master/integration/external_display_controllers/nv3007.html This example demonstrates how to use the NV3007 display with the Arduino framework over SPI. It includes platform-specific functions for sending commands and color data, and the setup for LVGL initialization. ```c #include /* Platform-specific includes */ #include #define LCD_DC 21 #define LCD_CS 5 #define LCD_RST 4 #define LCD_SCK 18 #define LCD_MOSI 23 #define LCD_MISO -1 #define LCD_BL 15 #define SPI_CLK 40000000 #define BUFFER_SIZE 142 * 50 uint8_t buf[BUFFER_SIZE]; /* Define your platform-specific functions to send commands and data */ 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) { SPI.beginTransaction(SPISettings(SPI_CLK, MSBFIRST, SPI_MODE0)); /* Send command */ digitalWrite(LCD_DC, LOW); /* command mode */ digitalWrite(LCD_CS, LOW); /* CS low */ SPI.transferBytes(cmd, NULL, cmd_size); /* Send parameters (if any) */ if (param != NULL && param_size > 0) { digitalWrite(LCD_DC, HIGH); /* data mode */ SPI.transferBytes(param, NULL, param_size); } digitalWrite(LCD_CS, HIGH); /* CS high */ SPI.endTransaction(); } void my_lcd_send_color(lv_display_t *disp, const uint8_t *cmd, size_t cmd_size, uint8_t *param, size_t param_size) { SPI.beginTransaction(SPISettings(SPI_CLK, MSBFIRST, SPI_MODE0)); digitalWrite(LCD_CS, LOW); /* Send the command first */ digitalWrite(LCD_DC, LOW); SPI.transferBytes(cmd, NULL, cmd_size); /* Then send the pixel data */ if (param && param_size > 0) { digitalWrite(LCD_DC, HIGH); SPI.transferBytes(param, NULL, param_size); } digitalWrite(LCD_CS, HIGH); SPI.endTransaction(); /* Important: signal LVGL that we're done */ lv_display_flush_ready(disp); } void setup() { pinMode(LCD_BL, OUTPUT); digitalWrite(LCD_BL, HIGH); /* turn on backlight */ pinMode(LCD_DC, OUTPUT); pinMode(LCD_CS, OUTPUT); pinMode(LCD_RST, OUTPUT); /* reset sequence */ digitalWrite(LCD_RST, HIGH); delay(100); digitalWrite(LCD_RST, LOW); delay(120); digitalWrite(LCD_RST, HIGH); delay(120); SPI.begin(LCD_SCK, LCD_MISO, LCD_MOSI, LCD_CS); /* SCK, MISO, MOSI, SS */ digitalWrite(LCD_CS, HIGH); /* disable device */ delay(100); /* wait for device to stabilize */ lv_init(); lv_tick_set_cb(my_tick); /* Create NV3007 display */ lv_display_t *disp = lv_nv3007_create(142, 428, LV_LCD_FLAG_NONE, my_lcd_send_cmd, my_lcd_send_color); lv_nv3007_set_gap(disp, 0, 14); lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270); lv_display_set_color_format(disp, LV_COLOR_FORMAT_RGB565_SWAPPED); lv_display_set_buffers(disp, buf, NULL, BUFFER_SIZE, LV_DISP_RENDER_MODE_PARTIAL); /* Create a simple label on the display */ lv_obj_t *label = lv_label_create(lv_screen_active()); lv_label_set_text(label, "Hello NV3007!"); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); } void loop() { lv_task_handler(); delay(5); } ``` -------------------------------- ### Basic DRM Usage Example Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/integration/embedded_linux/drivers/drm.rst.txt Initialize LVGL, create a DRM display, set the device path, and run the LVGL task loop. Ensure proper permissions for the DRM device. ```c #include "lvgl/lvgl.h" #include "lvgl/demos/lv_demos.h" int main(void) { /* Initialize LVGL */ lv_init(); /* DRM device node */ const char *device = "/dev/dri/card0"; /* Create a DRM display */ lv_display_t *disp = lv_linux_drm_create(); /* Set DRM device file and connector */ /* The 2nd argument is the DRM device path */ /* The 3rd argument is the connector_id (-1 = auto-select first available) */ lv_linux_drm_set_file(disp, device, -1); /* Create demo widgets */ lv_demo_widgets(); /* Handle LVGL tasks */ 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; } ``` -------------------------------- ### Basic LVGL Setup with OpenGL ES and glTF Demo Source: https://github.com/lvgl/docs/blob/gh-pages/master/libs/gltf.html Initializes LVGL, sets up an OpenGL ES window and display using GLFW, and loads a glTF demo model. The main loop continuously handles LVGL timers and delays. ```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; } ``` -------------------------------- ### Monochrome Display Rounder Callback Example Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/main-modules/display/color_format.rst.txt Implement a rounder callback to ensure redrawn areas start and end on byte boundaries for monochrome displays. This example rounds coordinates to the nearest multiple of 8. ```c static void my_rounder_cb(lv_event_t *e) { lv_area_t *area = lv_event_get_param(e); /* Round the height to the nearest multiple of 8 */ area->y1 = (area->y1 & ~0x7); area->y2 = (area->y2 | 0x7); } lv_display_add_event_cb(display, my_rounder_cb, LV_EVENT_INVALIDATE_AREA, display); ``` -------------------------------- ### lv_obj_get_style_radial_offset Source: https://github.com/lvgl/docs/blob/gh-pages/master/API/core/lv_obj_style_gen_h.html Gets the radial offset, which is used to move the start point of an object radially (e.g., for scale ticks). ```APIDOC ## lv_obj_get_style_radial_offset ### Description Move start point of object (e.g. scale tick) radially. ### Parameters * **obj** – Pointer to Widget * **part** – One of the `LV_PART_...` enum values ### Return Value int32_t - The radial offset value. ``` -------------------------------- ### LVGL Windows Driver Usage Example Source: https://github.com/lvgl/docs/blob/gh-pages/master/integration/pc/windows.html This example demonstrates how to initialize LVGL, create a display window, acquire input devices, and run a demo on Windows. ```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; } ``` -------------------------------- ### Include LVGL Demos and Examples in PlatformIO Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/integration/frameworks/platformio.rst.txt Add these lines to your platformio.ini file to force PlatformIO to compile and include all LVGL demos and examples. Remove these lines when you start working on your own project to avoid conflicts and unnecessary compilation. ```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> ``` -------------------------------- ### Create and Load Media with GStreamer Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/libs/video_support/gstreamer.rst.txt Demonstrates creating a GStreamer object, setting a media source via URI, and starting playback. Ensure the GStreamer factory and property are correctly specified for the 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); ``` -------------------------------- ### List Input Devices with libinput Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/integration/embedded_linux/drivers/libinput.rst.txt Use this command to list available input devices and verify their setup for libinput. Ensure libinput-dev is installed. ```console $ sudo libinput list-devices ... ``` -------------------------------- ### Example: Set Display Buffers (Partial Render) Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/main-modules/display/setup.rst.txt Example demonstrating how to set up draw buffers for a display using partial rendering. Ensure BYTES_PER_PIXEL is correctly defined based on your color format. ```c /* Declare buffer for 1/10 screen size; BYTES_PER_PIXEL will be 2 for RGB565. */ #define BYTES_PER_PIXEL (LV_COLOR_FORMAT_GET_SIZE(LV_COLOR_FORMAT_RGB565)) static uint8_t buf1[MY_DISP_HOR_RES * MY_DISP_VER_RES / 10 * BYTES_PER_PIXEL]; /* Set display buffer for display `display1`. */ lv_display_set_buffers(display1, buf1, NULL, sizeof(buf1), LV_DISPLAY_RENDER_MODE_PARTIAL); ``` -------------------------------- ### Get Text Selection Start Index Source: https://github.com/lvgl/docs/blob/gh-pages/master/_sources/widgets/textarea.rst.txt Retrieve the zero-based index of the first character of the selected text. `LV_DRAW_LABEL_NO_TXT_SEL` indicates that no text is currently selected. ```c lv_label_get_text_selection_start(ta_label); ``` -------------------------------- ### Create Project Directory and Dockerfile Source: https://github.com/lvgl/docs/blob/gh-pages/master/integration/embedded_linux/os/torizon/torizon_os.html Use these commands to set up the project structure, including the main directory and the Dockerfile for building the Torizon OS image. ```bash mkdir -p ~/lvgl_torizon_os/ cd ~/lvgl_torizon_os/ touch Dockerfile ``` ```bash git clone --depth 1 https://github.com/lvgl/lv_port_linux git -C lv_port_linux submodule update --init ```