|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Martin Stumpf <[email protected]> |
| 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 | + |
| 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_scr_act(), LV_OPA_TRANSP, LV_PART_MAIN); |
| 25 | + lv_disp_set_bg_opa(NULL, LV_OPA_TRANSP); |
| 26 | + lv_obj_set_style_bg_color(lv_scr_act(), lv_color_hex(0x000000), LV_PART_MAIN); |
| 27 | + |
| 28 | + /* Create a label, set its text and align it to the center */ |
| 29 | + label = lv_label_create(lv_scr_act()); |
| 30 | + lv_label_set_text(label, "Hello, world!"); |
| 31 | + lv_obj_set_style_text_color(lv_scr_act(), lv_color_hex(0xff00ff), LV_PART_MAIN); |
| 32 | + lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); |
| 33 | +} |
| 34 | + |
| 35 | +int main(void) |
| 36 | +{ |
| 37 | + int err; |
| 38 | + const struct device *display_dev; |
| 39 | + struct display_capabilities display_caps; |
| 40 | + |
| 41 | + display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display)); |
| 42 | + if (!device_is_ready(display_dev)) { |
| 43 | + LOG_ERR("Device not ready, aborting test"); |
| 44 | + return -ENODEV; |
| 45 | + } |
| 46 | + |
| 47 | + display_get_capabilities(display_dev, &display_caps); |
| 48 | + if (!(display_caps.supported_pixel_formats | PIXEL_FORMAT_ARGB_8888)) { |
| 49 | + LOG_ERR("Display does not support ARGB8888 mode"); |
| 50 | + return -ENOTSUP; |
| 51 | + } |
| 52 | + |
| 53 | + if (PIXEL_FORMAT_ARGB_8888 != display_caps.current_pixel_format) { |
| 54 | + err = display_set_pixel_format(display_dev, PIXEL_FORMAT_ARGB_8888); |
| 55 | + if (err != 0) { |
| 56 | + LOG_ERR("Failed to set ARGB8888 pixel format"); |
| 57 | + return err; |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + initialize_gui(); |
| 62 | + |
| 63 | + lv_task_handler(); |
| 64 | + display_blanking_off(display_dev); |
| 65 | + |
| 66 | + while (1) { |
| 67 | + uint32_t sleep_ms = lv_task_handler(); |
| 68 | + |
| 69 | + k_msleep(MIN(sleep_ms, INT32_MAX)); |
| 70 | + } |
| 71 | + |
| 72 | + return 0; |
| 73 | +} |
0 commit comments