1 /*
2 * Copyright (c) 2024 Martin Stumpf <finomnis@gmail.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/device.h>
8 #include <zephyr/devicetree.h>
9 #include <zephyr/drivers/display.h>
10
11 #include <lvgl.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <zephyr/kernel.h>
15
16 #include <zephyr/logging/log.h>
17 LOG_MODULE_REGISTER(app, CONFIG_LOG_DEFAULT_LEVEL);
18
initialize_gui(void)19 static void initialize_gui(void)
20 {
21 lv_obj_t *label;
22
23 /* Configure screen and background for transparency */
24 lv_obj_set_style_bg_opa(lv_screen_active(), LV_OPA_TRANSP, LV_PART_MAIN);
25 lv_obj_set_style_bg_opa(lv_layer_bottom(), LV_OPA_TRANSP, LV_PART_MAIN);
26
27 /* Create a label, set its text and align it to the center */
28 label = lv_label_create(lv_screen_active());
29 lv_label_set_text(label, "Hello, world!");
30 lv_obj_set_style_text_color(label, lv_color_hex(0xff00ff), LV_PART_MAIN);
31 lv_obj_align(label, LV_ALIGN_CENTER, 0, -20);
32 label = lv_label_create(lv_screen_active());
33 lv_label_set_text(label, "RED");
34 lv_obj_set_style_text_color(label, lv_color_hex(0xff0000), LV_PART_MAIN);
35 lv_obj_align(label, LV_ALIGN_CENTER, -70, 20);
36 label = lv_label_create(lv_screen_active());
37 lv_label_set_text(label, "GREEN");
38 lv_obj_set_style_text_color(label, lv_color_hex(0x00ff00), LV_PART_MAIN);
39 lv_obj_align(label, LV_ALIGN_CENTER, 0, 20);
40 label = lv_label_create(lv_screen_active());
41 lv_label_set_text(label, "BLUE");
42 lv_obj_set_style_text_color(label, lv_color_hex(0x0000ff), LV_PART_MAIN);
43 lv_obj_align(label, LV_ALIGN_CENTER, 70, 20);
44 }
45
main(void)46 int main(void)
47 {
48 const struct device *display_dev;
49 int ret;
50
51 display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
52 if (!device_is_ready(display_dev)) {
53 LOG_ERR("Device not ready, aborting test");
54 return -ENODEV;
55 }
56
57 initialize_gui();
58
59 lv_timer_handler();
60 ret = display_blanking_off(display_dev);
61 if (ret < 0 && ret != -ENOSYS) {
62 LOG_ERR("Failed to turn blanking off (error %d)", ret);
63 return 0;
64 }
65
66 while (1) {
67 uint32_t sleep_ms = lv_timer_handler();
68
69 k_msleep(MIN(sleep_ms, INT32_MAX));
70 }
71
72 return 0;
73 }
74