|
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | 6 |
|
| 7 | +#include <stdio.h> |
| 8 | +#include <string.h> |
| 9 | + |
| 10 | +#include <lvgl.h> |
| 11 | +#include <lvgl_input_device.h> |
| 12 | + |
| 13 | +#include <zephyr/kernel.h> |
7 | 14 | #include <zephyr/device.h> |
8 | 15 | #include <zephyr/devicetree.h> |
| 16 | +#include <zephyr/logging/log.h> |
| 17 | + |
9 | 18 | #include <zephyr/drivers/display.h> |
10 | 19 | #include <zephyr/drivers/gpio.h> |
11 | 20 | #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> |
| 21 | +#include <zephyr/drivers/rtc.h> |
| 22 | + |
18 | 23 | #include "user_interface/ui.h" |
| 24 | +#include "bluetooth/current_time_service.h" |
19 | 25 |
|
20 | | -LOG_MODULE_REGISTER(SmartWatch_OS, LOG_LEVEL_INF); |
| 26 | +LOG_MODULE_REGISTER(ZephyrWatch, LOG_LEVEL_INF); |
21 | 27 |
|
22 | 28 |
|
23 | 29 | int main(void) { |
| 30 | + int ret; |
| 31 | + |
| 32 | + // Initialize the RTC device. |
| 33 | + const struct device *rtc_dev = DEVICE_DT_GET(DT_NODELABEL(rtc)); |
| 34 | + if (!device_is_ready(rtc_dev)) { |
| 35 | + LOG_ERR("RTC device is not ready, exiting..."); |
| 36 | + return 0; |
| 37 | + } |
| 38 | + LOG_INF("RTC device is ready."); |
| 39 | + |
| 40 | + // struct rtc_time time = { |
| 41 | + // .tm_sec = 0, |
| 42 | + // .tm_min = 58, |
| 43 | + // .tm_hour = 0, |
| 44 | + // .tm_mday = 15, |
| 45 | + // .tm_mon = 5, |
| 46 | + // .tm_year = 2024, |
| 47 | + // .tm_wday = 4, |
| 48 | + // .tm_yday = 0, |
| 49 | + // .tm_isdst = 0, |
| 50 | + // .tm_nsec = 0, |
| 51 | + // }; |
| 52 | + |
| 53 | + // ret = rtc_set_time(rtc_dev, &time); |
| 54 | + // if (ret < 0) { |
| 55 | + // LOG_ERR("Failed to set time to RTC, exiting..."); |
| 56 | + // return 0; |
| 57 | + // } |
| 58 | + // LOG_INF("Time set to RTC."); |
| 59 | + |
| 60 | + // ret = rtc_get_time(rtc_dev, &time); |
| 61 | + // if (ret < 0) { |
| 62 | + // LOG_ERR("Failed to get time from RTC, exiting..."); |
| 63 | + // return 0; |
| 64 | + // } |
| 65 | + //LOG_INF("Current time: %d-%d-%d %d:%d:%d", time.tm_year, time.tm_mon, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec); |
24 | 66 |
|
25 | 67 | // Check if the display device is ready. |
26 | 68 | const struct device *display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display)); |
27 | 69 | if (!device_is_ready(display_dev)) { |
28 | 70 | LOG_ERR("Display device is not ready, exiting..."); |
29 | 71 | return 0; |
30 | 72 | } |
| 73 | + LOG_INF("Display device is ready."); |
31 | 74 |
|
32 | 75 | const struct pwm_dt_spec backlight = PWM_DT_SPEC_GET_BY_IDX(DT_NODELABEL(pwm_lcd0), 0); |
33 | 76 | if (!pwm_is_ready_dt(&backlight)) { |
34 | 77 | LOG_ERR("PWM device is not ready, exiting..."); |
35 | 78 | return 0; |
36 | 79 | } |
| 80 | + LOG_INF("PWM device is ready."); |
37 | 81 |
|
38 | 82 | // Initialize the PWM device. |
39 | | - int ret = pwm_set_dt(&backlight, 500, 250); |
| 83 | + ret = pwm_set_dt(&backlight, 500, 250); |
40 | 84 | if (ret < 0) { |
41 | 85 | LOG_ERR("Failed to set PWM pulse, exiting..."); |
42 | 86 | return 0; |
43 | 87 | } |
| 88 | + LOG_INF("PWM pulse for LCD backlight set."); |
44 | 89 |
|
45 | 90 | // Initialize the display device with initial GUI. |
46 | 91 | ui_init(); |
| 92 | + LOG_INF("UI initialized."); |
47 | 93 |
|
48 | 94 | lv_task_handler(); |
49 | 95 | display_blanking_off(display_dev); |
50 | 96 |
|
51 | 97 | while (1) { |
52 | 98 | lv_task_handler(); |
53 | | - k_usleep(10); |
| 99 | + k_sleep(K_USEC(10)); |
54 | 100 | } |
55 | 101 | } |
0 commit comments