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(lv_screen_active(), lv_color_hex(0xff00ff), LV_PART_MAIN);
31 	lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
32 }
33 
main(void)34 int main(void)
35 {
36 	int err;
37 	const struct device *display_dev;
38 	struct display_capabilities display_caps;
39 
40 	display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
41 	if (!device_is_ready(display_dev)) {
42 		LOG_ERR("Device not ready, aborting test");
43 		return -ENODEV;
44 	}
45 
46 	display_get_capabilities(display_dev, &display_caps);
47 	if (!(display_caps.supported_pixel_formats | PIXEL_FORMAT_ARGB_8888)) {
48 		LOG_ERR("Display does not support ARGB8888 mode");
49 		return -ENOTSUP;
50 	}
51 
52 	if (PIXEL_FORMAT_ARGB_8888 != display_caps.current_pixel_format) {
53 		err = display_set_pixel_format(display_dev, PIXEL_FORMAT_ARGB_8888);
54 		if (err != 0) {
55 			LOG_ERR("Failed to set ARGB8888 pixel format");
56 			return err;
57 		}
58 	}
59 
60 	initialize_gui();
61 
62 	lv_timer_handler();
63 	display_blanking_off(display_dev);
64 
65 	while (1) {
66 		uint32_t sleep_ms = lv_timer_handler();
67 
68 		k_msleep(MIN(sleep_ms, INT32_MAX));
69 	}
70 
71 	return 0;
72 }
73