1 /* 2 * Copyright (c) 2023 Fabian Blatz <fabianblatz@gmail.com> 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 #include <zephyr/drivers/display.h> 9 #include <lvgl.h> 10 #include <lvgl_mem.h> 11 #include <lv_demos.h> 12 #include <stdio.h> 13 14 #define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL 15 #include <zephyr/logging/log.h> 16 LOG_MODULE_REGISTER(app); 17 main(void)18int main(void) 19 { 20 const struct device *display_dev; 21 #ifdef CONFIG_LV_Z_DEMO_RENDER_SCENE_DYNAMIC 22 k_timepoint_t next_scene_switch; 23 lv_demo_render_scene_t cur_scene = LV_DEMO_RENDER_SCENE_FILL; 24 #endif /* CONFIG_LV_Z_DEMO_RENDER_SCENE_DYNAMIC */ 25 26 display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display)); 27 if (!device_is_ready(display_dev)) { 28 LOG_ERR("Device not ready, aborting test"); 29 return 0; 30 } 31 32 #if defined(CONFIG_LV_Z_DEMO_MUSIC) 33 lv_demo_music(); 34 #elif defined(CONFIG_LV_Z_DEMO_BENCHMARK) 35 lv_demo_benchmark(); 36 #elif defined(CONFIG_LV_Z_DEMO_STRESS) 37 lv_demo_stress(); 38 #elif defined(CONFIG_LV_Z_DEMO_WIDGETS) 39 lv_demo_widgets(); 40 #elif defined(CONFIG_LV_Z_DEMO_FLEX_LAYOUT) 41 lv_demo_flex_layout(); 42 #elif defined(CONFIG_LV_Z_DEMO_KEYPAD_AND_ENCODER) 43 lv_demo_keypad_encoder(); 44 #elif defined(CONFIG_LV_Z_DEMO_RENDER) 45 46 #ifdef CONFIG_LV_Z_DEMO_RENDER_SCENE_DYNAMIC 47 lv_demo_render(cur_scene, 255); 48 next_scene_switch = 49 sys_timepoint_calc(K_SECONDS(CONFIG_LV_Z_DEMO_RENDER_DYNAMIC_SCENE_TIMEOUT)); 50 #else 51 lv_demo_render(CONFIG_LV_Z_DEMO_RENDER_SCENE_INDEX, 255); 52 #endif /* CONFIG_LV_Z_DEMO_RENDER_SCENE_DYNAMIC */ 53 54 #elif defined(CONFIG_LV_Z_DEMO_SCROLL) 55 lv_demo_scroll(); 56 #elif defined(CONFIG_LV_Z_DEMO_MULTILANG) 57 lv_demo_multilang(); 58 #else 59 #error Enable one of the demos CONFIG_LV_Z_DEMO_* 60 #endif 61 62 lv_timer_handler(); 63 display_blanking_off(display_dev); 64 #ifdef CONFIG_LV_Z_MEM_POOL_SYS_HEAP 65 lvgl_print_heap_info(false); 66 #else 67 printf("lvgl in malloc mode\n"); 68 #endif 69 while (1) { 70 uint32_t sleep_ms = lv_timer_handler(); 71 72 k_msleep(MIN(sleep_ms, INT32_MAX)); 73 #ifdef CONFIG_LV_Z_DEMO_RENDER_SCENE_DYNAMIC 74 if (sys_timepoint_expired(next_scene_switch)) { 75 cur_scene = (cur_scene + 1) % _LV_DEMO_RENDER_SCENE_NUM; 76 lv_demo_render(cur_scene, 255); 77 next_scene_switch = sys_timepoint_calc( 78 K_SECONDS(CONFIG_LV_Z_DEMO_RENDER_DYNAMIC_SCENE_TIMEOUT)); 79 } 80 #endif /* CONFIG_LV_Z_DEMO_RENDER_SCENE_DYNAMIC */ 81 } 82 83 return 0; 84 } 85