|
| 1 | +/* |
| 2 | + * Copyright (c) 2018 Jan Van Winkel <[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 | +#include <zephyr/drivers/gpio.h> |
| 11 | +#include <zephyr/drivers/pwm.h> |
| 12 | +#include <lvgl.h> |
| 13 | +#include <stdio.h> |
| 14 | +#include <string.h> |
| 15 | +#include <zephyr/kernel.h> |
| 16 | +#include <zephyr/logging/log.h> |
| 17 | +#include <lvgl_input_device.h> |
| 18 | + |
| 19 | +#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL |
| 20 | +LOG_MODULE_REGISTER(SmartWatch_OS); |
| 21 | + |
| 22 | +static void lv_btn_click_callback(lv_event_t *e) { |
| 23 | + LOG_INF("Button clicked"); |
| 24 | +} |
| 25 | + |
| 26 | +int main(void) { |
| 27 | + |
| 28 | + // Check if the display device is ready. |
| 29 | + const struct device *display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display)); |
| 30 | + if (!device_is_ready(display_dev)) { |
| 31 | + LOG_ERR("Display device is not ready, exiting..."); |
| 32 | + return 0; |
| 33 | + } |
| 34 | + LOG_INF("Display device is ready."); |
| 35 | + |
| 36 | + const struct pwm_dt_spec backlight = PWM_DT_SPEC_GET_BY_IDX(DT_NODELABEL(pwm_lcd0), 0); |
| 37 | + if (!pwm_is_ready_dt(&backlight)) { |
| 38 | + LOG_ERR("PWM device is not ready, exiting..."); |
| 39 | + return 0; |
| 40 | + } |
| 41 | + LOG_INF("PWM device is ready."); |
| 42 | + |
| 43 | + // Log PWM backlight information. |
| 44 | + LOG_INF("PWM device: %s", backlight.dev->name); |
| 45 | + LOG_INF("PWM channel: %d", backlight.channel); |
| 46 | + LOG_INF("PWM period: %d", backlight.period); |
| 47 | + LOG_INF("PWM flags: %d", backlight.flags); |
| 48 | + |
| 49 | + // Initialize the PWM device. |
| 50 | + int ret = pwm_set_dt(&backlight, 500, 250); |
| 51 | + if (ret < 0) { |
| 52 | + LOG_ERR("Failed to set PWM pulse, exiting..."); |
| 53 | + return 0; |
| 54 | + } |
| 55 | + |
| 56 | + // Initialize the display device with initial GUI. |
| 57 | + if (IS_ENABLED(CONFIG_LV_Z_POINTER_INPUT)) { |
| 58 | + |
| 59 | + // Create a button. |
| 60 | + lv_obj_t *hello_world_button = lv_btn_create(lv_scr_act()); |
| 61 | + lv_obj_align(hello_world_button, LV_ALIGN_CENTER, 0, -15); |
| 62 | + lv_obj_add_event_cb(hello_world_button, |
| 63 | + lv_btn_click_callback, |
| 64 | + LV_EVENT_CLICKED, NULL); |
| 65 | + // Create a label for the button. |
| 66 | + lv_obj_t *hello_world_label = lv_label_create(hello_world_button); |
| 67 | + lv_label_set_text(hello_world_label, "Hello world!"); |
| 68 | + lv_obj_align(hello_world_label, LV_ALIGN_CENTER, 0, 0); |
| 69 | + |
| 70 | + LOG_INF("LVGL initialized."); |
| 71 | + } |
| 72 | + |
| 73 | + lv_task_handler(); |
| 74 | + display_blanking_off(display_dev); |
| 75 | + |
| 76 | + while (1) { |
| 77 | + lv_task_handler(); |
| 78 | + k_sleep(K_MSEC(10)); |
| 79 | + } |
| 80 | +} |
0 commit comments